diff win/dw.c @ 2127:663467f6eee4

Code cleanup: Add constants to header for dark mode, buffer sizes and Unicode support. Windows and OS/2 can both be built without Unicode support for legacy platforms and apps. Some new Windows features require Unicode (notifications, edge) and Unicode is buggy on OS/2. Can now check if Unicode is supported with the DW_FEATURE_UTF8_UNICODE feature test. Dark mode constants added DW_DARK_MODE_DISABLED/BASIC/FULL/FORCED. Win: Include dw.h in the WinToast glue for the constants, and improve safety in Edge glue.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 28 Jun 2020 20:34:25 +0000
parents 97839ff3c985
children 9e6e4ebd5e96
line wrap: on
line diff
--- a/win/dw.c	Sun Jun 28 05:39:08 2020 +0000
+++ b/win/dw.c	Sun Jun 28 20:34:25 2020 +0000
@@ -278,8 +278,8 @@
  */
 static char _dw_alternate_temp_dir[MAX_PATH+1] = {0};
 static char _dw_exec_dir[MAX_PATH+1] = {0};
-static char _dw_app_id[101]= {0};
-static char _dw_app_name[101]= {0};
+static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
+static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0};
 
 int main(int argc, char *argv[]);
 
@@ -4276,8 +4276,8 @@
          if((pos++) && !_dw_app_id[0])
          {
             /* If we have a binary name, use that for the Application ID instead. */
-            _snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, pos);
-            strncpy(_dw_app_name, pos, 100);
+            _snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.%s", DW_APP_DOMAIN_DEFAULT, pos);
+            strncpy(_dw_app_name, pos, _DW_APP_ID_SIZE);
          }
       }
    }
@@ -4434,17 +4434,17 @@
    if(!_dw_app_id[0])
    {
       /* Generate an Application ID based on the PID if all else fails. */
-      _snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
+      _snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
    }
    if(!_dw_app_name[0])
    {
       /* If we still don't have an app name, get the executable name */
-      char fullpath[261] = {0}, *pos;
-      GetModuleFileNameA(DWInstance, fullpath, 260);
+      char fullpath[MAX_PATH+1] = {0}, *pos;
+      GetModuleFileNameA(DWInstance, fullpath, MAX_PATH);
       pos = strrchr(fullpath, '\\');
       if(pos)
          pos++;
-      strncpy(_dw_app_name, pos ? pos : fullpath, 100);
+      strncpy(_dw_app_name, pos ? pos : fullpath, _DW_APP_ID_SIZE);
    }
     
 #if (defined(BUILD_DLL) || defined(BUILD_HTML))
@@ -12914,9 +12914,9 @@
  */
 int API dw_app_id_set(const char *appid, const char *appname)
 {
-    strncpy(_dw_app_id, appid, 100);
+    strncpy(_dw_app_id, appid, _DW_APP_ID_SIZE);
     if(appname)
-        strncpy(_dw_app_name, appname, 100);
+        strncpy(_dw_app_name, appname, _DW_APP_ID_SIZE);
     return DW_ERROR_NONE;
 }
 
@@ -13378,6 +13378,9 @@
 {
     switch(feature)
     {
+#ifdef UNICODE
+        case DW_FEATURE_UTF8_UNICODE:
+#endif
 #if (defined(BUILD_DLL) || defined(BUILD_HTML))
         case DW_FEATURE_HTML:
         case DW_FEATURE_HTML_RESULT:
@@ -13430,6 +13433,9 @@
     switch(feature)
     {
         /* These features are supported but not configurable */
+#ifdef UNICODE
+        case DW_FEATURE_UTF8_UNICODE:
+#endif
 #if (defined(BUILD_DLL) || defined(BUILD_HTML))
         case DW_FEATURE_HTML:
         case DW_FEATURE_HTML_RESULT: