mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-30 14:25:36 +08:00
allow loading .ini
file with the same name as the cold client loader exe name
This commit is contained in:
parent
27a8bba702
commit
8be6efcfc2
@ -1,3 +1,9 @@
|
||||
* for Windows ColdClientLoader: allow loading `.ini` file with the same name as the loader
|
||||
ex: if the loader is named `game_cold_loader.exe`, then it will first try to load `game_cold_loader.ini`,
|
||||
if that doesn't exist, it will fallback to `ColdClientLoader.ini`
|
||||
|
||||
---
|
||||
|
||||
## 2024/5/5
|
||||
|
||||
* **[Clompress]** update Turkish translation
|
||||
|
@ -383,6 +383,11 @@ size_t pe_helpers::get_pe_size(HMODULE hModule)
|
||||
|
||||
static std::wstring path_w{};
|
||||
static std::string path_a{};
|
||||
|
||||
static std::wstring modulename_w{};
|
||||
static std::string modulename_a{};
|
||||
|
||||
|
||||
const std::string& pe_helpers::get_current_exe_path()
|
||||
{
|
||||
if (path_a.empty()) {
|
||||
@ -409,14 +414,27 @@ const std::wstring& pe_helpers::get_current_exe_path_w()
|
||||
}
|
||||
|
||||
if ((read_chars < path_w.size()) && path_w[0]) {
|
||||
path_w = path_w.substr(0, path_w.find_last_of(L"\\/") + 1);
|
||||
auto modulename_idx = path_w.find_last_of(L"\\/") + 1;
|
||||
modulename_w = path_w.substr(modulename_idx, read_chars - modulename_idx);
|
||||
path_w = path_w.substr(0, modulename_idx);
|
||||
|
||||
{
|
||||
auto cvt_state = std::mbstate_t();
|
||||
const wchar_t* src = &path_w[0];
|
||||
size_t conversion_bytes = std::wcsrtombs(nullptr, &src, 0, &cvt_state);
|
||||
path_a.resize(conversion_bytes + 1);
|
||||
std::wcsrtombs(&path_a[0], &src, path_a.size(), &cvt_state);
|
||||
path_a = path_a.substr(0, conversion_bytes);
|
||||
}
|
||||
|
||||
{
|
||||
auto cvt_state = std::mbstate_t();
|
||||
const wchar_t* src = &modulename_w[0];
|
||||
size_t conversion_bytes = std::wcsrtombs(nullptr, &src, 0, &cvt_state);
|
||||
modulename_a.resize(conversion_bytes + 1);
|
||||
std::wcsrtombs(&modulename_a[0], &src, modulename_a.size(), &cvt_state);
|
||||
modulename_a = modulename_a.substr(0, conversion_bytes);
|
||||
}
|
||||
} else {
|
||||
path_w.clear();
|
||||
}
|
||||
@ -428,10 +446,28 @@ const std::wstring& pe_helpers::get_current_exe_path_w()
|
||||
return path_w;
|
||||
}
|
||||
|
||||
bool pe_helpers::ends_with_i(PUNICODE_STRING target, const std::wstring &query)
|
||||
const std::string& pe_helpers::get_current_exe_name()
|
||||
{
|
||||
if (modulename_a.empty()) {
|
||||
get_current_exe_path_w();
|
||||
}
|
||||
|
||||
return modulename_a;
|
||||
}
|
||||
|
||||
const std::wstring& pe_helpers::get_current_exe_name_w()
|
||||
{
|
||||
if (modulename_w.empty()) {
|
||||
get_current_exe_path_w();
|
||||
}
|
||||
|
||||
return modulename_w;
|
||||
}
|
||||
|
||||
bool pe_helpers::ends_with_i(PUNICODE_STRING target, const std::wstring_view &query)
|
||||
{
|
||||
return common_helpers::ends_with_i(
|
||||
std::wstring(target->Buffer, (PWSTR)((char*)target->Buffer + target->Length)),
|
||||
std::wstring_view( target->Buffer, target->Length / sizeof(target->Buffer[0]) ),
|
||||
query
|
||||
);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <winternl.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace pe_helpers
|
||||
{
|
||||
@ -44,7 +45,11 @@ const std::string& get_current_exe_path();
|
||||
|
||||
const std::wstring& get_current_exe_path_w();
|
||||
|
||||
bool ends_with_i(PUNICODE_STRING target, const std::wstring &query);
|
||||
const std::string& get_current_exe_name();
|
||||
|
||||
const std::wstring& get_current_exe_name_w();
|
||||
|
||||
bool ends_with_i(PUNICODE_STRING target, const std::wstring_view &query);
|
||||
|
||||
MEMORY_BASIC_INFORMATION get_mem_page_details(const void* mem);
|
||||
|
||||
|
@ -12,12 +12,13 @@
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
|
||||
|
||||
static const std::wstring IniFile = pe_helpers::get_current_exe_path_w() + L"ColdClientLoader.ini";
|
||||
static const std::wstring dbg_file = pe_helpers::get_current_exe_path_w() + L"COLD_LDR_LOG.txt";
|
||||
static std::wstring IniFile{};
|
||||
static const std::wstring dbg_file = pe_helpers::get_current_exe_path_w() + pe_helpers::get_current_exe_name_w() + L".log";
|
||||
constexpr static const char STEAM_UNIVERSE[] = "Public";
|
||||
constexpr static const char STEAM_URL_PROTOCOL[] = "URL:steam protocol";
|
||||
|
||||
@ -339,9 +340,16 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
|
||||
{
|
||||
dbg_log::init(dbg_file.c_str());
|
||||
|
||||
IniFile = pe_helpers::get_current_exe_path_w() + std::filesystem::path(pe_helpers::get_current_exe_name_w()).stem().wstring() + L".ini";
|
||||
dbg_log::write(L"Searching for configuration file: " + IniFile);
|
||||
if (!common_helpers::file_exist(IniFile)) {
|
||||
dbg_log::write(L"Couldn't find the configuration file: " + dbg_file);
|
||||
MessageBoxA(NULL, "Couldn't find the configuration file ColdClientLoader.ini.", "ColdClientLoader", MB_ICONERROR);
|
||||
IniFile = pe_helpers::get_current_exe_path_w() + L"ColdClientLoader.ini";
|
||||
dbg_log::write(L"Searching for configuration file: " + IniFile);
|
||||
}
|
||||
|
||||
if (!common_helpers::file_exist(IniFile)) {
|
||||
dbg_log::write(L"Couldn't find the configuration file");
|
||||
MessageBoxA(NULL, "Couldn't find the configuration file.", "ColdClientLoader", MB_ICONERROR);
|
||||
dbg_log::close();
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user