Skip to content

Commit

Permalink
Merge branch 'master' into multiple_sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulgen301 committed Aug 8, 2024
2 parents 67e640f + 366940d commit 6291c9c
Show file tree
Hide file tree
Showing 31 changed files with 406 additions and 307 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ endif ()
add_library(standard STATIC ${LIBSTANDARD_SOURCES})
target_compile_definitions(standard PRIVATE C4ENGINE)

if (WIN32)
target_compile_definitions(standard PUBLIC UNICODE _UNICODE)
endif ()

# Set C4_OS macro
if (APPLE)
set(C4_OS "mac")
Expand Down Expand Up @@ -433,6 +437,9 @@ if (WIN32)
if (USE_SDL_MIXER)
target_link_libraries(clonk imm32.lib setupapi.lib version.lib)
endif ()

target_link_libraries(clonk comctl32)
target_link_options(clonk PRIVATE "/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'")
endif ()

# Link C++/WinRT
Expand Down
6 changes: 3 additions & 3 deletions src/C4Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ C4Application::~C4Application()
{
#ifdef _WIN32
char strCommandLine[_MAX_PATH + 1]; SCopy(Config.AtExePath(C4CFN_Editor), strCommandLine);
STARTUPINFO StartupInfo{};
STARTUPINFOA StartupInfo{};
StartupInfo.cb = sizeof(StartupInfo);
PROCESS_INFORMATION ProcessInfo{};
CreateProcess(nullptr, strCommandLine, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo);
CreateProcessA(nullptr, strCommandLine, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo);
#endif
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ void C4Application::DoInit()

#if defined(_WIN32) && !defined(USE_CONSOLE)
// Register clonk file classes - notice: this will only work if we have administrator rights
char szModule[_MAX_PATH + 1]; GetModuleFileName(nullptr, szModule, _MAX_PATH);
char szModule[_MAX_PATH + 1]; GetModuleFileNameA(nullptr, szModule, _MAX_PATH);
SetC4FileClasses(szModule);
#endif

Expand Down
20 changes: 7 additions & 13 deletions src/C4ComponentHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <C4Language.h>

#ifdef _WIN32
#include "C4Console.h"
#include "StdRegistry.h"
#include "res/engine_resource.h"
#endif
Expand Down Expand Up @@ -279,13 +280,13 @@ INT_PTR CALLBACK C4ComponentHost::ComponentDlgProc(const HWND hDlg, const UINT m
const auto &componentHost = *reinterpret_cast<C4ComponentHost *>(lParam);

SetWindowLongPtr(hDlg, DWLP_USER, lParam);
SetWindowText(hDlg, componentHost.Name);
SetDlgItemText(hDlg, IDOK, LoadResStr(C4ResStrTableKey::IDS_BTN_OK));
SetDlgItemText(hDlg, IDCANCEL, LoadResStr(C4ResStrTableKey::IDS_BTN_CANCEL));
SetWindowText(hDlg, StdStringEncodingConverter::WinAcpToUtf16(componentHost.Name).c_str());
SetDlgItemText(hDlg, IDOK, StdStringEncodingConverter::WinAcpToUtf16(LoadResStr(C4ResStrTableKey::IDS_BTN_OK)).c_str());
SetDlgItemText(hDlg, IDCANCEL, StdStringEncodingConverter::WinAcpToUtf16(LoadResStr(C4ResStrTableKey::IDS_BTN_CANCEL)).c_str());

if (const char *const data{componentHost.GetData()}; data)
{
SetDlgItemText(hDlg, IDC_EDITDATA, data);
SetDlgItemText(hDlg, IDC_EDITDATA, StdStringEncodingConverter::WinAcpToUtf16(data).c_str());
}

RestoreWindowPosition(hDlg, "Component", Config.GetSubkeyPath("Console"));
Expand Down Expand Up @@ -320,15 +321,8 @@ INT_PTR CALLBACK C4ComponentHost::ComponentDlgProc(const HWND hDlg, const UINT m
}
else
{
StdStrBuf &data{componentHost.Data};
data.SetLength(size);
GetDlgItemText(hDlg, IDC_EDITDATA, data.getMData(), static_cast<int>(size + 1));

const std::size_t actualSize{std::strlen(data.getData())};
if (actualSize != size)
{
data.SetLength(size);
}
const std::string text{StdStringEncodingConverter::Utf16ToWinAcp(C4Console::GetDialogItemText(hDlg, IDC_EDITDATA))};
componentHost.Data.Copy(text.c_str(), text.size());
}

componentHost.Modified = true;
Expand Down
26 changes: 19 additions & 7 deletions src/C4Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool C4Config::Load(bool forceWorkingDirectory, const char *szConfigFile)
StdStrBuf filename(getenv("HOME"), false);
if (filename) { filename += "/"; }
filename += ".legacyclonk";
CreateDirectory(filename.getData());
MakeDirectory(filename.getData());
}
#endif
// Buggy StdCompiler crashes when compiling a Null-StdStrBuf
Expand Down Expand Up @@ -584,17 +584,29 @@ bool C4Config::Save()
return true;
}

