UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>

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. More...
 
char * Sys_FindNext (unsigned musthave, unsigned canthave)
 Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask. More...
 
void Sys_FindClose (void)
 Closes the find handle. More...
 
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. More...
 
char * Sys_Cwd (void)
 Get current working dir. More...
 
void Sys_NormPath (char *path)
 Normalize path (remove all \ ) More...
 
char * Sys_GetHomeDirectory (void)
 Get the home directory in Application Data. More...
 
void Sys_Sleep (int milliseconds)
 Calls the win32 sleep function. More...
 
int Sys_Setenv (const char *name, const char *value)
 set/unset environment variables (empty value removes it) More...
 
void Sys_InitSignals (void)
 
void Sys_Mkfifo (const char *ospath, qFILE *f)
 
void Sys_OpenURL (const char *url)
 
FILESys_Fopen (const char *filename, const char *mode)
 
int Sys_Remove (const char *filename)
 
int Sys_Rename (const char *oldname, const char *newname)
 
int Sys_Access (const char *filename, int mode)
 

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

#define MAX_FOUND_FILES   0x1000

Definition at line 270 of file win_shared.cpp.

Function Documentation

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

Definition at line 171 of file win_shared.cpp.

References SFF_ARCH, SFF_HIDDEN, SFF_RDONLY, SFF_SUBDIR, and SFF_SYSTEM.

Referenced by Sys_FindFirst(), and Sys_FindNext().

int Sys_Access ( const char *  filename,
int  mode 
)

Definition at line 546 of file win_shared.cpp.

References lengthof, MAX_OSPATH, and Sys_Utf8ToUtf16().

Referenced by FS_FileExists().

void Sys_Breakpoint ( void  )

Definition at line 71 of file win_shared.cpp.

Referenced by Com_BreakIntoDebugger().

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, and Sys_Utf16ToUtf8().

Referenced by FS_GetCwd().

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.

Referenced by FS_ListFiles().

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_sprintf(), CompareAttributes(), findpath, lengthof, Q_streq, Sys_Error(), Sys_Utf16ToUtf8(), and Sys_Utf8ToUtf16().

Referenced by FS_ListFiles().

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

Definition at line 236 of file win_shared.cpp.

References Com_sprintf(), CompareAttributes(), findpath, Q_streq, and Sys_Utf16ToUtf8().

Referenced by FS_ListFiles().

FILE* Sys_Fopen ( const char *  filename,
const char *  mode 
)
const char* Sys_GetCurrentUser ( void  )

Get current user.

Definition at line 387 of file win_shared.cpp.

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

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_Utf16ToUtf8(), and Sys_Utf8ToUtf16().

Referenced by FS_GetHomeDirectory().

const char* Sys_GetLocale ( void  )

Definition at line 156 of file win_shared.cpp.

Referenced by CL_LanguageInit().

void Sys_InitSignals ( void  )

Definition at line 508 of file win_shared.cpp.

Referenced by main(), and Qcommon_Init().

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

Definition at line 64 of file win_shared.cpp.

References lengthof, MAX_OSPATH, and Sys_Utf8ToUtf16().

Referenced by FS_CreatePath().

void Sys_Mkfifo ( const char *  ospath,
qFILE f 
)

Definition at line 512 of file win_shared.cpp.

Referenced by FS_CreateOpenPipeFile().

void Sys_NormPath ( char *  path)

Normalize path (remove all \ )

Definition at line 420 of file win_shared.cpp.

Referenced by FS_NormPath().

void Sys_OpenURL ( const char *  url)

Definition at line 516 of file win_shared.cpp.

Referenced by CL_OpenURL_f().

void Sys_Quit ( void  )
int Sys_Remove ( const char *  filename)

Definition at line 530 of file win_shared.cpp.

References lengthof, MAX_OSPATH, and Sys_Utf8ToUtf16().

Referenced by CL_HTTP_Cleanup(), FS_RemoveFile(), and FS_WriteFile().

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

Definition at line 537 of file win_shared.cpp.

References lengthof, MAX_OSPATH, and Sys_Utf8ToUtf16().

Referenced by FS_RenameFile().

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.

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

const char* Sys_SetLocale ( const char *  localeID)

Definition at line 147 of file win_shared.cpp.

References Sys_Setenv().

Referenced by CL_LanguageTryToSet().

void Sys_Sleep ( int  milliseconds)

Calls the win32 sleep function.

Definition at line 484 of file win_shared.cpp.

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

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

Variable Documentation

char findbase[MAX_OSPATH]
static

Definition at line 165 of file win_shared.cpp.

intptr_t findhandle
static

Definition at line 169 of file win_shared.cpp.

char findname[MAX_OSPATH]
static

Definition at line 167 of file win_shared.cpp.

char findpath[MAX_OSPATH]
static

Definition at line 166 of file win_shared.cpp.

Referenced by Sys_FindFirst(), and Sys_FindNext().

HINSTANCE global_hInstance

Definition at line 39 of file win_shared.cpp.

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

WCHAR wfindpath[MAX_OSPATH]
static

Definition at line 168 of file win_shared.cpp.