diff options
author | kinddragon <kinddragon@users.sourceforge.net> | 2010-05-01 22:59:00 +0400 |
---|---|---|
committer | kinddragon <kinddragon@users.sourceforge.net> | 2010-05-01 22:59:00 +0400 |
commit | 54e9d9b9b122b78647d514b742e99c6cfd3b3e11 (patch) | |
tree | bd6be129d1bb24db171f845ac523fc55d1b1dec3 | |
parent | c9a65fbbbdc38f9938e3f13e7f15e9735278d454 (diff) |
Problem with auto-loading subtitles fixed
This commit fixes ticket #456
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1825 10f7b99b-c216-0410-bff0-8a66a9350fd8
-rw-r--r-- | src/apps/mplayerc/MainFrm.cpp | 72 | ||||
-rw-r--r-- | src/apps/mplayerc/PlayerPlaylistBar.cpp | 113 | ||||
-rw-r--r-- | src/apps/mplayerc/PlayerPlaylistBar.h | 3 | ||||
-rw-r--r-- | src/apps/mplayerc/Playlist.cpp | 83 | ||||
-rw-r--r-- | src/apps/mplayerc/Playlist.h | 1 | ||||
-rw-r--r-- | src/apps/mplayerc/WebClientSocket.cpp | 4 | ||||
-rw-r--r-- | src/subtitles/STS.cpp | 5 |
7 files changed, 155 insertions, 126 deletions
diff --git a/src/apps/mplayerc/MainFrm.cpp b/src/apps/mplayerc/MainFrm.cpp index adaa4e8c5..bafe3aab5 100644 --- a/src/apps/mplayerc/MainFrm.cpp +++ b/src/apps/mplayerc/MainFrm.cpp @@ -4232,7 +4232,7 @@ void CMainFrame::OnDropFiles(HDROP hDropInfo) void CMainFrame::OnFileSaveAs()
{
- CString ext, in = m_wndPlaylistBar.GetCur(), out = in;
+ CString ext, in = m_wndPlaylistBar.GetCurFileName(), out = in;
if(out.Find(_T("://")) < 0)
{
@@ -4271,7 +4271,7 @@ void CMainFrame::OnUpdateFileSaveAs(CCmdUI* pCmdUI) return;
}
- CString fn = m_wndPlaylistBar.GetCur();
+ CString fn = m_wndPlaylistBar.GetCurFileName();
CString ext = fn.Mid(fn.ReverseFind('.')+1).MakeLower();
if(fn.Find(_T("://")) >= 0)
@@ -4764,13 +4764,13 @@ void CMainFrame::SaveThumbnails(LPCTSTR fn) DVD_HMSF_TIMECODE hmsf = RT2HMSF(rtDur, 25);
- CPath path(m_wndPlaylistBar.GetCur());
+ CPath path(m_wndPlaylistBar.GetCurFileName());
path.StripPath();
CStringW fn = (LPCTSTR)path;
CStringW fs;
WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile(m_wndPlaylistBar.GetCur(), &wfd);
+ HANDLE hFind = FindFirstFile(m_wndPlaylistBar.GetCurFileName(), &wfd);
if(hFind != INVALID_HANDLE_VALUE)
{
FindClose(hFind);
@@ -4887,7 +4887,7 @@ void CMainFrame::OnFileSaveImage() CStringW prefix = _T("snapshot");
if(GetPlaybackMode() == PM_FILE)
{
- CPath path(m_wndPlaylistBar.GetCur());
+ CPath path(m_wndPlaylistBar.GetCurFileName());
path.StripPath();
prefix.Format(_T("%s_snapshot_%s"), path, GetVidPos());
}
@@ -4934,7 +4934,7 @@ void CMainFrame::OnFileSaveImageAuto() CStringW prefix = _T("snapshot");
if(GetPlaybackMode() == PM_FILE)
{
- CPath path(m_wndPlaylistBar.GetCur());
+ CPath path(m_wndPlaylistBar.GetCurFileName());
path.StripPath();
prefix.Format(_T("%s_snapshot_%s"), path, GetVidPos());
}
@@ -4968,7 +4968,7 @@ void CMainFrame::OnFileSaveThumbnails() CStringW prefix = _T("thumbs");
if(GetPlaybackMode() == PM_FILE)
{
- CPath path(m_wndPlaylistBar.GetCur());
+ CPath path(m_wndPlaylistBar.GetCurFileName());
path.StripPath();
prefix.Format(_T("%s_thumbs"), path);
}
@@ -5071,7 +5071,7 @@ void CMainFrame::OnFileSavesubtitle() if(OpenFileData* p = dynamic_cast<OpenFileData*>(pOMD))
{
// HACK: get the file name from the current playlist item
- suggestedFileName = m_wndPlaylistBar.GetCur();
+ suggestedFileName = m_wndPlaylistBar.GetCurFileName();
suggestedFileName = suggestedFileName.Left(suggestedFileName.ReverseFind('.')); // exclude the extension, it will be auto completed
}
@@ -5161,7 +5161,7 @@ void CMainFrame::OnUpdateFileISDBUpload(CCmdUI *pCmdUI) void CMainFrame::OnFileISDBDownload()
{
filehash fh;
- if(!::hash((CString)m_wndPlaylistBar.GetCur(), fh))
+ if(!::hash((CString)m_wndPlaylistBar.GetCurFileName(), fh))
{
MessageBeep(-1);
return;
@@ -5278,7 +5278,7 @@ void CMainFrame::OnUpdateFileISDBDownload(CCmdUI *pCmdUI) void CMainFrame::OnFileProperties()
{
- CPPageFileInfoSheet m_fileinfo(m_wndPlaylistBar.GetCur(), this, GetModalParent());
+ CPPageFileInfoSheet m_fileinfo(m_wndPlaylistBar.GetCurFileName(), this, GetModalParent());
m_fileinfo.DoModal();
}
@@ -8013,7 +8013,7 @@ void CMainFrame::OnFavoritesAdd() if(GetPlaybackMode() == PM_FILE)
{
- CString fn = m_wndPlaylistBar.GetCur();
+ CString fn = m_wndPlaylistBar.GetCurFileName();
if(fn.IsEmpty()) return;
CString desc = fn;
@@ -8119,7 +8119,7 @@ void CMainFrame::OnFavoritesQuickAddFavorite() if(GetPlaybackMode() == PM_FILE)
{
- CString fn = m_wndPlaylistBar.GetCur();
+ CString fn = m_wndPlaylistBar.GetCurFileName();
if(fn.IsEmpty()) return;
CString desc = fn;
@@ -10356,7 +10356,7 @@ void CMainFrame::OpenSetupStatusBar() if(GetPlaybackMode() == PM_FILE)
{
- CString fn = m_wndPlaylistBar.GetCur();
+ CString fn = m_wndPlaylistBar.GetCurFileName();
CString ext = fn.Mid(fn.ReverseFind('.')+1);
hIcon = LoadIcon(ext, true);
}
@@ -10530,7 +10530,7 @@ bool CMainFrame::OpenMediaPrivate(CAutoPtr<OpenMediaData> pOMD) while ( pos != NULL )
{
CString path = pOFD->fns.GetNext( pos );
- TRACE("--> CMainFrame::OpenMediaPrivate - pOFD->fns[%d]: %ws\n", index, path.GetString()); // %ws - wide character string always
+ TRACE(_T("--> CMainFrame::OpenMediaPrivate - pOFD->fns[%d]: %ws\n"), index, path.GetString()); // %ws - wide character string always
index++;
}
}
@@ -13600,29 +13600,29 @@ void CMainFrame::SendNowPlayingToApi() DVD_HMSF_TIMECODE tcDur = RT2HMSF(rtDur);
lDuration = tcDur.bHours*60*60 + tcDur.bMinutes*60 + tcDur.bSeconds;
}
- /* CString label = !pli.m_label.IsEmpty() ? pli.m_label : pli.m_fns.GetHead();
+ /*CString label = !pli.m_label.IsEmpty() ? pli.m_label : pli.m_fns.GetHead();
- if(GetPlaybackMode() == PM_FILE)
- {
- CString fn = label;
- if(fn.Find(_T("://")) >= 0) {int i = fn.Find('?'); if(i >= 0) fn = fn.Left(i);}
- CPath path(fn);
- path.StripPath();
- path.MakePretty();
- path.RemoveExtension();
- title = (LPCTSTR)path;
- author.Empty();
- }
- else if(GetPlaybackMode() == PM_CAPTURE)
- {
- title = label != pli.m_fns.GetHead() ? label : _T("Live");
- author.Empty();
- }
- else if(GetPlaybackMode() == PM_DVD)
- {
- title = _T("DVD");
- author.Empty();
- }*/
+ if(GetPlaybackMode() == PM_FILE)
+ {
+ CString fn = label;
+ if(fn.Find(_T("://")) >= 0) {int i = fn.Find('?'); if(i >= 0) fn = fn.Left(i);}
+ CPath path(fn);
+ path.StripPath();
+ path.MakePretty();
+ path.RemoveExtension();
+ title = (LPCTSTR)path;
+ author.Empty();
+ }
+ else if(GetPlaybackMode() == PM_CAPTURE)
+ {
+ title = label != pli.m_fns.GetHead() ? label : _T("Live");
+ author.Empty();
+ }
+ else if(GetPlaybackMode() == PM_DVD)
+ {
+ title = _T("DVD");
+ author.Empty();
+ }*/
}
title.Replace(L"|", L"\\|");
diff --git a/src/apps/mplayerc/PlayerPlaylistBar.cpp b/src/apps/mplayerc/PlayerPlaylistBar.cpp index a46ddd64a..48aa713e4 100644 --- a/src/apps/mplayerc/PlayerPlaylistBar.cpp +++ b/src/apps/mplayerc/PlayerPlaylistBar.cpp @@ -97,17 +97,6 @@ BOOL CPlayerPlaylistBar::PreTranslateMessage(MSG* pMsg) return CSizingControlBarG::PreTranslateMessage(pMsg);
}
-bool FindFileInList(CAtlList<CString>& sl, CString fn)
-{
- bool fFound = false;
- POSITION pos = sl.GetHeadPosition();
- while(pos && !fFound)
- {
- if(!sl.GetNext(pos).CompareNoCase(fn)) fFound = true;
- }
- return(fFound);
-}
-
void CPlayerPlaylistBar::AddItem(CString fn, CAtlList<CString>* subs)
{
CAtlList<CString> sl;
@@ -136,65 +125,7 @@ void CPlayerPlaylistBar::AddItem(CAtlList<CString>& fns, CAtlList<CString>* subs }
}
- if(pli.m_fns.IsEmpty()) return;
-
- CString fn = pli.m_fns.GetHead();
-
- if(AfxGetAppSettings().fAutoloadAudio && fn.Find(_T("://")) < 0)
- {
- int i = fn.ReverseFind('.');
- if(i > 0)
- {
- CMediaFormats& mf = AfxGetAppSettings().Formats;
-
- CString ext = fn.Mid(i+1).MakeLower();
-
- if(!mf.FindExt(ext, true))
- {
- CString path = fn;
- path.Replace('/', '\\');
- path = path.Left(path.ReverseFind('\\')+1);
-
- WIN32_FIND_DATA fd = {0};
- HANDLE hFind = FindFirstFile(fn.Left(i) + _T("*.*"), &fd);
- if(hFind != INVALID_HANDLE_VALUE)
- {
- do
- {
- if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue;
-
- CString fullpath = path + fd.cFileName;
- CString ext2 = fullpath.Mid(fullpath.ReverseFind('.')+1).MakeLower();
- if(!FindFileInList(pli.m_fns, fullpath) && ext != ext2
- && mf.FindExt(ext2, true) && mf.IsUsingEngine(fullpath, DirectShow))
- {
- pli.m_fns.AddTail(fullpath);
- }
- }
- while(FindNextFile(hFind, &fd));
-
- FindClose(hFind);
- }
- }
- }
- }
-
- if(AfxGetAppSettings().fAutoloadSubtitles)
- {
- CAtlArray<CString> paths;
- paths.Add(_T("."));
- paths.Add(_T(".\\subtitles"));
- paths.Add(_T("c:\\subtitles"));
-
- CAtlArray<SubFile> ret;
- GetSubFileNames(fn, paths, ret);
-
- for(int i = 0; i < ret.GetCount(); i++)
- {
- if(!FindFileInList(pli.m_subs, ret[i].fn))
- pli.m_subs.AddTail(ret[i].fn);
- }
- }
+ pli.AutoLoadFiles();
m_pl.AddTail(pli);
}
@@ -648,11 +579,18 @@ bool CPlayerPlaylistBar::GetCur(CPlaylistItem& pli) return(true);
}
-CString CPlayerPlaylistBar::GetCur()
+CPlaylistItem* CPlayerPlaylistBar::GetCur()
+{
+ if(!m_pl.GetPos()) return NULL;
+ return &m_pl.GetAt(m_pl.GetPos());
+}
+
+CString CPlayerPlaylistBar::GetCurFileName()
{
CString fn;
- CPlaylistItem pli;
- if(GetCur(pli) && !pli.m_fns.IsEmpty()) fn = pli.m_fns.GetHead();
+ CPlaylistItem* pli = GetCur();
+ if(pli && !pli->m_fns.IsEmpty())
+ fn = pli->m_fns.GetHead();
return(fn);
}
@@ -730,32 +668,35 @@ void CPlayerPlaylistBar::SetCurTime(REFERENCE_TIME rt) OpenMediaData* CPlayerPlaylistBar::GetCurOMD(REFERENCE_TIME rtStart)
{
- CPlaylistItem pli;
- if(!GetCur(pli)) return NULL;
+ CPlaylistItem* pli = GetCur();
+ if(pli == NULL)
+ return NULL;
- CString fn = CString(pli.m_fns.GetHead()).MakeLower();
+ pli->AutoLoadFiles();
+
+ CString fn = CString(pli->m_fns.GetHead()).MakeLower();
if(fn.Find(_T("video_ts.ifo")) >= 0
|| fn.Find(_T(".ratdvd")) >= 0)
{
if(OpenDVDData* p = DNew OpenDVDData())
{
- p->path = pli.m_fns.GetHead();
- p->subs.AddTailList(&pli.m_subs);
+ p->path = pli->m_fns.GetHead();
+ p->subs.AddTailList(&pli->m_subs);
return p;
}
}
- if(pli.m_type == CPlaylistItem::device)
+ if(pli->m_type == CPlaylistItem::device)
{
if(OpenDeviceData* p = DNew OpenDeviceData())
{
- POSITION pos = pli.m_fns.GetHeadPosition();
+ POSITION pos = pli->m_fns.GetHeadPosition();
for(int i = 0; i < countof(p->DisplayName) && pos; i++)
- p->DisplayName[i] = pli.m_fns.GetNext(pos);
- p->vinput = pli.m_vinput;
- p->vchannel = pli.m_vchannel;
- p->ainput = pli.m_ainput;
+ p->DisplayName[i] = pli->m_fns.GetNext(pos);
+ p->vinput = pli->m_vinput;
+ p->vchannel = pli->m_vchannel;
+ p->ainput = pli->m_ainput;
return p;
}
}
@@ -763,8 +704,8 @@ OpenMediaData* CPlayerPlaylistBar::GetCurOMD(REFERENCE_TIME rtStart) {
if(OpenFileData* p = DNew OpenFileData())
{
- p->fns.AddTailList(&pli.m_fns);
- p->subs.AddTailList(&pli.m_subs);
+ p->fns.AddTailList(&pli->m_fns);
+ p->subs.AddTailList(&pli->m_subs);
p->rtStart = rtStart;
return p;
}
diff --git a/src/apps/mplayerc/PlayerPlaylistBar.h b/src/apps/mplayerc/PlayerPlaylistBar.h index efe8e50e8..7e4b61e4e 100644 --- a/src/apps/mplayerc/PlayerPlaylistBar.h +++ b/src/apps/mplayerc/PlayerPlaylistBar.h @@ -80,7 +80,8 @@ public: void SetSelIdx(int i);
bool IsAtEnd();
bool GetCur(CPlaylistItem& pli);
- CString GetCur();
+ CPlaylistItem* GetCur();
+ CString GetCurFileName();
void SetNext();
void SetPrev();
void SetFirstSelected();
diff --git a/src/apps/mplayerc/Playlist.cpp b/src/apps/mplayerc/Playlist.cpp index 57900f5b8..71b3ea110 100644 --- a/src/apps/mplayerc/Playlist.cpp +++ b/src/apps/mplayerc/Playlist.cpp @@ -128,6 +128,89 @@ CString CPlaylistItem::GetLabel(int i) return str;
}
+bool FindFileInList(CAtlList<CString>& sl, CString fn)
+{
+ bool fFound = false;
+ POSITION pos = sl.GetHeadPosition();
+ while(pos && !fFound)
+ {
+ if(!sl.GetNext(pos).CompareNoCase(fn)) fFound = true;
+ }
+ return(fFound);
+}
+
+void CPlaylistItem::AutoLoadFiles()
+{
+ if(m_fns.IsEmpty()) return;
+
+ CString fn = m_fns.GetHead();
+
+ if(AfxGetAppSettings().fAutoloadAudio && fn.Find(_T("://")) < 0)
+ {
+ int i = fn.ReverseFind('.');
+ if(i > 0)
+ {
+ CMediaFormats& mf = AfxGetAppSettings().Formats;
+
+ CString ext = fn.Mid(i+1).MakeLower();
+
+ if(!mf.FindExt(ext, true))
+ {
+ CString path = fn;
+ path.Replace('/', '\\');
+ path = path.Left(path.ReverseFind('\\')+1);
+
+ WIN32_FIND_DATA fd = {0};
+ HANDLE hFind = FindFirstFile(fn.Left(i) + _T("*.*"), &fd);
+ if(hFind != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue;
+
+ CString fullpath = path + fd.cFileName;
+ CString ext2 = fullpath.Mid(fullpath.ReverseFind('.')+1).MakeLower();
+ if(!FindFileInList(m_fns, fullpath) && ext != ext2
+ && mf.FindExt(ext2, true) && mf.IsUsingEngine(fullpath, DirectShow))
+ {
+ m_fns.AddTail(fullpath);
+ }
+ }
+ while(FindNextFile(hFind, &fd));
+
+ FindClose(hFind);
+ }
+ }
+ }
+ }
+
+ if(AfxGetAppSettings().fAutoloadSubtitles)
+ {
+ CAtlArray<CString> paths;
+ paths.Add(_T("."));
+ paths.Add(_T(".\\subtitles"));
+ paths.Add(_T("c:\\subtitles"));
+
+ CString dir = fn;
+ dir.Replace('\\', '/');
+ int l = fn.GetLength(), l2 = l;
+ l2 = dir.ReverseFind('.');
+ l = dir.ReverseFind('/') + 1;
+ if(l2 < l) l2 = l;
+ CString title = dir.Mid(l, l2-l);
+ paths.Add(title.GetString());
+
+ CAtlArray<SubFile> ret;
+ GetSubFileNames(fn, paths, ret);
+
+ for(int i = 0; i < ret.GetCount(); i++)
+ {
+ if(!FindFileInList(m_subs, ret[i].fn))
+ m_subs.AddTail(ret[i].fn);
+ }
+ }
+}
+
//
// CPlaylist
//
diff --git a/src/apps/mplayerc/Playlist.h b/src/apps/mplayerc/Playlist.h index cbe9a0b6d..81617b8e2 100644 --- a/src/apps/mplayerc/Playlist.h +++ b/src/apps/mplayerc/Playlist.h @@ -51,6 +51,7 @@ public: CPlaylistItem& operator = (const CPlaylistItem& pli);
POSITION FindFile(LPCTSTR path);
+ void AutoLoadFiles();
CString GetLabel(int i = 0);
};
diff --git a/src/apps/mplayerc/WebClientSocket.cpp b/src/apps/mplayerc/WebClientSocket.cpp index 005d81ce1..dcbb3bb8a 100644 --- a/src/apps/mplayerc/WebClientSocket.cpp +++ b/src/apps/mplayerc/WebClientSocket.cpp @@ -471,7 +471,7 @@ bool CWebClientSocket::OnBrowser(CStringA& hdr, CStringA& body, CStringA& mime) }
else
{
- path = m_pMainFrame->m_wndPlaylistBar.GetCur();
+ path = m_pMainFrame->m_wndPlaylistBar.GetCurFileName();
if(CFileGetStatus(path, fs) && !(fs.m_attribute&CFile::directory))
{
@@ -604,7 +604,7 @@ bool CWebClientSocket::OnBrowser(CStringA& hdr, CStringA& body, CStringA& mime) bool CWebClientSocket::OnControls(CStringA& hdr, CStringA& body, CStringA& mime)
{
- CString path = m_pMainFrame->m_wndPlaylistBar.GetCur();
+ CString path = m_pMainFrame->m_wndPlaylistBar.GetCurFileName();
CString dir;
if(!path.IsEmpty())
diff --git a/src/subtitles/STS.cpp b/src/subtitles/STS.cpp index 4f0e1e949..775ca7a08 100644 --- a/src/subtitles/STS.cpp +++ b/src/subtitles/STS.cpp @@ -2647,7 +2647,10 @@ bool CSimpleTextSubtitle::Open(CString fn, int CharSet, CString name) {
name = fn.Left(fn.ReverseFind('.'));
name = name.Mid(name.ReverseFind('/')+1);
- name = name.Mid(name.ReverseFind('.')+1);
+ int len = name.GetLength();
+ int pos = name.ReverseFind('.') + 1;
+ if ((len - pos) > 1)
+ name = name.Mid(pos);
}
return(Open(&f, CharSet, name));
|