@@ -176,6 +176,12 @@ private static bool extractZip(LoadOptions options, ObjectInfo objInfo, HashSet<
176176 try {
177177 ext = options . Password ? . Length > 0 ? new SevenZipExtractor ( options . FilePath , options . Password ) :
178178 new SevenZipExtractor ( options . FilePath ) ;
179+ //check for multi-volume archives (nope doesnt work)
180+ //if (ext.VolumeFileNames.Count > 1 && ext.FileName != ext.VolumeFileNames[0]) {
181+ // objInfo.Flags = FileFlags.Unknown;
182+ // return true;
183+ //}
184+
179185 var isThumb = options . DecodeSize == ( SizeInt ) Setting . ThumbnailSize ;
180186 bool fromDisk = false ;
181187
@@ -187,18 +193,19 @@ private static bool extractZip(LoadOptions options, ObjectInfo objInfo, HashSet<
187193 toDo = ext . ArchiveFileData
188194 . Where ( d => ! d . IsDirectory && GetFileType ( d . FileName ) == FileFlags . Image )
189195 . Select ( d => d . FileName ) . ToArray ( ) ;
190-
196+
191197 //for archives with encrypted file names, ext.ArchiveFileData will be empty.
192198 if ( toDo == null || toDo . Length == 0 ) return false ;
193199
194- foreach ( var fileName in toDo ) {
195- if ( tknSrc ? . IsCancellationRequested == true ) break ;
200+ //iterate over each file and extract when needed
201+ if ( options . LoadImage && options . CldInfoCallback != null ) {
202+ foreach ( var fileName in toDo ) {
203+ if ( tknSrc ? . IsCancellationRequested == true ) break ;
196204
197- //skip if already done
198- if ( done . Contains ( fileName ) ) continue ;
205+ //skip if already done
206+ if ( done . Contains ( fileName ) ) continue ;
199207
200- ImageSource source = null ;
201- if ( options . LoadImage ) {
208+ ImageSource source = null ;
202209 if ( options . TryCache && isThumb ) {
203210 //try load from cache
204211 source = SQLiteHelper . GetFromThumbDB ( options . FilePath , options . DecodeSize , fileName ) ? . Item1 ;
@@ -217,18 +224,16 @@ private static bool extractZip(LoadOptions options, ObjectInfo objInfo, HashSet<
217224 }
218225 if ( isThumb && source != null ) SQLiteHelper . AddToThumbDB ( source , options . FilePath , fileName , options . DecodeSize ) ;
219226 }
220- }
221-
222- if ( options . CldInfoCallback != null ) {
223227 var cldInfo = new ObjectInfo ( options . FilePath , FileFlags . Image | FileFlags . Archive ) {
224228 FileName = fileName ,
225229 SourcePaths = new [ ] { fileName } ,
226- ImageSource = source ,
227230 } ;
231+ if ( source == null ) cldInfo . Flags |= FileFlags . Error ;
232+ else cldInfo . ImageSource = source ;
228233 options . CldInfoCallback . Invoke ( cldInfo ) ;
234+
235+ done . Add ( fileName ) ;
229236 }
230-
231- done . Add ( fileName ) ;
232237 }
233238
234239 //update objInfo
@@ -244,7 +249,8 @@ private static bool extractZip(LoadOptions options, ObjectInfo objInfo, HashSet<
244249 catch ( Exception ex ) {
245250 if ( ex is ExtractionFailedException ||
246251 ex is SevenZipArchiveException ||
247- ex is NotSupportedException ) return false ;
252+ ex is NotSupportedException ||
253+ ex is ArgumentOutOfRangeException ) return false ;
248254
249255 if ( ext != null ) {
250256 ext . Dispose ( ) ;
@@ -406,14 +412,12 @@ public static ImageSource GetImageSource(ObjectInfo objInfo, string sourcePath,
406412 switch ( objInfo . Flags ) {
407413 case FileFlags . Directory :
408414 if ( sourcePath != null )
409- source = GetImageSource ( Path . Combine ( objInfo . FileSystemPath , sourcePath ) , decodeSize , tryCache ) ;
410- if ( source == null )
415+ source = GetImageSource ( Path . Combine ( objInfo . FileSystemPath , sourcePath ) , decodeSize , tryCache ) ?? App . fa_image ;
416+ else
411417 source = App . fa_folder ;
412418 break ;
413419 case FileFlags . Image :
414- source = GetImageSource ( objInfo . FileSystemPath , decodeSize , tryCache ) ;
415- if ( source == null )
416- source = App . fa_image ;
420+ source = GetImageSource ( objInfo . FileSystemPath , decodeSize , tryCache ) ?? App . fa_image ;
417421 break ;
418422 case FileFlags . Archive :
419423 if ( sourcePath != null ) {
@@ -426,16 +430,15 @@ public static ImageSource GetImageSource(ObjectInfo objInfo, string sourcePath,
426430 CldInfoCallback = oi => source = oi . ImageSource ,
427431 ObjInfoCallback = oi => objInfo . Flags = oi . Flags
428432 } ) ;
433+ if ( source == null ) source = App . fa_image ; //CldInfoCallback may not get called when error
429434 }
430- if ( source == null )
435+ else
431436 source = App . fa_archive ;
432437 break ;
433438 case FileFlags . Archive | FileFlags . Image :
434439 //archives are loaded with ImageSource in a single thread
435440 //this is only pointing to the source
436- source = objInfo . ImageSource ;
437- if ( source == null )
438- source = App . fa_image ;
441+ source = objInfo . ImageSource ?? App . fa_image ;
439442 break ;
440443 }
441444 }
@@ -448,6 +451,7 @@ public static ImageSource GetImageSource(ObjectInfo objInfo, string sourcePath,
448451 Console . WriteLine ( $ "Helpers.GetImageSource() exited after { watch . ElapsedMilliseconds } ms. Leaving { LoadThrottle . CurrentCount } slots.") ;
449452#endif
450453 }
454+
451455 return source ;
452456 }
453457
0 commit comments