tWin32 client now reads both global and local config. files - vaccinewars - be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars
Log
Files
Refs
README
LICENSE
---
commit 23abfd8c3bbd968cce0cd856c32f238e6dc38af9
parent 419b37f2853f268ae5a516fbf750b859dfe7ad09
Author: Ben Webb 
Date:   Mon, 26 Nov 2001 17:51:05 +0000

Win32 client now reads both global and local config. files


Diffstat:
  M TODO                                |       3 +++
  M src/dopewars.c                      |      37 +++++++++++++++++++++----------
  M src/winmain.c                       |      36 ++++++++++++++++++++++++++------
  A src/winmain.h                       |      31 +++++++++++++++++++++++++++++++

4 files changed, 89 insertions(+), 18 deletions(-)
---
diff --git a/TODO b/TODO
t@@ -1,3 +1,6 @@
+- Win32 install for current user/all users
+- Test code under Win98
+- Document new server interface
 - Admin of running NT Service servers
 - Configuration file editor thingy in the client?
 - GSS_API SOCKS support?
diff --git a/src/dopewars.c b/src/dopewars.c
t@@ -49,6 +49,7 @@
 #include "serverside.h"
 #include "tstring.h"
 #include "AIPlayer.h"
+#include "winmain.h"
 
 #ifdef GUI_SERVER
 #include "gtkport.h"
t@@ -1849,22 +1850,34 @@ void SetupParameters(void) {
       AssignName(&StoppedTo[i],_(DefaultStoppedTo[i]));
    }
 
+#ifdef CYGWIN
+
+/* Read the global configuration from the directory the binary is
+   installed in */
+  pt=GetBinaryDir();
+  if (pt) {
+    ConfigFile=g_strdup_printf("%s/dopewars-config.txt",pt);
+    ReadConfigFile(ConfigFile);
+    g_free(ConfigFile); g_free(pt);
+  }
+
+/* Now read the local configuration from the current directory */
+  ReadConfigFile("dopewars-config.txt");
+
+#else /* CYGWIN */
+
 /* Now read in the global configuration file */
-   ReadConfigFile("/etc/dopewars");
+  ReadConfigFile("/etc/dopewars");
 
 /* Next, try to read in the .dopewars file in the user's home directory */
-   pt=getenv("HOME");
-   if (pt) {
-      ConfigFile=g_strdup_printf("%s/.dopewars",pt);
-      ReadConfigFile(ConfigFile);
-      g_free(ConfigFile);
-   }
+  pt=getenv("HOME");
+  if (pt) {
+    ConfigFile=g_strdup_printf("%s/.dopewars",pt);
+    ReadConfigFile(ConfigFile);
+    g_free(ConfigFile);
+  }
 
-#ifdef CYGWIN
-/* Finally, try dopewars-config.txt in the current directory (Windows
-   systems only) */
-   ReadConfigFile("dopewars-config.txt");
-#endif
+#endif /* CYGWIN */
 
 /* Save this configuration, so we can restore those elements that get
    overwritten when we connect to a dopewars server */
diff --git a/src/winmain.c b/src/winmain.c
t@@ -1,4 +1,4 @@
-/* winmain.c      Startup code for dopewars on the Win32 platform       */
+/* winmain.c      Startup code and support for the Win32 platform       */
 /* Copyright (C)  1998-2001  Ben Webb                                   */
 /*                Email: ben@bellatrix.pcl.ox.ac.uk                     */
 /*                WWW: http://dopewars.sourceforge.net/                 */
t@@ -39,6 +39,7 @@
 #include "message.h"
 #include "serverside.h"
 #include "gtkport.h"
+#include "winmain.h"
 
 static void ServerLogMessage(const gchar *log_domain,GLogLevelFlags log_level,
                              const gchar *message,gpointer user_data) {
t@@ -98,6 +99,31 @@ static void LogFileEnd(void) {
   if (LogFile) fclose(LogFile);
 }
 
+gchar *GetBinaryDir(void) {
+  gchar *filename=NULL,*lastslash;
+  gint filelen=80;
+  DWORD retval;
+
+  while(1) {
+    filename = g_realloc(filename,filelen);
+    filename[filelen-1]='\0';
+    retval = GetModuleFileName(NULL,filename,filelen);
+
+    if (retval==0) {
+      g_free(filename); filename=NULL; break;
+    } else if (filename[filelen-1]) {
+      filelen*=2;
+    } else break;
+  }
+
+  if (filename) {
+    lastslash=strrchr(filename,'\\');
+    if (lastslash) *lastslash='\0';
+  }
+
+  return filename;
+}
+
 #ifdef ENABLE_NLS
 static gchar *GetWindowsLocale(void) {
   LCID userID;
t@@ -148,7 +174,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
   gchar **split;
   int argc;
   gboolean is_service;
-  gchar modpath[300],*lastslash;
+  gchar *modpath;
 #ifdef ENABLE_NLS
   gchar *winlocale;
 #endif
t@@ -157,11 +183,9 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
   is_service = (lpszCmdParam && strncmp(lpszCmdParam,"-N",2)==0);
 
   if (is_service) {
-    modpath[0]='\0';
-    GetModuleFileName(NULL,modpath,300);
-    lastslash=strrchr(modpath,'\\');
-    if (lastslash) *lastslash='\0';
+    modpath=GetBinaryDir();
     SetCurrentDirectory(modpath);
+    g_free(modpath);
   }
 
   LogFileStart();
diff --git a/src/winmain.h b/src/winmain.h
t@@ -0,0 +1,31 @@
+/* winmain.h      Startup code and support for the Win32 platform       */
+/* Copyright (C)  1998-2001  Ben Webb                                   */
+/*                Email: ben@bellatrix.pcl.ox.ac.uk                     */
+/*                WWW: http://dopewars.sourceforge.net/                 */
+
+/* This program is free software; you can redistribute it and/or        */
+/* modify it under the terms of the GNU General Public License          */
+/* as published by the Free Software Foundation; either version 2       */
+/* of the License, or (at your option) any later version.               */
+
+/* This program is distributed in the hope that it will be useful,      */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
+/* GNU General Public License for more details.                         */
+
+/* You should have received a copy of the GNU General Public License    */
+/* along with this program; if not, write to the Free Software          */
+/* Foundation, Inc., 59 Temple Place - Suite 330, Boston,               */
+/*                   MA  02111-1307, USA.                               */
+
+
+#ifndef __WINMAIN_H__
+#define __WINMAIN_H__
+
+#ifdef CYGWIN
+
+gchar *GetBinaryDir(void);
+
+#endif /* CYGWIN */
+
+#endif /* __WINMAIN_H__ */