Giter Site home page Giter Site logo

Comments (7)

ncruces avatar ncruces commented on May 18, 2024 1

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.

ncruces avatar ncruces commented on May 18, 2024

Try removing/commenting this line:

bi.displayName = &buf[0]

And replacing:

return stringFromUtf16Ptr(bi.displayName), true

With:

return stringFromUtf16Ptr(&buf[0]), true 

from dlgs.

philenius avatar philenius commented on May 18, 2024

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.

philenius avatar philenius commented on May 18, 2024

Thank you. I agree with you, the "display name" is not being used nor returned from this function, so it's useless.

from dlgs.

gen2brain avatar gen2brain commented on May 18, 2024

@philenius Can I merge PR? I cannot test on Windows.

from dlgs.

ncruces avatar ncruces commented on May 18, 2024

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.

philenius avatar philenius commented on May 18, 2024

@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:

dlgs

from dlgs.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.