Skip to content

Commit

Permalink
Some improvements for file history
Browse files Browse the repository at this point in the history
  • Loading branch information
clsid2 committed Feb 22, 2024
1 parent 130b638 commit b18387f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
21 changes: 9 additions & 12 deletions src/mpc-hc/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,12 +1272,8 @@ void CAppSettings::SaveSettings(bool write_full_history /* = false */)
pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_MOUSE_LEFTUP_DELAY, iMouseLeftUpDelay);
pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_CAPTURE_DEINTERLACE, bCaptureDeinterlace);

if (fKeepHistory) {
if (write_full_history) {
MRU.SaveMediaHistory();
} else {
MRU.WriteCurrentEntry();
}
if (fKeepHistory && write_full_history) {
MRU.SaveMediaHistory();
}

size_t maxsize = AfxGetAppSettings().fKeepHistory ? iRecentFilesNumber : 0;
Expand Down Expand Up @@ -3282,9 +3278,11 @@ void CAppSettings::CRecentFileListWithMoreInfo::WriteMediaHistoryEntry(RecentFil
CStringW subSection, t;
subSection.Format(L"%s\\%s", m_section, static_cast<LPCWSTR>(r.hash));

bool isNewEntry = pApp->GetProfileStringW(subSection, L"Filename", L"").IsEmpty();

pApp->WriteProfileStringW(subSection, L"Filename", r.fns.GetHead());
CString storedFilename = pApp->GetProfileStringW(subSection, L"Filename", L"");
bool isNewEntry = storedFilename.IsEmpty();
if (isNewEntry || storedFilename != r.fns.GetHead()) {
pApp->WriteProfileStringW(subSection, L"Filename", r.fns.GetHead());
}

if (r.fns.GetCount() > 1) {
int k = 2;
Expand Down Expand Up @@ -3356,13 +3354,12 @@ void CAppSettings::CRecentFileListWithMoreInfo::WriteMediaHistoryEntry(RecentFil
auto now = std::chrono::system_clock::now();
auto nowISO = date::format<wchar_t>(L"%FT%TZ", date::floor<std::chrono::milliseconds>(now));
r.lastOpened = CStringW(nowISO.c_str());
pApp->WriteProfileStringW(subSection, L"LastOpened", r.lastOpened);
if (isNewEntry) {
long lastAddedLong = std::chrono::time_point_cast<std::chrono::seconds>(now).time_since_epoch().count();
rfe_last_added = (int)lastAddedLong;
rfe_last_added = (int)std::chrono::time_point_cast<std::chrono::seconds>(now).time_since_epoch().count();
pApp->WriteProfileInt(m_section, L"LastAdded", rfe_last_added);
}
}
pApp->WriteProfileStringW(subSection, L"LastOpened", r.lastOpened);
}

void CAppSettings::CRecentFileListWithMoreInfo::SaveMediaHistory() {
Expand Down
55 changes: 40 additions & 15 deletions src/mpc-hc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,6 @@ LRESULT CMainFrame::OnGraphNotify(WPARAM wParam, LPARAM lParam)
}
break;
case EC_DVD_CURRENT_HMSF_TIME: {
// Casimir666 : Save current position in the chapter
s.MRU.UpdateCurrentDVDTimecode((DVD_HMSF_TIMECODE*)&evParam1);
}
break;
Expand Down Expand Up @@ -18125,26 +18124,43 @@ void CMainFrame::CloseMedia(bool bNextIsQueued/* = false*/)
ASSERT(!m_bSettingUpMenus);
}

auto& s = AfxGetAppSettings();
bool savehistory = false;
if (GetLoadState() == MLS::LOADED) {
// abort sub search
m_pSubtitlesProviders->Abort(SubtitlesThreadType(STT_SEARCH | STT_DOWNLOAD));
m_wndSubtitlesDownloadDialog.DoClear();

// save playback position
auto& s = AfxGetAppSettings();
if (m_bRememberFilePos && !m_fEndOfStream && m_dwReloadPos == 0 && m_pMS) {
REFERENCE_TIME rtNow = 0;
m_pMS->GetCurrentPosition(&rtNow);
if (rtNow > 0) {
REFERENCE_TIME rtDur = 0;
m_pMS->GetDuration(&rtDur);
if (rtNow >= rtDur || rtDur - rtNow < 50000000LL) { // at end of file
rtNow = 0;
if (s.fKeepHistory) {
if (m_bRememberFilePos && !m_fEndOfStream && m_dwReloadPos == 0 && m_pMS) {
REFERENCE_TIME rtNow = 0;
m_pMS->GetCurrentPosition(&rtNow);
if (rtNow > 0) {
REFERENCE_TIME rtDur = 0;
m_pMS->GetDuration(&rtDur);
if (rtNow >= rtDur || rtDur - rtNow < 50000000LL) { // at end of file
rtNow = 0;
}
}
s.MRU.UpdateCurrentFilePosition(rtNow, true);
} else if (GetPlaybackMode() == PM_DVD && m_pDVDI) {
DVD_DOMAIN DVDDomain;
if (SUCCEEDED(m_pDVDI->GetCurrentDomain(&DVDDomain))) {
if (DVDDomain == DVD_DOMAIN_Title) {
DVD_PLAYBACK_LOCATION2 Location2;
if (SUCCEEDED(m_pDVDI->GetCurrentLocation(&Location2))) {
DVD_POSITION dvdPosition = s.MRU.GetCurrentDVDPosition();
if (dvdPosition.llDVDGuid) {
dvdPosition.lTitle = Location2.TitleNum;
dvdPosition.timecode = Location2.TimeCode;
}
}
}
}
}
s.MRU.UpdateCurrentFilePosition(rtNow, true);
}

// abort sub search
m_pSubtitlesProviders->Abort(SubtitlesThreadType(STT_SEARCH | STT_DOWNLOAD));
m_wndSubtitlesDownloadDialog.DoClear();

// save external subtitle
if (g_bExternalSubtitle &&
m_pCurrentSubInput.pSubStream && m_pCurrentSubInput.pSubStream->GetPath().IsEmpty()) {
Expand All @@ -18162,6 +18178,10 @@ void CMainFrame::CloseMedia(bool bNextIsQueued/* = false*/)
SubtitlesSave(dir, true);
}
}

if (s.fKeepHistory) {
savehistory = true;
}
}

// delay showing auto-hidden controls if new media is queued
Expand Down Expand Up @@ -18276,6 +18296,11 @@ void CMainFrame::CloseMedia(bool bNextIsQueued/* = false*/)
// graph is destroyed, update stuff
OnFilePostClosemedia(bNextIsQueued);

if (savehistory) {
s.MRU.WriteCurrentEntry();
}
s.MRU.current_rfe_hash.Empty();

TRACE(_T("Close media completed\n"));
}

Expand Down

0 comments on commit b18387f

Please sign in to comment.