88using Popstation ;
99using Popstation . Cue ;
1010using Popstation . M3u ;
11- using SevenZipExtractor ;
11+ using SevenZip ;
1212
1313namespace PSXPackager
1414{
@@ -104,6 +104,20 @@ public bool ProcessFile(
104104 var files = new List < string > ( ) ;
105105 var tocs = new List < string > ( ) ;
106106 var m3UFile = M3uFileReader . Read ( file ) ;
107+
108+ if ( m3UFile . FileEntries . Count == 0 )
109+ {
110+ _notifications ? . Notify ( PopstationEventEnum . Info , $ "Invalid number of entries, found { m3UFile . FileEntries . Count } ") ;
111+ return false ;
112+ }
113+ else if ( m3UFile . FileEntries . Count > 5 )
114+ {
115+ _notifications ? . Notify ( PopstationEventEnum . Info , $ "Invalid number of entries, found { m3UFile . FileEntries . Count } , max is 5") ;
116+ return false ;
117+ }
118+
119+ _notifications ? . Notify ( PopstationEventEnum . Info , $ "Found { m3UFile . FileEntries . Count } entries") ;
120+
107121 foreach ( var fileEntry in m3UFile . FileEntries )
108122 {
109123 if ( FileExtensionHelper . IsCue ( fileEntry ) )
@@ -112,10 +126,16 @@ public bool ProcessFile(
112126 files . Add ( outfile ) ;
113127 tocs . Add ( srcToc ) ;
114128 }
115- else
129+ else if ( FileExtensionHelper . IsImageFile ( fileEntry ) )
116130 {
117131 files . Add ( Path . Combine ( filePath , fileEntry ) ) ;
118132 }
133+ else
134+ {
135+ _notifications ? . Notify ( PopstationEventEnum . Info , $ "Unsupported playlist entry '{ fileEntry } '") ;
136+ _notifications ? . Notify ( PopstationEventEnum . Info , "Only the following are supported: .cue .img .bin .iso" ) ;
137+ return false ;
138+ }
119139 }
120140 result = ConvertIsos ( files . ToArray ( ) , tocs . ToArray ( ) , outPath , compressionLevel , checkIfFileExists , cancellationToken ) ;
121141 }
@@ -149,7 +169,7 @@ public bool ProcessFile(
149169 catch ( Exception ex )
150170 {
151171 Console . WriteLine ( ex . Message ) ;
152- throw ;
172+ // throw;
153173 }
154174 finally
155175 {
@@ -239,7 +259,7 @@ static MergedBin MergeBins(string file, CueFile cueFilex, string tempPath)
239259 var newIndex = new CueIndex
240260 {
241261 Number = idx . Number ,
242- Position = idx . Position + Helper . PositionFromFrames ( currentFrame )
262+ Position = idx . Position + TOCHelper . PositionFromFrames ( currentFrame )
243263 } ;
244264 indexes . Add ( newIndex ) ;
245265 }
@@ -275,42 +295,67 @@ static string Shorten(ulong size)
275295 }
276296 }
277297
278- static List < string > Unpack ( string file , string tempPath , CancellationToken cancellationToken )
298+ List < string > Unpack ( string file , string tempPath , CancellationToken cancellationToken )
279299 {
280- var files = new List < string > ( ) ;
300+ List < string > files ;
281301
282- using ( ArchiveFile archiveFile = new ArchiveFile ( file ) )
302+ using ( var archiveFile = new SevenZipExtractor ( file ) )
283303 {
304+ var archiveFiles = archiveFile . ArchiveFileData . Select ( x => x . FileName ) . ToList ( ) ;
305+
306+ archiveFile . FileExtractionStarted += ( sender , args ) => _notifications . Notify ( PopstationEventEnum . DecompressStart , args . FileInfo . FileName ) ;
307+ archiveFile . Extracting += ArchiveFileOnExtracting ;
308+ archiveFile . FileExtractionFinished += ( sender , args ) => _notifications . Notify ( PopstationEventEnum . DecompressComplete , null ) ;
309+ //archiveFile.BeginExtractFiles(ExtractFileCallback);
284310 //var unpackTasks = new List<Task>();
285- foreach ( Entry entry in archiveFile . Entries )
286- {
287- if ( FileExtensionHelper . IsImageFile ( entry . FileName ) || FileExtensionHelper . IsCue ( entry . FileName ) )
288- {
289- Console . WriteLine ( $ "Extracting { entry . FileName } ({ Shorten ( entry . Size ) } )") ;
290- var path = Path . Combine ( tempPath , entry . FileName ) ;
291- // extract to file
292- files . Add ( path ) ;
293- entry . Extract ( path , false ) ;
294-
295- //unpackTasks.Add(Task.Run(() =>
296- //{
297- // entry.Extract(path, false);
298- // files.Add(path);
299- //}, cancellationToken));
300- }
301- if ( cancellationToken . IsCancellationRequested )
302- {
303- return files ;
304- }
305- }
311+ archiveFile . ExtractFiles ( tempPath , archiveFiles . ToArray ( ) ) ;
312+
313+ files = archiveFiles . Select ( x => Path . Combine ( tempPath , x ) ) . ToList ( ) ;
314+
315+ //foreach (var entry in archiveFile.ArchiveFileData)
316+ //{
317+ // if (FileExtensionHelper.IsImageFile(entry.FileName) || FileExtensionHelper.IsCue(entry.FileName))
318+ // {
319+ // //Console.WriteLine($"Extracting {entry.FileName} ({Shorten(entry.Size)})");
320+ // var path = Path.Combine(tempPath, entry.FileName);
321+ // // extract to file
322+ // files.Add(path);
323+
324+ // _notifications.Notify(PopstationEventEnum.DecompressStart, entry.FileName);
325+ // _notifications.Notify(PopstationEventEnum.DecompressComplete, null);
326+
327+ // using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
328+ // {
329+ // _notifications.Notify(PopstationEventEnum.DecompressStart, entry.FileName);
330+ // archiveFile.ExtractFile(entry.FileName, stream);
331+ // _notifications.Notify(PopstationEventEnum.DecompressComplete, null);
332+ // }
333+
334+ // }
335+ // if (cancellationToken.IsCancellationRequested)
336+ // {
337+ // return files;
338+ // }
339+ //}
306340
307341 //Task.WaitAll(unpackTasks.ToArray());
342+ archiveFile . Extracting -= ArchiveFileOnExtracting ;
308343
309344 }
310345
311346 return files ;
312347 }
313348
349+ //private void ExtractFileCallback(ExtractFileCallbackArgs extractfilecallbackargs)
350+ //{
351+ // extractfilecallbackargs.CancelExtraction
352+ //}
353+
354+ private void ArchiveFileOnExtracting ( object sender , ProgressEventArgs e )
355+ {
356+ _notifications . Notify ( PopstationEventEnum . DecompressProgress , e . PercentDone ) ;
357+ }
358+
314359 private const int RING_BUFFER_SIZE = 14 ;
315360
316361 string [ ] gamecodes =
@@ -529,9 +574,11 @@ private bool ConvertIsos(
529574 } ) ;
530575 }
531576
532- var popstation = new Popstation . Popstation ( ) ;
533- popstation . ActionIfFileExists = _notifications . ActionIfFileExists ;
534- popstation . OnEvent = _notifications . Notify ;
577+ var popstation = new Popstation . Popstation
578+ {
579+ ActionIfFileExists = _notifications . ActionIfFileExists ,
580+ OnEvent = _notifications . Notify
581+ } ;
535582
536583 return popstation . Convert ( info , cancellationToken ) ;
537584 }
@@ -577,9 +624,11 @@ private bool ConvertIso(
577624 CheckIfFileExists = checkIfFileExists
578625 } ;
579626
580- var popstation = new Popstation . Popstation ( ) ;
581- popstation . ActionIfFileExists = _notifications . ActionIfFileExists ;
582- popstation . OnEvent = _notifications . Notify ;
627+ var popstation = new Popstation . Popstation
628+ {
629+ ActionIfFileExists = _notifications . ActionIfFileExists ,
630+ OnEvent = _notifications . Notify
631+ } ;
583632
584633 return popstation . Convert ( info , cancellationToken ) ;
585634 }
@@ -603,9 +652,11 @@ private void ExtractPbp(
603652 CheckIfFileExists = checkIfFileExists
604653 } ;
605654
606- var popstation = new Popstation . Popstation ( ) ;
607- popstation . ActionIfFileExists = _notifications . ActionIfFileExists ;
608- popstation . OnEvent = _notifications . Notify ;
655+ var popstation = new Popstation . Popstation
656+ {
657+ ActionIfFileExists = _notifications . ActionIfFileExists ,
658+ OnEvent = _notifications . Notify
659+ } ;
609660
610661 popstation . Extract ( info , cancellationToken ) ;
611662 }
0 commit comments