43 const int len = MultiByteToWideChar(CP_UTF8, 0, source, -1,
dest, destlen - 1);
49 const int len = WideCharToMultiByte(CP_UTF8, 0, source, -1,
dest, destsize - 1,
nullptr,
nullptr);
59 base = timeGetTime() & 0xffff0000;
61 return timeGetTime() - base;
75#elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
76 __asm__ __volatile__ (
"int $3\n\t" );
91 HANDLE proc = GetCurrentProcess();
103 SetPriorityClass(proc, NORMAL_PRIORITY_CLASS);
107 SetPriorityClass(proc, HIGH_PRIORITY_CLASS);
111 SetPriorityClass(proc, REALTIME_PRIORITY_CLASS);
119 GetSystemInfo(&sysInfo);
120 Com_Printf(
"Found %i processors\n", (
int)sysInfo.dwNumberOfProcessors);
122 if (sysInfo.dwNumberOfProcessors >= 2) {
126 procAffinity = (1 << sysInfo.dwNumberOfProcessors) - 1;
140 SetProcessAffinityMask(proc, procAffinity);
158 if (getenv(
"LANGUAGE"))
159 return getenv(
"LANGUAGE");
173 if ((found & _A_RDONLY) && (canthave &
SFF_RDONLY))
175 if ((found & _A_HIDDEN) && (canthave &
SFF_HIDDEN))
177 if ((found & _A_SYSTEM) && (canthave &
SFF_SYSTEM))
179 if ((found & _A_SUBDIR) && (canthave &
SFF_SUBDIR))
181 if ((found & _A_ARCH) && (canthave &
SFF_ARCH))
184 if ((musthave &
SFF_RDONLY) && !(found & _A_RDONLY))
186 if ((musthave &
SFF_HIDDEN) && !(found & _A_HIDDEN))
188 if ((musthave &
SFF_SYSTEM) && !(found & _A_SYSTEM))
190 if ((musthave &
SFF_SUBDIR) && !(found & _A_SUBDIR))
192 if ((musthave &
SFF_ARCH) && !(found & _A_ARCH))
204 struct _wfinddata_t findinfo;
207 Sys_Error(
"Sys_BeginFind without close");
221 }
else if (_wfindnext(
findhandle, &findinfo) == -1) {
238 struct _wfinddata_t findinfo;
244 while (_wfindnext(
findhandle, &findinfo) != -1) {
270#define MAX_FOUND_FILES 0x1000
276 struct _wfinddata_t findinfo;
278 if (subdirs[0] !=
'\0') {
279 Com_sprintf(search,
sizeof(search),
"%s\\%s\\*", basedir, subdirs);
281 Com_sprintf(search,
sizeof(search),
"%s\\*", basedir);
290 if (findinfo.attrib & _A_SUBDIR) {
293 if (subdirs[0] !=
'\0') {
305 }
while (_wfindnext(
findhandle, &findinfo) != -1);
332static void Sys_ColoredOutput (
const char* text,
unsigned int fgColor,
bool toStdOut)
335 unsigned int cliPaintColor = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
337 unsigned int cliCurColor = cliPaintColor;
338 CONSOLE_SCREEN_BUFFER_INFO cliInfo;
339 const DWORD handle = toStdOut ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE;
340 const HANDLE console = GetStdHandle(handle);
342 if (GetConsoleScreenBufferInfo(console, &cliInfo)) {
344 cliCurColor = cliInfo.wAttributes;
346 if (cliCurColor == (fgColor << 4)) {
348 cliPaintColor = fgColor;
351 cliPaintColor = cliCurColor >> 4;
354 cliPaintColor |= fgColor;
358 SetConsoleTextAttribute(console, cliPaintColor);
360 fprintf(stdout,
"%s\n", text);
362 fprintf(stderr,
"Error: %s\n", text);
363 SetConsoleTextAttribute(console, cliCurColor);
365 CloseHandle(console);
373 va_start(argptr, error);
378 Sys_ColoredOutput(text, FOREGROUND_RED | FOREGROUND_INTENSITY,
false);
389 static char s_userName[1024];
390 WCHAR w_userName[1024];
393 if (!GetUserNameW(w_userName, &
size))
394 Q_strncpyz(s_userName,
"",
sizeof(s_userName));
409 if (_wgetcwd(wcwd,
lengthof(wcwd)) ==
nullptr)
428 *tmp = tolower(*tmp);
441 static char path[MAX_PATH];
443 const HMODULE shfolder = LoadLibrary(
"shfolder.dll");
445 if (shfolder ==
nullptr) {
450 typedef HRESULT WINAPI SHGetFolderPath_t(HWND,
int, HANDLE, DWORD, LPWSTR);
451 SHGetFolderPath_t*
const qSHGetFolderPath = (SHGetFolderPath_t*)GetProcAddress(shfolder,
"SHGetFolderPathW");
452 if (qSHGetFolderPath ==
nullptr) {
453 Com_Printf(
"Unable to find SHGetFolderPath in SHFolder.dll\n");
454 FreeLibrary(shfolder);
458 WCHAR wpath[MAX_PATH];
459 if (!SUCCEEDED(qSHGetFolderPath(
nullptr, CSIDL_APPDATA,
nullptr, 0, wpath))) {
460 Com_Printf(
"Unable to detect CSIDL_APPDATA\n");
461 FreeLibrary(shfolder);
466 Q_strcat(path,
sizeof(path),
"\\UFOAI");
467 FreeLibrary(shfolder);
470 if (!CreateDirectoryW(wpath,
nullptr)) {
471 if (GetLastError() != ERROR_ALREADY_EXISTS) {
472 Com_Printf(
"Unable to create directory \"%s\"\n", path);
486 if (milliseconds < 1)
498 const size_t n = strlen(
name) + strlen(value) + 2;
499 char* str = (
char*)malloc(n);
501 strcat(strcat(strcpy(str,
name),
"="), value);
505 return SetEnvironmentVariable(
name, value);
518 ShellExecute(NULL,
"open", url, NULL, NULL, SW_SHOWNORMAL);
527 return _wfopen(wname, wmode);
534 return _wremove(wname);
543 return _wrename(woldname, wnewname);
550 return _waccess(wname,
mode);
void CL_Shutdown(void)
Saves configuration file and shuts the client systems down.
void Com_Printf(const char *const fmt,...)
void Qcommon_Shutdown(void)
definitions common between client and server, but not game lib
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
void Sys_Error(const char *error,...)
void LIST_AddString(linkedList_t **listDest, const char *data)
Adds an string to a new or to an already existing linked list. The string is copied here.
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN GLenum GLuint * dest
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
#define Q_strcasecmp(a, b)
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
void Com_FilePath(const char *in, char *out, size_t size)
Returns the path up to, but not including the last /.
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
int Com_Filter(const char *pattern, const char *text)
Match the pattern PATTERN against the string TEXT;.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void Sys_SetAffinityAndPriority(void)
static char findbase[MAX_OSPATH]
static char findpath[MAX_OSPATH]
Win32-specific UFO header file.
HINSTANCE global_hInstance
void Sys_Sleep(int milliseconds)
Calls the win32 sleep function.
char * Sys_Cwd(void)
Get current working dir.
void Sys_Breakpoint(void)
void Sys_NormPath(char *path)
Normalize path (remove all \ ).
FILE * Sys_Fopen(const char *filename, const char *mode)
void Sys_InitSignals(void)
int Sys_Remove(const char *filename)
const char * Sys_GetLocale(void)
static intptr_t findhandle
void Sys_OpenURL(const char *url)
int Sys_Rename(const char *oldname, const char *newname)
char * Sys_GetHomeDirectory(void)
Get the home directory in Application Data.
void Sys_ListFilteredFiles(const char *basedir, const char *subdirs, const char *filter, linkedList_t **list)
static bool CompareAttributes(unsigned found, unsigned musthave, unsigned canthave)
static WCHAR wfindpath[MAX_OSPATH]
void Sys_Mkfifo(const char *ospath, qFILE *f)
char * Sys_FindFirst(const char *path, unsigned musthave, unsigned canthave)
Opens the directory and returns the first file that matches our searchrules.
int Sys_Milliseconds(void)
void Sys_Mkdir(const char *path)
void Sys_FindClose(void)
Closes the find handle.
static char findname[MAX_OSPATH]
int Sys_Setenv(const char *name, const char *value)
set/unset environment variables (empty value removes it)
static void Sys_Utf16ToUtf8(const LPWSTR source, char *dest, size_t destsize)
int Sys_Access(const char *filename, int mode)
static void Sys_Utf8ToUtf16(const char *source, LPWSTR dest, size_t destlen)
const char * Sys_GetCurrentUser(void)
Get current user.
char * Sys_FindNext(unsigned musthave, unsigned canthave)
Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask.
const char * Sys_SetLocale(const char *localeID)