My documents path

Started by mot, September 27, 2006, 15:19:53

Previous topic - Next topic

mot

Does LWJGL provide an interface to call SHGetSpecialFolderLocation? If it doesn't, is it going to? It would be very useful; I don't see any other way to get the location of My documents (the Java user.home property only points to \Documents and Settings\user\)

Or is there an easy way to call the native API without creating my own glue DLLs?

Thanks...

Matzon

no current way. Doesn't make sense in mac or linux environments anyway.
perhaps you can check some user properties set by the VM ?

wolf_m

http://jdj.sys-con.com/read/35688.htm

The correct DLL for Win2000 and above is shfolder.dll / system32.dll, for previous versions you'll have to ship shfolder.dll with your app.

See also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shgetfolderpath.asp

By the way, I tried to use the native method and didn't succeed, so I assume you'll have to know how this whole JNI mumbo-jumbo works.

I've always got a
java.lang.UnsatisfiedLinkError: SHGetFolderPath

I probably used the wrong parameter types / return type. Dunno.

Edit: To get you started, you need to determine whether your program is running on windows. Then, you have to load the correct dll. After that, you have to use the native method in some way to figure out the correct path.
/*
 * Created on 28.09.2006 by wolf_m
 */
package nativeTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * @author wolf_m
 */
public class TestPath {

/*

Seems to be crap:	
	private static native void SHGetFolderPath(
			int hwndOwner, int folder, int hToken, int Flags, char[] strPath);

*/

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(System.getProperty("os.name").toLowerCase().contains("windows")){
			String windir = "";
			try {
				BufferedReader br = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("cmd /c echo %WINDIR%").getInputStream()));
				windir += br.readLine();
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Runtime.getRuntime().load(windir+"\\system32\\shell32.dll");
			String path="";

/*

Seems to be nonsense:
			SHGetFolderPath(0, 5, 0, 0 , path.toCharArray());
			System.out.println(path);

*/
		}
		
	}

}

llama

Hm... doesn't the Swing file dialog usually open in My Documents if you don't specify anything else? Maybe you can grab the path somehow without opening the dialog.

wolf_m

I recall that default path being \Documents and Settings\user\