From 1677b73c079301c051122d0fddf551593411bcd2 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 4 Apr 2023 00:32:13 -0700 Subject: [PATCH] Prevent having two DynOS packs with the same name loaded --- data/dynos_mgr_pack.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/data/dynos_mgr_pack.cpp b/data/dynos_mgr_pack.cpp index b1bbc5bd..a6fa559d 100644 --- a/data/dynos_mgr_pack.cpp +++ b/data/dynos_mgr_pack.cpp @@ -130,10 +130,35 @@ PackData* DynOS_Pack_GetFromPath(const SysPath& aPath) { return NULL; } +PackData* DynOS_Pack_GetFromDisplayName(const char* aDisplayName) { + for (auto& packData : DynosPacks()) { + if (!strcmp(packData.mDisplayName.begin(), aDisplayName)) { + return &packData; + } + } + return NULL; +} + PackData* DynOS_Pack_Add(const SysPath& aPath) { PackData* existing = DynOS_Pack_GetFromPath(aPath); if (existing != NULL) { return existing; } + // extract basename + const char* displayName = aPath.c_str(); + const char* ctoken = displayName; + while (*ctoken != '\0') { + if (*ctoken == '/' || *ctoken == '\\') { + if (*(ctoken + 1) != '\0') { + displayName = (ctoken + 1); + } + } + ctoken++; + } + + existing = DynOS_Pack_GetFromDisplayName(displayName); + if (existing != NULL) { return existing; } + + auto& _DynosPacks = DynosPacks(); s32 index = _DynosPacks.Count(); const PackData packData = { @@ -150,18 +175,7 @@ PackData* DynOS_Pack_Add(const SysPath& aPath) { PackData* _Pack = &_DynosPacks[index]; - // extract basename - const char* cpath = aPath.c_str(); - const char* ctoken = cpath; - while (*ctoken != '\0') { - if (*ctoken == '/' || *ctoken == '\\') { - if (*(ctoken + 1) != '\0') { - cpath = (ctoken + 1); - } - } - ctoken++; - } - _Pack->mDisplayName = cpath; + _Pack->mDisplayName = displayName; _Pack->mEnabled = true; _Pack->mEnabledSet = false;