Set NWjs Open File Dialog Path

Get help using Construct 2

Post » Fri Jul 29, 2016 3:48 pm

Does anyone know a way to set the NWjs Open File Dialog path, so that the dialog opens in a particular folder?

What for...? I would like to establish a database for game-save objects and would like the player to select one for import (or navigate to somewhere else on their drive, if they wish). The default game-save folder will be buried in a not-easy-to-find folder at c:\Users\Name\GameTitle\Data - thus I would like the File Dialog to open in the Data folder if possible. There's some info on GitHub but I don't see a way to achieve this through c2.

Is this possible or am I just dreaming....?

Thanks.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,205
Reputation: 43,832

Post » Fri Jul 29, 2016 3:54 pm

Edit - I had a thought - I could use the Browser Object to open a window at the save location URL, for the player to then drag/drop the file into the NWjs window. This is a solution, but I consider it a bit untidy as the rest of the game uses Open dialog windows (no drag/drop), but using this will be better than nothing if no other solutions can be found.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,205
Reputation: 43,832

Post » Fri Jul 29, 2016 4:15 pm

Use the browser object to execute some javascript:
"document.getElementById('c2nwOpenFileDialog').setAttribute('nwworkingdir', 'your path goes here');"
That will set the open file path.

Make sure it is before you call to open the file dialog.

note: you may want to use the application path or user path provided by the nw.js object expression, to ensure it is correct across all platforms (mac,windows,linux).. since the path will be different for each I think.
edit: I think the app/user path from nw.js object only work when project is exported.
B
42
S
19
G
65
Posts: 1,097
Reputation: 37,906

Post » Fri Jul 29, 2016 5:48 pm

@Prominent - thank you very much! However, I cannot get it to work in my W10... Both export and preview give similar problems. I put the variable NWjs.UserFolder in the "your path goes here" position (capx) but the open dialog location is incorrect (I am not sure if the apostrophes are required, but with or without them results in an incorrect location being opened).
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,205
Reputation: 43,832

Post » Wed Dec 07, 2016 7:23 pm

Sorry to bring this back from the dead, but @Colludium, did you ever get this to work?
B
12
S
1
Posts: 8
Reputation: 473

Post » Wed Dec 07, 2016 7:50 pm

@BipolarMike - sorry to say that I gave up because I couldn't figure a way of setting the opening folder dialog. Instead I opted for asking the player to drop a file into the game window instead. Won't work for kiosk mode though!!
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,205
Reputation: 43,832

Post » Wed Dec 07, 2016 9:11 pm

Yeah file dropping is what I've settled on for now too, thanks :)
B
12
S
1
Posts: 8
Reputation: 473


Return to How do I....?

Who is online

Users browsing this forum: eochranek, Unconnected and 20 guests