@@ -306,23 +306,36 @@ public static string UnpackARC(string arc, string tempPath)
306306 if ( drive . IsReady && drive . Name == Path . GetPathRoot ( Environment . SystemDirectory ) )
307307 if ( drive . AvailableFreeSpace > new FileInfo ( arc ) . Length )
308308 {
309- Directory . CreateDirectory ( tempPath ) ; // Create temporary location
310- File . Copy ( arc , Path . Combine ( tempPath , Path . GetFileName ( arc ) ) ) ; // Copy archive to temporary location
311-
312- // Extracts the archive in the temporary location
313- var unpack = new ProcessStartInfo ( )
309+ try
314310 {
315- FileName = Program . Arctool ,
316- Arguments = $ "-d \" { Path . Combine ( tempPath , Path . GetFileName ( arc ) ) } \" ",
317- WorkingDirectory = Path . GetDirectoryName ( Program . Arctool ) ,
318- WindowStyle = ProcessWindowStyle . Hidden
319- } ;
311+ Directory . CreateDirectory ( tempPath ) ; // Create temporary location
312+ File . Copy ( arc , Path . Combine ( tempPath , Path . GetFileName ( arc ) ) ) ; // Copy archive to temporary location
313+
314+ // Extracts the archive in the temporary location
315+ var unpack = new ProcessStartInfo ( )
316+ {
317+ FileName = Program . Arctool ,
318+ Arguments = $ "-d \" { Path . Combine ( tempPath , Path . GetFileName ( arc ) ) } \" ",
319+ WorkingDirectory = Path . GetDirectoryName ( Program . Arctool ) ,
320+ WindowStyle = ProcessWindowStyle . Hidden
321+ } ;
320322
321- var Unpack = Process . Start ( unpack ) ;
322- Unpack . WaitForExit ( ) ;
323- Unpack . Close ( ) ;
323+ var Unpack = Process . Start ( unpack ) ;
324+ Unpack . WaitForExit ( ) ;
325+ Unpack . Close ( ) ;
324326
325- return tempPath ;
327+ return tempPath ;
328+ }
329+ catch ( System . ComponentModel . Win32Exception ex )
330+ {
331+ if ( ! File . Exists ( Program . Arctool ) )
332+ {
333+ skipped . Add ( $ "► { Path . GetFileName ( arc ) } (a required pre-requisite is missing - check the debug log for more information)") ;
334+ Console . WriteLine ( $ "[{ DateTime . Now : HH:mm:ss tt} ] [Error] { Properties . Resources . Exception_ArctoolMissing + Program . Arctool } \n { ex } ") ;
335+ }
336+
337+ return string . Empty ;
338+ }
326339 }
327340 else
328341 throw new InsufficientMemoryException ( $ "Unable to extract '{ Path . GetFileName ( arc ) } ' due to insufficient drive space...") ;
@@ -333,46 +346,62 @@ public static string UnpackARC(string arc, string tempPath)
333346 /// <summary>
334347 /// Repacks an archive from a temporary location.
335348 /// </summary>
336- public static void RepackARC ( string arc , string output ) {
337- ArcPacker repack = new ArcPacker ( ) ;
338- repack . WriteArc ( output , Path . Combine ( arc , Path . GetFileNameWithoutExtension ( output ) ) ) ;
339-
340- // Erases temporary repack data
341- try {
342- DirectoryInfo tempData = new DirectoryInfo ( arc ) ;
343- if ( Directory . Exists ( arc ) ) {
344- foreach ( FileInfo file in tempData . GetFiles ( ) ) file . Delete ( ) ;
345- foreach ( DirectoryInfo directory in tempData . GetDirectories ( ) ) directory . Delete ( true ) ;
346- Directory . Delete ( arc ) ;
347- }
348- } catch { }
349+ public static void RepackARC ( string arc , string output )
350+ {
351+ if ( arc != string . Empty )
352+ {
353+ ArcPacker repack = new ArcPacker ( ) ;
354+ repack . WriteArc ( output , Path . Combine ( arc , Path . GetFileNameWithoutExtension ( output ) ) ) ;
355+
356+ // Erases temporary repack data
357+ try {
358+ DirectoryInfo tempData = new DirectoryInfo ( arc ) ;
359+ if ( Directory . Exists ( arc ) ) {
360+ foreach ( FileInfo file in tempData . GetFiles ( ) ) file . Delete ( ) ;
361+ foreach ( DirectoryInfo directory in tempData . GetDirectories ( ) ) directory . Delete ( true ) ;
362+ Directory . Delete ( arc ) ;
363+ }
364+ } catch { }
365+ }
349366 }
350367
351368 /// <summary>
352369 /// Merges two archives into a single archive.
353370 /// </summary>
354- public static void Merge ( string arc1 , string arc2 ) {
355- string tempPath = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ; // Defines the temporary path.
356- Directory . CreateDirectory ( tempPath ) ;
357- string unpack1 = UnpackARC ( arc1 , tempPath ) ;
358- ProcessStartInfo arctool ;
359-
360- File . Copy ( arc2 , Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) , true ) ; // Copies the input ARC to the temporary path.
361-
362- // Defines the arctool process.
363- arctool = new ProcessStartInfo ( ) {
364- FileName = Program . Arctool ,
365- Arguments = $ "-d \" { Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) } \" ",
366- WorkingDirectory = Path . GetDirectoryName ( Program . Arctool ) ,
367- WindowStyle = ProcessWindowStyle . Hidden
368- } ;
371+ public static void Merge ( string arc1 , string arc2 )
372+ {
373+ try
374+ {
375+ string tempPath = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ; // Defines the temporary path.
376+ Directory . CreateDirectory ( tempPath ) ;
377+ string unpack1 = UnpackARC ( arc1 , tempPath ) ;
378+ ProcessStartInfo arctool ;
379+
380+ File . Copy ( arc2 , Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) , true ) ; // Copies the input ARC to the temporary path.
381+
382+ // Defines the arctool process.
383+ arctool = new ProcessStartInfo ( ) {
384+ FileName = Program . Arctool ,
385+ Arguments = $ "-d \" { Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) } \" ",
386+ WorkingDirectory = Path . GetDirectoryName ( Program . Arctool ) ,
387+ WindowStyle = ProcessWindowStyle . Hidden
388+ } ;
369389
370- var Unpack2 = Process . Start ( arctool ) ; // Unpacks the merge ARC.
371- Unpack2 . WaitForExit ( ) ;
390+ var Unpack2 = Process . Start ( arctool ) ; // Unpacks the merge ARC.
391+ Unpack2 . WaitForExit ( ) ;
372392
373- File . Delete ( Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) ) ; // Deletes the temporary merge ARC.
393+ File . Delete ( Path . Combine ( tempPath , Path . GetFileName ( arc2 ) ) ) ; // Deletes the temporary merge ARC.
374394
375- RepackARC ( unpack1 , arc1 ) ;
395+ RepackARC ( unpack1 , arc1 ) ;
396+ }
397+ catch ( System . ComponentModel . Win32Exception ex )
398+ {
399+ if ( ! File . Exists ( Program . Arctool ) )
400+ {
401+ skipped . Add ( $ "► { Path . GetFileName ( arc1 ) } (a required pre-requisite is missing - check the debug log for more information)") ;
402+ Console . WriteLine ( $ "[{ DateTime . Now : HH:mm:ss tt} ] [Error] { Properties . Resources . Exception_ArctoolMissing + Program . Arctool } \n { ex } ") ;
403+ }
404+ }
376405 }
377406 }
378407
0 commit comments