edvin / fxlauncher

Auto updating launcher for JavaFX Applications
Apache License 2.0
713 stars 110 forks source link

Working Directory #66

Closed TravFitz closed 7 years ago

TravFitz commented 7 years ago

Hi Guys, how would I go about adjusting the working directory.

Our App starts well using fxlauncher (which is working well to download the files initially but fails with a NullPointer during the fxLauncher.LibarayFile.needsUpdate when checking for updates or new files in a folder inside of the primary folder when opening it after the initial download has been done) however is there any way that we can set the working Directory for the application, what I mean is if I call the fxlauncher.jar from outside of the folder that I need to run files in it is unable to run an executable file that we require to run as well.

it tells me that the file cannot be found (as it is looking for the file in the current directory that called fxlauncher, if running it from cmd).

for example C:\Windows> java -jar C:\users\user\appdata\local\appfolder\fxlauncher.jar --app=http:\somedomain.com\app.xml --uri=http:\somedomain.com\appfolder\

calling this means that the working directory is C:\Windows and when fxlauncher starts it tries to find required external files to run in C:\Windows\resources (which doesn't exist) for example.

ronsmits commented 7 years ago

@TravFitz I have another windows issue to investigate this weekend, I will look at this one too

ronsmits commented 7 years ago

@TravFitz which version of fxlauncher are you using?

TravFitz commented 7 years ago

sorry for the late reply @ronsmits its been the Easter Long weekend here in Oz, I am using version 1.0.17

TravFitz commented 7 years ago

@ronsmits I have worked out what the bracketed issue was about the NullPointer error in needsUpdate, it was because I was not aware that the checksum was non-optional, had a few issues doing the conversion from Adler32 hex to Long but got it in the end, if anyone is having issues with that too, this link has an application that will convert any file you choose to Adler32 hex, you will just need to do the hex to long conversion yourself (lots of resources online for that though) JavaHash 1.1

edvin commented 7 years ago

@TravFitz I'm confused? Do you create the app.xml manifest manually? The CreateManifest functionality already takes care of that?

TravFitz commented 7 years ago

@edvin yeah I did create it manually. I wasn't aware that it would create a manifest, whoops. oh well its setup now. I got the working directory thing sorted out as well, I added if (OS.current.toString().equals("win")) { if (superLauncher.getManifest().cacheDir.contains("USERLIB/")) { System.setProperty("user.dir", superLauncher.getManifest().cacheDir.replace("USERLIB/", System.getenv("LocalAppData")+"\\")); } else { System.setProperty("user.dir", superLauncher.getManifest().cacheDir); } } else if (OS.current.toString().equals("linux")) { if (superLauncher.getManifest().cacheDir.contains("USERLIB/")) { System.setProperty("user.dir", superLauncher.getManifest().cacheDir.replace("USERLIB", System.getenv("user.home"))); } else { System.setProperty("user.dir", superLauncher.getManifest().cacheDir); } }

into the launchAppFromManifest just before app.init(); this changes the working dir to the directory specified in the app.xml I still needed to add a map to my interface in my app to link the working directory and add that before file calls, but at least its dynamic. This way I can put fxlauncher in a separate location to the main app and still be able to open the main app and its resources, or potentially use it to call multiple applications in different folders and different app.xml's without fxlauncher needing to be put in every folder.