From 903d7688db915c5a7f6e526f676f9c1f6db07418 Mon Sep 17 00:00:00 2001
From: Ilya Shpigor <shpigor@etersoft.ru>
Date: Wed, 4 Mar 2009 10:18:31 +0300
Subject: [PATCH] etermsg/kernel32: Add the error message when running wine in the unknown disk or the bad command name (eterbug #3593)

---
 dlls/kernel32/process.c     |   22 +++++++++++++---------
 programs/etermsg/En.rc      |    2 ++
 programs/etermsg/Ru.rc      |    2 ++
 programs/etermsg/etermsg.c  |   18 +++++++++++++++++-
 programs/etermsg/resource.h |    2 ++
 5 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 0f449d8..89ef95a 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -742,7 +742,7 @@ static void init_current_directory( CURDIR *cur_dir, BOOL *got_current_dir )
     UNICODE_STRING dir_str;
     char *cwd;
     int size;
-    *got_current_dir = FALSE;
+    *got_current_dir = TRUE;
     /* if we received a cur dir from the parent, try this first */
 
     if (cur_dir->DosPath.Length)
@@ -1091,24 +1091,28 @@ void CDECL __wine_kernel_init(void)
         FIXME("%d: %s(%s)\n",got_current_dir, debugstr_w(params->CurrentDirectory.DosPath.Buffer), debugstr_w(DIR_Windows));
 
         /* Etersoft: Generate user dialog about the error */
-        /* TODO: write winedialog program for message box output */
-        /* Note: we can't load user32.dll (too early stage, i think) */
-        /* !got_current_dir - run in unknown disk */
-        /* got_current_dir - just bad command name */
-        if (0 && !got_current_dir) {
+        {
             PROCESS_INFORMATION info;
             STARTUPINFOA    startup;
             BOOL        ret = FALSE;
             CHAR cmdline[1000];
-            sprintf(cmdline, "winedialog Warning: Wine could not load\n%s\n: %s", debugstr_w(main_exe_name), msg );
 
-            //TRACE("Starting debugger %s\n", debugstr_a(cmdline));
+            if (!got_current_dir)
+                sprintf(cmdline, "etermsg -ed");
+            else
+                sprintf(cmdline, "etermsg -ea");
+
             memset(&startup, 0, sizeof(startup));
             startup.cb = sizeof(startup);
             startup.dwFlags = STARTF_USESHOWWINDOW;
             startup.wShowWindow = SW_SHOWNORMAL;
             ret = CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info);
-
+            if (ret)
+            {
+                WaitForSingleObject( info.hProcess, INFINITE );
+                CloseHandle(info.hProcess);
+                CloseHandle(info.hThread);
+            }
         }
         ExitProcess( error );
     }
diff --git a/programs/etermsg/En.rc b/programs/etermsg/En.rc
index 03d9324..07f05e8 100644
--- a/programs/etermsg/En.rc
+++ b/programs/etermsg/En.rc
@@ -28,4 +28,6 @@ BEGIN
     IDS_FILE_NOT_FOUND  "The license file is not found"
     IDS_FILE_CORRUPT    "The license file is corrupt"
     IDS_LICENSE_EXP     "The license has expired"
+    IDS_ERROR_DIR       "Wine have been run in the unknown disk"
+    IDS_ERROR_APP       "The specified application doesn't exist"
 END
diff --git a/programs/etermsg/Ru.rc b/programs/etermsg/Ru.rc
index 28c0987..9242924 100644
--- a/programs/etermsg/Ru.rc
+++ b/programs/etermsg/Ru.rc
@@ -28,4 +28,6 @@ BEGIN
     IDS_FILE_NOT_FOUND  "Ôàéë ëèöåíçèè íå íàéäåí"
     IDS_FILE_CORRUPT    "Ôàéë ëèöåíçèè ïîâðåæäåí"
     IDS_LICENSE_EXP     "Ñðîê äåéñòâèÿ ëèöåíçèè èñòåê"
+    IDS_ERROR_DIR       "Wine áûë çàïóùåí íà íåèçâåñòíîì äèñêå"
+    IDS_ERROR_APP      "Óêàçàííîãî ïðèëîæåíèÿ íå ñóùåñòâóåò"
 END
diff --git a/programs/etermsg/etermsg.c b/programs/etermsg/etermsg.c
index 5ebe2ac..20f4268 100644
--- a/programs/etermsg/etermsg.c
+++ b/programs/etermsg/etermsg.c
@@ -94,6 +94,22 @@ int main(int argc, char** argv)
 
         return 0;
     }
+    else if (argc && !strcmp(argv[0], "-ed"))
+    {
+        ret = LoadStringW(GetModuleHandleW(NULL), IDS_ERROR_DIR, Text, LOADSTRING_SIZE);
+        if (!ret) return 0;
+
+        MessageBoxW(NULL, Text, Msg, MB_ICONWARNING | MB_OK);
+        return 0;
+    }
+    else if (argc && !strcmp(argv[0], "-ea"))
+    {
+        ret = LoadStringW(GetModuleHandleW(NULL), IDS_ERROR_APP, Text, LOADSTRING_SIZE);
+        if (!ret) return 0;
+
+        MessageBoxW(NULL, Text, Msg, MB_ICONWARNING | MB_OK);
+        return 0;
+    }
     else if ((argc == 2) && !strcmp(argv[0], "-a"))
     {
         ret = LoadStringW(GetModuleHandleW(NULL), IDS_SUPPORT_APP, Text, LOADSTRING_SIZE);
@@ -110,7 +126,7 @@ int main(int argc, char** argv)
             MessageBoxW(NULL, Text, Msg, MB_ICONINFORMATION | MB_OK);
     }
     else
-        printf("Usage:\n\tetermsg [ -lf | -lc | -ld <date> | -a <prog-name> ]\n");
+        printf("Usage:\n\tetermsg [ -lf | -lc | -ld <date> | -a <prog-name> | -ed | -ea ]\n");
 
     return 0;
 }
diff --git a/programs/etermsg/resource.h b/programs/etermsg/resource.h
index 138dfea..6a37488 100644
--- a/programs/etermsg/resource.h
+++ b/programs/etermsg/resource.h
@@ -23,3 +23,5 @@
 #define IDS_FILE_NOT_FOUND  3
 #define IDS_FILE_CORRUPT    4
 #define IDS_LICENSE_EXP     5
+#define IDS_ERROR_DIR       6
+#define IDS_ERROR_APP       7
-- 
1.6.1.3.GIT

