Skip to content

Commit

Permalink
Fix bug when extracting multi-disc PBPs
Browse files Browse the repository at this point in the history
Allow wildcards for -i
Code cleanup
Improved notifications
  • Loading branch information
RupertAvery committed Dec 2, 2020
1 parent b6e669f commit f692b95
Show file tree
Hide file tree
Showing 16 changed files with 1,020 additions and 676 deletions.
101 changes: 101 additions & 0 deletions PSXPackager/ConsoleNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using Popstation;

namespace PSXPackager
{
public class ConsoleNotifications
{
private int _cursorYPos;
private long _total;
private long _lastTicks;
private int _charsToDelete;

public Action OverwriteAllSelected { get; set; }
public Action CancelSelected { get; set; }

public void Notify(PopstationEventEnum @event, object value)
{
switch (@event)
{
case PopstationEventEnum.Info:
Console.WriteLine($"{value}");
break;
case PopstationEventEnum.Warning:
Console.WriteLine($"WARNING: {value}");
break;

case PopstationEventEnum.GetIsoSize:
_total = Convert.ToInt64(value);
break;
case PopstationEventEnum.ConvertSize:
case PopstationEventEnum.WriteSize:
_total = Convert.ToInt64(value);
break;

case PopstationEventEnum.ConvertStart:
Console.Write($"Converting Disc {value} - ");
_cursorYPos = Console.CursorTop;
Console.CursorVisible = false;
break;
case PopstationEventEnum.WriteStart:
Console.Write($"Writing Disc {value} - ");
_cursorYPos = Console.CursorTop;
Console.CursorVisible = false;
break;
case PopstationEventEnum.ExtractStart:
Console.Write($"Extracting Disc {value} - ");
_cursorYPos = Console.CursorTop;
Console.CursorVisible = false;
break;

case PopstationEventEnum.ConvertComplete:
case PopstationEventEnum.ExtractComplete:
case PopstationEventEnum.WriteComplete:
_charsToDelete = 0;
Console.CursorVisible = true;
Console.WriteLine();
break;

case PopstationEventEnum.ConvertProgress:
case PopstationEventEnum.ExtractProgress:
case PopstationEventEnum.WriteProgress:
//Console.SetCursorPosition(0, _cursorYPos);
if (DateTime.Now.Ticks - _lastTicks > 100000)
{
Overwrite($"{Math.Round(Convert.ToInt32(value) / (double)_total * 100, 0) }%");
_lastTicks = DateTime.Now.Ticks;
}
break;
}
}

public void Overwrite(string text)
{
Console.Write(new string('\b', _charsToDelete));
Console.Write(text);
_charsToDelete = text.Length;
}

public ActionIfFileExistsEnum ActionIfFileExists(string arg)
{
while (true)
{
Console.WriteLine($"{arg} alreasy exists. Overwrite? (Y)es|(N)o|(A)ll|(C)ancel");
var key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.Y:
return ActionIfFileExistsEnum.Overwrite;
case ConsoleKey.N:
return ActionIfFileExistsEnum.Skip;
case ConsoleKey.A:
OverwriteAllSelected?.Invoke();
return ActionIfFileExistsEnum.OverwriteAll;
case ConsoleKey.C:
CancelSelected?.Invoke();
return ActionIfFileExistsEnum.Abort;
}
}
}
}
}
28 changes: 16 additions & 12 deletions PSXPackager/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ namespace PSXPackager
{
public class Options
{
[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
public bool Verbose { get; set; }

[Option('l', "level", Required = false, HelpText = "Set compression level 0-9, default 5", Default = 5)]
public int CompressionLevel { get; set; }
[Option('i', "input", Group = "input", HelpText = "The input file or path to convert. The filename may contain wildcards.")]
public string InputPath { get; set; }

[Option('o', "output", Required = false
, HelpText = "The output path where the converted file will be written")]
[Option('o', "output", Required = false, HelpText = "The output path where the converted file(s) will be written.")]
public string OutputPath { get; set; }

[Option('i', "input", Group = "input", HelpText = "The input file to convert")]
public string InputPath { get; set; }
[Option('l', "level", Required = false, HelpText = "Set compression level 0-9, default 5.", Default = 5)]
public int CompressionLevel { get; set; }

[Option('b', "batch", Group = "input", HelpText = "The path to batch process a set of files")]
[Option('b', "batch", Group = "input", HelpText = "The path to batch process a set of files.")]
public string Batch { get; set; }

[Option('e', "ext", Required = false, HelpText = "The extension of the files to process in the batch folder, e.g. .7z")]
public string BatchExtension { get; set; }
[Option('e', "ext", Required = false, HelpText = "The semi-colon or pipe-separated extension(s) of the files to process in the batch folder, e.g. .7z or .iso|.bin|.img")]
public string Filters { get; set; }

[Option('d', "discs", Required = false, HelpText = "A comma-separated list of disc numbers to extract from a PBP.")]
public string Discs { get; set; }

[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
public bool Verbose { get; set; }

[Option('y', "yes", Required = false, HelpText = "If specified, will overwrite a file if it exists, otherwise will ask confirmation.")]
public bool OverwriteIfExists { get; set; }
}
}
16 changes: 5 additions & 11 deletions PSXPackager/PSXPackager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net48;netcoreapp3.1</TargetFrameworks>
<PublishTrimmed>true</PublishTrimmed>
<FileVersion>1.3.0.0</FileVersion>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<Authors>RupertAvery</Authors>
<Version>1.3.0</Version>
</PropertyGroup>


Expand All @@ -25,17 +29,7 @@

<Target Name="ILMerge">
<!-- the ILMergePath property points to the location of ILMerge.exe console application -->
<Exec Command="$(ILMergeConsolePath) bin\Debug\netcoreapp3.1\PSXPackager.exe ^
/out:PSXPackager2.exe ^
bin\Debug\netcoreapp3.1\CommandLine.dll ^
bin\Debug\netcoreapp3.1\DiscUtils.Core.dll ^
bin\Debug\netcoreapp3.1\DiscUtils.Iso9660.dll ^
bin\Debug\netcoreapp3.1\DiscUtils.Streams.dll ^
bin\Debug\netcoreapp3.1\ICSharpCode.SharpZipLib.dll ^
bin\Debug\netcoreapp3.1\Popstation.dll ^
bin\Debug\netcoreapp3.1\PSXPackager.dll ^
bin\Debug\netcoreapp3.1\SevenZipExtractor.dll ^
bin\Debug\netcoreapp3.1\System.ValueTuple.dll" />
<Exec Command="$(ILMergeConsolePath) bin\Debug\netcoreapp3.1\PSXPackager.exe ^&#xD;&#xA;/out:PSXPackager2.exe ^&#xD;&#xA;bin\Debug\netcoreapp3.1\CommandLine.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\DiscUtils.Core.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\DiscUtils.Iso9660.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\DiscUtils.Streams.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\ICSharpCode.SharpZipLib.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\Popstation.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\PSXPackager.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\SevenZipExtractor.dll ^&#xD;&#xA;bin\Debug\netcoreapp3.1\System.ValueTuple.dll" />
</Target>

</Project>
Loading

0 comments on commit f692b95

Please sign in to comment.