ilikecats567 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

IDE should use SHGetFolderPath() to locate preferences file on Windows. #949

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?
IDE should use HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS 
NT\CurrentVersion\ProfileList\<profileID>\ProfileImagePath value from the 
registry when storing preferences. Currently it seems to use Windows installed 
\Users folder, but this could be different. 

Why?
Current behavior is not correct. E.g. if user have profile data stored in 
different place (e.g. this could be he case when using small size SSD with 
Windows installed and store user data on different drive) the preferences will 
be stored in windows installed drive. This could be problematic when using 
Visual Micro that search preferences using ProfileImagePath value. Using this 

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?
Mose users probably don't notice any change. Migration process can be 
implemented. 

Original issue reported on code.google.com by mariusz....@gmail.com on 6 Jun 2012 at 8:18

GoogleCodeExporter commented 9 years ago
Hmm, are you running into problems because of the current setting?  It's always 
hard to know what's going to happen when you change things like this, so it 
probably only makes sense if people are having problems with the current 
behavior.

Looking at Processing, they take yet another approach to this 
(http://code.google.com/p/processing/source/browse/trunk/processing/app/src/proc
essing/app/windows/Platform.java):

  // looking for Documents and Settings/blah/Application Data/Processing
  public File getSettingsFolder() throws Exception {
    // HKEY_CURRENT_USER\Software\Microsoft
    //   \Windows\CurrentVersion\Explorer\Shell Folders
    // Value Name: AppData
    // Value Type: REG_SZ
    // Value Data: path

    //String keyPath =
    //  "Software\\Microsoft\\Windows\\CurrentVersion" +
    // "\\Explorer\\Shell Folders";
    //String appDataPath =
    //  Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "AppData");

    // Fix for Issue 410
    // Java 1.6 doesn't provide a good workaround (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6519127)
    // Using JNA and SHGetFolderPath instead.

    char[] pszPath = new char[Shell32.MAX_PATH]; // this will be contain the path if SHGetFolderPath is successful
    int hResult = Shell32.INSTANCE.SHGetFolderPath(null, Shell32.CSIDL_APPDATA, null, Shell32.SHGFP_TYPE_CURRENT, pszPath);

    if (Shell32.S_OK != hResult){ 
      throw new Exception("Problem city, population your computer");
    }

    String appDataPath = new String(pszPath);
    int len = appDataPath.indexOf("\0");
    appDataPath = appDataPath.substring(0, len);

    // DEBUG
    //throw new Exception("win: " + appDataPath);
    return new File(appDataPath, "Processing");
  }

There's more detail in their issue: 
http://code.google.com/p/processing/issues/detail?id=410.  This seems like it's 
probably the best way to solve this problem, if people are having one.

Original comment by dmel...@gmail.com on 17 Jul 2012 at 3:24