From 1ed29175d641e230cf09ea93734bc16cd1f65311 Mon Sep 17 00:00:00 2001 From: Isaac <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 14 Mar 2022 11:09:57 +1000 Subject: [PATCH] Allowed DynOS Packs to be placed in %appdata%/sm64ex-coop (#27) --- data/dynos_gfx_init.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/data/dynos_gfx_init.cpp b/data/dynos_gfx_init.cpp index 4f758cc2..53a8c1be 100644 --- a/data/dynos_gfx_init.cpp +++ b/data/dynos_gfx_init.cpp @@ -70,5 +70,46 @@ Array DynOS_Gfx_Init() { SysPath _DirName = _Pack->mPath.substr(MAX(_DirSep1, _DirSep2)); _PackNames.Add(_DirName.c_str()); } + +#ifdef COOP + Array &pDynosUserPacks = DynOS_Gfx_GetPacks(); + SysPath _DynosPacksUserFolder = fstring("%s/%s", DYNOS_USER_FOLDER, DYNOS_PACKS_FOLDER); + DIR *_DynosPacksUserDir = opendir(_DynosPacksUserFolder.c_str()); + if (_DynosPacksUserDir) { + struct dirent *_DynosPacksUserEnt = NULL; + while ((_DynosPacksUserEnt = readdir(_DynosPacksUserDir)) != NULL) { + + // Skip . and .. + if (SysPath(_DynosPacksUserEnt->d_name) == ".") continue; + if (SysPath(_DynosPacksUserEnt->d_name) == "..") continue; + + // If pack folder exists, add it to the pack list + SysPath _PackFolder = fstring("%s/%s", _DynosPacksUserFolder.c_str(), _DynosPacksUserEnt->d_name); + if (fs_sys_dir_exists(_PackFolder.c_str())) { + PackData *_Pack = New(); + + // Scan folder for subfolders to convert into .bin files + _Pack->mPath = _PackFolder; + DynOS_Gfx_GeneratePack(_PackFolder); + + // Add pack to pack list + pDynosPacks.Add(_Pack); + + // Add enabled flag + DynOS_Gfx_GetPacksEnabled().Add(true); + + } + } + closedir(_DynosPacksUserDir); + } + for (const auto& _Pack : pDynosUserPacks) { + u64 _DirSep1 = _Pack->mPath.find_last_of('\\'); + u64 _DirSep2 = _Pack->mPath.find_last_of('/'); + if (_DirSep1++ == SysPath::npos) _DirSep1 = 0; + if (_DirSep2++ == SysPath::npos) _DirSep2 = 0; + SysPath _DirName = _Pack->mPath.substr(MAX(_DirSep1, _DirSep2)); + _PackNames.Add(_DirName.c_str()); + } +#endif return _PackNames; }