UFO: Alien Invasion
Loading...
Searching...
No Matches
win_shared.cpp File Reference

Windows shared functions. More...

#include "../../common/common.h"
#include "win_local.h"
#include <fcntl.h>
#include <direct.h>
#include <io.h>
#include <conio.h>
#include <mmsystem.h>
#include <shellapi.h>
Include dependency graph for win_shared.cpp:

Go to the source code of this file.

Macros

#define MAX_FOUND_FILES   0x1000

Functions

static void Sys_Utf8ToUtf16 (const char *source, LPWSTR dest, size_t destlen)
static void Sys_Utf16ToUtf8 (const LPWSTR source, char *dest, size_t destsize)
int Sys_Milliseconds (void)
void Sys_Mkdir (const char *path)
void Sys_Breakpoint (void)
const char * Sys_SetLocale (const char *localeID)
const char * Sys_GetLocale (void)
static bool CompareAttributes (unsigned found, unsigned musthave, unsigned canthave)
char * Sys_FindFirst (const char *path, unsigned musthave, unsigned canthave)
 Opens the directory and returns the first file that matches our searchrules.
char * Sys_FindNext (unsigned musthave, unsigned canthave)
 Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask.
void Sys_FindClose (void)
 Closes the find handle.
void Sys_ListFilteredFiles (const char *basedir, const char *subdirs, const char *filter, linkedList_t **list)
void Sys_Quit (void)
const char * Sys_GetCurrentUser (void)
 Get current user.
char * Sys_Cwd (void)
 Get current working dir.
void Sys_NormPath (char *path)
 Normalize path (remove all \ ).
char * Sys_GetHomeDirectory (void)
 Get the home directory in Application Data.
void Sys_Sleep (int milliseconds)
 Calls the win32 sleep function.
int Sys_Setenv (const char *name, const char *value)
 set/unset environment variables (empty value removes it)
void Sys_InitSignals (void)
void Sys_Mkfifo (const char *ospath, qFILE *f)
void Sys_OpenURL (const char *url)
FILE * Sys_Fopen (const char *filenamefilename, const char *modemode)
int Sys_Remove (const char *filenamefilename)
int Sys_Rename (const char *oldname, const char *newname)
int Sys_Access (const char *filenamefilename, int modemode)

Variables

HINSTANCE global_hInstance
static char findbase [MAX_OSPATH]
static char findpath [MAX_OSPATH]
static char findname [MAX_OSPATH]
static WCHAR wfindpath [MAX_OSPATH]
static intptr_t findhandle

Detailed Description

Windows shared functions.

Definition in file win_shared.cpp.

Macro Definition Documentation

◆ MAX_FOUND_FILES

#define MAX_FOUND_FILES   0x1000

Definition at line 270 of file win_shared.cpp.

Function Documentation

◆ CompareAttributes()

bool CompareAttributes ( unsigned found,
unsigned musthave,
unsigned canthave )
static

Definition at line 171 of file win_shared.cpp.

References CompareAttributes(), SFF_ARCH, SFF_HIDDEN, SFF_RDONLY, SFF_SUBDIR, and SFF_SYSTEM.

◆ Sys_Access()

int Sys_Access ( const char * filename,
int mode )

◆ Sys_Breakpoint()

void Sys_Breakpoint ( void )

Definition at line 71 of file win_shared.cpp.

References Sys_Breakpoint().

Referenced by Com_BreakIntoDebugger(), Sys_Breakpoint(), and Sys_SetAffinityAndPriority().

◆ Sys_Cwd()

char * Sys_Cwd ( void )

Get current working dir.

Returns
nullptr if getcwd failed

Definition at line 404 of file win_shared.cpp.

References lengthof, MAX_OSPATH, Sys_Cwd(), and Sys_Utf16ToUtf8().

Referenced by FS_GetCwd(), Sys_Cwd(), and Sys_Mkfifo().

◆ Sys_FindClose()

void Sys_FindClose ( void )

Closes the find handle.

Note
Call this before calling a new Sys_FindFirst
See also
Sys_FindNext
Sys_FindFirst

Definition at line 263 of file win_shared.cpp.

References fdir, findhandle, and Sys_FindClose().

Referenced by format(), FS_ListFiles(), and Sys_FindClose().

◆ Sys_FindFirst()

char * Sys_FindFirst ( const char * path,
unsigned musthave,
unsigned canthave )

Opens the directory and returns the first file that matches our searchrules.

See also
Sys_FindNext
Sys_FindClose

Definition at line 202 of file win_shared.cpp.

References Com_FilePath(), Com_Filter(), Com_sprintf(), CompareAttributes(), fdir, findbase, findhandle, findname, findpath, findpattern, lengthof, Q_streq, Q_strncpyz(), Sys_Error(), Sys_FindFirst(), Sys_Utf16ToUtf8(), Sys_Utf8ToUtf16(), and wfindpath.

Referenced by format(), FS_ListFiles(), and Sys_FindFirst().

◆ Sys_FindNext()

char * Sys_FindNext ( unsigned musthave,
unsigned canthave )

Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask.

See also
Sys_FindFirst
Sys_FindClose
Sys_FindClose
Sys_FindFirst
static var findpattern

Definition at line 236 of file win_shared.cpp.

References Com_Filter(), Com_sprintf(), CompareAttributes(), fdir, findbase, findhandle, findname, findpath, findpattern, Q_streq, Sys_FindNext(), and Sys_Utf16ToUtf8().

Referenced by format(), FS_ListFiles(), and Sys_FindNext().

◆ Sys_Fopen()

◆ Sys_GetCurrentUser()

