[kernel32,
tools] use the right argv[0] and cwd for .EXE double-clicks
Damjan Jovanovic
damjan.jov at gmail.com
Sat Jul 28 08:40:00 CDT 2007
Changelog:
* Double-clicking on .EXE files now uses the same argv[0] and current
working directory as Windows does.
Damjan Jovanovic
-------------- next part --------------
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 1eaf195..9029038 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -614,7 +614,57 @@ static void init_current_directory( CURDIR *cur_dir )
char *cwd;
int size;
- /* if we received a cur dir from the parent, try this first */
+ /* if the executable was started by a double-click,
+ use the right argv[0] and current directory */
+
+ if (getenv("WINE_FREEDESKTOP_LAUNCH") != NULL)
+ {
+ WCHAR *dos_path = wine_get_dos_file_name(__wine_main_argv[1]);
+ unsetenv("WINE_FREEDESKTOP_LAUNCH");
+ if (dos_path)
+ {
+ int i;
+ int count = 0;
+ char *args = NULL;
+ char **argv = NULL;
+ WCHAR *pos;
+
+ count = strlen(__wine_main_argv[0]);
+ count += WideCharToMultiByte(CP_UNIXCP, 0, dos_path, -1, NULL, 0, NULL, NULL);
+ for (i = 2; i < __wine_main_argc; ++i)
+ count += strlen(__wine_main_argv[i]);
+ argv = HeapAlloc(GetProcessHeap(), 0, (__wine_main_argc + 1) * sizeof(char*));
+ args = HeapAlloc(GetProcessHeap(), 0, count + __wine_main_argc);
+ if (argv && args)
+ {
+ argv[0] = args;
+ strcpy(args, __wine_main_argv[0]);
+ args += strlen(__wine_main_argv[0]);
+ argv[1] = args;
+ args += WideCharToMultiByte(CP_UNIXCP, 0, dos_path, -1, args, -1, NULL, NULL);
+ for (i = 2; i < __wine_main_argc; ++i)
+ {
+ argv[i] = args;
+ strcpy(args, __wine_main_argv[i]);
+ args += strlen(__wine_main_argv[i]);
+ }
+ argv[i] = NULL;
+ __wine_main_argv = argv;
+
+ pos = strrchrW(dos_path, L'\\');
+ pos[1] = 0;
+ RtlInitUnicodeString(&dir_str, dos_path);
+ RtlSetCurrentDirectory_U(&dir_str);
+ HeapFree(GetProcessHeap(), 0, dos_path);
+ goto done;
+ }
+ HeapFree(GetProcessHeap(), 0, args);
+ HeapFree(GetProcessHeap(), 0, argv);
+ HeapFree(GetProcessHeap(), 0, dos_path);
+ }
+ }
+
+ /* if we received a cur dir from the parent, try this next */
if (cur_dir->DosPath.Length)
{
diff --git a/tools/wine.desktop b/tools/wine.desktop
index ed09306..ff9fb1e 100644
--- a/tools/wine.desktop
+++ b/tools/wine.desktop
@@ -3,6 +3,6 @@ Type=Application
Encoding=UTF-8
Name=Wine Windows Emulator
Name[de]=Wine Windows-Emulator
-Exec=wine %f
+Exec=env WINE_FREEDESKTOP_LAUNCH=1 wine %f
MimeType=application/x-ms-dos-executable;application/x-msdos-program;application/x-msdownload;application/exe;application/x-exe;application/dos-exe;vms/exe;application/x-winexe;application/msdos-windows;application/x-msdos-program;application/x-zip-compressed;application/x-executable
NoDisplay=true
More information about the wine-patches
mailing list