Skip to content

Commit 6ee7f55

Browse files
committed
Improve clearing recent file list
1 parent b18387f commit 6ee7f55

File tree

4 files changed

+68
-44
lines changed

4 files changed

+68
-44
lines changed

src/mpc-hc/AppSettings.cpp

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,22 @@ CString CAppSettings::SelectedAudioRenderer() const
860860
return strResult;
861861
}
862862

863+
void CAppSettings::ClearRecentFiles() {
864+
MRU.RemoveAll();
865+
866+
for (int i = MRUDub.GetSize() - 1; i >= 0; i--) {
867+
MRUDub.Remove(i);
868+
}
869+
MRUDub.WriteList();
870+
871+
// Empty the Windows "Recent" jump list
872+
CComPtr<IApplicationDestinations> pDests;
873+
HRESULT hr = pDests.CoCreateInstance(CLSID_ApplicationDestinations, nullptr, CLSCTX_INPROC_SERVER);
874+
if (SUCCEEDED(hr)) {
875+
pDests->RemoveAllDestinations();
876+
}
877+
}
878+
863879
void CAppSettings::SaveSettings(bool write_full_history /* = false */)
864880
{
865881
CMPlayerCApp* pApp = AfxGetMyApp();
@@ -1276,19 +1292,39 @@ void CAppSettings::SaveSettings(bool write_full_history /* = false */)
12761292
MRU.SaveMediaHistory();
12771293
}
12781294

1279-
size_t maxsize = AfxGetAppSettings().fKeepHistory ? iRecentFilesNumber : 0;
1280-
CStringW section = L"PlaylistHistory";
1281-
auto timeToHash = LoadHistoryHashes(section, L"LastUpdated");
1295+
pApp->FlushProfile();
1296+
}
12821297

