00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../../common/common.h"
00027 #include "../../common/msg.h"
00028 #include "win_local.h"
00029 #include <fcntl.h>
00030 #include <float.h>
00031 #include <direct.h>
00032 #include <io.h>
00033
00034 qboolean s_win95, s_win2k, s_winxp, s_vista;
00035
00036 #define MAX_NUM_ARGVS 128
00037 static int argc;
00038 static const char *argv[MAX_NUM_ARGVS];
00039
00040 void Sys_Init (void)
00041 {
00042 OSVERSIONINFO vinfo;
00043 #if 0
00044 MEMORYSTATUS mem;
00045 #endif
00046
00047 sys_affinity = Cvar_Get("sys_affinity", "3", CVAR_ARCHIVE, "Which core to use - 1 = only first, 2 = only second, 3 = both");
00048 sys_priority = Cvar_Get("sys_priority", "0", CVAR_ARCHIVE, "Process priority - 0 = normal, 1 = high, 2 = realtime");
00049
00050 timeBeginPeriod(1);
00051
00052 vinfo.dwOSVersionInfoSize = sizeof(vinfo);
00053
00054 if (!GetVersionEx(&vinfo))
00055 Sys_Error("Couldn't get OS info");
00056
00057 if (vinfo.dwMajorVersion < 4)
00058 Sys_Error("UFO: AI requires windows version 4 or greater");
00059 if (vinfo.dwPlatformId == VER_PLATFORM_WIN32s)
00060 Sys_Error("UFO: AI doesn't run on Win32s");
00061 else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
00062 s_win95 = qtrue;
00063 else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
00064 if (vinfo.dwMajorVersion == 5 && vinfo.dwMinorVersion == 0)
00065 s_win2k = qtrue;
00066 else if (vinfo.dwMajorVersion == 5)
00067 s_winxp = qtrue;
00068 else if (vinfo.dwMajorVersion == 6)
00069 s_vista = qtrue;
00070 }
00071
00072 if (s_win95)
00073 sys_os = Cvar_Get("sys_os", "win95", CVAR_SERVERINFO, NULL);
00074 else if (s_win2k)
00075 sys_os = Cvar_Get("sys_os", "win2K", CVAR_SERVERINFO, NULL);
00076 else if (s_winxp)
00077 sys_os = Cvar_Get("sys_os", "winXP", CVAR_SERVERINFO, NULL);
00078 else if (s_vista)
00079 sys_os = Cvar_Get("sys_os", "winVista", CVAR_SERVERINFO, NULL);
00080 else
00081 sys_os = Cvar_Get("sys_os", "win", CVAR_SERVERINFO, NULL);
00082
00083 #if 0
00084 GlobalMemoryStatus(&mem);
00085 Com_Printf("Memory: %u MB\n", mem.dwTotalPhys >> 20);
00086 #endif
00087 }
00088
00093 void Sys_SetAffinityAndPriority (void)
00094 {
00095 SYSTEM_INFO sysInfo;
00096
00097
00098
00099 HANDLE proc = GetCurrentProcess();
00100
00101 if (sys_priority->modified) {
00102 if (sys_priority->integer < 0)
00103 Cvar_SetValue("sys_priority", 0);
00104 else if (sys_priority->integer > 2)
00105 Cvar_SetValue("sys_priority", 2);
00106
00107 sys_priority->modified = qfalse;
00108
00109 switch (sys_priority->integer) {
00110 case 0:
00111 SetPriorityClass(proc, NORMAL_PRIORITY_CLASS);
00112 Com_Printf("Priority changed to NORMAL\n");
00113 break;
00114 case 1:
00115 SetPriorityClass(proc, HIGH_PRIORITY_CLASS);
00116 Com_Printf("Priority changed to HIGH\n");
00117 break;
00118 default:
00119 SetPriorityClass(proc, REALTIME_PRIORITY_CLASS);
00120 Com_Printf("Priority changed to REALTIME\n");
00121 break;
00122 }
00123 }
00124
00125 if (sys_affinity->modified) {
00126 DWORD_PTR procAffinity = 0;
00127 GetSystemInfo(&sysInfo);
00128 Com_Printf("Found %i processors\n", (int)sysInfo.dwNumberOfProcessors);
00129 sys_affinity->modified = qfalse;
00130 if (sysInfo.dwNumberOfProcessors == 2) {
00131 switch (sys_affinity->integer) {
00132 case 1:
00133 Com_Printf("Only use the first core\n");
00134 procAffinity = 1;
00135 break;
00136 case 2:
00137 Com_Printf("Only use the second core\n");
00138 procAffinity = 2;
00139 break;
00140 case 3:
00141 Com_Printf("Use both cores\n");
00142 Cvar_SetValue("r_threads", 1);
00143 procAffinity = 3;
00144 break;
00145 }
00146 } else if (sysInfo.dwNumberOfProcessors > 2) {
00147 switch (sys_affinity->integer) {
00148 case 1:
00149 Com_Printf("Use all cores\n");
00150 procAffinity = (1 << sysInfo.dwNumberOfProcessors) - 1;
00151 break;
00152 case 2:
00153 Com_Printf("Only use two cores\n");
00154 procAffinity = 3;
00155 break;
00156 case 3:
00157 Com_Printf("Only use one core\n");
00158 procAffinity = 1;
00159 break;
00160 }
00161 } else {
00162 Com_Printf("...only use one processor\n");
00163 }
00164 SetProcessAffinityMask(proc, procAffinity);
00165 }
00166
00167 CloseHandle(proc);
00168 }
00169
00170
00171 const char *Sys_SetLocale (const char *localeID)
00172 {
00173 Sys_Setenv("LANG", localeID);
00174 Sys_Setenv("LANGUAGE", localeID);
00175
00176 return localeID;
00177 }
00178
00179 const char *Sys_GetLocale (void)
00180 {
00181 if (getenv("LANGUAGE"))
00182 return getenv("LANGUAGE");
00183 else
00184
00185 return "en";
00186 }
00187
00188 static void ParseCommandLine (LPSTR lpCmdLine)
00189 {
00190 argc = 1;
00191 argv[0] = "exe";
00192
00193 while (*lpCmdLine && (argc < MAX_NUM_ARGVS)) {
00194 while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
00195 lpCmdLine++;
00196
00197 if (*lpCmdLine) {
00198 argv[argc] = lpCmdLine;
00199 argc++;
00200
00201 while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
00202 lpCmdLine++;
00203
00204 if (*lpCmdLine) {
00205 *lpCmdLine = 0;
00206 lpCmdLine++;
00207 }
00208 }
00209 }
00210 }
00211
00212 static void FixWorkingDirectory (void)
00213 {
00214 char *p;
00215 char curDir[MAX_PATH];
00216
00217 GetModuleFileName(NULL, curDir, sizeof(curDir)-1);
00218
00219 p = strrchr(curDir, '\\');
00220 p[0] = 0;
00221
00222 if (strlen(curDir) > (MAX_OSPATH - MAX_QPATH))
00223 Sys_Error("Current path is too long. Please move your installation to a shorter path.");
00224
00225 SetCurrentDirectory(curDir);
00226 }
00227
00228 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
00229 {
00230
00231 if (hPrevInstance)
00232 return 0;
00233
00234 global_hInstance = hInstance;
00235
00236 ParseCommandLine(lpCmdLine);
00237
00238 Sys_ConsoleInit();
00239
00240
00241 FixWorkingDirectory();
00242
00243 Qcommon_Init(argc, argv);
00244
00245
00246 while (1)
00247 Qcommon_Frame();
00248
00249
00250 return FALSE;
00251 }