1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 14:14:47 +01:00
cnc-ddraw/config/cnc-ddraw config.cpp

82 lines
1.9 KiB
C++
Raw Permalink Normal View History

2021-07-01 18:02:16 +02:00
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
2023-08-15 15:38:50 +02:00
#include <IniFiles.hpp>
#include <IOUtils.hpp>
2023-08-15 15:38:50 +02:00
#include <System.Hash.hpp>
2021-07-01 18:02:16 +02:00
#include <tchar.h>
//---------------------------------------------------------------------------
#include <Vcl.Styles.hpp>
#include <Vcl.Themes.hpp>
USEFORM("ConfigFormUnit.cpp", ConfigForm);
//---------------------------------------------------------------------------
#define GAME_PATH (TPath::GetDirectoryName(Application->ExeName) + "\\")
2021-07-01 18:02:16 +02:00
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
2023-08-13 17:15:59 +02:00
2023-08-15 15:38:50 +02:00
HWND hwnd =
FindWindow(
THashSHA1::GetHashString(Application->ExeName).w_str(), NULL);
2023-08-15 16:16:49 +02:00
if (hwnd && ParamStr(1) != L"-restart") {
2023-08-15 15:38:50 +02:00
if (IsIconic(hwnd)) {
ShowWindow(hwnd, SW_RESTORE);
}
SetForegroundWindow(hwnd);
return 0;
}
auto iniPath = System::Sysutils::GetEnvironmentVariable(
"CNC_DDRAW_CONFIG_FILE");
auto *ini =
new TIniFile(iniPath.Length() ? iniPath : GAME_PATH + "ddraw.ini");
2023-08-13 17:15:59 +02:00
auto theme = ini->ReadString("ddraw", "configtheme", "Windows10");
TStyleManager::TrySetStyle(
theme == "Cobalt XEMedia" ? "Cobalt XEMedia" : "Windows10");
delete ini;
2021-07-01 18:02:16 +02:00
Application->CreateForm(__classid(TConfigForm), &ConfigForm);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
// dummy functions to avoid Wtsapi32.dll imports
EXTERN_C BOOL WINAPI WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
{
return TRUE;
}
EXTERN_C BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd)
{
return TRUE;
}
2021-07-01 18:02:16 +02:00
//---------------------------------------------------------------------------