Sort mods list

This commit is contained in:
MysterD 2022-04-23 00:30:43 -07:00
parent 80a5638bd1
commit 58282f7752
1 changed files with 22 additions and 0 deletions

View File

@ -90,6 +90,25 @@ void mods_activate(struct Mods* mods) {
mod_cache_save(); mod_cache_save();
} }
static void mods_sort(struct Mods* mods) {
if (mods->entryCount <= 1) {
return;
}
// By default, this is the alphabetical order on name
for (s32 i = 1; i < mods->entryCount; ++i) {
struct Mod* mod = mods->entries[i];
for (s32 j = 0; j < i; ++j) {
struct Mod* mod2 = mods->entries[j];
if (strcmp(mod->name, mod2->name) < 0) {
mods->entries[i] = mod2;
mods->entries[j] = mod;
mod = mods->entries[i];
}
}
}
}
static void mods_load(struct Mods* mods, char* modsBasePath) { static void mods_load(struct Mods* mods, char* modsBasePath) {
// generate bins // generate bins
dynos_generate_packs(modsBasePath); dynos_generate_packs(modsBasePath);
@ -160,6 +179,9 @@ void mods_init(void) {
strncat(defaultModsPath, MOD_DIRECTORY, SYS_MAX_PATH-1); strncat(defaultModsPath, MOD_DIRECTORY, SYS_MAX_PATH-1);
mods_load(&gLocalMods, defaultModsPath); mods_load(&gLocalMods, defaultModsPath);
// sort
mods_sort(&gLocalMods);
// calculate total size // calculate total size
gLocalMods.size = 0; gLocalMods.size = 0;
for (int i = 0; i < gLocalMods.entryCount; i++) { for (int i = 0; i < gLocalMods.entryCount; i++) {