Skip to content

Handle invalid CWD when creating file dialogs#840

Open
nikoskalogridis wants to merge 2 commits into
cyanfish:masterfrom
nikoskalogridis:fix/savefiledialog-invalid-cwd-crash
Open

Handle invalid CWD when creating file dialogs#840
nikoskalogridis wants to merge 2 commits into
cyanfish:masterfrom
nikoskalogridis:fix/savefiledialog-invalid-cwd-crash

Conversation

@nikoskalogridis

Copy link
Copy Markdown

Summary

  • fix a crash when SaveFileDialog is created while the process current working directory has been deleted/unmounted
  • proactively validate and repair current directory before creating file dialogs
  • retry SaveFileDialog construction after setting a safe fallback directory
  • apply the same pre-check before OpenFileDialog creation

Root cause

On Linux/GTK, constructing Eto file dialogs may call Environment.CurrentDirectory (GetCwd). If the original working directory no longer exists, this throws System.IO.FileNotFoundException and the dialog never opens.

Changes

  • NAPS2.Lib/EtoForms/EtoDialogHelper.cs
    • add EnsureCurrentDirectoryIsAccessible()
    • add SetSafeCurrentDirectory() with fallback order:
      1. Environment.SpecialFolder.UserProfile
      2. Path.GetTempPath()
    • add CreateSaveFileDialog() wrapper that catches FileNotFoundException, resets CWD, and retries
    • use CreateSaveFileDialog() in PromptToSavePdfOrImage, PromptToSavePdf, and PromptToSaveImage
    • call EnsureCurrentDirectoryIsAccessible() in PromptToImport

Validation

  • file diagnostics for EtoDialogHelper.cs: clean
  • full build not run in this environment (dotnet CLI unavailable)

Fixes #839

@nikoskalogridis nikoskalogridis marked this pull request as ready for review June 23, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SaveFileDialog crashes when current working directory is deleted/unmounted at runtime

1 participant