From b75055c154047efc941c0385b1d2eadc44aabbe8 Mon Sep 17 00:00:00 2001
From: Ilya Shpigor <shpigor@etersoft.ru>
Date: Thu, 26 Feb 2009 16:57:04 +0300
Subject: [PATCH] etermsg/kernel32: Add checking to license and showing warning messages (eterbug #1436)

---
 dlls/kernel32/process.c     |   23 ++++++++++++++++++-
 programs/etermsg/En.rc      |    1 +
 programs/etermsg/Ru.rc      |    1 +
 programs/etermsg/etermsg.c  |   51 ++++++++++++++++++++++++++++++++-----------
 programs/etermsg/resource.h |    3 +-
 5 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 073200c..828042d 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -53,6 +53,7 @@
 #include "wine/debug.h"
 
 #define ETERSOFT_FUNC_VERSION
+#define ETERSOFT_FUNC_LICENSE
 #include "wine/etersoft.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(process);
@@ -1109,12 +1110,31 @@ void CDECL __wine_kernel_init(void)
             BOOL ret = FALSE;
             CHAR cmdline[1000];
 
-            sprintf(cmdline, "etermsg -a %s", name);
             memset(&info, 0, sizeof(info));
             memset(&startup, 0, sizeof(startup));
             startup.cb = sizeof(startup);
             startup.dwFlags = STARTF_USESHOWWINDOW;
             startup.wShowWindow = SW_SHOWNORMAL;
+            cmdline[0]='\0';
+
+            LOADETER_FUNC(etersoft_getlicense);
+            if (etersoft_getlicense(ETERSOFT_LICENSE_PATH, 0))
+            {
+                FILE *file;
+                file = fopen(etersoft_getlicense(ETERSOFT_LICENSE_PATH, 0), "r");
+                if (!file)
+                    sprintf(cmdline, "etermsg -lf");
+                else
+                    fclose(file);
+            }
+
+            LOADETER_FUNC(etersoft_correct_license)
+            if (!etersoft_correct_license())
+                sprintf(cmdline, "etermsg -lc");
+
+            LOADETER_FUNC(etersoft_valid_license)
+            if (!etersoft_valid_license() && !strlen(cmdline))
+                sprintf(cmdline, "etermsg -ld %s", etersoft_getlicense(ETERSOFT_LICENSE_END_DATE, 0));
 
             ret = CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info);
             if (ret)
@@ -1122,6 +1142,7 @@ void CDECL __wine_kernel_init(void)
                 WaitForSingleObject( info.hProcess, INFINITE );
                 CloseHandle(info.hProcess);
                 CloseHandle(info.hThread);
+                goto error;
             }
         }
     }
diff --git a/programs/etermsg/En.rc b/programs/etermsg/En.rc
index cd4333b..03d9324 100644
--- a/programs/etermsg/En.rc
+++ b/programs/etermsg/En.rc
@@ -26,5 +26,6 @@ STRINGTABLE DISCARDABLE
 BEGIN
     IDS_SUPPORT_APP     "This application is supported by a commercial version of WINE@Etersoft"
     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"
 END
diff --git a/programs/etermsg/Ru.rc b/programs/etermsg/Ru.rc
index 8573227..28c0987 100644
--- a/programs/etermsg/Ru.rc
+++ b/programs/etermsg/Ru.rc
@@ -26,5 +26,6 @@ STRINGTABLE DISCARDABLE
 BEGIN
     IDS_SUPPORT_APP     "Ýòî ïðèëîæåíèå ïîääåðæèâàåòñÿ êîììåð÷åñêîé âåðñèåé WINE@Etersoft"
     IDS_FILE_NOT_FOUND  "Ôàéë ëèöåíçèè íå íàéäåí"
+    IDS_FILE_CORRUPT    "Ôàéë ëèöåíçèè ïîâðåæäåí"
     IDS_LICENSE_EXP     "Ñðîê äåéñòâèÿ ëèöåíçèè èñòåê"
 END