1283-
int entries = 0;
1284-
for (auto iter = timeToHash.rbegin(); iter != timeToHash.rend(); ++iter, ++entries) {
1285-
CStringW hash = iter->second;
1286-
if (entries >= maxsize) {
1287-
PurgeExpiredHash(section, hash);
1298+
void CAppSettings::PurgeMediaHistory(size_t maxsize) {
1299+
CStringW section = L"MediaHistory";
1300+
auto timeToHash = LoadHistoryHashes(section, L"LastUpdated");
1301+
size_t entries = timeToHash.size();
1302+
if (entries > maxsize) {
1303+
for (auto iter = timeToHash.rbegin(); iter != timeToHash.rend(); ++iter) {
1304+
if (entries > maxsize) {
1305+
PurgeExpiredHash(section, iter->second);
1306+
entries--;
1307+
} else {
1308+
break;
1309+
}
12881310
}
12891311
}
1312+
}
12901313

1291-
pApp->FlushProfile();
1314+
void CAppSettings::PurgePlaylistHistory(size_t maxsize) {
1315+
CStringW section = L"PlaylistHistory";
1316+
auto timeToHash = LoadHistoryHashes(section, L"LastUpdated");
1317+
size_t entries = timeToHash.size();
1318+
if (entries > maxsize) {
1319+
for (auto iter = timeToHash.rbegin(); iter != timeToHash.rend(); ++iter) {
1320+
if (entries > maxsize) {
1321+
PurgeExpiredHash(section, iter->second);
1322+
entries--;
1323+
} else {
1324+
break;
1325+
}
1326+
}
1327+
}
12921328
}
12931329

12941330
std::multimap<CStringW, CStringW> CAppSettings::LoadHistoryHashes(CStringW section, CStringW dateField) {
@@ -2807,6 +2843,7 @@ CStringW getRFEHash(RecentFileEntry &r) {
28072843
}
28082844
}
28092845

2846+
/*
28102847
void CAppSettings::CRecentFileListWithMoreInfo::Remove(size_t nIndex) {
28112848
if (nIndex >= 0 && nIndex < rfe_array.GetCount()) {
28122849
auto pApp = AfxGetMyApp();
@@ -2822,6 +2859,7 @@ void CAppSettings::CRecentFileListWithMoreInfo::Remove(size_t nIndex) {
28222859
current_rfe_hash.Empty();
28232860
}
28242861
}
2862+
*/
28252863

28262864
void CAppSettings::CRecentFileListWithMoreInfo::Add(LPCTSTR fn) {
28272865
RecentFileEntry r;
@@ -3232,6 +3270,9 @@ void CAppSettings::CRecentFileListWithMoreInfo::ReadMediaHistory() {
32323270
} else {
32333271
rfe_last_added = lastAddedStored;
32343272
}
3273+
3274+
// The playlist history size is not managed elsewhere
3275+
CAppSettings::PurgePlaylistHistory(maxsize);
32353276
}
32363277

32373278
void CAppSettings::CRecentFileListWithMoreInfo::WriteMediaHistoryAudioIndex(RecentFileEntry& r) {
@@ -3386,8 +3427,18 @@ void CAppSettings::CRecentFileListWithMoreInfo::SetSize(size_t nSize) {
33863427
m_maxSize = nSize;
33873428
if (rfe_array.GetCount() > m_maxSize) {
33883429
rfe_array.SetCount(m_maxSize);
3430+
PurgeMediaHistory(m_maxSize);
3431+
PurgePlaylistHistory(m_maxSize);
33893432
}
33903433
rfe_array.FreeExtra();
3434+
3435+
if (nSize == 0) {
3436+
current_rfe_hash.Empty();
3437+
}
3438+
}
3439+
3440+
void CAppSettings::CRecentFileListWithMoreInfo::RemoveAll() {
3441+
SetSize(0);
33913442
}
33923443

33933444
bool CAppSettings::IsVSFilterInstalled()

src/mpc-hc/AppSettings.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class CAppSettings
521521
return rfe_array[nIndex];
522522
}
523523

524-
void Remove(size_t nIndex);
524+
//void Remove(size_t nIndex);
525525
void Add(LPCTSTR fn);
526526
void Add(LPCTSTR fn, ULONGLONG llDVDGuid);
527527
void Add(RecentFileEntry r, bool current_open = false);
@@ -552,6 +552,7 @@ class CAppSettings
552552
bool LoadMediaHistoryEntry(CStringW hash, RecentFileEntry& r);
553553
void MigrateLegacyHistory();
554554
void SetSize(size_t nSize);
555+
void RemoveAll();
555556
};
556557

557558
public:
@@ -1014,8 +1015,11 @@ class CAppSettings
10141015
CAppSettings& operator = (const CAppSettings&) = delete;
10151016

10161017
void SaveSettings(bool write_full_history = false);
1018+
void ClearRecentFiles();
1019+
static void PurgeMediaHistory(size_t maxsize = 0);
1020+
static void PurgePlaylistHistory(size_t maxsize = 0);
10171021
static std::multimap<CStringW, CStringW> LoadHistoryHashes(CStringW section, CStringW dateField);
1018-
static void PurgeExpiredHash(CStringW section, CStringW hash);
1022+
static void PurgeExpiredHash(CStringW section, CStringW hash);
10191023
void LoadSettings();
10201024
void SaveExternalFilters() {
10211025
if (bInitialized) {

src/mpc-hc/MainFrm.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10587,24 +10587,7 @@ void CMainFrame::OnRecentFileClear()
1058710587
}
1058810588

1058910589
CAppSettings& s = AfxGetAppSettings();
10590-
10591-
// Empty MPC-HC's recent menu (iterating reverse because the indexes change)
10592-
for (int i = s.MRU.GetSize() - 1; i >= 0; i--) {
10593-
s.MRU.Remove(i);
10594-
}
10595-
for (int i = s.MRUDub.GetSize() - 1; i >= 0; i--) {
10596-
s.MRUDub.Remove(i);
10597-
}
10598-
s.MRUDub.WriteList();
10599-
10600-
// Empty the "Recent" jump list
10601-
CComPtr<IApplicationDestinations> pDests;
10602-
HRESULT hr = pDests.CoCreateInstance(CLSID_ApplicationDestinations, nullptr, CLSCTX_INPROC_SERVER);
10603-
if (SUCCEEDED(hr)) {
10604-
pDests->RemoveAllDestinations();
10605-
}
10606-
10607-
// Remove the saved positions in media
10590+
s.ClearRecentFiles();
1060810591
}
1060910592

1061010593
void CMainFrame::OnUpdateRecentFileClear(CCmdUI* pCmdUI)

src/mpc-hc/PPagePlayer.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,7 @@ BOOL CPPagePlayer::OnApply()
142142
s.bEnableCoverArt = !!m_bEnableCoverArt;
143143

144144
if (!m_fKeepHistory) {
145-
// Empty MPC-HC's recent menu (iterating reverse because the indexes change)
146-
for (int i = s.MRU.GetSize() - 1; i >= 0; i--) {
147-
s.MRU.Remove(i);
148-
}
149-
for (int i = s.MRUDub.GetSize() - 1; i >= 0; i--) {
150-
s.MRUDub.Remove(i);
151-
}
152-
s.MRUDub.WriteList();
153-
154-
// Empty the "Recent" jump list
155-
CComPtr<IApplicationDestinations> pDests;
156-
HRESULT hr = pDests.CoCreateInstance(CLSID_ApplicationDestinations, nullptr, CLSCTX_INPROC_SERVER);
157-
if (SUCCEEDED(hr)) {
158-
pDests->RemoveAllDestinations();
159-
}
145+
s.ClearRecentFiles();
160146

161147
// Ensure no new items are added in Windows recent menu and in the "Recent" jump list
162148
s.fileAssoc.SetNoRecentDocs(true, true);

0 commit comments

Comments
 (0)