Update to 1.10.0-beta1
This commit is contained in:
@@ -26,9 +26,6 @@
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
/* printf format specification for 32/64-bit addresses. */
|
||||
#ifdef _M_AMD64
|
||||
#define PRINTF_PTR "0x%016IX"
|
||||
@@ -43,14 +40,14 @@ class CrashLogWindows : public CrashLog {
|
||||
/** Information about the encountered exception */
|
||||
EXCEPTION_POINTERS *ep;
|
||||
|
||||
/* virtual */ char *LogOSVersion(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogError(char *buffer, const char *last, const char *message) const;
|
||||
/* virtual */ char *LogStacktrace(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogRegisters(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogModules(char *buffer, const char *last) const;
|
||||
char *LogOSVersion(char *buffer, const char *last) const override;
|
||||
char *LogError(char *buffer, const char *last, const char *message) const override;
|
||||
char *LogStacktrace(char *buffer, const char *last) const override;
|
||||
char *LogRegisters(char *buffer, const char *last) const override;
|
||||
char *LogModules(char *buffer, const char *last) const override;
|
||||
public:
|
||||
#if defined(_MSC_VER)
|
||||
/* virtual */ int WriteCrashDump(char *filename, const char *filename_last) const;
|
||||
int WriteCrashDump(char *filename, const char *filename_last) const override;
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const;
|
||||
#else
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const { return buffer; }
|
||||
@@ -69,7 +66,7 @@ public:
|
||||
* A crash log is always generated when it's generated.
|
||||
* @param ep the data related to the exception.
|
||||
*/
|
||||
CrashLogWindows(EXCEPTION_POINTERS *ep = NULL) :
|
||||
CrashLogWindows(EXCEPTION_POINTERS *ep = nullptr) :
|
||||
ep(ep)
|
||||
{
|
||||
this->crashlog[0] = '\0';
|
||||
@@ -84,7 +81,7 @@ public:
|
||||
static CrashLogWindows *current;
|
||||
};
|
||||
|
||||
/* static */ CrashLogWindows *CrashLogWindows::current = NULL;
|
||||
/* static */ CrashLogWindows *CrashLogWindows::current = nullptr;
|
||||
|
||||
/* virtual */ char *CrashLogWindows::LogOSVersion(char *buffer, const char *last) const
|
||||
{
|
||||
@@ -117,7 +114,7 @@ public:
|
||||
" Message: %s\n\n",
|
||||
(int)ep->ExceptionRecord->ExceptionCode,
|
||||
(size_t)ep->ExceptionRecord->ExceptionAddress,
|
||||
message == NULL ? "<none>" : message
|
||||
message == nullptr ? "<none>" : message
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,7 +156,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
|
||||
HANDLE file;
|
||||
memset(dfi, 0, sizeof(*dfi));
|
||||
|
||||
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
||||
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, 0);
|
||||
if (file != INVALID_HANDLE_VALUE) {
|
||||
byte buffer[1024];
|
||||
DWORD numread;
|
||||
@@ -168,7 +165,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
|
||||
uint32 crc = (uint32)-1;
|
||||
|
||||
for (;;) {
|
||||
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0) {
|
||||
if (ReadFile(file, buffer, sizeof(buffer), &numread, nullptr) == 0 || numread == 0) {
|
||||
break;
|
||||
}
|
||||
filesize += numread;
|
||||
@@ -177,7 +174,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
|
||||
dfi->size = filesize;
|
||||
dfi->crc32 = crc ^ (uint32)-1;
|
||||
|
||||
if (GetFileTime(file, NULL, NULL, &write_time)) {
|
||||
if (GetFileTime(file, nullptr, nullptr, &write_time)) {
|
||||
FileTimeToSystemTime(&write_time, &dfi->file_time);
|
||||
}
|
||||
CloseHandle(file);
|
||||
@@ -220,7 +217,7 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
|
||||
BOOL res;
|
||||
|
||||
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
|
||||
if (proc != NULL) {
|
||||
if (proc != nullptr) {
|
||||
res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
|
||||
CloseHandle(proc);
|
||||
if (res) {
|
||||
@@ -231,7 +228,7 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
|
||||
}
|
||||
}
|
||||
}
|
||||
output = PrintModuleInfo(output, last, NULL);
|
||||
output = PrintModuleInfo(output, last, nullptr);
|
||||
return output + seprintf(output, last, "\n");
|
||||
}
|
||||
|
||||
@@ -322,6 +319,9 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
#pragma warning(disable:4091)
|
||||
#include <dbghelp.h>
|
||||
#pragma warning(default:4091)
|
||||
@@ -362,7 +362,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
||||
if (LoadLibraryList((Function*)&proc, dbg_import)) {
|
||||
/* Initialize symbol handler. */
|
||||
HANDLE hCur = GetCurrentProcess();
|
||||
proc.pSymInitialize(hCur, NULL, TRUE);
|
||||
proc.pSymInitialize(hCur, nullptr, TRUE);
|
||||
/* Load symbols only when needed, fail silently on errors, demangle symbol names. */
|
||||
proc.pSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_UNDNAME);
|
||||
|
||||
@@ -399,7 +399,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
||||
#else
|
||||
IMAGE_FILE_MACHINE_I386,
|
||||
#endif
|
||||
hCur, GetCurrentThread(), &frame, &ctx, NULL, proc.pSymFunctionTableAccess64, proc.pSymGetModuleBase64, NULL)) break;
|
||||
hCur, GetCurrentThread(), &frame, &ctx, nullptr, proc.pSymFunctionTableAccess64, proc.pSymGetModuleBase64, nullptr)) break;
|
||||
|
||||
if (frame.AddrPC.Offset == frame.AddrReturn.Offset) {
|
||||
buffer += seprintf(buffer, last, " <infinite loop>\n");
|
||||
@@ -443,16 +443,16 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
||||
{
|
||||
int ret = 0;
|
||||
HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll"));
|
||||
if (dbghelp != NULL) {
|
||||
if (dbghelp != nullptr) {
|
||||
typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE,
|
||||
MINIDUMP_TYPE,
|
||||
CONST PMINIDUMP_EXCEPTION_INFORMATION,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
||||
MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump");
|
||||
if (funcMiniDumpWriteDump != NULL) {
|
||||
if (funcMiniDumpWriteDump != nullptr) {
|
||||
seprintf(filename, filename_last, "%scrash.dmp", _personal_dir);
|
||||
HANDLE file = CreateFile(OTTD2FS(filename), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
||||
HANDLE file = CreateFile(OTTD2FS(filename), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0);
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
DWORD procid = GetCurrentProcessId();
|
||||
MINIDUMP_EXCEPTION_INFORMATION mdei;
|
||||
@@ -470,7 +470,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
||||
mdei.ExceptionPointers = ep;
|
||||
mdei.ClientPointers = false;
|
||||
|
||||
funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, NULL);
|
||||
funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, nullptr);
|
||||
ret = 1;
|
||||
} else {
|
||||
ret = -1;
|
||||
@@ -488,11 +488,11 @@ static void ShowCrashlogWindow();
|
||||
* Stack pointer for use when 'starting' the crash handler.
|
||||
* Not static as gcc's inline assembly needs it that way.
|
||||
*/
|
||||
void *_safe_esp = NULL;
|
||||
void *_safe_esp = nullptr;
|
||||
|
||||
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
||||
{
|
||||
if (CrashLogWindows::current != NULL) {
|
||||
if (CrashLogWindows::current != nullptr) {
|
||||
CrashLog::AfterCrashLogCleanup();
|
||||
ExitProcess(2);
|
||||
}
|
||||
@@ -501,7 +501,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
||||
static const TCHAR _emergency_crash[] =
|
||||
_T("A serious fault condition occurred in the game. The game will shut down.\n")
|
||||
_T("As you loaded an emergency savegame no crash information will be generated.\n");
|
||||
MessageBox(NULL, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
|
||||
MessageBox(nullptr, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
|
||||
ExitProcess(3);
|
||||
}
|
||||
|
||||
@@ -510,7 +510,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
||||
_T("A serious fault condition occurred in the game. The game will shut down.\n")
|
||||
_T("As you loaded an savegame for which you do not have the required NewGRFs\n")
|
||||
_T("no crash information will be generated.\n");
|
||||
MessageBox(NULL, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR);
|
||||
MessageBox(nullptr, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR);
|
||||
ExitProcess(3);
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
||||
/* Close any possible log files */
|
||||
CloseConsoleLogIfActive();
|
||||
|
||||
if ((VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != NULL) {
|
||||
if ((VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != nullptr) {
|
||||
#ifdef _M_AMD64
|
||||
ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow;
|
||||
ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
|
||||
@@ -542,7 +542,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
||||
|
||||
static void CDECL CustomAbort(int signal)
|
||||
{
|
||||
RaiseException(0xE1212012, 0, 0, NULL);
|
||||
RaiseException(0xE1212012, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
/* static */ void CrashLog::InitialiseCrashLog()
|
||||
@@ -693,5 +693,5 @@ static void ShowCrashlogWindow()
|
||||
{
|
||||
ShowCursor(TRUE);
|
||||
ShowWindow(GetActiveWindow(), FALSE);
|
||||
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc);
|
||||
DialogBox(GetModuleHandle(nullptr), MAKEINTRESOURCE(100), nullptr, CrashDialogFunc);
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,9,3,!!ISODATE!!
|
||||
PRODUCTVERSION 1,9,3,!!ISODATE!!
|
||||
FILEVERSION 1,10,0,!!ISODATE!!
|
||||
PRODUCTVERSION 1,10,0,!!ISODATE!!
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
||||
@@ -86,34 +86,35 @@ public:
|
||||
int num_glyphs;
|
||||
Font *font;
|
||||
|
||||
mutable int *glyph_to_char = NULL;
|
||||
mutable int *glyph_to_char = nullptr;
|
||||
|
||||
public:
|
||||
UniscribeVisualRun(const UniscribeRun &range, int x);
|
||||
virtual ~UniscribeVisualRun()
|
||||
UniscribeVisualRun(UniscribeVisualRun &&other) noexcept;
|
||||
~UniscribeVisualRun() override
|
||||
{
|
||||
free(this->glyph_to_char);
|
||||
}
|
||||
|
||||
virtual const GlyphID *GetGlyphs() const { return &this->glyphs[0]; }
|
||||
virtual const float *GetPositions() const { return &this->positions[0]; }
|
||||
virtual const int *GetGlyphToCharMap() const;
|
||||
const GlyphID *GetGlyphs() const override { return &this->glyphs[0]; }
|
||||
const float *GetPositions() const override { return &this->positions[0]; }
|
||||
const int *GetGlyphToCharMap() const override;
|
||||
|
||||
virtual const Font *GetFont() const { return this->font; }
|
||||
virtual int GetLeading() const { return this->font->fc->GetHeight(); }
|
||||
virtual int GetGlyphCount() const { return this->num_glyphs; }
|
||||
const Font *GetFont() const override { return this->font; }
|
||||
int GetLeading() const override { return this->font->fc->GetHeight(); }
|
||||
int GetGlyphCount() const override { return this->num_glyphs; }
|
||||
int GetAdvance() const { return this->total_advance; }
|
||||
};
|
||||
|
||||
/** A single line worth of VisualRuns. */
|
||||
class UniscribeLine : public AutoDeleteSmallVector<UniscribeVisualRun *, 4>, public ParagraphLayouter::Line {
|
||||
class UniscribeLine : public std::vector<UniscribeVisualRun>, public ParagraphLayouter::Line {
|
||||
public:
|
||||
virtual int GetLeading() const;
|
||||
virtual int GetWidth() const;
|
||||
virtual int CountRuns() const { return this->Length(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return *this->Get(run); }
|
||||
int GetLeading() const override;
|
||||
int GetWidth() const override;
|
||||
int CountRuns() const override { return (uint)this->size(); }
|
||||
const VisualRun &GetVisualRun(int run) const override { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(WChar c) const
|
||||
int GetInternalCharLength(WChar c) const override
|
||||
{
|
||||
/* Uniscribe uses UTF-16 internally which means we need to account for surrogate pairs. */
|
||||
return c >= 0x010000U ? 2 : 1;
|
||||
@@ -125,28 +126,30 @@ public:
|
||||
this->Reflow();
|
||||
}
|
||||
|
||||
virtual ~UniscribeParagraphLayout() {}
|
||||
~UniscribeParagraphLayout() override {}
|
||||
|
||||
virtual void Reflow()
|
||||
void Reflow() override
|
||||
{
|
||||
this->cur_range = this->ranges.begin();
|
||||
this->cur_range_offset = 0;
|
||||
}
|
||||
|
||||
virtual const Line *NextLine(int max_width);
|
||||
std::unique_ptr<const Line> NextLine(int max_width) override;
|
||||
};
|
||||
|
||||
void UniscribeResetScriptCache(FontSize size)
|
||||
{
|
||||
if (_script_cache[size] != NULL) {
|
||||
if (_script_cache[size] != nullptr) {
|
||||
ScriptFreeCache(&_script_cache[size]);
|
||||
_script_cache[size] = NULL;
|
||||
_script_cache[size] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the matching native Windows font. */
|
||||
static HFONT HFontFromFont(Font *font)
|
||||
{
|
||||
if (font->fc->GetOSHandle() != nullptr) return CreateFontIndirect((PLOGFONT)font->fc->GetOSHandle());
|
||||
|
||||
LOGFONT logfont;
|
||||
ZeroMemory(&logfont, sizeof(LOGFONT));
|
||||
logfont.lfHeight = font->fc->GetHeight();
|
||||
@@ -167,9 +170,9 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
/* The char-to-glyph array is the same size as the input. */
|
||||
range.char_to_glyph.resize(range.len);
|
||||
|
||||
HDC temp_dc = NULL;
|
||||
HFONT old_font = NULL;
|
||||
HFONT cur_font = NULL;
|
||||
HDC temp_dc = nullptr;
|
||||
HFONT old_font = nullptr;
|
||||
HFONT cur_font = nullptr;
|
||||
|
||||
while (true) {
|
||||
/* Shape the text run by determining the glyphs needed for display. */
|
||||
@@ -194,15 +197,19 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
}
|
||||
for (int i = 0; i < range.len; i++) {
|
||||
if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) {
|
||||
range.ft_glyphs[range.char_to_glyph[i]] = range.font->fc->MapCharToGlyph(buff[range.pos + i]);
|
||||
range.offsets[range.char_to_glyph[i]].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[range.char_to_glyph[i]])->height - 1; // Align sprite glyphs to font baseline.
|
||||
auto pos = range.char_to_glyph[i];
|
||||
range.ft_glyphs[pos] = range.font->fc->MapCharToGlyph(buff[range.pos + i]);
|
||||
range.offsets[pos].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[pos])->height - 1; // Align sprite glyphs to font baseline.
|
||||
range.advances[pos] = range.font->fc->GetGlyphWidth(range.ft_glyphs[pos]);
|
||||
}
|
||||
}
|
||||
|
||||
/* FreeType and GDI/Uniscribe seems to occasionally disagree over the width of a glyph. */
|
||||
range.total_advance = 0;
|
||||
for (size_t i = 0; i < range.advances.size(); i++) {
|
||||
#ifdef WITH_FREETYPE
|
||||
/* FreeType and GDI/Uniscribe seems to occasionally disagree over the width of a glyph. */
|
||||
if (range.advances[i] > 0 && range.ft_glyphs[i] != 0xFFFF) range.advances[i] = range.font->fc->GetGlyphWidth(range.ft_glyphs[i]);
|
||||
#endif
|
||||
range.total_advance += range.advances[i];
|
||||
}
|
||||
break;
|
||||
@@ -216,9 +223,9 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
} else if (hr == E_PENDING) {
|
||||
/* Glyph data is not in cache, load native font. */
|
||||
cur_font = HFontFromFont(range.font);
|
||||
if (cur_font == NULL) return false; // Sorry, no dice.
|
||||
if (cur_font == nullptr) return false; // Sorry, no dice.
|
||||
|
||||
temp_dc = CreateCompatibleDC(NULL);
|
||||
temp_dc = CreateCompatibleDC(nullptr);
|
||||
SetMapMode(temp_dc, MM_TEXT);
|
||||
old_font = (HFONT)SelectObject(temp_dc, cur_font);
|
||||
} else if (hr == USP_E_SCRIPT_NOT_IN_FONT && range.sa.eScript != SCRIPT_UNDEFINED) {
|
||||
@@ -226,19 +233,19 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
range.sa.eScript = SCRIPT_UNDEFINED;
|
||||
} else {
|
||||
/* Some unknown other error. */
|
||||
if (temp_dc != NULL) {
|
||||
if (temp_dc != nullptr) {
|
||||
SelectObject(temp_dc, old_font);
|
||||
DeleteObject(cur_font);
|
||||
ReleaseDC(NULL, temp_dc);
|
||||
ReleaseDC(nullptr, temp_dc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_dc != NULL) {
|
||||
if (temp_dc != nullptr) {
|
||||
SelectObject(temp_dc, old_font);
|
||||
DeleteObject(cur_font);
|
||||
ReleaseDC(NULL, temp_dc);
|
||||
ReleaseDC(nullptr, temp_dc);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -279,16 +286,16 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
{
|
||||
int32 length = buff_end - buff;
|
||||
/* Can't layout an empty string. */
|
||||
if (length == 0) return NULL;
|
||||
if (length == 0) return nullptr;
|
||||
|
||||
/* Can't layout our in-built sprite fonts. */
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
if (i->second->fc->IsBuiltInFont()) return NULL;
|
||||
for (auto const &pair : fontMapping) {
|
||||
if (pair.second->fc->IsBuiltInFont()) return nullptr;
|
||||
}
|
||||
|
||||
/* Itemize text. */
|
||||
std::vector<SCRIPT_ITEM> items = UniscribeItemizeString(buff, length);
|
||||
if (items.size() == 0) return NULL;
|
||||
if (items.size() == 0) return nullptr;
|
||||
|
||||
/* Build ranges from the items and the font map. A range is a run of text
|
||||
* that is part of a single item and formatted using a single font style. */
|
||||
@@ -296,16 +303,16 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
|
||||
int cur_pos = 0;
|
||||
std::vector<SCRIPT_ITEM>::iterator cur_item = items.begin();
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
while (cur_pos < i->first && cur_item != items.end() - 1) {
|
||||
for (auto const &i : fontMapping) {
|
||||
while (cur_pos < i.first && cur_item != items.end() - 1) {
|
||||
/* Add a range that spans the intersection of the remaining item and font run. */
|
||||
int stop_pos = min(i->first, (cur_item + 1)->iCharPos);
|
||||
int stop_pos = min(i.first, (cur_item + 1)->iCharPos);
|
||||
assert(stop_pos - cur_pos > 0);
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i->second, cur_item->a));
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i.second, cur_item->a));
|
||||
|
||||
/* Shape the range. */
|
||||
if (!UniscribeShapeRun(buff, ranges.back())) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* If we are at the end of the current item, advance to the next item. */
|
||||
@@ -317,12 +324,12 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
return new UniscribeParagraphLayout(ranges, buff);
|
||||
}
|
||||
|
||||
/* virtual */ const ParagraphLayouter::Line *UniscribeParagraphLayout::NextLine(int max_width)
|
||||
/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> UniscribeParagraphLayout::NextLine(int max_width)
|
||||
{
|
||||
std::vector<UniscribeRun>::iterator start_run = this->cur_range;
|
||||
std::vector<UniscribeRun>::iterator last_run = this->cur_range;
|
||||
|
||||
if (start_run == this->ranges.end()) return NULL;
|
||||
if (start_run == this->ranges.end()) return nullptr;
|
||||
|
||||
/* Add remaining width of the first run if it is a broken run. */
|
||||
int cur_width = 0;
|
||||
@@ -354,7 +361,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
int last_cluster = this->cur_range_offset + 1;
|
||||
for (std::vector<UniscribeRun>::iterator r = start_run; r != last_run; r++) {
|
||||
log_attribs.resize(r->pos - start_run->pos + r->len);
|
||||
if (FAILED(ScriptBreak(this->text_buffer + r->pos + start_offs, r->len - start_offs, &r->sa, &log_attribs[r->pos - start_run->pos + start_offs]))) return NULL;
|
||||
if (FAILED(ScriptBreak(this->text_buffer + r->pos + start_offs, r->len - start_offs, &r->sa, &log_attribs[r->pos - start_run->pos + start_offs]))) return nullptr;
|
||||
|
||||
std::vector<int> dx(r->len);
|
||||
ScriptGetLogicalWidths(&r->sa, r->len, (int)r->glyphs.size(), &r->advances[0], &r->char_to_glyph[0], &r->vis_attribs[0], &dx[0]);
|
||||
@@ -400,10 +407,10 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
bidi_level.push_back(r->sa.s.uBidiLevel);
|
||||
}
|
||||
std::vector<INT> vis_to_log(bidi_level.size());
|
||||
if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], NULL))) return NULL;
|
||||
if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], nullptr))) return nullptr;
|
||||
|
||||
/* Create line. */
|
||||
UniscribeLine *line = new UniscribeLine();
|
||||
std::unique_ptr<UniscribeLine> line(new UniscribeLine());
|
||||
|
||||
int cur_pos = 0;
|
||||
for (std::vector<INT>::iterator l = vis_to_log.begin(); l != vis_to_log.end(); l++) {
|
||||
@@ -414,17 +421,17 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
if (i_run == last_run - 1 && remaing_offset < (last_run - 1)->len) {
|
||||
run.len = remaing_offset - 1;
|
||||
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return NULL;
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return nullptr;
|
||||
}
|
||||
if (i_run == start_run && this->cur_range_offset > 0) {
|
||||
assert(run.len - this->cur_range_offset > 0);
|
||||
run.pos += this->cur_range_offset;
|
||||
run.len -= this->cur_range_offset;
|
||||
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return NULL;
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return nullptr;
|
||||
}
|
||||
|
||||
*line->Append() = new UniscribeVisualRun(run, cur_pos);
|
||||
line->emplace_back(run, cur_pos);
|
||||
cur_pos += run.total_advance;
|
||||
}
|
||||
|
||||
@@ -448,8 +455,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
{
|
||||
int leading = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
leading = max(leading, (*run)->GetLeading());
|
||||
for (const auto &run : *this) {
|
||||
leading = max(leading, run.GetLeading());
|
||||
}
|
||||
|
||||
return leading;
|
||||
@@ -462,8 +469,8 @@ int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetWidth() const
|
||||
{
|
||||
int length = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
length += (*run)->GetAdvance();
|
||||
for (const auto &run : *this) {
|
||||
length += run.GetAdvance();
|
||||
}
|
||||
|
||||
return length;
|
||||
@@ -484,9 +491,17 @@ UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(const Uniscribe
|
||||
this->positions[this->num_glyphs * 2] = advance + x;
|
||||
}
|
||||
|
||||
UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(UniscribeVisualRun&& other) noexcept
|
||||
: glyphs(std::move(other.glyphs)), positions(std::move(other.positions)), char_to_glyph(std::move(other.char_to_glyph)),
|
||||
start_pos(other.start_pos), total_advance(other.total_advance), num_glyphs(other.num_glyphs), font(other.font)
|
||||
{
|
||||
this->glyph_to_char = other.glyph_to_char;
|
||||
other.glyph_to_char = nullptr;
|
||||
}
|
||||
|
||||
const int *UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() const
|
||||
{
|
||||
if (this->glyph_to_char == NULL) {
|
||||
if (this->glyph_to_char == nullptr) {
|
||||
this->glyph_to_char = CallocT<int>(this->GetGlyphCount());
|
||||
|
||||
/* The char to glyph array contains the first glyph index of the cluster that is associated
|
||||
|
||||
@@ -81,10 +81,10 @@ class UniscribeStringIterator : public StringIterator {
|
||||
size_t cur_pos; ///< Current iteration position.
|
||||
|
||||
public:
|
||||
virtual void SetString(const char *s);
|
||||
virtual size_t SetCurPosition(size_t pos);
|
||||
virtual size_t Next(IterType what);
|
||||
virtual size_t Prev(IterType what);
|
||||
void SetString(const char *s) override;
|
||||
size_t SetCurPosition(size_t pos) override;
|
||||
size_t Next(IterType what) override;
|
||||
size_t Prev(IterType what) override;
|
||||
};
|
||||
|
||||
#endif /* defined(WITH_UNISCRIBE) */
|
||||
|
||||
+46
-57
@@ -30,6 +30,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../../language.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
@@ -60,14 +61,14 @@ bool LoadLibraryList(Function proc[], const char *dll)
|
||||
HMODULE lib;
|
||||
lib = LoadLibrary(MB_TO_WIDE(dll));
|
||||
|
||||
if (lib == NULL) return false;
|
||||
if (lib == nullptr) return false;
|
||||
for (;;) {
|
||||
FARPROC p;
|
||||
|
||||
while (*dll++ != '\0') { /* Nothing */ }
|
||||
if (*dll == '\0') break;
|
||||
p = GetProcAddress(lib, dll);
|
||||
if (p == NULL) return false;
|
||||
if (p == nullptr) return false;
|
||||
*proc++ = (Function)p;
|
||||
}
|
||||
dll++;
|
||||
@@ -83,7 +84,7 @@ void ShowOSErrorBox(const char *buf, bool system)
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
{
|
||||
ShellExecute(GetActiveWindow(), _T("open"), OTTD2FS(url), NULL, NULL, SW_SHOWNORMAL);
|
||||
ShellExecute(GetActiveWindow(), _T("open"), OTTD2FS(url), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
/* Code below for windows version of opendir/readdir/closedir copied and
|
||||
@@ -141,7 +142,7 @@ DIR *opendir(const TCHAR *path)
|
||||
|
||||
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
d = dir_calloc();
|
||||
if (d != NULL) {
|
||||
if (d != nullptr) {
|
||||
TCHAR search_path[MAX_PATH];
|
||||
bool slash = path[_tcslen(path) - 1] == '\\';
|
||||
|
||||
@@ -157,14 +158,14 @@ DIR *opendir(const TCHAR *path)
|
||||
d->at_first_entry = true;
|
||||
} else {
|
||||
dir_free(d);
|
||||
d = NULL;
|
||||
d = nullptr;
|
||||
}
|
||||
} else {
|
||||
errno = ENOMEM;
|
||||
}
|
||||
} else {
|
||||
/* path not found or not a directory */
|
||||
d = NULL;
|
||||
d = nullptr;
|
||||
errno = ENOENT;
|
||||
}
|
||||
|
||||
@@ -178,11 +179,11 @@ struct dirent *readdir(DIR *d)
|
||||
|
||||
if (d->at_first_entry) {
|
||||
/* the directory was empty when opened */
|
||||
if (d->hFind == INVALID_HANDLE_VALUE) return NULL;
|
||||
if (d->hFind == INVALID_HANDLE_VALUE) return nullptr;
|
||||
d->at_first_entry = false;
|
||||
} else if (!FindNextFile(d->hFind, &d->fd)) { // determine cause and bail
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES) SetLastError(prev_err);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* This entry has passed all checks; return information about it.
|
||||
@@ -250,7 +251,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
|
||||
DWORD spc, bps, nfc, tnc;
|
||||
|
||||
_sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]);
|
||||
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
||||
if (tot != nullptr && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
||||
*tot = ((spc * bps) * (uint64)nfc);
|
||||
retval = true;
|
||||
}
|
||||
@@ -338,9 +339,9 @@ void CreateConsole()
|
||||
*stderr = *fdopen(2, "w" );
|
||||
#endif
|
||||
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
setvbuf(stdin, nullptr, _IONBF, 0);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
setvbuf(stderr, nullptr, _IONBF, 0);
|
||||
}
|
||||
|
||||
/** Temporary pointer to get the help message to the window */
|
||||
@@ -397,7 +398,7 @@ void ShowInfo(const char *str)
|
||||
* ShowInfo are much shorter, or so long they need this way of displaying
|
||||
* them anyway. */
|
||||
_help_msg = str;
|
||||
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(101), NULL, HelpDialogFunc);
|
||||
DialogBox(GetModuleHandle(nullptr), MAKEINTRESOURCE(101), nullptr, HelpDialogFunc);
|
||||
} else {
|
||||
/* We need to put the text in a separate buffer because the default
|
||||
* buffer in OTTD2FS might not be large enough (512 chars). */
|
||||
@@ -458,28 +459,28 @@ void DetermineBasePaths(const char *exe)
|
||||
char tmp[MAX_PATH];
|
||||
TCHAR path[MAX_PATH];
|
||||
#ifdef WITH_PERSONAL_DIR
|
||||
if (SUCCEEDED(OTTDSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) {
|
||||
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
||||
strecpy(tmp, FS2OTTD(path), lastof(tmp));
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
strecat(tmp, PERSONAL_DIR, lastof(tmp));
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_PERSONAL_DIR] = stredup(tmp);
|
||||
} else {
|
||||
_searchpaths[SP_PERSONAL_DIR] = NULL;
|
||||
_searchpaths[SP_PERSONAL_DIR] = nullptr;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(OTTDSHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, SHGFP_TYPE_CURRENT, path))) {
|
||||
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
||||
strecpy(tmp, FS2OTTD(path), lastof(tmp));
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
strecat(tmp, PERSONAL_DIR, lastof(tmp));
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_SHARED_DIR] = stredup(tmp);
|
||||
} else {
|
||||
_searchpaths[SP_SHARED_DIR] = NULL;
|
||||
_searchpaths[SP_SHARED_DIR] = nullptr;
|
||||
}
|
||||
#else
|
||||
_searchpaths[SP_PERSONAL_DIR] = NULL;
|
||||
_searchpaths[SP_SHARED_DIR] = NULL;
|
||||
_searchpaths[SP_PERSONAL_DIR] = nullptr;
|
||||
_searchpaths[SP_SHARED_DIR] = nullptr;
|
||||
#endif
|
||||
|
||||
/* Get the path to working directory of OpenTTD */
|
||||
@@ -487,15 +488,15 @@ void DetermineBasePaths(const char *exe)
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_WORKING_DIR] = stredup(tmp);
|
||||
|
||||
if (!GetModuleFileName(NULL, path, lengthof(path))) {
|
||||
if (!GetModuleFileName(nullptr, path, lengthof(path))) {
|
||||
DEBUG(misc, 0, "GetModuleFileName failed (%lu)\n", GetLastError());
|
||||
_searchpaths[SP_BINARY_DIR] = NULL;
|
||||
_searchpaths[SP_BINARY_DIR] = nullptr;
|
||||
} else {
|
||||
TCHAR exec_dir[MAX_PATH];
|
||||
_tcsncpy(path, convert_to_fs(exe, path, lengthof(path)), lengthof(path));
|
||||
if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, NULL)) {
|
||||
if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, nullptr)) {
|
||||
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
|
||||
_searchpaths[SP_BINARY_DIR] = NULL;
|
||||
_searchpaths[SP_BINARY_DIR] = nullptr;
|
||||
} else {
|
||||
strecpy(tmp, convert_from_fs(exec_dir, tmp, lengthof(tmp)), lastof(tmp));
|
||||
char *s = strrchr(tmp, PATHSEPCHAR);
|
||||
@@ -504,8 +505,8 @@ void DetermineBasePaths(const char *exe)
|
||||
}
|
||||
}
|
||||
|
||||
_searchpaths[SP_INSTALLATION_DIR] = NULL;
|
||||
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
|
||||
_searchpaths[SP_INSTALLATION_DIR] = nullptr;
|
||||
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -515,18 +516,18 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
const char *ptr;
|
||||
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
||||
OpenClipboard(NULL);
|
||||
OpenClipboard(nullptr);
|
||||
cbuf = GetClipboardData(CF_UNICODETEXT);
|
||||
|
||||
ptr = (const char*)GlobalLock(cbuf);
|
||||
int out_len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ptr, -1, buffer, (last - buffer) + 1, NULL, NULL);
|
||||
int out_len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ptr, -1, buffer, (last - buffer) + 1, nullptr, nullptr);
|
||||
GlobalUnlock(cbuf);
|
||||
CloseClipboard();
|
||||
|
||||
if (out_len == 0) return false;
|
||||
#if !defined(UNICODE)
|
||||
} else if (IsClipboardFormatAvailable(CF_TEXT)) {
|
||||
OpenClipboard(NULL);
|
||||
OpenClipboard(nullptr);
|
||||
cbuf = GetClipboardData(CF_TEXT);
|
||||
|
||||
ptr = (const char*)GlobalLock(cbuf);
|
||||
@@ -543,12 +544,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
}
|
||||
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
Sleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to OpenTTD's encoding from that of the local environment.
|
||||
* When the project is built in UNICODE, the system codepage is irrelevant and
|
||||
@@ -601,7 +596,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||
const WCHAR *wide_buf = name;
|
||||
#else
|
||||
/* Convert string from the local codepage to UTF-16. */
|
||||
int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
|
||||
int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, nullptr, 0);
|
||||
if (wide_len == 0) {
|
||||
utf8_buf[0] = '\0';
|
||||
return utf8_buf;
|
||||
@@ -612,7 +607,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||
#endif
|
||||
|
||||
/* Convert UTF-16 string to UTF-8. */
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, NULL, NULL);
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr);
|
||||
if (len == 0) utf8_buf[0] = '\0';
|
||||
|
||||
return utf8_buf;
|
||||
@@ -635,7 +630,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen);
|
||||
if (len == 0) system_buf[0] = '\0';
|
||||
#else
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0);
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0);
|
||||
if (len == 0) {
|
||||
system_buf[0] = '\0';
|
||||
return system_buf;
|
||||
@@ -644,7 +639,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co
|
||||
WCHAR *wide_buf = AllocaM(WCHAR, len);
|
||||
MultiByteToWideChar(CP_UTF8, 0, name, -1, wide_buf, len);
|
||||
|
||||
len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, NULL, NULL);
|
||||
len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, nullptr, nullptr);
|
||||
if (len == 0) system_buf[0] = '\0';
|
||||
#endif
|
||||
|
||||
@@ -659,7 +654,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co
|
||||
*/
|
||||
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
|
||||
{
|
||||
static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL;
|
||||
static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = nullptr;
|
||||
static bool first_time = true;
|
||||
|
||||
/* We only try to load the library one time; if it fails, it fails */
|
||||
@@ -679,7 +674,7 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags,
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
|
||||
if (SHGetFolderPath != nullptr) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
|
||||
|
||||
/* SHGetFolderPath doesn't exist, try a more conservative approach,
|
||||
* eg environment variables. This is only included for legacy modes
|
||||
@@ -703,7 +698,7 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags,
|
||||
HKEY key;
|
||||
if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break;
|
||||
DWORD len = MAX_PATH;
|
||||
ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), NULL, NULL, (LPBYTE)pszPath, &len);
|
||||
ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), nullptr, nullptr, (LPBYTE)pszPath, &len);
|
||||
RegCloseKey(key);
|
||||
if (ret == ERROR_SUCCESS) return (HRESULT)0;
|
||||
break;
|
||||
@@ -723,21 +718,13 @@ const char *GetCurrentLocale(const char *)
|
||||
if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lang, lengthof(lang)) == 0 ||
|
||||
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, country, lengthof(country)) == 0) {
|
||||
/* Unable to retrieve the locale. */
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
/* Format it as 'en_us'. */
|
||||
static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0};
|
||||
return retbuf;
|
||||
}
|
||||
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
static WCHAR _cur_iso_locale[16] = L"";
|
||||
|
||||
@@ -763,7 +750,7 @@ void Win32SetCurrentLocaleName(const char *iso_code)
|
||||
int OTTDStringCompare(const char *s1, const char *s2)
|
||||
{
|
||||
typedef int (WINAPI *PFNCOMPARESTRINGEX)(LPCWSTR, DWORD, LPCWCH, int, LPCWCH, int, LPVOID, LPVOID, LPARAM);
|
||||
static PFNCOMPARESTRINGEX _CompareStringEx = NULL;
|
||||
static PFNCOMPARESTRINGEX _CompareStringEx = nullptr;
|
||||
static bool first_time = true;
|
||||
|
||||
#ifndef SORT_DIGITSASNUMBERS
|
||||
@@ -778,10 +765,10 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
if (_CompareStringEx != NULL) {
|
||||
if (_CompareStringEx != nullptr) {
|
||||
/* CompareStringEx takes UTF-16 strings, even in ANSI-builds. */
|
||||
int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, NULL, 0);
|
||||
int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, NULL, 0);
|
||||
int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, nullptr, 0);
|
||||
int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, nullptr, 0);
|
||||
|
||||
if (len_s1 != 0 && len_s2 != 0) {
|
||||
LPWSTR str_s1 = AllocaM(WCHAR, len_s1);
|
||||
@@ -790,7 +777,7 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
||||
MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1, len_s1);
|
||||
MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2, len_s2);
|
||||
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, NULL, NULL, 0);
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, nullptr, nullptr, 0);
|
||||
if (result != 0) return result;
|
||||
}
|
||||
}
|
||||
@@ -816,12 +803,12 @@ PACK_N(struct THREADNAME_INFO {
|
||||
/**
|
||||
* Signal thread name to any attached debuggers.
|
||||
*/
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
void SetCurrentThreadName(const char *threadName)
|
||||
{
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = threadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwThreadID = -1;
|
||||
info.dwFlags = 0;
|
||||
|
||||
#pragma warning(push)
|
||||
@@ -832,4 +819,6 @@ void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
}
|
||||
#pragma warning(pop)
|
||||
}
|
||||
#else
|
||||
void SetCurrentThreadName(const char *) {}
|
||||
#endif
|
||||
|
||||
@@ -39,12 +39,6 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
|
||||
#define SHGFP_TYPE_CURRENT 0
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
|
||||
#else
|
||||
static inline void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
|
||||
#endif
|
||||
|
||||
void Win32SetCurrentLocaleName(const char *iso_code);
|
||||
int OTTDStringCompare(const char *s1, const char *s2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user