Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Win32 namespaced paths #32

Closed
parasyte opened this issue Dec 14, 2021 · 2 comments · Fixed by #33
Closed

Not working with Win32 namespaced paths #32

parasyte opened this issue Dec 14, 2021 · 2 comments · Fixed by #33

Comments

@parasyte
Copy link
Contributor

Paths with a Win32 namespace look like this: \\?\C:\windows. See https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces for details. Paths of this form are returned by Path::canonicalize() and fs::canonicalize().

When these namespaced paths are used with FileDialog::set_directory(), the dialog opens in the current working directory or the user's documents instead of the requested directory (at least in 0.6.0. The dialog fails to open at all in 0.5.1!)

For instance, this patch:

diff --git a/examples/simple.rs b/examples/simple.rs
index fca64c2..8f7105c 100644
--- a/examples/simple.rs
+++ b/examples/simple.rs
@@ -1,11 +1,9 @@
 #[cfg(not(target_arch = "wasm32"))]
 fn main() {
-    let path = std::env::current_dir().unwrap();
-
     let res = rfd::FileDialog::new()
         .add_filter("text", &["txt", "rs"])
         .add_filter("rust", &["rs", "toml"])
-        .set_directory(&path)
+        .set_directory(r"\\?\C:\windows")
         .pick_files();

     println!("The user choose: {:#?}", res);

Should open the dialog in the C:\windows directory when running the simple example on Windows. Remove the \\?\ namespace prefix and it works as expected.

@PolyMeilex
Copy link
Owner

So that would mean that IFileDialog::SetFolder does not support namespaced paths.

To be honest, I did not know about existence of namespaced paths before, so I'm not sure how to proceed with this. Can we just strip those?

@parasyte
Copy link
Contributor Author

I am stripping the prefix to make it work in my app. I can submit a PR.

I also noticed SHCreateItemFromParsingName returns an error with these paths, but it is useless beyond "there was an error".

Error {
    code: 0x80070057,
    message: "The parameter is incorrect.",
    win32_error: 87,
},

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 a pull request may close this issue.

2 participants