Skip to content

Commit ec89b8b

Browse files
committed
Fixed bug where converting to PBP with no CUE would result in a TOC with an index of 00:02:01 from the default PSAR
Change to SevenZipSharp for notifications during extraction Get DiscID from PBP Disc Entry Add output file to tempfiles so cancelling will delete as well Added option to format filename Add option to generate log Add option for verbosity levels
1 parent 9f656a7 commit ec89b8b

29 files changed

+1257
-680
lines changed

PSXPackager/AggregateNotifier.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using Popstation;
3+
4+
namespace PSXPackager
5+
{
6+
public class AggregateNotifier : INotifier
7+
{
8+
private readonly List<INotifier> _notifiers;
9+
public AggregateNotifier()
10+
{
11+
_notifiers = new List<INotifier>();
12+
}
13+
14+
public void Add(INotifier notifier)
15+
{
16+
_notifiers.Add(notifier);
17+
}
18+
19+
public void Notify(PopstationEventEnum @event, object value)
20+
{
21+
foreach (var notifier in _notifiers)
22+
{
23+
notifier.Notify(@event, value);
24+
}
25+
}
26+
}
27+
}

PSXPackager/ConsoleNotifications.cs

Lines changed: 0 additions & 115 deletions
This file was deleted.

PSXPackager/ConsoleNotifier.cs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
using System;
2+
using Popstation;
3+
4+
namespace PSXPackager
5+
{
6+
public class ConsoleNotifier : INotifier
7+
{
8+
private int _cursorYPos;
9+
private long _total;
10+
private long _lastTicks;
11+
private int _charsToDelete;
12+
private DateTime _startDateTime;
13+
private readonly int _logLevel;
14+
15+
public ConsoleNotifier(int logLevel)
16+
{
17+
_logLevel = logLevel;
18+
}
19+
20+
private int GetLogLevel(PopstationEventEnum @event)
21+
{
22+
switch (@event)
23+
{
24+
case PopstationEventEnum.ProcessingStart:
25+
case PopstationEventEnum.ProcessingComplete:
26+
return -1;
27+
28+
case PopstationEventEnum.Error:
29+
return -1;
30+
31+
case PopstationEventEnum.Warning:
32+
return 1;
33+
34+
case PopstationEventEnum.Info:
35+
return 3;
36+
37+
38+
case PopstationEventEnum.FileName:
39+
return 0;
40+
41+
case PopstationEventEnum.GetIsoSize:
42+
case PopstationEventEnum.ConvertSize:
43+
case PopstationEventEnum.ExtractSize:
44+
case PopstationEventEnum.WriteSize:
45+
return -1;
46+
47+
case PopstationEventEnum.ConvertStart:
48+
case PopstationEventEnum.WriteStart:
49+
case PopstationEventEnum.ExtractStart:
50+
case PopstationEventEnum.DecompressStart:
51+
52+
case PopstationEventEnum.ConvertProgress:
53+
case PopstationEventEnum.ExtractProgress:
54+
case PopstationEventEnum.WriteProgress:
55+
case PopstationEventEnum.DecompressProgress:
56+
57+
case PopstationEventEnum.ConvertComplete:
58+
case PopstationEventEnum.ExtractComplete:
59+
case PopstationEventEnum.WriteComplete:
60+
case PopstationEventEnum.DecompressComplete:
61+
return 2;
62+
}
63+
return -1;
64+
}
65+
66+
public void Notify(PopstationEventEnum @event, object value)
67+
{
68+
if (GetLogLevel(@event) > _logLevel) return;
69+
70+
switch (@event)
71+
{
72+
case PopstationEventEnum.ProcessingStart:
73+
_startDateTime = DateTime.Now;
74+
WriteLine(@event, $"Processing started: {_startDateTime.Hour:00}:{_startDateTime.Minute:00}:{_startDateTime.Second:00}");
75+
break;
76+
77+
case PopstationEventEnum.ProcessingComplete:
78+
var elapsedSpan = DateTime.Now - _startDateTime;
79+
WriteLine(@event, $"Processing completed: {elapsedSpan.TotalHours:00}h {elapsedSpan.Minutes:00}m {elapsedSpan.Seconds:00}s");
80+
break;
81+
82+
case PopstationEventEnum.Error:
83+
_charsToDelete = 0;
84+
Console.CursorVisible = true;
85+
WriteLine(@event, $"\r\n{value}");
86+
break;
87+
case PopstationEventEnum.FileName:
88+
case PopstationEventEnum.Info:
89+
WriteLine(@event, $"{value}");
90+
break;
91+
case PopstationEventEnum.Warning:
92+
var lastColor = Console.ForegroundColor;
93+
Console.ForegroundColor = ConsoleColor.DarkYellow;
94+
WriteLine(@event, $"WARNING: {value}");
95+
Console.ForegroundColor = lastColor;
96+
break;
97+
98+
case PopstationEventEnum.GetIsoSize:
99+
_total = Convert.ToInt64(value);
100+
break;
101+
case PopstationEventEnum.ConvertSize:
102+
case PopstationEventEnum.ExtractSize:
103+
case PopstationEventEnum.WriteSize:
104+
_total = Convert.ToInt64(value);
105+
break;
106+
107+
case PopstationEventEnum.ConvertStart:
108+
Write(@event, $"Converting Disc {value} - ");
109+
_cursorYPos = Console.CursorTop;
110+
Console.CursorVisible = false;
111+
break;
112+
case PopstationEventEnum.WriteStart:
113+
Write(@event, $"Writing Disc {value} - ");
114+
_cursorYPos = Console.CursorTop;
115+
Console.CursorVisible = false;
116+
break;
117+
case PopstationEventEnum.ExtractStart:
118+
Write(@event, $"Extracting Disc {value} - ");
119+
_cursorYPos = Console.CursorTop;
120+
Console.CursorVisible = false;
121+
break;
122+
case PopstationEventEnum.DecompressStart:
123+
Write(@event, $"Decompressing file {value} - ");
124+
_cursorYPos = Console.CursorTop;
125+
Console.CursorVisible = false;
126+
break;
127+
case PopstationEventEnum.ConvertComplete:
128+
case PopstationEventEnum.ExtractComplete:
129+
case PopstationEventEnum.WriteComplete:
130+
case PopstationEventEnum.DecompressComplete:
131+
_charsToDelete = 0;
132+
Console.CursorVisible = true;
133+
Console.WriteLine();
134+
break;
135+
136+
case PopstationEventEnum.ConvertProgress:
137+
case PopstationEventEnum.ExtractProgress:
138+
case PopstationEventEnum.WriteProgress:
139+
//Console.SetCursorPosition(0, _cursorYPos);
140+
if (DateTime.Now.Ticks - _lastTicks > 100000)
141+
{
142+
Overwrite($"{Math.Round(Convert.ToInt32(value) / (double)_total * 100, 0) }%");
143+
_lastTicks = DateTime.Now.Ticks;
144+
}
145+
break;
146+
case PopstationEventEnum.DecompressProgress:
147+
//Console.SetCursorPosition(0, _cursorYPos);
148+
if (DateTime.Now.Ticks - _lastTicks > 100000)
149+
{
150+
Overwrite($"{value}%");
151+
_lastTicks = DateTime.Now.Ticks;
152+
}
153+
break;
154+
}
155+
}
156+
157+
private string TimeStamp(PopstationEventEnum @event)
158+
{
159+
if (_logLevel < 4) return string.Empty;
160+
var currentTime = DateTime.Now;
161+
switch (@event)
162+
{
163+
case PopstationEventEnum.ConvertProgress:
164+
case PopstationEventEnum.ExtractProgress:
165+
case PopstationEventEnum.WriteProgress:
166+
case PopstationEventEnum.DecompressProgress:
167+
break;
168+
default:
169+
return $"[{currentTime.Hour:00}:{currentTime.Minute:00}:{currentTime.Second:00}]: ";
170+
}
171+
return string.Empty;
172+
}
173+
174+
private void WriteLine(PopstationEventEnum @event, string text)
175+
{
176+
Console.WriteLine(TimeStamp(@event) + text);
177+
}
178+
179+
private void Write(PopstationEventEnum @event, string text)
180+
{
181+
Console.Write(TimeStamp(@event) + text);
182+
}
183+
184+
private void Overwrite(string text)
185+
{
186+
Console.Write(new string('\b', _charsToDelete));
187+
Console.Write(text);
188+
_charsToDelete = text.Length;
189+
}
190+
191+
}
192+
}

