OpenTTD Source 20260129-master-g2bb01bd0e4
win32.cpp File Reference

Implementation of MS Windows system calls. More...

#include "../../stdafx.h"
#include "../../debug.h"
#include "../../gfx_func.h"
#include "../../strings_func.h"
#include "../../textbuf_gui.h"
#include "../../fileio_func.h"
#include <windows.h>
#include <fcntl.h>
#include <mmsystem.h>
#include <regstr.h>
#include <shlobj.h>
#include <shellapi.h>
#include <winnls.h>
#include <io.h>
#include "win32.h"
#include "../../fios.h"
#include "../../string_func.h"
#include <sys/stat.h>
#include "../../language.h"
#include "../../thread.h"
#include "../../library_loader.h"
#include "table/strings.h"
#include "../../safeguards.h"

Go to the source code of this file.

Macros

#define NO_SHOBJIDL_SORTDIRECTION
 
#define SORT_DIGITSASNUMBERS   0x00000008
 
#define LINGUISTIC_IGNORECASE   0x00000010
 

Functions

bool MyShowCursor (bool show, bool toggle)
 
void ShowOSErrorBox (std::string_view buf, bool)
 Show an error message.
 
void OSOpenBrowser (const std::string &url)
 Opens browser on MacOS.
 
bool FiosIsRoot (const std::string &file)
 
void FiosGetDrives (FileList &file_list)
 
bool FiosIsHiddenFile (const std::filesystem::path &path)
 
std::optional< uint64_t > FiosGetDiskFreeSpace (const std::string &path)
 
void CreateConsole ()
 
static std::string ConvertLfToCrLf (std::string_view msg)
 Replace linefeeds with carriage-return and linefeed.
 
static INT_PTR CALLBACK HelpDialogFunc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
 Callback function to handle the window.
 
void ShowInfoI (std::string_view str)
 
char * getcwd (char *buf, size_t size)
 
void DetermineBasePaths (std::string_view exe)
 
std::optional< std::string > GetClipboardContents ()
 Try to retrieve the current clipboard contents.
 
std::string FS2OTTD (std::wstring_view name)
 Convert to OpenTTD's encoding from a wide string.
 
std::wstring OTTD2FS (std::string_view name)
 Convert from OpenTTD's encoding to a wide string.
 
std::string_view convert_from_fs (const std::wstring_view src, std::span< char > dst_buf)
 Convert to OpenTTD's encoding from that of the environment in UNICODE.
 
wchar_t * convert_to_fs (std::string_view src, std::span< wchar_t > dst_buf)
 Convert from OpenTTD's encoding to that of the environment in UNICODE.
 
std::optional< std::string > GetCurrentLocale (const char *)
 Determine the current user's locale.
 
void Win32SetCurrentLocaleName (std::string iso_code)
 
static LibraryLoader::Function GetKernel32Function (const std::string &symbol_name)
 
int OTTDStringCompare (std::string_view s1, std::string_view s2)
 
int Win32StringContains (std::string_view str, std::string_view value, bool case_insensitive)
 Search if a string is contained in another string using the current locale.
 
void SetCurrentThreadName (const std::string &)
 Name the thread this function is called on for the debugger.
 

Variables

static bool _has_console
 
static bool _cursor_disable = true
 
static bool _cursor_visible = true
 
std::string _config_file
 Configuration file of OpenTTD.
 
static WCHAR _cur_iso_locale [16] = L""
 

Detailed Description

Implementation of MS Windows system calls.

Definition in file win32.cpp.

Macro Definition Documentation

◆ NO_SHOBJIDL_SORTDIRECTION

#define NO_SHOBJIDL_SORTDIRECTION

Definition at line 20 of file win32.cpp.

Function Documentation

◆ convert_from_fs()

std::string_view convert_from_fs ( const std::wstring_view  src,
std::span< char >  dst_buf 
)

Convert to OpenTTD's encoding from that of the environment in UNICODE.

OpenTTD encoding is UTF8, local is wide.

Parameters
srcwide string that will be converted
dst_bufspan of valid char buffer that will receive the converted string
Returns
pointer to dst_buf. If conversion fails the string is of zero-length

Definition at line 375 of file win32.cpp.

Referenced by HandleIMEComposition(), MusicDriver_DMusic::Start(), and MusicDriver_Win32::Start().

◆ convert_to_fs()

wchar_t * convert_to_fs ( std::string_view  src,
std::span< wchar_t >  dst_buf 
)

Convert from OpenTTD's encoding to that of the environment in UNICODE.

OpenTTD encoding is UTF8, local is wide.

Parameters
srcstring that will be converted
dst_bufspan of valid wide-char buffer that will receive the converted string
Returns
pointer to dst_buf. If conversion fails the string is of zero-length

Definition at line 392 of file win32.cpp.

Referenced by HFontFromFont(), and Win32FontCacheFactory::LoadFont().

◆ ConvertLfToCrLf()

static std::string ConvertLfToCrLf ( std::string_view  msg)
static

Replace linefeeds with carriage-return and linefeed.

Parameters
msgstring with LF linefeeds.
Returns
String with Lf linefeeds converted to CrLf linefeeds.

Definition at line 168 of file win32.cpp.

◆ CreateConsole()

void CreateConsole ( )

Definition at line 110 of file win32.cpp.

◆ DetermineBasePaths()

void DetermineBasePaths ( std::string_view  exe)

Definition at line 237 of file win32.cpp.

◆ FiosGetDiskFreeSpace()

std::optional< uint64_t > FiosGetDiskFreeSpace ( const std::string &  path)

Definition at line 97 of file win32.cpp.

◆ FiosGetDrives()

void FiosGetDrives ( FileList file_list)

