mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-24 21:15:12 +00:00
Prevent having two DynOS packs with the same name loaded
This commit is contained in:
parent
e7ebce5207
commit
1677b73c07
1 changed files with 26 additions and 12 deletions
|
@ -130,10 +130,35 @@ PackData* DynOS_Pack_GetFromPath(const SysPath& aPath) {
|
||||||
return NULL;
|
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* DynOS_Pack_Add(const SysPath& aPath) {
|
||||||
PackData* existing = DynOS_Pack_GetFromPath(aPath);
|
PackData* existing = DynOS_Pack_GetFromPath(aPath);
|
||||||
if (existing != NULL) { return existing; }
|
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();
|
auto& _DynosPacks = DynosPacks();
|
||||||
s32 index = _DynosPacks.Count();
|
s32 index = _DynosPacks.Count();
|
||||||
const PackData packData = {
|
const PackData packData = {
|
||||||
|
@ -150,18 +175,7 @@ PackData* DynOS_Pack_Add(const SysPath& aPath) {
|
||||||
|
|
||||||
PackData* _Pack = &_DynosPacks[index];
|
PackData* _Pack = &_DynosPacks[index];
|
||||||
|
|
||||||
// extract basename
|
_Pack->mDisplayName = displayName;
|
||||||
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->mEnabled = true;
|
_Pack->mEnabled = true;
|
||||||
_Pack->mEnabledSet = false;
|
_Pack->mEnabledSet = false;
|
||||||
|
|
Loading…
Reference in a new issue