Convert unix paths in kernel32.
authorAlexander Morozov <amorozov@etersoft.ru>
Tue, 11 Jan 2011 15:25:02 +0000 (18:25 +0300)
committerAlexander Morozov <amorozov@etersoft.ru>
Tue, 11 Jan 2011 17:18:50 +0000 (20:18 +0300)
dlls/kernel32/process.c
etersoft/scripts/wine.in

index 568e1cebe7e3eb66ab9c256f163176310ef53796..8cfebe4cec7033e6eaebabccd9283ebb17e28e78 100644 (file)
@@ -1231,6 +1231,52 @@ static BOOL etersoft_check_license(const WCHAR *main_exe_name, const CHAR *pname
     return TRUE;
 }
 
+static char **convert_unix_paths( char **argv )
+{
+    int ac, argc = 0;
+    char **ret;
+
+    while (argv[++argc]);
+    ret = RtlAllocateHeap( GetProcessHeap(), 0, (argc + 1) * sizeof(*argv) );
+
+    for (ac = 0; ac < argc; ++ac)
+    {
+        WCHAR *dos_path;
+        int fd, len;
+
+        fd = open( argv[ac], O_RDONLY );
+        if (fd < 0)
+        {
+            len = strlen(argv[ac]) + 1;
+            ret[ac] = RtlAllocateHeap( GetProcessHeap(), 0, len );
+            strcpy( ret[ac], argv[ac] );
+        }
+        else
+        {
+            close( fd );
+            dos_path = wine_get_dos_file_name( argv[ac] );
+            len = WideCharToMultiByte( CP_UNIXCP, 0, dos_path, -1, ret[ac], 0,
+                                       NULL, NULL );
+            ret[ac] = RtlAllocateHeap( GetProcessHeap(), 0, len );
+            WideCharToMultiByte( CP_UNIXCP, 0, dos_path, -1, ret[ac], len, NULL,
+                                 NULL );
+            RtlFreeHeap( GetProcessHeap(), 0, dos_path );
+        }
+    }
+    ret[ac] = NULL;
+
+    return ret;
+}
+
+static void free_converted_paths( char **argv )
+{
+    int ac;
+
+    for (ac = 0; argv[ac]; ++ac)
+        RtlFreeHeap( GetProcessHeap(), 0, argv[ac] );
+    RtlFreeHeap( GetProcessHeap(), 0, argv );
+}
+
 /***********************************************************************
  *           __wine_kernel_init
  *
@@ -1248,6 +1294,7 @@ void CDECL __wine_kernel_init(void)
     HANDLE boot_events[2];
     BOOL got_environment = TRUE;
     BOOL got_current_dir = FALSE;
+    char **argv;
 
     /* Initialize everything */
 
@@ -1274,7 +1321,9 @@ void CDECL __wine_kernel_init(void)
     init_current_directory( &params->CurrentDirectory, &got_current_dir );
 
     set_process_name( __wine_main_argc, __wine_main_argv );
-    set_library_wargv( __wine_main_argv );
+    argv = convert_unix_paths( __wine_main_argv );
+    set_library_wargv( argv );
+    free_converted_paths( argv );
     boot_events[0] = boot_events[1] = 0;
 
     if (peb->ProcessParameters->ImagePathName.Buffer)
index 91cd593b6ef0469e0af6aec4f844aece64a97a7c..e2039f4291c6dc3ff9d09afb808bfdc1f7a429d0 100644 (file)
@@ -481,20 +481,6 @@ if [ -n "$WINEWORKDIRPATH" ] ; then
        cd "$WINEWORKDIRPATH"
 fi
 
-# translate args from unix path to windows, if possible (eterbug #4933)
-args_to_winpath()
-{
-       for i in "$@" ; do
-               local TP="$i"
-               local TR=${i/\~/$HOME}
-               if [ -r "$TR" ] ; then
-                       WP=$($WINELOADER winepath -w "$TR" 2>/dev/null)
-                       [ -z "$WP" ] || TP="$WP"
-               fi
-               echo "'$TP' "
-       done
-}
-
 STARTCOM=
 # if file is exists in Unix or Wine notation
 WINEPROGRAMUNIXPATH=$($WINELOADER winepath "$1")
@@ -510,5 +496,4 @@ if [ -n "$1" ] && [ -f "$WINEPROGRAMUNIXPATH" ] ; then
        fi
 fi
 
-eval run_wine $STARTCOM $(args_to_winpath "$@")
-
+run_wine $STARTCOM "$@"