4
4
#include " Helpers.h"
5
5
#include " DirectoryWatcher.h"
6
6
#include " Shlwapi.h"
7
+ #include < sstream>
7
8
8
9
// /////////////////////////////////////////////////////////////////////////////////
9
10
// Helpers
@@ -60,7 +61,7 @@ static bool IsNoLogicalStrCmpSetInRegistryHive(HKEY hKeyRoot) {
60
61
static bool UseLogicalStringCompare () {
61
62
if (!s_bUseLogicalStringCompareValid) {
62
63
s_bUseLogicalStringCompareValid = true ;
63
- s_bUseLogicalStringCompare = !(IsNoLogicalStrCmpSetInRegistryHive (HKEY_LOCAL_MACHINE) ||
64
+ s_bUseLogicalStringCompare = !(IsNoLogicalStrCmpSetInRegistryHive (HKEY_LOCAL_MACHINE) ||
64
65
IsNoLogicalStrCmpSetInRegistryHive (HKEY_CURRENT_USER));
65
66
}
66
67
return s_bUseLogicalStringCompare;
@@ -123,19 +124,12 @@ void CFileDesc::SetModificationDate(const FILETIME& lastModDate) {
123
124
// Public interface
124
125
// /////////////////////////////////////////////////////////////////////////////////
125
126
126
- // image file types supported internally (there are additional endings for RAW and WIC - these come from INI file)
127
- // NOTE: when adding more supported filetypes, update installer to add another extension for "SupportedTypes"
128
- static const int cnNumEndingsInternal = 17 ;
129
- static const TCHAR* csFileEndingsInternal[cnNumEndingsInternal] = {_T (" jpg" ), _T (" jpeg" ), _T (" jfif" ), _T (" bmp" ), _T (" png" ),
130
- _T (" tif" ), _T (" tiff" ), _T (" gif" ), _T (" webp" ), _T (" jxl" ), _T (" avif" ), _T (" heif" ), _T (" heic" ), _T (" tga" ), _T (" qoi" ), _T (" psd" ), _T (" psb" ) };
127
+ // Image file types supported internally and come from INI file.
128
+ typedef std::set<std::wstring> file_endings_type;
129
+
131
130
// supported camera RAW formats
132
131
static const TCHAR* csFileEndingsRAW = _T(" *.pef;*.dng;*.crw;*.nef;*.cr2;*.mrw;*.rw2;*.orf;*.x3f;*.arw;*.kdc;*.nrw;*.dcr;*.sr2;*.raf" );
133
132
134
-
135
- static const int MAX_ENDINGS = 48 ;
136
- static int nNumEndings;
137
- static LPCTSTR* sFileEndings ;
138
-
139
133
__declspec (dllimport) bool __stdcall WICPresent(void );
140
134
141
135
// Check if Windows Image Codecs library is present
@@ -148,46 +142,58 @@ static bool WICPresentGuarded(void) {
148
142
}
149
143
150
144
// Parses a semicolon separated list of file endings of the form "*.nef;*.cr2;*.dng"
151
- static void ParseAndAddFileEndings (LPCTSTR sEndings ) {
152
- if (_tcslen (sEndings ) > 2 ) {
153
- LPTSTR buffer = new TCHAR[_tcslen (sEndings ) + 1 ]; // this buffer will not be freed deliberately!
154
- _tcscpy (buffer, sEndings );
155
- LPTSTR sStart = buffer, sCurrent = buffer;
156
- while (*sCurrent != 0 && nNumEndings < MAX_ENDINGS) {
157
- while (*sCurrent != 0 && *sCurrent != _T (' ;' )) {
158
- sCurrent ++;
159
- }
160
- if (*sCurrent == _T (' ;' )) {
161
- *sCurrent = 0 ;
162
- sCurrent ++;
163
- }
164
- if (_tcslen (sStart ) > 2 ) {
165
- sFileEndings [nNumEndings++] = sStart + 2 ;
166
- }
167
- sStart = sCurrent ;
168
- }
145
+ template <typename OUT_ITER>
146
+ static void ParseAndAddFileEndings (const std::wstring& input, OUT_ITER output) {
147
+ if (input.size () > 2 )
148
+ {
149
+ std::wstringstream ss (input);
150
+ std::wstring item;
151
+ while (std::getline (ss, item, L' ;' ))
152
+ output = item.substr (2 );
169
153
}
170
154
}
171
155
172
156
// Gets all supported file endings, including the ones from WIC.
173
157
// The length of the returned list is nNumEndings
174
- static LPCTSTR* GetSupportedFileEndingList () {
175
- if (sFileEndings == NULL ) {
176
- sFileEndings = new LPCTSTR[MAX_ENDINGS];
177
- for (nNumEndings = 0 ; nNumEndings < cnNumEndingsInternal; nNumEndings++) {
178
- sFileEndings [nNumEndings] = csFileEndingsInternal[nNumEndings];
179
- }
180
-
181
- LPCTSTR sFileEndingsWIC = CSettingsProvider::This ().FilesProcessedByWIC ();
182
- if (_tcslen (sFileEndingsWIC ) > 2 && WICPresentGuarded ()) {
183
- ParseAndAddFileEndings (sFileEndingsWIC );
184
- }
185
- ParseAndAddFileEndings (CSettingsProvider::This ().FileEndingsRAW ());
186
- }
187
- return sFileEndings ;
188
- }
189
-
190
- CFileList::CFileList (const CString & sInitialFile , CDirectoryWatcher & directoryWatcher,
158
+ static file_endings_type& GetSupportedFileEndingList ()
159
+ {
160
+ static file_endings_type file_endings;
161
+ if (!file_endings.empty ())
162
+ return file_endings;
163
+
164
+ // Gets all supported file endings, including the ones from WIC.
165
+ // Please, keep it ordered when adding a new extension.
166
+ file_endings =
167
+ {
168
+ _T (" avif" ),
169
+ _T (" bmp" ),
170
+ _T (" gif" ),
171
+ _T (" heic" ),
172
+ _T (" heif" ),
173
+ _T (" jfif" ),
174
+ _T (" jpeg" ),
175
+ _T (" jpg" ),
176
+ _T (" jxl" ),
177
+ _T (" png" ),
178
+ _T (" psb" ),
179
+ _T (" psd" ),
180
+ _T (" qoi" ),
181
+ _T (" tga" ),
182
+ _T (" tif" ),
183
+ _T (" tiff" ),
184
+ _T (" webp" )
185
+ };
186
+
187
+ LPCTSTR sFileEndingsWIC = CSettingsProvider::This ().FilesProcessedByWIC ();
188
+ if (_tcslen (sFileEndingsWIC ) > 2 && WICPresentGuarded ()) {
189
+ ParseAndAddFileEndings (sFileEndingsWIC , std::inserter (file_endings, file_endings.end ()));
190
+ }
191
+ ParseAndAddFileEndings (CSettingsProvider::This ().FileEndingsRAW (), std::inserter (file_endings, file_endings.end ()));
192
+
193
+ return file_endings;
194
+ }
195
+
196
+ CFileList::CFileList (const CString & sInitialFile , CDirectoryWatcher & directoryWatcher,
191
197
Helpers::ESorting eInitialSorting, bool isSortedAscending, bool bWrapAroundFolder, int nLevel, bool forceSorting)
192
198
: m_directoryWatcher(directoryWatcher) {
193
199
@@ -206,7 +212,7 @@ CFileList::CFileList(const CString & sInitialFile, CDirectoryWatcher & directory
206
212
bool bImageFile = !bIsDirectory && IsImageFile (sExtensionInitialFile );
207
213
if (!bIsDirectory && !bImageFile && !sExtensionInitialFile .IsEmpty () && _tcsstr (csFileEndingsRAW, _T (" *." ) + sExtensionInitialFile ) != NULL ) {
208
214
// initial file is a supported camera raw file but was excluded in INI file - add temporarily to file ending list
209
- ParseAndAddFileEndings (_T (" *." ) + sExtensionInitialFile );
215
+ ParseAndAddFileEndings ((LPCWSTR)( _T (" *." ) + sExtensionInitialFile ), std::inserter ( GetSupportedFileEndingList (), GetSupportedFileEndingList (). end ()) );
210
216
CSettingsProvider::This ().AddTemporaryRAWFileEnding (sExtensionInitialFile );
211
217
bImageFile = true ;
212
218
}
@@ -242,15 +248,22 @@ CFileList::~CFileList() {
242
248
m_fileList.clear ();
243
249
}
244
250
245
- CString CFileList::GetSupportedFileEndings () {
246
- LPCTSTR* allFileEndings = GetSupportedFileEndingList ();
247
- CString sList ;
248
- for (int i = 0 ; i < nNumEndings; i++) {
249
- sList += _T (" *." );
250
- sList += allFileEndings[i];
251
- if (i+1 < nNumEndings) sList += _T (" ;" );
251
+ CString CFileList::GetSupportedFileEndings ()
252
+ {
253
+ const auto & extensions = GetSupportedFileEndingList ();
254
+ std::wostringstream str;
255
+ bool first = true ;
256
+ for (const auto & extension : extensions)
257
+ {
258
+ if (!first)
259
+ str << L" ;" ;
260
+ else
261
+ first = false ;
262
+
263
+ str << L" *." << extension;
252
264
}
253
- return sList ;
265
+
266
+ return CString (str.str ().c_str ());
254
267
}
255
268
256
269
void CFileList::Reload (LPCTSTR sFileName , bool clearForwardHistory) {
@@ -614,7 +627,7 @@ void CFileList::DeleteHistory(bool onlyForward) {
614
627
m_prev = NULL ;
615
628
}
616
629
m_next = NULL ;
617
-
630
+
618
631
}
619
632
620
633
// /////////////////////////////////////////////////////////////////////////////////
@@ -815,12 +828,14 @@ void CFileList::FindFiles() {
815
828
m_fileList.clear ();
816
829
if (!m_sDirectory.IsEmpty ()) {
817
830
CFindFile fileFind;
818
- LPCTSTR* allFileEndings = GetSupportedFileEndingList ();
819
- for (int i = 0 ; i < nNumEndings; i++) {
820
- if (fileFind.FindFile (m_sDirectory + _T (" \\ *." ) + allFileEndings[i])) {
821
- AddToFileList (m_fileList, fileFind, allFileEndings[i]);
831
+ const auto & extensions = GetSupportedFileEndingList ();
832
+ for (const auto & extension : extensions)
833
+ {
834
+ const auto c_extension = extension.c_str ();
835
+ if (fileFind.FindFile (m_sDirectory + _T (" \\ *." ) + c_extension)) {
836
+ AddToFileList (m_fileList, fileFind, c_extension);
822
837
while (fileFind.FindNextFile ()) {
823
- AddToFileList (m_fileList, fileFind, allFileEndings[i] );
838
+ AddToFileList (m_fileList, fileFind, c_extension );
824
839
}
825
840
}
826
841
}
@@ -841,16 +856,11 @@ void CFileList::VerifyFiles() {
841
856
}
842
857
}
843
858
844
- bool CFileList::IsImageFile (const CString & sEnding ) {
859
+ bool CFileList::IsImageFile (const CString & sEnding ) const {
845
860
CString sEndingLC = sEnding ;
846
861
sEndingLC .MakeLower ();
847
- LPCTSTR* allFileEndings = GetSupportedFileEndingList ();
848
- for (int i = 0 ; i < nNumEndings; i++) {
849
- if (allFileEndings[i] == sEndingLC ) {
850
- return true ;
851
- }
852
- }
853
- return false ;
862
+ const auto & allFileEndings = GetSupportedFileEndingList ();
863
+ return allFileEndings.find ((LPCWSTR)sEndingLC ) != allFileEndings.end ();
854
864
}
855
865
856
866
bool CFileList::TryReadingSlideShowList (const CString & sSlideShowFile ) {
@@ -965,9 +975,10 @@ bool CFileList::TryReadingSlideShowList(const CString & sSlideShowFile) {
965
975
pStart--;
966
976
} else {
967
977
// try to find file name with relative path
968
- LPCTSTR* allFileEndings = GetSupportedFileEndingList ();
969
- for (int i = 0 ; i < nNumEndings; i++) {
970
- pStart = Helpers::stristr (lineBuff, (LPCTSTR)(CString (_T (" ." )) + allFileEndings[i]));
978
+ const auto & extensions = GetSupportedFileEndingList ();
979
+ for (const auto & extension : extensions)
980
+ {
981
+ pStart = Helpers::stristr (lineBuff, (LPCTSTR)(CString (_T (" ." )) + extension.c_str ()));
971
982
if (pStart != NULL ) {
972
983
while (pStart >= lineBuff && *pStart != _T (' "' ) && *pStart != _T (' >' )) pStart--;
973
984
pStart++;
@@ -976,7 +987,7 @@ bool CFileList::TryReadingSlideShowList(const CString & sSlideShowFile) {
976
987
}
977
988
}
978
989
}
979
-
990
+
980
991
}
981
992
if (pStart != NULL ) {
982
993
// extract file name and add to list of files to show
0 commit comments