#if defined(_WIN32) && defined(C4ENGINE)
namespace C4CrashHandlerWin32
{
void SetUserPath(std::string_view);
}
#endif

void C4ConfigGeneral::DeterminePaths(bool forceWorkingDirectory)
{
#ifdef _WIN32
// Exe path
if (GetModuleFileName(nullptr, ExePath, CFG_MaxString))
if (GetModuleFileNameA(nullptr, ExePath, CFG_MaxString))
{
TruncatePath(ExePath); AppendBackslash(ExePath);
}
// Temp path
GetTempPath(CFG_MaxString, TempPath);
GetTempPathA(CFG_MaxString, TempPath);
if (TempPath[0]) AppendBackslash(TempPath);

#ifdef C4ENGINE
C4CrashHandlerWin32::SetUserPath(UserPath);
#endif

#elif defined(__linux__)
#ifdef C4ENGINE
GetParentPath(Application.Location, ExePath);
Expand Down Expand Up @@ -635,7 +647,7 @@ void C4ConfigGeneral::DeterminePaths(bool forceWorkingDirectory)
#ifdef C4ENGINE
// Create user path if it doesn't already exist
if (!DirectoryExists(Config.AtUserPath("")))
CreateDirectory(Config.AtUserPath(""), nullptr); // currently no error handling here; also: no recursive directory creation
MakeDirectory(Config.AtUserPath(""), nullptr); // currently no error handling here; also: no recursive directory creation
#endif
}

Expand Down Expand Up @@ -687,7 +699,7 @@ const char *C4Config::AtScreenshotPath(const char *szFilename)
if (const auto len = SLen(AtPathFilename); len > 0)
if (AtPathFilename[len - 1] == DirectorySeparator)
AtPathFilename[len - 1] = '\0';
if (!DirectoryExists(AtPathFilename) && !CreateDirectory(AtPathFilename, nullptr))
if (!DirectoryExists(AtPathFilename) && !MakeDirectory(AtPathFilename, nullptr))
{
SCopy(General.ExePath, General.ScreenshotPath, CFG_MaxString - 1);
SCopy(General.ScreenshotPath, AtPathFilename, _MAX_PATH);
Expand All @@ -704,7 +716,7 @@ bool C4ConfigGeneral::CreateSaveFolder(const char *strDirectory, const char *str
{
// Create directory if needed
if (!DirectoryExists(strDirectory))
if (!CreateDirectory(strDirectory, nullptr))
if (!MakeDirectory(strDirectory, nullptr))
return false;
// Create title component if needed
char lang[3]; SCopy(Config.General.Language, lang, 2);
Expand Down Expand Up @@ -918,7 +930,7 @@ void C4Config::ExpandEnvironmentVariables(char *strPath, int iMaxLen)
{
#ifdef _WIN32
char buf[_MAX_PATH + 1];
ExpandEnvironmentStrings(strPath, buf, _MAX_PATH);
ExpandEnvironmentStringsA(strPath, buf, _MAX_PATH);
SCopy(buf, strPath, iMaxLen);
#else // __linux__ or __APPLE___
StdStrBuf home(getenv("HOME"), false);
Expand Down
Loading

0 comments on commit 6291c9c

Please sign in to comment.