2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
29 _T("srt"), _T("sub"), _T("smi"), _T("psb"),
30 _T("ssa"), _T("ass"), _T("idx"), _T("usf"),
31 _T("xss"), _T("txt"), _T("ssf"), _T("rt"), _T("sup")
34 static TCHAR
* ext
[2][countof(exttypestr
)] =
37 _T(".srt"), _T(".sub"), _T(".smi"), _T(".psb"),
38 _T(".ssa"), _T(".ass"), _T(".idx"), _T(".usf"),
39 _T(".xss"), _T(".txt"), _T(".ssf"), _T(".rt"), _T(".sup")
42 _T(".*.srt"), _T(".*.sub"), _T(".*.smi"), _T(".*.psb"),
43 _T(".*.ssa"), _T(".*.ass"), _T(".*.dummyidx"), _T(".*.usf"),
44 _T(".*.xss"), _T(".*.txt"), _T(".*.ssf"), _T(".*.rt"), _T(".*.sup")
48 #define WEBSUBEXT _T(".wse")
50 static int SubFileCompare(const void* elem1
, const void* elem2
)
52 return(((SubFile
*)elem1
)->fn
.CompareNoCase(((SubFile
*)elem2
)->fn
));
55 void GetSubFileNames(CString fn
, CAtlArray
<CString
>& paths
, CAtlArray
<SubFile
>& ret
)
59 int extlistnum
= countof(ext
);
60 int extsubnum
= countof(ext
[0]);
62 fn
.Replace('\\', '/');
66 // int i = fn.Find(_T("://"));
67 int i
= fn
.Find(_T("http://"));
68 if(i
> 0) {fn
= _T("http") + fn
.Mid(i
); fWeb
= true;}
71 int l
= fn
.GetLength(), l2
= l
;
72 l2
= fn
.ReverseFind('.');
73 l
= fn
.ReverseFind('/') + 1;
76 CString orgpath
= fn
.Left(l
);
77 CString title
= fn
.Mid(l
, l2
-l
);
78 CString filename
= title
+ _T(".nooneexpectsthespanishinquisition");
82 // struct _tfinddata_t file, file2;
83 // long hFile, hFile2 = 0;
85 WIN32_FIND_DATA wfd
, wfd2
;
88 for(int k
= 0; k
< paths
.GetCount(); k
++)
90 CString path
= paths
[k
];
91 path
.Replace('\\', '/');
94 if(l
> 0 && path
[l
-1] != '/') path
+= '/';
96 if(path
.Find(':') == -1 && path
.Find(_T("\\\\")) != 0) path
= orgpath
+ path
;
98 path
.Replace(_T("/./"), _T("/"));
99 path
.Replace('/', '\\');
101 // CAtlList<CString> sl;
105 if((hFile
= FindFirstFile(path
+ title
+ _T("*"), &wfd
)) != INVALID_HANDLE_VALUE
)
109 if(filename
.CompareNoCase(wfd
.cFileName
) != 0)
112 // sl.AddTail(path + file.name);
115 while(FindNextFile(hFile
, &wfd
));
120 // TODO: use 'sl' in the next step to find files (already a nice speedup as it is now...)
123 for(int j
= 0; j
< extlistnum
; j
++)
125 for(int i
= 0; i
< extsubnum
; i
++)
127 if((hFile
= FindFirstFile(path
+ title
+ ext
[j
][i
], &wfd
)) != INVALID_HANDLE_VALUE
)
131 CString fn
= path
+ wfd
.cFileName
;
133 hFile2
= INVALID_HANDLE_VALUE
;
135 if(j
== 0 || (hFile2
= FindFirstFile(fn
.Left(fn
.ReverseFind('.')) + _T(".avi"), &wfd2
)) == INVALID_HANDLE_VALUE
)
142 if(hFile2
!= INVALID_HANDLE_VALUE
)
147 while(FindNextFile(hFile
, &wfd
));
157 CWebTextFile wtf
; // :)
158 if(wtf
.Open(orgpath
+ title
+ WEBSUBEXT
))
161 while(wtf
.ReadString(fn
) && fn
.Find(_T("://")) >= 0)
170 // sort files, this way the user can define the order (movie.00.English.srt, movie.01.Hungarian.srt, etc)
172 qsort(ret
.GetData(), ret
.GetCount(), sizeof(SubFile
), SubFileCompare
);