Pyrogenesis  trunk
Classes | Functions | Variables
wsysdep.cpp File Reference
#include "precompiled.h"
#include "lib/sysdep/sysdep.h"
#include "lib/alignment.h"
#include "lib/sysdep/os/win/win.h"
#include <shlobj.h>
#include <shellapi.h>
#include <Wincrypt.h>
#include <WindowsX.h>
#include <winhttp.h>
#include "lib/sysdep/clipboard.h"
#include "lib/sysdep/os/win/error_dialog.h"
#include "lib/sysdep/os/win/wutil.h"
Include dependency graph for wsysdep.cpp:

Classes

struct  DialogParams
 

Functions

bool sys_IsDebuggerPresent ()
 
std::wstring sys_WideFromArgv (const char *argv_i)
 
void sys_display_msg (const wchar_t *caption, const wchar_t *msg)
 display a message. More...
 
static void dlg_OnMove (HWND hDlg, int x, int y)
 
static void dlg_ResizeControl (HWND hDlg, int dlgItem, int dx, int dy, size_t anchors)
 
static void dlg_OnSize (HWND hDlg, UINT state, int clientSizeX, int clientSizeY)
 
static void dlg_OnGetMinMaxInfo (HWND hDlg, LPMINMAXINFO mmi)
 
static BOOL dlg_OnInitDialog (HWND hDlg, HWND hWndFocus, LPARAM lParam)
 
static void dlg_OnCommand (HWND hDlg, int id, HWND hWndCtl, UINT codeNotify)
 
static void dlg_OnSysCommand (HWND hDlg, UINT cmd, int x, int y)
 
static INT_PTR CALLBACK dlg_OnMessage (HWND hDlg, unsigned int msg, WPARAM wParam, LPARAM lParam)
 
ErrorReactionInternal sys_display_error (const wchar_t *text, size_t flags)
 show the error dialog. More...
 
Status sys_StatusDescription (int user_err, wchar_t *buf, size_t max_chars)
 describe the current OS error state. More...
 
static Status GetModulePathname (HMODULE hModule, OsPath &pathname)
 
Status sys_get_module_filename (void *addr, OsPath &pathname)
 determine filename of the module to whom an address belongs. More...
 
OsPath sys_ExecutablePathname ()
 
std::wstring sys_get_user_name ()
 Get the current user's login name. More...
 
static int CALLBACK BrowseCallback (HWND hWnd, unsigned int msg, LPARAM lParam, LPARAM lpData)
 
Status sys_pick_directory (OsPath &path)
 Have the user choose a directory via OS dialog. More...
 
Status sys_open_url (const std::string &url)
 Open the user's default web browser to the given URL. More...
 
Status sys_generate_random_bytes (u8 *buffer, size_t size)
 generate high-quality random bytes. More...
 
FILE * sys_OpenFile (const OsPath &pathname, const char *mode)
 open a file like with fopen (but taking an OsPath argument). More...
 

Variables

static POINTS dlg_clientOrigin
 
static POINTS dlg_prevClientSize
 
static const size_t ANCHOR_LEFT = 0x01
 
static const size_t ANCHOR_RIGHT = 0x02
 
static const size_t ANCHOR_TOP = 0x04
 
static const size_t ANCHOR_BOTTOM = 0x08
 
static const size_t ANCHOR_ALL = 0x0F
 

Function Documentation

static int CALLBACK BrowseCallback ( HWND  hWnd,
unsigned int  msg,
LPARAM  lParam,
LPARAM  lpData 
)
static
static void dlg_OnCommand ( HWND  hDlg,
int  id,
HWND  hWndCtl,
UINT  codeNotify 
)
static
static void dlg_OnGetMinMaxInfo ( HWND  hDlg,
LPMINMAXINFO  mmi 
)
static
static BOOL dlg_OnInitDialog ( HWND  hDlg,
HWND  hWndFocus,
LPARAM  lParam 
)
static
static INT_PTR CALLBACK dlg_OnMessage ( HWND  hDlg,
unsigned int  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static
static void dlg_OnMove ( HWND  hDlg,
int  x,
int  y 
)
static
static void dlg_OnSize ( HWND  hDlg,
UINT  state,
int  clientSizeX,
int  clientSizeY 
)
static
static void dlg_OnSysCommand ( HWND  hDlg,
UINT  cmd,
int  x,
int  y 
)
static
static void dlg_ResizeControl ( HWND  hDlg,
int  dlgItem,
int  dx,
int  dy,
size_t  anchors 
)
static
static Status GetModulePathname ( HMODULE  hModule,
OsPath pathname 
)
static
ErrorReactionInternal sys_display_error ( const wchar_t text,
size_t  flags 
)

show the error dialog.

Parameters
textto display (practically unlimited length)
flagssee DebugDisplayErrorFlags.
Returns
ErrorReactionInternal (except ERI_EXIT, which is acted on immediately)

called from debug_DisplayError unless overridden by means of ah_display_error.

void sys_display_msg ( const wchar_t caption,
const wchar_t msg 
)

display a message.

Parameters
captiontitle message
msgmessage contents

implemented as a MessageBox on Win32 and printf on Unix. called from debug_DisplayMessage.

OsPath sys_ExecutablePathname ( )
Returns
full pathname of the current executable.

this is useful for determining installation directory, e.g. for VFS.

Status sys_generate_random_bytes ( u8 buf,
size_t  count 
)

generate high-quality random bytes.

this should only be used with small numbers of bytes, to avoid hogging the system's entropy.

Status sys_get_module_filename ( void *  addr,
OsPath pathname 
)

determine filename of the module to whom an address belongs.

Parameters
addr
pathnameFull path to module (unchanged unless INFO::OK is returned).
Returns
Status

note: this is useful for handling exceptions in other modules.

std::wstring sys_get_user_name ( )

Get the current user's login name.

Returns
login name, or empty string on error
bool sys_IsDebuggerPresent ( )
Returns
whether a debugger is attached to the process (if so, it is safe to use debug_break; otherwise, that would raise an exception)
Status sys_open_url ( const std::string &  url)

Open the user's default web browser to the given URL.

FILE* sys_OpenFile ( const OsPath pathname,
const char *  mode 
)

open a file like with fopen (but taking an OsPath argument).

Status sys_pick_directory ( OsPath path)

Have the user choose a directory via OS dialog.

Parameters
pathPath's input value determines the starting directory for faster browsing. if INFO::OK is returned, it receives chosen directory path.
Status sys_StatusDescription ( int  err,
wchar_t buf,
size_t  max_chars 
)

describe the current OS error state.

Parameters
errif not 0, use that as the error code to translate; otherwise, uses GetLastError or similar.
bufoutput buffer
max_charsrationale: it is expected to be rare that OS return/error codes are actually seen by user code, but we leave the possibility open.
std::wstring sys_WideFromArgv ( const char *  argv_i)
Returns
a wide string conversion of the platform's encoding of main's argv.

(NB: wseh.cpp defines a wmain that converts argv to UTF-8 and calls main(), but only if LIB_STATIC_LINK)

Variable Documentation

const size_t ANCHOR_ALL = 0x0F
static
const size_t ANCHOR_BOTTOM = 0x08
static
const size_t ANCHOR_LEFT = 0x01
static
const size_t ANCHOR_RIGHT = 0x02
static
const size_t ANCHOR_TOP = 0x04
static
POINTS dlg_clientOrigin
static
POINTS dlg_prevClientSize
static