NickThissen
Dec 10th, 2009, 03:42 PM
Hey,
I'm creating a game in Java and during distribution (installation) I copy a directory of level files (which can be edited by the user also; hence I cannot embed them or anything) to the installation directory. The directory is called "levels", so if the executable* is in "C:\Program Files\Game\game.exe" then the directory is at "C:\Program Files\Game\levels\...".
When the game loads, I want to load one of those levels. But, the problem is that I don't know their absolute paths.
From within the IDE, I have been using relative paths (starting the path at "\levels") and this worked fine, but it is no longer working after compiling and installing the game.
When I print the paths used, from within the IDE it tells me "C:\NetbeansProjects\...", the correct path. But after installation, running the executable*, it starts at "levels" so is incorrect.
I searched for this but the only thing I found that seemed useful was using System.getProperty like this:
String exePath = System.getProperty("user.dir");
Now I got a similar, but different problem. In the IDE it tells me the correct path to the folder. Also, when I browse to the installed executable file and run that manually, it also returns the correct path. But, when I run the executable from a shortcut (from the Start menu actually, a shortcut anywhere else works fine), it suddenly tells me "C:\Windows\System32" ???
* This may be important. I wanted to use Inno Setup to create the installer, and to get it to work properly I decided to convert the JAR file to an EXE file, using Launch4J (if anyone knows it..). Hence I'm talking about executable and not about jar files.
Now, in Inno Setup I have the following code in the script which I believe takes care of creating a start menu entry:
[Icons]
Name: "{group}\GameName"; Filename: "{app}\GameName.exe"
It creates the start menu entry fine, and runs the game, but for some reason the getProperty("user.dir") suddenly returns the System32 folder... Why is that? How can I get around this?
I'm creating a game in Java and during distribution (installation) I copy a directory of level files (which can be edited by the user also; hence I cannot embed them or anything) to the installation directory. The directory is called "levels", so if the executable* is in "C:\Program Files\Game\game.exe" then the directory is at "C:\Program Files\Game\levels\...".
When the game loads, I want to load one of those levels. But, the problem is that I don't know their absolute paths.
From within the IDE, I have been using relative paths (starting the path at "\levels") and this worked fine, but it is no longer working after compiling and installing the game.
When I print the paths used, from within the IDE it tells me "C:\NetbeansProjects\...", the correct path. But after installation, running the executable*, it starts at "levels" so is incorrect.
I searched for this but the only thing I found that seemed useful was using System.getProperty like this:
String exePath = System.getProperty("user.dir");
Now I got a similar, but different problem. In the IDE it tells me the correct path to the folder. Also, when I browse to the installed executable file and run that manually, it also returns the correct path. But, when I run the executable from a shortcut (from the Start menu actually, a shortcut anywhere else works fine), it suddenly tells me "C:\Windows\System32" ???
* This may be important. I wanted to use Inno Setup to create the installer, and to get it to work properly I decided to convert the JAR file to an EXE file, using Launch4J (if anyone knows it..). Hence I'm talking about executable and not about jar files.
Now, in Inno Setup I have the following code in the script which I believe takes care of creating a start menu entry:
[Icons]
Name: "{group}\GameName"; Filename: "{app}\GameName.exe"
It creates the start menu entry fine, and runs the game, but for some reason the getProperty("user.dir") suddenly returns the System32 folder... Why is that? How can I get around this?