# HG changeset patch # User jrice@netbeans.org # Date 1205509781 0 # Node ID 26cd68076a26cbb0850fa680394b4e8294744df6 # Parent ad43c5a1848927ff1452d849721b1a8cff81fa86 #126803: Username setting on Windows diff -r ad43c5a18489 -r 26cd68076a26 mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java --- a/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Fri Mar 14 00:29:37 2008 +0100 +++ b/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Fri Mar 14 15:49:41 2008 +0000 @@ -52,6 +52,7 @@ import java.util.Properties; import java.util.Properties; import java.util.logging.Level; import org.ini4j.Ini; +import org.netbeans.modules.mercurial.HgModuleConfig; import org.netbeans.modules.mercurial.Mercurial; import org.openide.filesystems.FileUtil; import org.openide.util.Utilities; @@ -83,18 +84,22 @@ public class HgConfigFiles { /** The repository directory if this instance is for a repository */ private File dir; - private static final String WINDOWS_USER_APPDATA = getAPPDATA(); - private static final String WINDOWS_CONFIG_DIR = WINDOWS_USER_APPDATA + "\\Mercurial"; // NOI18N - private static final String WINDOWS_GLOBAL_CONFIG_DIR = getGlobalAPPDATA() + "\\Mercurial"; // NOI18N public static final String HG_RC_FILE = "hgrc"; // NOI18N public static final String HG_REPO_DIR = ".hg"; // NOI18N - + + private static final String WINDOWS_HG_RC_FILE = "Mercurial.ini"; // NOI18N + private static final String WINDOWS_DEFAULT_MECURIAL_INI_PATH = "C:\\Mercurial\\Mercurial.ini"; // NOI18N + /** * Creates a new instance */ private HgConfigFiles() { // get the system hgrc file - hgrc = loadFile(HG_RC_FILE); + if(Utilities.isWindows()) { + hgrc = loadFile(WINDOWS_HG_RC_FILE); + }else{ + hgrc = loadFile(HG_RC_FILE); + } } /** @@ -110,8 +115,9 @@ public class HgConfigFiles { } public HgConfigFiles(File file) { - dir = file; - hgrc = loadFile(file, HG_RC_FILE); + dir = file; + // /.hg/hgrc on all platforms + hgrc = loadFile(file); } public void setProperty(String name, String value) { @@ -230,7 +236,7 @@ public class HgConfigFiles { if (dir == null) { hgrc = loadFile(HG_RC_FILE); } else { - hgrc = loadFile(dir, HG_RC_FILE); + hgrc = loadFile(dir); } } @@ -259,23 +265,10 @@ public class HgConfigFiles { } /** - * Returns the path for the Mercurial configuration directory - * - * @return the path - * - */ - public static String getUserConfigPath() { - if(Utilities.isUnix()) { - String path = System.getProperty("user.home") ; // NOI18N - return path + "/."; // NOI18N - } else if (Utilities.isWindows()){ - return WINDOWS_CONFIG_DIR + "/"; // NOI18N - } - return ""; // NOI18N - } - - private Ini loadFile(File dir, String fileName) { - String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + fileName; // NOI18N + * Loads Repository configuration file /.hg/hgrc on all platforms + * */ + private Ini loadFile(File dir) { + String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + HG_RC_FILE; // NOI18N File file = FileUtil.normalizeFile(new File(filePath)); Ini system = null; try { @@ -293,11 +286,11 @@ public class HgConfigFiles { return system; } /** - * Loads the configuration file + * Loads user and system configuration files * The settings are loaded and merged together in the folowing order: *
    - *
  1. The per-user configuration file, i.e ~/.hgrc - *
  2. The system-wide file, i.e. /etc/mercurial/hgrc + *
  3. The per-user configuration file, Unix: ~/.hgrc, Windows: %USERPROFILE%\Mercurial.ini + *
  4. The system-wide file, Unix: /etc/mercurial/hgrc, Windows: Mercurial_Install\Mercurial.ini *
* * @param fileName the file name @@ -335,7 +328,6 @@ public class HgConfigFiles { } return system; } - /** * Merges only sections/keys/values into target which are not already present in source * @@ -362,6 +354,22 @@ public class HgConfigFiles { } } + + /** + * Return the path for the user command lines configuration directory + */ + private static String getUserConfigPath() { + if(Utilities.isUnix()) { + String path = System.getProperty("user.home") ; // NOI18N + return path + "/."; // NOI18N + } else if (Utilities.isWindows()){ + String userConfigPath = getUSERPROFILE(); + return userConfigPath.equals("")? "": userConfigPath + File.separator; // NOI18N + } + return ""; // NOI18N + } + + /** * Return the path for the systemwide command lines configuration directory */ @@ -369,52 +377,30 @@ public class HgConfigFiles { if(Utilities.isUnix()) { return "/etc/mercurial"; // NOI18N } else if (Utilities.isWindows()){ - return WINDOWS_GLOBAL_CONFIG_DIR; + // \Mercurial.ini + String mercurialPath = HgModuleConfig.getDefault().getExecutableBinaryPath (); + if(mercurialPath != null){ + File f = new File(mercurialPath); + File ini = new File(f.getParentFile(), WINDOWS_HG_RC_FILE); + if(ini != null && ini.exists() && ini.canRead()){ + return ini.getParentFile().getAbsolutePath(); + } + } + // C:\Mercurial\Mercurial.ini + File ini = new File(WINDOWS_DEFAULT_MECURIAL_INI_PATH);// NOI18N + if(ini != null && ini.exists() && ini.canRead()){ + return ini.getParentFile().getAbsolutePath(); + } } return ""; // NOI18N } - /** - * Returns the value for the %APPDATA% env variable on windows - * - */ - private static String getAPPDATA() { - String appdata = ""; // NOI18N + private static String getUSERPROFILE() { + String userprofile = ""; // NOI18N if(Utilities.isWindows()) { - appdata = System.getenv("APPDATA");// NOI18N + userprofile = System.getenv("USERPROFILE");// NOI18N } - return appdata!= null? appdata: ""; // NOI18N + return userprofile!= null? userprofile: ""; // NOI18N } - /** - * Returns the value for the %ALLUSERSPROFILE% + the last foder segment from %APPDATA% env variables on windows - * - */ - private static String getGlobalAPPDATA() { - if(Utilities.isWindows()) { - String globalProfile = System.getenv("ALLUSERSPROFILE"); // NOI18N - if(globalProfile == null || globalProfile.trim().equals("")) { // NOI18N - globalProfile = ""; // NOI18N - } - String appdataPath = WINDOWS_USER_APPDATA; - if(appdataPath == null || appdataPath.equals("")) { // NOI18N - return ""; // NOI18N - } - String appdata = ""; // NOI18N - int idx = appdataPath.lastIndexOf("\\"); // NOI18N - if(idx > -1) { - appdata = appdataPath.substring(idx + 1); - if(appdata.trim().equals("")) { // NOI18N - int previdx = appdataPath.lastIndexOf("\\", idx); // NOI18N - if(idx > -1) { - appdata = appdataPath.substring(previdx + 1, idx); - } - } - } else { - return ""; // NOI18N - } - return globalProfile + "/" + appdata; // NOI18N - } - return ""; // NOI18N - } }