[PATCH 2 of 4] Windows fix: use ShGetSpecialFolder instead of expanduser

VolkerKleinfeld Volker.Kleinfeld at gmx.de
Thu Sep 29 14:25:34 CDT 2005


# HG changeset patch
# User Volker Kleinfeld <Volker.Kleinfeld at gmx.de>
# Node ID 9e8c7489ab8777e061aba1015a5ad3d0ce665ae9
# Parent  16b9ee2b044f14eac0006fb0632a1235e5c125c4
Windows fix: use ShGetSpecialFolder instead of expanduser.

On win98 the os.path.expanuser('~') does not result in
a useable directory. The MSDN recommended method for storing
application data on windows is the %APPDATA% directory which
is returned by the shell.ShGetSpecialFolder function.

The path used are:
Per Maschine:
   C:\mercurial\mercurial.ini
Per user on win2k and winXP:
   C:\Documents and Settings\<user>\Application Data\mercurial\mercurial.ini

diff -r 16b9ee2b044f -r 9e8c7489ab87 mercurial/util.py
--- a/mercurial/util.py	09/27/05 08:13:57 +0200
+++ b/mercurial/util.py	09/27/05 08:19:48 +0200
@@ -371,8 +371,14 @@
 if os.name == 'nt':
     nulldev = 'NUL:'
 
-    rcpath = (r'c:\mercurial\mercurial.ini',
-              os.path.join(os.path.expanduser('~'), 'mercurial.ini'))
+    try: # The win32 extentsions need to be available
+        from win32com.shell import shell, shellcon
+        userconfig = shell.SHGetPathFromIDList (
+                         shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA))
+        userconfig = os.path.join(userconfig,'mercurial','mercurial.ini')
+        rcpath = (r'c:\mercurial\mercurial.ini', userconfig)
+    except:
+        rcpath = (r'c:\mercurial\mercurial.ini',)
 
     def parse_patch_output(output_line):
         """parses the output produced by patch and returns the file name"""


More information about the Mercurial mailing list