Files
gMod/source/uMod_ArrayHandler.cpp
T
DubbleClick ab2d8cdb0a 1.5.4 (#7)
* toggle use_folders on

* Rename pipelines

* its a strcpy :(

* add miniz, add xorstream, add non-working ziploader

* start integrating libzip (WIP)

* use ExternalProject test (doesnt work maybe?!)

* further work in integrating libzippp [WIP]
can't build libzip yet (neither manually nor in the vs build), as it doesn't find zlib

* LibZip build script

* make libzip build too
todo: specify cmake find_library to check the paths we install to

* prepare everything in cmake

* fix rebuilding of libzip/zlib

* fix stupid double quotes

* libzippp works

* Setup libzippp archive loading

* Remove allocation of new data when adding file to TextureServer

* Enable CI on dev

* Create LICENSE (#5)

* add mbedtls

* fix cmake (forgot to substitute, woops)

* fix %lu warnings for printing addresses

* enable debug messages, some formatting

* remove mbedtls, fix libzip for /MD(d)

* some code changes

* fix cmake logic, str replace min cmake version in libzip-src/CMakeLists.txt to 3.15

* linker errors in release

* c++ify a little

* remove unnecessary duplicate c++23 definition

* Fixes to gMod_XorStream when calculating stream length

* Fix loading tpf contents with password

* Implemented complete parsing

* Cleanup file loading

* Change to NI

* Revert "Change to NI"

This reverts commit 19b511d907.

* update XorStreamReader to read whole file, then xor

* delete a lot of unused code

* loading logic

* rename console window

* 1.5.4

* remove pointless mutex

* wtf is this code

---------

Co-authored-by: Alex Macocian <amacocian@yahoo.com>
2023-11-17 21:58:04 +01:00

93 lines
2.6 KiB
C++

#include "uMod_Main.h"
uMod_FileHandler::uMod_FileHandler()
{
Message("uMod_FileHandler(): %p\n", this);
}
uMod_FileHandler::~uMod_FileHandler()
{
Message("~uMod_FileHandler(): %p\n", this);
if (Files != nullptr) {
for (int i = 0; i < FieldCounter; i++) {
delete [] Files[i];
}
delete [] Files;
}
}
int uMod_FileHandler::Add(TextureFileStruct* file)
{
Message("uMod_FileHandler::Add(%p): %p\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (file->Reference >= 0) {
return RETURN_UPDATE_ALLREADY_ADDED;
}
if (Number / FieldLength == FieldCounter) // get more memory
{
TextureFileStruct*** temp = nullptr;
try { temp = new TextureFileStruct**[FieldCounter + 10]; }
catch (...) {
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
for (int i = 0; i < FieldCounter; i++) {
temp[i] = Files[i]; //copy to new allocated memory
}
for (int i = FieldCounter; i < FieldCounter + 10; i++) {
temp[i] = nullptr; // initialize unused parts to zero
}
FieldCounter += 10;
delete [] Files;
Files = temp;
}
if (Number % FieldLength == 0) // maybe we need to get more memory
{
try {
if (Files[Number / FieldLength] == nullptr) {
Files[Number / FieldLength] = new TextureFileStruct*[FieldLength];
}
}
catch (...) {
Files[Number / FieldLength] = nullptr;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
}
Files[Number / FieldLength][Number % FieldLength] = file;
file->Reference = Number++; //set the reference for a fast deleting
return RETURN_OK;
}
int uMod_FileHandler::Remove(TextureFileStruct* file)
{
Message("uMod_FileHandler::Remove(%p): %p\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
const int ref = file->Reference;
if (ref < 0) {
return RETURN_OK; // returning if no Reference is set
}
file->Reference = -1; //set reference outside of bound
if (ref < (--Number)) //if reference is unequal to Number-1 we copy the last entry to the index "ref"
{
Files[ref / FieldLength][ref % FieldLength] = Files[Number / FieldLength][Number % FieldLength];
Files[ref / FieldLength][ref % FieldLength]->Reference = ref; //set the new reference entry
}
return RETURN_OK;
}