Extending File Dialog to include unix file paths [1/4]

Michael Lin mlin at corvu.com.au
Thu May 12 22:57:48 CDT 2005


This patch extends the file dialog to be able to browse and accept unix 
file paths.
Some people don't agree with unix file paths on file dialogs, while some 
believe it is
needed for winelib applications.

This patch will not affect wine user running windows applications.
This patch will only affect winelib applications compiled with
WINE_UNIX_PATHS flag defined. Else it will behave the same as before.

This is the first part of the 4 part patch.

ChangeLog:
- change separator from just '\\' to include '/' as well
- added utility functions to detect absolute unix path

-------------- next part --------------
Index: dlls/shlwapi/path.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/path.c,v
retrieving revision 1.53
diff -u -r1.53 path.c
--- dlls/shlwapi/path.c	18 Apr 2005 15:36:20 -0000	1.53
+++ dlls/shlwapi/path.c	13 May 2005 02:17:12 -0000
@@ -37,6 +37,7 @@
 #include "shlwapi.h"
 #include "wine/debug.h"
 
+#define IS_SEPARATOR(ch)  ((ch) == '\\' || (ch) == '/')
 WINE_DEFAULT_DEBUG_CHANNEL(shell);
 
 /* Get a function pointer from a DLL handle */
@@ -1491,7 +1492,9 @@
 
   if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
     return TRUE;
-  if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
+  if (PathIsUnixAbsoluteA(lpszPath))
+    return FALSE;
+  else if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
     return FALSE;
   return TRUE;
 }
@@ -1507,7 +1510,10 @@
 
   if (!lpszPath || !*lpszPath)
     return TRUE;
-  if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
+  
+  if (PathIsUnixAbsoluteW(lpszPath))
+    return FALSE;
+  else if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
     return FALSE;
   return TRUE;
 }
@@ -2190,6 +2196,42 @@
   return FALSE;
 }
 
+
+/*************************************************************************
+ * PathIsUnixAbsoluteA	[SHLWAPI.@]
+ *
+ * Determine if a path is an absolute Unix file path.
+ *
+ * PARAMS
+ *  lpszPath [I] Path to check
+ *
+ * RETURNS
+ *  TRUE: The path is a absolute Unix path.
+ *  FALSE: The path is not absolute Unix path or is NULL.
+ */
+BOOL WINAPI PathIsUnixAbsoluteA(LPCSTR lpszPath)
+{
+  TRACE("(%s)\n",debugstr_a(lpszPath));
+
+  if (lpszPath && (lpszPath[0]=='/') && (lpszPath[1]!='/'))
+    return TRUE;
+  return FALSE;
+}
+
+/*************************************************************************
+ * PathIsUnixAbsoluteW	[SHLWAPI.@]
+ *
+ * See PathIsUnixA.
+ */
+BOOL WINAPI PathIsUnixAbsoluteW(LPCWSTR lpszPath)
+{
+  TRACE("(%s)\n",debugstr_w(lpszPath));
+
+  if (lpszPath && (lpszPath[0]=='/') && (lpszPath[1]!='/'))
+    return TRUE;
+  return FALSE;
+}
+
 /*************************************************************************
  * PathIsUNCServerA   [SHLWAPI.@]
  *
@@ -2377,7 +2419,7 @@
   }
 
   /* Copy path root */
-  if (*lpszSrc == '\\')
+  if (IS_SEPARATOR(*lpszSrc))
   {
     *lpszDst++ = *lpszSrc++;
   }
@@ -2395,11 +2437,11 @@
   {
     if (*lpszSrc == '.')
     {
-      if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
+      if (IS_SEPARATOR(lpszSrc[1]) && (lpszSrc == lpszPath || IS_SEPARATOR(lpszSrc[-1]) || lpszSrc[-1] == ':'))
       {
         lpszSrc += 2; /* Skip .\ */
       }
-      else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
+      else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || IS_SEPARATOR(lpszDst[-1])))
       {
         /* \.. backs up a directory, over the root if it has no \ following X:.
          * .. is ignored if it would remove a UNC server name or inital \\
@@ -2407,15 +2449,15 @@
         if (lpszDst != lpszBuf)
         {
           *lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
-          if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
-             (lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
+          if (lpszDst > lpszBuf+1 && IS_SEPARATOR(lpszDst[-1]) &&
+             (!IS_SEPARATOR(lpszDst[-2]) || lpszDst > lpszBuf+2))
           {
             if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
             {
               lpszDst -= 2;
-              while (lpszDst > lpszBuf && *lpszDst != '\\')
+              while (lpszDst > lpszBuf && !IS_SEPARATOR(*lpszDst))
                 lpszDst--;
-              if (*lpszDst == '\\')
+              if (IS_SEPARATOR(*lpszDst))
                 lpszDst++; /* Reset to last '\' */
               else
                 lpszDst = lpszBuf; /* Start path again from new root */
@@ -2423,7 +2465,7 @@
             else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
               lpszDst -= 2;
           }
-          while (lpszDst > lpszBuf && *lpszDst != '\\')
+          while (lpszDst > lpszBuf && !IS_SEPARATOR(*lpszDst))
             lpszDst--;
           if (lpszDst == lpszBuf)
           {
Index: dlls/shlwapi/shlwapi.spec
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/shlwapi.spec,v
retrieving revision 1.100
diff -u -r1.100 shlwapi.spec
--- dlls/shlwapi/shlwapi.spec	18 Mar 2005 14:01:16 -0000	1.100
+++ dlls/shlwapi/shlwapi.spec	13 May 2005 02:17:13 -0000
@@ -621,6 +621,8 @@
 @ stdcall PathIsUNCServerShareW(wstr)
 @ stdcall PathIsUNCServerW(wstr)
 @ stdcall PathIsUNCW(wstr)
+@ stdcall PathIsUnixAbsoluteA (str)
+@ stdcall PathIsUnixAbsoluteW(wstr)
 @ stdcall PathIsURLA(str)
 @ stdcall PathIsURLW(wstr)
 @ stdcall PathMakePrettyA(str)
Index: include/shlwapi.h
===================================================================
RCS file: /home/wine/wine/include/shlwapi.h,v
retrieving revision 1.54
diff -u -r1.54 shlwapi.h
--- include/shlwapi.h	13 Dec 2004 21:19:01 -0000	1.54
+++ include/shlwapi.h	13 May 2005 02:17:14 -0000
@@ -408,6 +408,10 @@
 BOOL WINAPI PathIsUNCW(LPCWSTR);
 #define PathIsUNC WINELIB_NAME_AW(PathIsUNC)
 
+BOOL WINAPI PathIsUnixAbsoluteA(LPCSTR);
+BOOL WINAPI PathIsUnixAbsoluteW(LPCWSTR);
+#define PathIsUnixAbsolute WINELIB_NAME_AW(PathIsUnixAbsolute)
+
 BOOL WINAPI PathIsUNCServerA(LPCSTR);
 BOOL WINAPI PathIsUNCServerW(LPCWSTR);
 #define PathIsUNCServer WINELIB_NAME_AW(PathIsUNCServer)


More information about the wine-patches mailing list