diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-07-22 21:57:16 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-07-22 21:57:39 +0200 |
commit | 91f695797fac3e1c2d20bea70f8c877d7df03b68 (patch) | |
tree | 09eda542a792e33a458fb46f26bb503c47816e15 | |
parent | 1de8b89807222b5673505fea2bec1af4c0af8c7d (diff) | |
download | OFQT-91f695797fac3e1c2d20bea70f8c877d7df03b68.tar.gz OFQT-91f695797fac3e1c2d20bea70f8c877d7df03b68.zip |
give vdf functions const argments, allow fetching arbitrary app installs
-rw-r--r-- | src/steam.c | 20 | ||||
-rw-r--r-- | src/steam.h | 3 | ||||
-rw-r--r-- | src/vdf/vdf.c | 12 | ||||
-rw-r--r-- | src/vdf/vdf.h | 11 |
4 files changed, 28 insertions, 18 deletions
diff --git a/src/steam.c b/src/steam.c index f8a809b..387c9b9 100644 --- a/src/steam.c +++ b/src/steam.c @@ -109,13 +109,13 @@ char* getOpenFortressDir(void) return sm_dir; } -char* getSourceSDK2013MpDir(void) +char* getAppInstallDir(const char* appid) { char* librayfolders = getSteamDir(); if (!librayfolders) return NULL; - librayfolders = realloc(librayfolders, strlen(librayfolders) + strlen(OS_PATH_SEP) + strlen(STEAMAPPS) + strlen(OS_PATH_SEP) + strlen(SOURCESDK_MANIFEST) + 1); + librayfolders = realloc(librayfolders, strlen(librayfolders) + strlen(OS_PATH_SEP) + strlen(STEAMAPPS) + strlen(OS_PATH_SEP) + strlen(LIBARYFOLDERS_VDF) + 1); strcat(librayfolders, OS_PATH_SEP); strcat(librayfolders, STEAMAPPS); @@ -134,14 +134,17 @@ char* getSourceSDK2013MpDir(void) struct vdf_object* library = vdf_object_index_array(o, i); struct vdf_object* apps = vdf_object_index_array_str(library, "apps"); - if (vdf_object_index_array_str(apps, SOURCESDK_APPID)) + if (vdf_object_index_array_str(apps, appid)) { + char* manifest = malloc(strlen(appid) + strlen(STEAM_MANIFEST) + 1); + sprintf(manifest, STEAM_MANIFEST, appid); + struct vdf_object* path = vdf_object_index_array_str(library, "path"); - size_t path_len = path->data.data_string.len + strlen(OS_PATH_SEP) + strlen(STEAMAPPS) + strlen(OS_PATH_SEP) + strlen(SOURCESDK_MANIFEST) + 1; + size_t path_len = path->data.data_string.len + strlen(OS_PATH_SEP) + strlen(STEAMAPPS) + strlen(OS_PATH_SEP) + strlen(manifest) + 1; char* path_str = malloc(path_len); - snprintf(path_str, path_len, "%s%s%s%s%s", vdf_object_get_string(path), OS_PATH_SEP, STEAMAPPS, OS_PATH_SEP, SOURCESDK_MANIFEST); + snprintf(path_str, path_len, "%s%s%s%s%s", vdf_object_get_string(path), OS_PATH_SEP, STEAMAPPS, OS_PATH_SEP, manifest); struct vdf_object* k = vdf_parse_file(path_str); free(path_str); @@ -158,6 +161,8 @@ char* getSourceSDK2013MpDir(void) vdf_free_object(k); } + + free(manifest); } } @@ -167,6 +172,11 @@ char* getSourceSDK2013MpDir(void) return sdkdir; } +char* getSourceSDK2013MpDir(void) +{ + return getAppInstallDir(SOURCESDK_APPID); +} + /** * function to fetch the PID of a running Steam process. * If none were found returns -1 diff --git a/src/steam.h b/src/steam.h index beffa06..c586137 100644 --- a/src/steam.h +++ b/src/steam.h @@ -21,7 +21,7 @@ extern "C" { #define LIBARYFOLDERS_VDF "libraryfolders.vdf" #define SOURCESDK_APPID "243750" -#define SOURCESDK_MANIFEST "appmanifest_" SOURCESDK_APPID ".acf" +#define STEAM_MANIFEST "appmanifest_%s.acf" #if defined(_WIN32) #define HL2_EXE "hl2.exe" @@ -53,6 +53,7 @@ extern "C" { char* getSteamDir(void); char* getSourcemodDir(void); char* getOpenFortressDir(void); +char* getAppInstallDir(const char* appid); char* getSourceSDK2013MpDir(void); long getSteamPID(void); int runOpenFortress(char**, size_t); diff --git a/src/vdf/vdf.c b/src/vdf/vdf.c index befe177..3b90a02 100644 --- a/src/vdf/vdf.c +++ b/src/vdf/vdf.c @@ -304,7 +304,7 @@ struct vdf_object* vdf_parse_file(const char* path) } -size_t vdf_object_get_array_length(struct vdf_object* o) +size_t vdf_object_get_array_length(const struct vdf_object* o) { assert(o); assert(o->type == VDF_TYPE_ARRAY); @@ -312,7 +312,7 @@ size_t vdf_object_get_array_length(struct vdf_object* o) return o->data.data_array.len; } -struct vdf_object* vdf_object_index_array(struct vdf_object* o, size_t index) +struct vdf_object* vdf_object_index_array(const struct vdf_object* o, const size_t index) { assert(o); assert(o->type == VDF_TYPE_ARRAY); @@ -321,7 +321,7 @@ struct vdf_object* vdf_object_index_array(struct vdf_object* o, size_t index) return o->data.data_array.data_value[index]; } -struct vdf_object* vdf_object_index_array_str(struct vdf_object* o, char* str) +struct vdf_object* vdf_object_index_array_str(const struct vdf_object* o, const char* str) { if (!o || !str || o->type != VDF_TYPE_ARRAY) return NULL; @@ -335,21 +335,21 @@ struct vdf_object* vdf_object_index_array_str(struct vdf_object* o, char* str) return NULL; } -const char* vdf_object_get_string(struct vdf_object* o) +const char* vdf_object_get_string(const struct vdf_object* o) { assert(o->type == VDF_TYPE_STRING); return o->data.data_string.str; } -int vdf_object_get_int(struct vdf_object* o) +int vdf_object_get_int(const struct vdf_object* o) { assert(o->type == VDF_TYPE_INT); return o->data.data_int; } -static void vdf_print_object_indent(struct vdf_object* o, int l) +static void vdf_print_object_indent(const struct vdf_object* o, const int l) { if (!o) return; diff --git a/src/vdf/vdf.h b/src/vdf/vdf.h index a07d286..38cd0b9 100644 --- a/src/vdf/vdf.h +++ b/src/vdf/vdf.h @@ -46,13 +46,12 @@ struct vdf_object struct vdf_object* vdf_parse_buffer(const char*, size_t); struct vdf_object* vdf_parse_file(const char*); -size_t vdf_object_get_array_length(struct vdf_object*); -struct vdf_object* vdf_object_index_array(struct vdf_object*, size_t); -struct vdf_object* vdf_object_index_array_str(struct vdf_object*, char*); +size_t vdf_object_get_array_length(const struct vdf_object*); +struct vdf_object* vdf_object_index_array(const struct vdf_object*, const size_t); +struct vdf_object* vdf_object_index_array_str(const struct vdf_object*, const char*); -const char* vdf_object_get_string(struct vdf_object*); - -int vdf_object_get_int(struct vdf_object*); +const char* vdf_object_get_string(const struct vdf_object*); +int vdf_object_get_int(const struct vdf_object*); void vdf_print_object(struct vdf_object*); void vdf_free_object(struct vdf_object*); |