PSXPackager/EventHandler.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using Popstation;
3+
4+
namespace PSXPackager
5+
{
6+
public class EventHandler: IEventHandler
7+
{
8+
public Action OverwriteAllSelected { get; set; }
9+
public Action CancelSelected { get; set; }
10+
public bool Cancelled { get; set; }
11+
public bool OverwriteIfExists { get; set; }
12+
13+
public ActionIfFileExistsEnum ActionIfFileExists(string arg)
14+
{
15+
while (true)
16+
{
17+
Console.CursorVisible = true;
18+
Console.Write($"\r\n{arg} alreasy exists. Overwrite? (Y)es|(N)o|(A)ll|(C)ancel ");
19+
var key = Console.ReadKey();
20+
21+
Console.WriteLine();
22+
23+
switch (key.Key)
24+
{
25+
case ConsoleKey.Y:
26+
27+
return ActionIfFileExistsEnum.Overwrite;
28+
case ConsoleKey.N:
29+
return ActionIfFileExistsEnum.Skip;
30+
case ConsoleKey.A:
31+
OverwriteIfExists = true;
32+
OverwriteAllSelected?.Invoke();
33+
return ActionIfFileExistsEnum.OverwriteAll;
34+
case ConsoleKey.C:
35+
Cancelled = true;
36+
CancelSelected?.Invoke();
37+
return ActionIfFileExistsEnum.Abort;
38+
}
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)