const char * Sys_GetCurrentUser ( void )

Get current user.

Definition at line 387 of file win_shared.cpp.

References lengthof, Q_strncpyz(), Sys_GetCurrentUser(), and Sys_Utf16ToUtf8().

◆ Sys_GetHomeDirectory()

char * Sys_GetHomeDirectory ( void )

Get the home directory in Application Data.

Returns the home environment variable (which hold the path of the user's homedir).

Note
Forced for Windows Vista
Use the cvar fs_usehomedir if you want to use the homedir for other Windows versions, too

Definition at line 439 of file win_shared.cpp.

References Com_Printf(), Q_strcat(), Sys_GetHomeDirectory(), Sys_Utf16ToUtf8(), and Sys_Utf8ToUtf16().

Referenced by format(), FS_GetHomeDirectory(), and Sys_GetHomeDirectory().

◆ Sys_GetLocale()

const char * Sys_GetLocale ( void )

Definition at line 156 of file win_shared.cpp.

References Sys_GetLocale().

Referenced by CL_LanguageInit(), and Sys_GetLocale().

◆ Sys_InitSignals()

void Sys_InitSignals ( void )

Definition at line 508 of file win_shared.cpp.

References Sys_InitSignals().

Referenced by main(), Qcommon_Init(), and Sys_InitSignals().

◆ Sys_ListFilteredFiles()

void Sys_ListFilteredFiles ( const char * basedir,
const char * subdirs,
const char * filter,
linkedList_t ** list )

◆ Sys_Milliseconds()

◆ Sys_Mkdir()

void Sys_Mkdir ( const char * path)

Definition at line 64 of file win_shared.cpp.

References Com_Printf(), lengthof, MAX_OSPATH, Sys_Mkdir(), and Sys_Utf8ToUtf16().

Referenced by format(), FS_CreatePath(), and Sys_Mkdir().

◆ Sys_Mkfifo()

void Sys_Mkfifo ( const char * ospath,
qFILE * f )

Definition at line 512 of file win_shared.cpp.

References f, and Sys_Mkfifo().

◆ Sys_NormPath()

void Sys_NormPath ( char * path)

Normalize path (remove all \ ).

Definition at line 420 of file win_shared.cpp.

References Sys_NormPath().

Referenced by FS_NormPath(), and Sys_NormPath().

◆ Sys_OpenURL()

void Sys_OpenURL ( const char * url)

Definition at line 516 of file win_shared.cpp.

References Com_sprintf(), and Sys_OpenURL().

Referenced by CL_OpenURL_f(), Sys_OpenURL(), and Sys_SetAffinityAndPriority().

◆ Sys_Quit()

void Sys_Quit ( void )
See also
Qcommon_Shutdown

Definition at line 310 of file win_shared.cpp.

References CL_Shutdown(), Mem_Shutdown(), Qcommon_Shutdown(), and Sys_Quit().

◆ Sys_Remove()

int Sys_Remove ( const char * filename)

◆ Sys_Rename()

int Sys_Rename ( const char * oldname,
const char * newname )

◆ Sys_Setenv()

int Sys_Setenv ( const char * name,
const char * value )

set/unset environment variables (empty value removes it)

Returns
nonzero if succeeds
Note
gettext FAQ recommends using both functions to set environment variable(s), so we do

Definition at line 496 of file win_shared.cpp.

References name, and Sys_Setenv().

Referenced by CL_Env_f(), CL_LanguageTest(), Rimp_Init(), Sys_Setenv(), and Sys_SetLocale().

◆ Sys_SetLocale()

const char * Sys_SetLocale ( const char * localeID)

Definition at line 147 of file win_shared.cpp.

References Sys_Setenv(), and Sys_SetLocale().

Referenced by CL_LanguageTryToSet(), and Sys_SetLocale().

◆ Sys_Sleep()

void Sys_Sleep ( int milliseconds)

Calls the win32 sleep function.

Definition at line 484 of file win_shared.cpp.

References long(), and Sys_Sleep().

Referenced by M_MusicStreamCallback(), NET_Wait(), R_RenderFrame(), R_RunThread(), Sys_Error(), and Sys_Sleep().

◆ Sys_Utf16ToUtf8()

void Sys_Utf16ToUtf8 ( const LPWSTR source,
char * dest,
size_t destsize )
static

◆ Sys_Utf8ToUtf16()

void Sys_Utf8ToUtf16 ( const char * source,
LPWSTR dest,
size_t destlen )
static

Variable Documentation

◆ findbase

char findbase[MAX_OSPATH]
static

Definition at line 165 of file win_shared.cpp.

◆ findhandle

intptr_t findhandle
static

Definition at line 169 of file win_shared.cpp.

Referenced by Sys_FindClose(), Sys_FindFirst(), Sys_FindNext(), and Sys_ListFilteredFiles().

◆ findname

char findname[MAX_OSPATH]
static

Definition at line 167 of file win_shared.cpp.

Referenced by Sys_FindFirst(), Sys_FindNext(), and Sys_ListFilteredFiles().

◆ findpath

char findpath[MAX_OSPATH]
static

Definition at line 166 of file win_shared.cpp.

◆ global_hInstance

HINSTANCE global_hInstance

Definition at line 39 of file win_shared.cpp.

Referenced by Sys_ConsoleInit(), Sys_ConsoleShutdown(), and WinMain().

◆ wfindpath

WCHAR wfindpath[MAX_OSPATH]
static

Definition at line 168 of file win_shared.cpp.

Referenced by Sys_FindFirst(), and Sys_ListFilteredFiles().