mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-21 01:49:31 +00:00
Cleanup file loading
This commit is contained in:
@@ -17,7 +17,6 @@ struct TpfEntry {
|
||||
|
||||
class gMod_FileLoader {
|
||||
std::string file_name;
|
||||
std::ifstream stream;
|
||||
const std::vector<uint8_t> TPF_PASSWORD{
|
||||
0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, 0xA6, 0xBD,
|
||||
0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
// define return values, a value less than zero indicates an error
|
||||
#define RETURN_OK 0
|
||||
#define RETURN_EXISTS -70
|
||||
|
||||
#define RETURN_FATAL_ERROR -1
|
||||
#define RETURN_NO_MEMORY -2
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
gMod_FileLoader::gMod_FileLoader(const std::string& fileName)
|
||||
{
|
||||
file_name = std::filesystem::absolute(fileName).string();
|
||||
stream = std::ifstream(file_name, std::ios::binary);
|
||||
if (!stream) {
|
||||
throw std::runtime_error("Failed to open file: " + file_name);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<TpfEntry> gMod_FileLoader::Load()
|
||||
@@ -41,6 +37,9 @@ std::vector<TpfEntry> gMod_FileLoader::GetTpfContents()
|
||||
});
|
||||
zipArchive->open();
|
||||
LoadEntries(*zipArchive, entries);
|
||||
zipArchive->close();
|
||||
istream.close();
|
||||
delete(zipArchive);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw std::runtime_error("Failed to open zip file: " + file_name + "\n" + e.what());
|
||||
@@ -57,6 +56,7 @@ std::vector<TpfEntry> gMod_FileLoader::GetFileContents()
|
||||
libzippp::ZipArchive zipArchive(file_name);
|
||||
zipArchive.open();
|
||||
LoadEntries(zipArchive, entries);
|
||||
zipArchive.close();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw std::runtime_error("Failed to open zip file: " + file_name);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "uMod_Main.h"
|
||||
#include "gMod_FileLoader.h"
|
||||
|
||||
long long loadedSize = 0;
|
||||
|
||||
uMod_TextureServer::uMod_TextureServer(char* game, char* uModName)
|
||||
{
|
||||
Message("uMod_TextureServer(): %p\n", this);
|
||||
@@ -188,7 +190,9 @@ int uMod_TextureServer::AddFile(char* dataPtr, unsigned int size, MyTypeHash has
|
||||
temp = CurrentMod[i];
|
||||
break;
|
||||
} // we need to reload it
|
||||
return RETURN_OK; // we still have added this texture
|
||||
|
||||
|
||||
return RETURN_EXISTS; // we still have added this texture
|
||||
}
|
||||
}
|
||||
if (temp == nullptr) // if not found, look through all old textures
|
||||
@@ -202,7 +206,8 @@ int uMod_TextureServer::AddFile(char* dataPtr, unsigned int size, MyTypeHash has
|
||||
if (force) {
|
||||
break; // we must reload it
|
||||
}
|
||||
return RETURN_OK; // we should not reload it
|
||||
|
||||
return RETURN_EXISTS; // we should not reload it
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,7 +519,14 @@ void uMod_TextureServer::LoadModsFromFile(char* source)
|
||||
if (!entries.empty()) {
|
||||
Message("Initialize: Texture count %zu %s\n", entries.size(), line.c_str());
|
||||
for (const auto& tpf_entry : entries) {
|
||||
AddFile(static_cast<char*>(tpf_entry.data), static_cast<unsigned int>(tpf_entry.size), tpf_entry.crc_hash, false);
|
||||
loadedSize += tpf_entry.size;
|
||||
if (AddFile(static_cast<char*>(tpf_entry.data), static_cast<unsigned int>(tpf_entry.size), tpf_entry.crc_hash, false) == RETURN_EXISTS) {
|
||||
//Texture is already loaded, so we need to clear our data
|
||||
loadedSize -= tpf_entry.size;
|
||||
delete[](tpf_entry.data);
|
||||
}
|
||||
|
||||
Message("LoadModsFromFile: Loaded %d bytes", loadedSize);
|
||||
}
|
||||
|
||||
PropagateUpdate(nullptr);
|
||||
|
||||
Reference in New Issue
Block a user