Skip to content

Commit 2e29185

Browse files
Refactor exception handling for InvalidImageException, add command-line hint for file paths, and bump version to 1.0.3.
1 parent 0bd4b78 commit 2e29185

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SimpleXisoDrive;
2+
3+
public class InvalidImageException : Exception
4+
{
5+
public InvalidImageException(string message, Exception? inner = null)
6+
: base(message, inner)
7+
{
8+
}
9+
}

SimpleXisoDrive/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ public static async Task<int> Main(string[] args)
8989
Console.ForegroundColor = ConsoleColor.Red;
9090
var errorMsg = $"ISO file not found at '{isoPath}'";
9191
await Console.Error.WriteLineAsync($"Error: {errorMsg}");
92+
93+
// Add a hint for common command-line mistakes
94+
if (args.Length > 2 && !isoPath.Contains(' '))
95+
{
96+
Console.ForegroundColor = ConsoleColor.Yellow;
97+
await Console.Error.WriteLineAsync("Hint: If your file path contains spaces, ensure it is wrapped in \"quotes\".");
98+
}
99+
92100
Console.ResetColor();
93101

94102
// Report this to the API so the developer knows the path was invalid
@@ -143,7 +151,7 @@ public static async Task<int> Main(string[] args)
143151

144152
return 0;
145153
}
146-
catch (VfsContainer.InvalidImageException ex)
154+
catch (InvalidImageException ex)
147155
{
148156
Console.ForegroundColor = ConsoleColor.Red;
149157
await Console.Error.WriteLineAsync($"Error: {ex.Message}");
@@ -176,10 +184,10 @@ public static async Task<int> Main(string[] args)
176184

177185
await ErrorLogger.LogErrorAsync(ex, "Fatal error in Main");
178186

179-
// Always wait for key press if drag-and-drop
180-
if (isDragAndDrop || args.Length == 1)
187+
// If we are in a context where the window might disappear (Drag & Drop or single arg)
188+
if (isDragAndDrop || args.Length <= 1)
181189
{
182-
DebugLogger.WriteLine("\nPress any key to exit.");
190+
Console.WriteLine("\nPress any key to exit.");
183191
Console.ReadKey();
184192
}
185193

SimpleXisoDrive/SimpleXisoDrive.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<Nullable>enable</Nullable>
99
<ApplicationIcon>icon\xiso.ico</ApplicationIcon>
1010
<IsPackable>false</IsPackable>
11-
<AssemblyVersion>1.0.2</AssemblyVersion>
12-
<FileVersion>1.0.2</FileVersion>
11+
<AssemblyVersion>1.0.3</AssemblyVersion>
12+
<FileVersion>1.0.3</FileVersion>
1313
<NeutralLanguage>en</NeutralLanguage>
1414
<DebugType>embedded</DebugType>
1515
<DebugSymbols>true</DebugSymbols>

SimpleXisoDrive/VfsContainer.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public VfsContainer(string isoPath)
3737
catch (Exception ex)
3838
{
3939
_isoSt.Dispose();
40+
4041
// Exception is re-thrown and caught by Program.cs, which handles the API reporting.
42+
if (ex is InvalidImageException)
43+
{
44+
throw;
45+
}
46+
4147
throw new InvalidImageException($"Failed to read Xbox ISO: {ex.Message}", ex);
4248
}
4349
}
@@ -291,12 +297,4 @@ public void Dispose()
291297
_isoSt.Dispose();
292298
GC.SuppressFinalize(this);
293299
}
294-
295-
public class InvalidImageException : Exception
296-
{
297-
public InvalidImageException(string message, Exception? inner = null)
298-
: base($"{message}. This might be an unsupported ISO format.", inner)
299-
{
300-
}
301-
}
302300
}

SimpleXisoDrive/XDVDFs/VolumeDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static VolumeDescriptor ReadFrom(IsoSt isoSt)
148148
}
149149

150150
// If we reach here, sectors were readable but failed validation
151-
throw new VfsContainer.InvalidImageException(
151+
throw new InvalidImageException(
152152
"Volume descriptor not found at sector 0 or 32 (including game partition offset). " +
153153
"This doesn't appear to be a valid Xbox ISO file."
154154
);

0 commit comments

Comments
 (0)