Skip to content

Commit

Permalink
Simplify error handling
Browse files Browse the repository at this point in the history
We already pre-check for FileInUse, so if we end up with an exception anyway we shouldn't make any assumptions as to the actual cause.

#531
  • Loading branch information
cyanfish committed Jan 26, 2025
1 parent afca464 commit 76a8154
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
12 changes: 0 additions & 12 deletions NAPS2.Lib/Pdf/SavePdfOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ public bool Start(string fileName, Placeholders placeholders, ICollection<Proces
{
InvokeError(MiscResources.DontHavePermission, ex);
}
catch (IOException ex)
{
if (File.Exists(subFileName) && !FileSystemHelper.IsDiskFullException(ex))
{
InvokeError(MiscResources.FileInUse, ex);
}
else
{
Log.ErrorException(MiscResources.ErrorSaving, ex);
InvokeError(MiscResources.ErrorSaving, ex);
}
}
catch (Exception ex)
{
Log.ErrorException(MiscResources.ErrorSaving, ex);
Expand Down
7 changes: 0 additions & 7 deletions NAPS2.Sdk/Util/FileSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

internal static class FileSystemHelper
{
private const int HR_ERROR_HANDLE_DISK_FULL = unchecked((int) 0x80070027);
private const int HR_ERROR_DISK_FULL = unchecked((int) 0x80070070);

/// <summary>
/// Creates the parent directory for the provided path if needed.
/// </summary>
Expand All @@ -18,10 +15,6 @@ public static void EnsureParentDirExists(string filePath)
}
}

// TODO: Can we detect this on Linux/Mac?
public static bool IsDiskFullException(IOException exception) =>
exception.HResult is HR_ERROR_DISK_FULL or HR_ERROR_HANDLE_DISK_FULL;

public static bool IsFileInUse(string filePath, out Exception? exception)
{
if (File.Exists(filePath))
Expand Down

0 comments on commit 76a8154

Please sign in to comment.