mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-15 15:09:30 +00:00
fix unicode characters like Umlaute üäÜÖßéè
This commit is contained in:
@@ -15,7 +15,7 @@ import <filesystem>;
|
||||
import ModfileLoader.TpfReader;
|
||||
|
||||
export class ModfileLoader {
|
||||
std::string file_name;
|
||||
std::filesystem::path file_name;
|
||||
const std::string TPF_PASSWORD{
|
||||
0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, static_cast<char>(0xA6), static_cast<char>(0xBD),
|
||||
0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F,
|
||||
@@ -26,7 +26,7 @@ export class ModfileLoader {
|
||||
};
|
||||
|
||||
public:
|
||||
ModfileLoader(const std::string& fileName);
|
||||
ModfileLoader(const std::filesystem::path& fileName);
|
||||
|
||||
std::vector<TexEntry> GetContents();
|
||||
|
||||
@@ -39,15 +39,15 @@ private:
|
||||
void LoadEntries(libzippp::ZipArchive& archive, std::vector<TexEntry>& entries);
|
||||
};
|
||||
|
||||
ModfileLoader::ModfileLoader(const std::string& fileName)
|
||||
ModfileLoader::ModfileLoader(const std::filesystem::path& fileName)
|
||||
{
|
||||
file_name = std::filesystem::absolute(fileName).string();
|
||||
file_name = std::filesystem::absolute(fileName);
|
||||
}
|
||||
|
||||
std::vector<TexEntry> ModfileLoader::GetContents()
|
||||
{
|
||||
try {
|
||||
return file_name.ends_with(".tpf") ? GetTpfContents() : GetFileContents();
|
||||
return file_name.wstring().ends_with(L".tpf") ? GetTpfContents() : GetFileContents();
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
Warning("Failed to open mod file: %s\n", file_name.c_str());
|
||||
@@ -81,7 +81,7 @@ std::vector<TexEntry> ModfileLoader::GetFileContents()
|
||||
{
|
||||
std::vector<TexEntry> entries;
|
||||
|
||||
libzippp::ZipArchive zip_archive(file_name);
|
||||
libzippp::ZipArchive zip_archive(file_name.string());
|
||||
zip_archive.open();
|
||||
LoadEntries(zip_archive, entries);
|
||||
zip_archive.close();
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
export module ModfileLoader.TpfReader;
|
||||
|
||||
import <filesystem>;
|
||||
import <string>;
|
||||
import <fstream>;
|
||||
import <vector>;
|
||||
|
||||
export class TpfReader {
|
||||
public:
|
||||
TpfReader(const std::string& path)
|
||||
TpfReader(const std::filesystem::path& path)
|
||||
{
|
||||
file_stream = std::ifstream(path, std::ios::binary);
|
||||
if (!file_stream.seekg(0, std::ios::end).good() || !file_stream.seekg(0, std::ios::beg).good()) {
|
||||
|
||||
@@ -164,7 +164,7 @@ gsl::owner<TextureFileStruct*> AddFile(TexEntry& entry, const bool compress, con
|
||||
return texture_file_struct;
|
||||
}
|
||||
|
||||
std::vector<gsl::owner<TextureFileStruct*>> ProcessModfile(const std::string& modfile, const std::filesystem::path& dll_path, const bool compress)
|
||||
std::vector<gsl::owner<TextureFileStruct*>> ProcessModfile(const std::filesystem::path& modfile, const std::filesystem::path& dll_path, const bool compress)
|
||||
{
|
||||
const auto hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
if (FAILED(hr)) return {};
|
||||
@@ -192,25 +192,29 @@ std::vector<gsl::owner<TextureFileStruct*>> ProcessModfile(const std::string& mo
|
||||
|
||||
void TextureClient::LoadModsFromFile(const char* source)
|
||||
{
|
||||
static std::vector<std::string> loaded_modfiles{};
|
||||
static std::vector<std::filesystem::path> loaded_modfiles{};
|
||||
Message("Initialize: searching in %s\n", source);
|
||||
|
||||
std::ifstream file(source);
|
||||
std::locale::global(std::locale(""));
|
||||
std::ifstream file(source, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
Warning("LoadModsFromFile: failed to open modlist.txt for reading; aborting!!!");
|
||||
return;
|
||||
}
|
||||
Message("Initialize: found modlist.txt. Reading\n");
|
||||
std::string line;
|
||||
std::vector<std::string> modfiles;
|
||||
std::vector<std::filesystem::path> modfiles;
|
||||
while (std::getline(file, line)) {
|
||||
// Remove newline character
|
||||
line.erase(std::ranges::remove(line, '\r').begin(), line.end());
|
||||
line.erase(std::ranges::remove(line, '\n').begin(), line.end());
|
||||
|
||||
if (!std::ranges::contains(loaded_modfiles, line)) {
|
||||
modfiles.push_back(line);
|
||||
loaded_modfiles.push_back(line);
|
||||
const auto wline = utils::utf8_to_wstring(line);
|
||||
const auto fsline = std::filesystem::path(wline);
|
||||
|
||||
if (!std::ranges::contains(loaded_modfiles, fsline)) {
|
||||
modfiles.push_back(fsline);
|
||||
loaded_modfiles.push_back(fsline);
|
||||
}
|
||||
}
|
||||
auto files_size = 0u;
|
||||
|
||||
Reference in New Issue
Block a user