I need to be able to find the location of the windows 7/vista "saved games" folder and I want to do it properly so my app will not have localization problems. I have used System.getenv and System.getProperty to find the locations of every other folder that I need but neither are able to get this folder. I defiantly need to find it somehow, if it's not possible in java does anyone know a way to get it using some kind of script called by a java app or any other technique?
I am not a Windoze user, so I don't know what this "saved games" folder is.
Is it a standard folder created by the OS? Does it have the same location for all users? Something like user.home/saved games?
In English versions of windows 7 its located in the personal folder, "C:\Users\[USERNAME]\Saved Games". I can get the path to the personal folder no problem but the trouble is it's possible to change the location of this folder to anything the user wants and it will have a different name in other languages.
While typing this I thought of checking the registry, upon looking I found the file paths for all windows "special folders" stored under [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]. I found this previous topic Read the Windows registry from java... which covers reading the registry in JAVA so hopefully that's problem solved. I'll try it and post results in the morning.
There are no new questions, but there may be new answers.
posted 9 years ago
If you google anything with the words "saved games" included you find a million and one people saying "Where do I find the saved games for (insert game here)". This windows special folder is not as easy to find as the other windows special folders in java either so searching for how to find another one also yielded me no usable results.
I've edited this post to be less rude. I apologize for before, I was tired and not thinking.
If you search for the folder in the registry, you're tied to Windows already. There should be a Windows function to obtain any of the special folders (I assume identified by some integer constant), which probably would be preferable, as it would save you from interpreting the registry (there are endless possible setups of Windows, and in some of them the value could be not there, for example). You might search MSDN for such function and call it via JNA.
Martin Vajsar wrote:There should be a Windows function to obtain any of the special folders (I assume identified by some integer constant), which probably would be preferable, as it would save you from interpreting the registry (there are endless possible setups of Windows, and in some of them the value could be not there, for example). You might search MSDN for such function and call it via JNA.
There are a few: SHGetSpecialFolder and its successor SHGetFolderPath are available since Windows 2000, and they both use the CSIDL constants. However, the saved games folder wasn't a special folder until Vista. It introduced SHGetKnownFolderPath (which I linked to earlier) which uses KNOWNFOLDERID instead of CSIDL. This type adds a few more special folders, one of which is the save games folder.
Sorry if I was rude last night. long day coupled with lack of sleep and pet cat and dog chasing each other all day must have left me short tempered
I'll edit the post
I know the folder is only on vista/7, my app is multi platrom as It will run on xp/vista/7 and mac as well. I check for the os version and was going to check the registry behind an if statement only if it were windows vista or 7. I already use a different method in my code to check the special folders for xp, that part of my app is finished.
I had already found an msdn page on special folders here but I thought that information was only accessible through .net or C# and if so I thought checking the registry would be better as it allows me to stay pure java.
This registry key should always be there for windows 7 and vista as it is a windows system folder now.
Which approach is better registry reading vs JNA? Never heard of JNA before now...
You don't need .NET or C#; regular C in JNI is also possible. JNA is similar to JNI, except it lets you write the native code in Java equivalents. It doesn't require you to write and compile a DLL (or .so for Unix) file.
Accessing the registry is also possible of course. It wouldn't even surprise me that the registry and the return value of SHGetKnownFolderPath are related.
looks like I need JNA to read the registry as well, shame, it makes my apps file size 10 times bigger than it was including the library...
Since this is the case I'll just use SHGetKnownFolderPath. Is there an example anywhere of JNA using SHGetKnownFolderPath? anywhere? I have not been programming very long and am only comfortable coding in java atm so I'm not sure how to implement this.
Just thought I'd mention double fantastic. I was also having trouble finding the install directories of several pieces of non windows software as well. I changed the registry key this solution points to the the keys for that software and it works. Not only that but I pointed it at a bunch of random registry keys and it gave me their values as well
Edit just read the linked article about this method, from what I understood of it my use of this method shouldn't cause any problem but in case it does I should catch all errors and if this method fails to find the directory I can prompt the user to input the directory in a dialogue if its needed.
Thanks again for all the help
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop