1.1 --- a/update_tool/update_tool.cpp Thu Apr 05 07:00:49 2007 +0000
1.2 +++ b/update_tool/update_tool.cpp Thu Apr 05 17:51:23 2007 +0000
1.3 @@ -3,9 +3,6 @@
1.4 #include <string.h>
1.5 #include <ctype.h>
1.6
1.7 -extern "C" void GetGameDir(char *buffer, int maxlength);
1.8 -extern "C" void *GetThisPointer();
1.9 -
1.10 #if defined _MSC_VER
1.11 #define SEPCHAR "\\"
1.12 #define MMPATH "addons\\metamod\\bin"
1.13 @@ -17,9 +14,17 @@
1.14 #include <unistd.h>
1.15 #endif
1.16
1.17 +#include <icvar.h>
1.18 +
1.19 +extern "C" void GetGameDir(char *buffer, int maxlength);
1.20 +extern "C" void *GetThisPointer();
1.21 +extern "C" void ServerCommand(const char *command);
1.22 +extern "C" ICvar *GetICvar();
1.23 +
1.24 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
1.25 bool s_isspace(char c);
1.26 bool RenameFile(const char *old, const char *newf);
1.27 +bool RemoveFile(const char *file);
1.28
1.29 /* This will be called by the thunk */
1.30 #if defined _MSC_VER
1.31 @@ -28,6 +33,13 @@
1.32 extern "C" void _LoadFunction()
1.33 #endif
1.34 {
1.35 + ICvar *pCvar = GetICvar();
1.36 + if (pCvar->FindVar("metamod_version") != NULL)
1.37 + {
1.38 + /* Already exists, bail out */
1.39 + return;
1.40 + }
1.41 +
1.42 char gamedir[260];
1.43 char mmpath[260];
1.44
1.45 @@ -141,6 +153,8 @@
1.46
1.47 char input[1024];
1.48 char backup[1024];
1.49 +
1.50 + bool bWroteOutput = false;
1.51
1.52 while (!feof(fp) && fgets(input, sizeof(input), fp) != NULL)
1.53 {
1.54 @@ -199,10 +213,11 @@
1.55 op = NULL;
1.56 break; /* Nothing more to do! */
1.57 } else {
1.58 - fputs("\t\t\tGameBin\t\t\t|gameinfo_path|", op);
1.59 + fputs("\t\t\tGameBin\t\t\t", op);
1.60 fputs(mmpath, op);
1.61 fputs("\n", op);
1.62 ps = Parse_None;
1.63 + bWroteOutput = true;
1.64 }
1.65 }
1.66 }
1.67 @@ -222,6 +237,13 @@
1.68 fclose(op);
1.69 fclose(fp);
1.70
1.71 + /* If we didn't change anything, abort here */
1.72 + if (!bWroteOutput)
1.73 + {
1.74 + RemoveFile(new_path);
1.75 + return;
1.76 + }
1.77 +
1.78 /* Move the old file to a backup name */
1.79 char backup_name[260];
1.80 UTIL_Format(backup_name, sizeof(backup_name), "%s" SEPCHAR "gameinfo.backup.txt", gamedir);
1.81 @@ -242,10 +264,17 @@
1.82 RenameFile(backup_name, old_path);
1.83 return;
1.84 }
1.85 + RemoveFile(new_path);
1.86 +
1.87 + Error("Server is restarting to load Metamod:Source");
1.88 +}
1.89 +
1.90 +bool RemoveFile(const char *file)
1.91 +{
1.92 #if defined _MSC_VER
1.93 - _unlink(new_path);
1.94 + return (_unlink(file) == 0);
1.95 #else
1.96 - unlink(new_path);
1.97 + return (unlink(file) == 0);
1.98 #endif
1.99 }
1.100