Definition at line 69 of file win32.cpp.

◆ FiosIsHiddenFile()

bool FiosIsHiddenFile ( const std::filesystem::path &  path)

Definition at line 86 of file win32.cpp.

◆ FiosIsRoot()

bool FiosIsRoot ( const std::string &  file)

Definition at line 64 of file win32.cpp.

◆ FS2OTTD()

std::string FS2OTTD ( std::wstring_view  name)

Convert to OpenTTD's encoding from a wide string.

OpenTTD internal encoding is UTF8.

Parameters
namevalid string that will be converted (local, or wide)
Returns
converted string; if failed string is of zero-length
See also
the current code-page comes from video\win32_v.cpp, event-notification WM_INPUTLANGCHANGE

Definition at line 340 of file win32.cpp.

Referenced by _ValidateSignatureFile(), TarScanner::AddFile(), NetworkError::AsString(), DetermineBasePaths(), FillLanguageList(), FiosGetFileList(), GetClipboardContents(), HandleIMEComposition(), InitializeLanguagePacks(), openttd_main(), ReadLanguagePack(), ReconsiderGameScriptLanguage(), NetworkAddress::Resolve(), ScanPath(), and SurveyConfiguration().

◆ GetClipboardContents()

std::optional< std::string > GetClipboardContents ( )

Try to retrieve the current clipboard contents.

Note
OS-specific function.
Returns
The (optional) clipboard contents.

Definition at line 316 of file win32.cpp.

References FS2OTTD().

◆ GetCurrentLocale()

std::optional< std::string > GetCurrentLocale ( const char *  )

Determine the current user's locale.

Definition at line 401 of file win32.cpp.

◆ getcwd()

char * getcwd ( char *  buf,
size_t  size 
)

Definition at line 227 of file win32.cpp.

◆ GetKernel32Function()

static LibraryLoader::Function GetKernel32Function ( const std::string &  symbol_name)
static

Definition at line 436 of file win32.cpp.

◆ HelpDialogFunc()

static INT_PTR CALLBACK HelpDialogFunc ( HWND  wnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Callback function to handle the window.

Definition at line 185 of file win32.cpp.

◆ MyShowCursor()

bool MyShowCursor ( bool  show,
bool  toggle 
)

Definition at line 41 of file win32.cpp.

◆ OSOpenBrowser()

void OSOpenBrowser ( const std::string &  url)

Opens browser on MacOS.

Parameters
urlWeb page address to open.

Definition at line 59 of file win32.cpp.

References OTTD2FS().

◆ OTTD2FS()

std::wstring OTTD2FS ( std::string_view  name)

Convert from OpenTTD's encoding to a wide string.

OpenTTD internal encoding is UTF8.

Parameters
namevalid string that will be converted (UTF8)
console_cpconvert to the console encoding instead of the normal system encoding.
Returns
converted string; if failed string is of zero-length

Definition at line 357 of file win32.cpp.

Referenced by _ValidateSignatureFile(), FiosFileScanner::AddFile(), TarScanner::AddFile(), DetermineBasePaths(), FileExists(), FillLanguageList(), FioCreateDirectory(), FioRemove(), FiosGetFileList(), VideoDriver_Win32Base::MakeWindow(), FileHandle::Open(), openttd_main(), OSOpenBrowser(), IniFile::SaveToDisk(), FileScanner::Scan(), FileScanner::Scan(), and ShowOSErrorBox().

◆ OTTDStringCompare()

int OTTDStringCompare ( std::string_view  s1,
std::string_view  s2 
)

Definition at line 442 of file win32.cpp.

◆ SetCurrentThreadName()

void SetCurrentThreadName ( const std::string &  name)

Name the thread this function is called on for the debugger.

Parameters
nameName to set for the thread..

Definition at line 534 of file win32.cpp.

Referenced by StartNewThread().

◆ ShowInfoI()

void ShowInfoI ( std::string_view  str)

Definition at line 204 of file win32.cpp.

◆ ShowOSErrorBox()

void ShowOSErrorBox ( std::string_view  buf,
bool  system 
)

Show an error message.

Parameters
bufText with error message.
systemWhether message text originates from OS.

Definition at line 53 of file win32.cpp.

References OTTD2FS(), and ShowMacDialog().

Referenced by FatalErrorI(), and UserErrorI().

◆ Win32SetCurrentLocaleName()

void Win32SetCurrentLocaleName ( std::string  iso_code)

Definition at line 419 of file win32.cpp.

◆ Win32StringContains()

int Win32StringContains ( std::string_view  str,
std::string_view  value,
bool  case_insensitive 
)

Search if a string is contained in another string using the current locale.

Parameters
strString to search in.
valueString to search for.
case_insensitiveSearch case-insensitive.
Returns
1 if value was found, 0 if it was not found, or -1 if not supported by the OS.

Definition at line 480 of file win32.cpp.

Referenced by StrNaturalContains(), and StrNaturalContainsIgnoreCase().

Variable Documentation

◆ _config_file

std::string _config_file
extern

Configuration file of OpenTTD.

Definition at line 64 of file settings.cpp.

Referenced by DeleteGRFPresetFromConfig(), GetGRFPresetList(), LoadFromConfig(), LoadGRFPresetFromConfig(), SaveGRFPresetToConfig(), and SaveToConfig().

◆ _cur_iso_locale

WCHAR _cur_iso_locale[16] = L""
static

Definition at line 417 of file win32.cpp.

◆ _cursor_disable

bool _cursor_disable = true
static

Definition at line 38 of file win32.cpp.

◆ _cursor_visible

bool _cursor_visible = true
static

Definition at line 39 of file win32.cpp.

◆ _has_console

bool _has_console
static

Definition at line 37 of file win32.cpp.