Skip to content

Commit

Permalink
Merge pull request #31 from Lehm2000/ja-gav-archiver
Browse files Browse the repository at this point in the history
SGV (Seekable Game Vault) Archive Support
  • Loading branch information
SamBoots authored Nov 10, 2024
2 parents 2649fce + 3140e80 commit 8c521b4
Show file tree
Hide file tree
Showing 15 changed files with 1,071 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ add_subdirectory ("sdl-master")
add_subdirectory ("physfs-main")
add_subdirectory ("RT")
add_subdirectory ("d1")
add_subdirectory ("sgv-archiver")
4 changes: 3 additions & 1 deletion RT/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ add_library(RT_CORE INTERFACE
"Config.h"
"String.h"
"Hash.h"
"FileIO.h")
"FileIO.h"
"Vault.h")

target_sources(RT_CORE INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/Config.cpp"
Expand All @@ -18,4 +19,5 @@ target_sources(RT_CORE INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/Common.c"
"${CMAKE_CURRENT_LIST_DIR}/String.c"
"${CMAKE_CURRENT_LIST_DIR}/VirtualMemory.c"
"${CMAKE_CURRENT_LIST_DIR}/Vault.cpp"
)
27 changes: 27 additions & 0 deletions RT/Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Core/Arena.h"
#include "Core/MemoryScope.hpp"
#include "Core/String.h"
#include "Core/Vault.h"

static inline void ConfigError(RT_Config *cfg, char *error)
{
Expand All @@ -24,6 +25,27 @@ void RT_InitializeConfig(RT_Config *cfg, RT_Arena *arena)
cfg->last_modified_time = RT_GetHighResTime().value;
}

bool RT_DeserializeConfigFromVault(RT_Config* cfg, const char* file_name)
{

RT_String file_name_string = RT_StringFromCString(file_name);
RT_String file_buffer;
file_buffer.bytes = nullptr;
file_buffer.count = 0;

if (RT_GetFileFromVaults(file_name_string, file_buffer))
{
// got the config file from the vault

// parse it
RT_DeserializeConfigFromString(cfg, file_buffer);

return true;
}

return false;
}

bool RT_DeserializeConfigFromFile(RT_Config *cfg, const char *file_name)
{
FILE *f = fopen(file_name, "rb");
Expand Down Expand Up @@ -432,3 +454,8 @@ bool RT_SerializeConfigToFile(RT_Config *cfg, char *file_name)

return result;
}

bool RT_ConfigFileExistsInVaults(const RT_String* file_name)
{
return RT_FileExistsInVaults(file_name);
}
2 changes: 2 additions & 0 deletions RT/Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct RT_Config
} RT_Config;

RT_API void RT_InitializeConfig(RT_Config *cfg, RT_Arena *arena);
RT_API bool RT_DeserializeConfigFromVault(RT_Config* cfg, const char* file_name);
RT_API bool RT_DeserializeConfigFromFile(RT_Config *cfg, const char *file_name);
RT_API void RT_DeserializeConfigFromString(RT_Config *cfg, RT_String string);
RT_API bool RT_ConfigReadString(RT_Config *cfg, RT_String key, RT_String *value);
Expand All @@ -50,6 +51,7 @@ RT_API void RT_ConfigWriteVec3(RT_Config *cfg, RT_String key, RT_Vec3 value);
RT_API bool RT_ConfigEraseKey(RT_Config *cfg, RT_String key); // Returns true if the key existed
RT_API RT_String RT_SerializeConfigToString(RT_Arena *arena, RT_Config *cfg);
RT_API bool RT_SerializeConfigToFile(RT_Config *cfg, char *file_name);
RT_API bool RT_ConfigFileExistsInVaults(const RT_String *file_name);

// Prefer the above functions for easy interpretation of values
RT_API RT_ConfigKeyValue *RT_ConfigFindKeyValue(RT_Config *cfg, RT_String key);
Expand Down
2 changes: 1 addition & 1 deletion RT/Core/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static inline RT_String RT_CopyString(RT_Arena *arena, RT_String string)
static inline const char *RT_CopyStringNullTerm(RT_Arena *arena, RT_String string)
{
char *result = (char *)RT_ArenaCopyArray(arena, string.bytes, string.count + 1);
result[string.count + 1] = 0;
result[string.count] = 0;
return result;
}

Expand Down
Loading

0 comments on commit 8c521b4

Please sign in to comment.