Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
wsysdep.cpp File Reference
#include "precompiled.h"
#include "lib/sysdep/sysdep.h"
#include "lib/alignment.h"
#include "lib/sysdep/os/win/win.h"
#include <SDL_clipboard.h>
#include <shlobj.h>
#include <shellapi.h>
#include <Wincrypt.h>
#include <WindowsX.h>
#include <winhttp.h>
#include "lib/sysdep/os/win/error_dialog.h"
#include "lib/sysdep/os/win/wutil.h"
#include <string_view>
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_OnClose (HWND hDlg)
 
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

◆ BrowseCallback()

static int CALLBACK BrowseCallback ( HWND  hWnd,
unsigned int  msg,
LPARAM  lParam,
LPARAM  lpData 
)
static

◆ dlg_OnClose()

static void dlg_OnClose ( HWND  hDlg)
static

◆ dlg_OnCommand()

static void dlg_OnCommand ( HWND  hDlg,
int  id,
HWND  hWndCtl,
UINT  codeNotify 
)
static

◆ dlg_OnGetMinMaxInfo()

static void dlg_OnGetMinMaxInfo ( HWND  hDlg,
LPMINMAXINFO  mmi 
)
static

◆ dlg_OnInitDialog()

static BOOL dlg_OnInitDialog ( HWND  hDlg,
HWND  hWndFocus,
LPARAM  lParam 
)
static

◆ dlg_OnMessage()

static INT_PTR CALLBACK dlg_OnMessage ( HWND  hDlg,
unsigned int  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

◆ dlg_OnMove()

static void dlg_OnMove ( HWND  hDlg,
int  x,
int  y 
)
static

◆ dlg_OnSize()

static void dlg_OnSize ( HWND  hDlg,
UINT  state,
int  clientSizeX,
int  clientSizeY 
)
static

◆ dlg_OnSysCommand()

static void dlg_OnSysCommand ( HWND  hDlg,
UINT  cmd,
int  x,
int  y 
)
static

◆ dlg_ResizeControl()

static void dlg_ResizeControl ( HWND  hDlg,
int  dlgItem,
int  dx,
int  dy,
size_t  anchors 
)
static

◆ GetModulePathname()

static Status GetModulePathname ( HMODULE  hModule,
OsPath pathname 
)
static

◆ sys_display_error()

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.

◆ sys_display_msg()

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.

◆ sys_ExecutablePathname()

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

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

◆ sys_generate_random_bytes()

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.

◆ sys_get_module_filename()

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.

◆ sys_get_user_name()

std::wstring sys_get_user_name ( )

Get the current user's login name.

Returns
login name, or empty string on error

◆ sys_IsDebuggerPresent()

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)

◆ sys_open_url()

Status sys_open_url ( const std::string &  url)

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

◆ sys_OpenFile()

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

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

◆ sys_pick_directory()

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.

◆ sys_StatusDescription()

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_chars

rationale: it is expected to be rare that OS return/error codes are actually seen by user code, but we leave the possibility open.

◆ sys_WideFromArgv()

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())

Variable Documentation

◆ ANCHOR_ALL

const size_t ANCHOR_ALL = 0x0F
static

◆ ANCHOR_BOTTOM

const size_t ANCHOR_BOTTOM = 0x08
static

◆ ANCHOR_LEFT

const size_t ANCHOR_LEFT = 0x01
static

◆ ANCHOR_RIGHT

const size_t ANCHOR_RIGHT = 0x02
static

◆ ANCHOR_TOP

const size_t ANCHOR_TOP = 0x04
static

◆ dlg_clientOrigin

POINTS dlg_clientOrigin
static

◆ dlg_prevClientSize

POINTS dlg_prevClientSize
static