From c1182c3f41a668385770a3d3b76fe5f8601070af Mon Sep 17 00:00:00 2001 From: Dustin Holden Date: Thu, 15 Aug 2024 13:57:24 -0400 Subject: [PATCH] Implement attach.ini config support --- .gitmodules | 3 +++ 3rdparty/minIni | 1 + Makefile | 6 ++++++ source/attach.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 160000 3rdparty/minIni diff --git a/.gitmodules b/.gitmodules index c01b68c..3abd744 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = 3rdparty/nxdk url = git@github.com:MakeMHz/nxdk.git branch = hack-cxbe-sections +[submodule "3rdparty/minIni"] + path = 3rdparty/minIni + url = git@github.com:compuphase/minIni.git diff --git a/3rdparty/minIni b/3rdparty/minIni new file mode 160000 index 0000000..1bb6557 --- /dev/null +++ b/3rdparty/minIni @@ -0,0 +1 @@ +Subproject commit 1bb6557030964c921da374e6541e6acb965588e2 diff --git a/Makefile b/Makefile index e8dfb6f..638f6ae 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,12 @@ CFLAGS += \ -I$(CURDIR)/source \ -DWIN32 +# minIni +SRCS += \ + $(CURDIR)/3rdparty/minIni/dev/minIni.c +CFLAGS += \ + -I$(CURDIR)/3rdparty/minIni/dev + # Optimize build by removing unused symbols CFLAGS += \ -ffunction-sections \ diff --git a/source/attach.c b/source/attach.c index 67223b2..08e8615 100644 --- a/source/attach.c +++ b/source/attach.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "attach.h" #include "helpers.h" @@ -43,7 +44,49 @@ ATTACH_SLICE_DATA AttachSliceData = { } }; +int AttachConfigCb(const char *Section, const char *Key, const char *Value, void *Userdata) { + (void)Section; // Unused + (void)Userdata; // Unused + + // Check if the key equals "VIRTUAL_IMAGE_FILE_PATH". + if(strcmp(Key, "VIRTUAL_IMAGE_FILE_PATH") == 0) { + // Make sure we have room for another slice. + if(AttachSliceData.NumberOfSlices >= MAX_IMAGE_SLICES) + return 0; + + // Path to the virtual disc image. + ANSI_STRING FilePath; + RtlInitAnsiString(&FilePath, Value); + + // Check if the length is greater than the maximum length. + if(FilePath.Length > (MAX_PATH - 1)) { + // On error we have to reset the number of slices back to zero since we can only assume that the config is + // corrupted. + AttachSliceData.NumberOfSlices = 0; + return 0; + } + + // New slice + PANSI_STRING Slice = &AttachSliceData.Files[AttachSliceData.NumberOfSlices]; + + // Copy the file path to the slice. + RtlCopyString(Slice, &FilePath); + + // Increment the number of slices. + AttachSliceData.NumberOfSlices++; + } + + return 1; +} + int main(void) { + // Parse the configuration file. + ini_browse(AttachConfigCb, NULL, "D:\\attach.ini"); + + // Check if we already have attach data. + if(AttachSliceData.NumberOfSlices > 0) + goto AttachVirtualDisc; + // Check if the virtual file paths have been modified (defined) in the XBE binary. // NOTE: This is a simple way to check if the virtual file paths have been modified. A more robust way would be to // check if the virtual file paths are valid and accessible, but also trying to avoid "VIRTUAL_IMAGE_FILE_PATH"