Comments (7)
My guess is that the shGetPathFromIDList
is not writing the null terminator to buf
.
So, because you're reusing the buffer for "display name" and the result ("full path"), you were getting F:\
(the "full path") partially overwriting ScanDisk (F:\)
(the "display name"). Or something like that.
The reason it only failed for root folders, is that the those are probably the only ones where "full path" is shorter than "display name". The fix works, because buf
is zero initialized and big enough to hold the result (MAX_PATH
) so shGetPathFromIDList
not writing a null terminator should not be a problem. And I don't see a point in trying to get the "display name" any way?
If it does work (I didn't test it) please do a PR with the fix for @gen2brain to consider?
from dlgs.
Try removing/commenting this line:
Line 90 in f2c7498
And replacing:
Line 96 in f2c7498
With:
return stringFromUtf16Ptr(&buf[0]), true
from dlgs.
Thank you for your response, @ncruces. If I understood you correctly, then you suggested to change the function dirDialog()
to look like this (?):
// dirDialog displays directory dialog.
func dirDialog(title string) (string, bool) {
var bi browseinfoW
buf := make([]uint16, maxPath)
t, _ := syscall.UTF16PtrFromString(title)
bi.title = t
// Commented this line
// bi.displayName = &buf[0]
bi.flags = bifEditBox | bifNewDialogStyle
lpItem := shBrowseForFolder(&bi)
ok := shGetPathFromIDList(lpItem, &buf[0])
if ok {
// Replaced this line
//return stringFromUtf16Ptr(bi.displayName), true
return stringFromUtf16Ptr(&buf[0]), true
}
return "", false
}
I don't understand why changing these two lines should make a difference? Nethertheless, I tried it with your changes and I still get an incorrect path when I select a USB device (same error as described in the first message of this issue).
Edit: my mistake, Go did not recompile the changes in my local copy of dlgs. It actually works! Now, I can select the root of USB devices as well as child directories of USB devices and dlgs returns the correct file / directory path. Would you mind explaining to me why passing the pointer directly to stringFromUtf16Ptr
works? Can this pointer / buffer only be read once?
from dlgs.
Thank you. I agree with you, the "display name" is not being used nor returned from this function, so it's useless.
from dlgs.
@philenius Can I merge PR? I cannot test on Windows.
from dlgs.
I think so, yes. This is how I do it in my lib:
https://github.com/ncruces/zenity/blob/master/file_windows.go#L306
Also thanks, your code helped me a lot with the text entry dialog (and will help me a lot with the list dialog)!
from dlgs.
@gen2brain sorry for my delayed response, yes you can merge the PR (I see that you already did so, thank you). I can only prove that my changes work at least on my Windows 10 machine. Here's a GIF where I select the root of a USB device subsequently a child directory. Both use cases work as expected:
from dlgs.
Related Issues (16)
- Color selector doesn't work HOT 5
- Save File dialog HOT 1
- FileMulti can only choose 10 files cant more HOT 4
- File filters not working on MacOS HOT 1
- Message Dialogs HOT 1
- any way to make the dialog on top ? HOT 2
- Any plans on having a CLI? HOT 2
- Causes False Positive Windows 10 HOT 7
- class already exits error HOT 5
- Error handling is bogus
- MacOS not working HOT 5
- Notifications HOT 1
- Width dialog box HOT 6
- Print dialog
- Entry bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dlgs.