diff --git a/programs/etermsg/etermsg.c b/programs/etermsg/etermsg.c
index faafcec..7f24dfc 100644
--- a/programs/etermsg/etermsg.c
+++ b/programs/etermsg/etermsg.c
@@ -21,10 +21,7 @@
 #include <windows.h>
 #include "resource.h"
 
-#define  ETERSOFT_FUNC_LICENSE 1
-#include "wine/etersoft.h"
-
-#define     APP_NAME_SIZE       32
+#define     ARG_SIZE            32
 #define     PATH_SIZE           128
 #define     LOADSTRING_SIZE     1024
 
@@ -50,17 +47,45 @@ int main(int argc, char** argv)
 {
     WCHAR Text[LOADSTRING_SIZE];
     WCHAR Msg[] = {'E','t','e','r','M','s','g','\0'};
-    char AppName[APP_NAME_SIZE];
+    char AppName[ARG_SIZE];
     int ret;
 
     argc--; argv++;
 
-    if (argc && !strcmp(argv[0], "-l"))
+    if (argc && !strcmp(argv[0], "-lf"))
+    {
+        ret = LoadStringW(GetModuleHandleW(NULL), IDS_FILE_NOT_FOUND, Text, LOADSTRING_SIZE);
+        if (!ret) return 0;
+
+        MessageBoxW(NULL, Text, Msg, MB_ICONWARNING | MB_OK);
+        return 0;
+    }
+    else if (argc && !strcmp(argv[0], "-lc"))
     {
-        /* TODO: add license checking through
-         * etersoft_license and etersoft_valid_license
-         * functions.
-         */
+        ret = LoadStringW(GetModuleHandleW(NULL), IDS_FILE_CORRUPT, Text, LOADSTRING_SIZE);
+        if (!ret) return 0;
+
+        MessageBoxW(NULL, Text, Msg, MB_ICONWARNING | MB_OK);
+        return 0;
+    }
+    else if ((argc == 2) && !strcmp(argv[0], "-ld"))
+    {
+        WCHAR date[ARG_SIZE];
+        WCHAR buf[LOADSTRING_SIZE];
+        WCHAR fmt[] = {'%','s',' ','%','s','\0'};
+
+        ret = LoadStringW(GetModuleHandleW(NULL), IDS_LICENSE_EXP, Text, LOADSTRING_SIZE);
+        if (!ret) return 0;
+
+        int i;
+        for(i = 0; i<ARG_SIZE; i++)
+        {
+            if (i == 0 && argv[1][i] == '\0') return 0;
+            date[i] = argv[1][i];
+        }
+
+        sprintfW(buf, fmt, Text, date);
+        MessageBoxW(NULL, buf, Msg, MB_ICONWARNING | MB_OK);
         return 0;
     }
     else if ((argc == 2) && !strcmp(argv[0], "-a"))
@@ -69,17 +94,17 @@ int main(int argc, char** argv)
         if (!ret) return 0;
 
         int i;
-        for(i = 0; i<APP_NAME_SIZE; i++)
+        for(i = 0; i<ARG_SIZE; i++)
         {
             if (i == 0 && argv[1][i] == '\0') return 0;
             AppName[i] = argv[1][i];
         }
 
         if (IsNeedNotify(AppName))
-            MessageBoxW(NULL, Text, Msg, MB_OK);
+            MessageBoxW(NULL, Text, Msg, MB_ICONINFORMATION | MB_OK);
     }
     else
-        printf("Usage:\n\tetermsg [ -l | -a <prog-name> ]\n");
+        printf("Usage:\n\tetermsg [ -lf | -lc | -ld <date> | -a <prog-name> ]\n");
 
     return 0;
 }
diff --git a/programs/etermsg/resource.h b/programs/etermsg/resource.h
index 9112b13..138dfea 100644
--- a/programs/etermsg/resource.h
+++ b/programs/etermsg/resource.h
@@ -21,4 +21,5 @@
 
 #define IDS_SUPPORT_APP     2
 #define IDS_FILE_NOT_FOUND  3
-#define IDS_LICENSE_EXP     4
+#define IDS_FILE_CORRUPT    4
+#define IDS_LICENSE_EXP     5
-- 
1.6.1.3.GIT

