From 7baf0ceaf9e0faf7facc3affe436bae622148ffc Mon Sep 17 00:00:00 2001 From: KrahJohlito <42090647+KrahJohlito@users.noreply.github.com> Date: Sun, 29 Sep 2019 12:17:26 +0930 Subject: [PATCH] fix: writing mc icon (#14) * mc: OPL folder and mc icon will now be checked and written when saving config to mc, if not found.. * gui: improve notifications code, slightly --- include/gui.h | 1 + include/opl.h | 3 --- include/util.h | 1 + src/gui.c | 23 ++++++++++++++++------- src/opl.c | 13 +++++-------- src/util.c | 37 +++++++++++++++++++++++++++++++------ 6 files changed, 54 insertions(+), 24 deletions(-) diff --git a/include/gui.h b/include/gui.h index a76f02bf7..5096f24a7 100644 --- a/include/gui.h +++ b/include/gui.h @@ -127,6 +127,7 @@ void guiShowNetConfig(); void guiShowParentalLockConfig(); void guiDelay(int milliSeconds); +void guiCheckNotifications(int checkTheme, int checkLang); /** Renders the given string on screen for the given function until it's io finishes * @note The ptr pointer is watched for it's value. The IO is considered finished when the value becomes zero. diff --git a/include/opl.h b/include/opl.h index 6c31b0376..c31752ad4 100644 --- a/include/opl.h +++ b/include/opl.h @@ -138,9 +138,6 @@ int gFadeDelay; int toggleSfx; int showCfgPopup; -int showThmPopup; -int showLngPopup; -int popupSfxPlayed; #ifdef IGS #define IGS_VERSION "0.1" diff --git a/include/util.h b/include/util.h index 966d18fea..a4820d5ac 100644 --- a/include/util.h +++ b/include/util.h @@ -5,6 +5,7 @@ int getmcID(void); int getFileSize(int fd); +void checkMCFolder(void); int openFile(char *path, int mode); void *readFile(char *path, int align, int *size); int listDir(char *path, const char *separator, int maxElem, diff --git a/src/gui.c b/src/gui.c index a57739979..6c7306f50 100644 --- a/src/gui.c +++ b/src/gui.c @@ -49,6 +49,10 @@ static int screenWidth; static int screenHeight; static int popupTimer; +static int popupSfxPlayed; + +static int showThmPopup; +static int showLngPopup; // forward decl. static void guiShow(); @@ -234,18 +238,23 @@ void guiShowAbout() toggleSfx = 0; } -static void guiBootNotifications(void) +void guiCheckNotifications(int checkTheme, int checkLang) { if (gEnableNotifications) { - if (thmGetGuiValue() != 0) - showThmPopup = 1; + if (checkTheme) { + if (thmGetGuiValue() != 0) + showThmPopup = 1; + } - if (lngGetGuiValue() != 0) - showLngPopup = 1; + if (checkLang) { + if (lngGetGuiValue() != 0) + showLngPopup = 1; + } if (showThmPopup || showLngPopup || showCfgPopup) { popupSfxPlayed = 0; - popupTimer -= 30; + if (showCfgPopup) + popupTimer -= 30; } } } @@ -2216,7 +2225,7 @@ void guiIntroLoop(void) void guiMainLoop(void) { guiResetNotifications(); - guiBootNotifications(); + guiCheckNotifications(1, 1); while (!gTerminate) { guiStartFrame(); diff --git a/src/opl.c b/src/opl.c index a438bbff4..e0e51f0a9 100644 --- a/src/opl.c +++ b/src/opl.c @@ -129,10 +129,7 @@ void moduleUpdateMenu(int mode, int themeChanged, int langChanged) if (langChanged) { guiUpdateScreenScale(); - if (lngGetGuiValue() != 0) { - showLngPopup = 1; - popupSfxPlayed = 0; - } + guiCheckNotifications(0, langChanged); } // refresh Hints @@ -160,10 +157,7 @@ void moduleUpdateMenu(int mode, int themeChanged, int langChanged) // refresh Cache if (themeChanged) { submenuRebuildCache(mod->subMenu); - if (thmGetGuiValue() != 0) { - showThmPopup = 1; - popupSfxPlayed = 0; - } + guiCheckNotifications(themeChanged, 0); } } @@ -1027,6 +1021,9 @@ int saveConfig(int types, int showUI) if (showUI) { if (lscret) { char *path = configGetDir(); + if (!strncmp(path, "mc", 2)) + checkMCFolder(); + snprintf(notification, sizeof(notification), _l(_STR_SETTINGS_SAVED), path); if ((col_pos = strchr(notification, ':')) != NULL) *(col_pos + 1) = '\0'; diff --git a/src/util.c b/src/util.c index 116ca225d..8261e5f7f 100644 --- a/src/util.c +++ b/src/util.c @@ -7,6 +7,7 @@ #include "include/opl.h" #include "include/util.h" #include "include/ioman.h" +#include "include/system.h" #include #include #include @@ -53,6 +54,32 @@ static void writeMCIcon(void) } } +void checkMCFolder(void) +{ + char path[32]; + + snprintf(path, sizeof(path), "mc%d:OPL", mcID); + int fd = fileXioDopen(path); + if (fd < 0) + fileXioMkdir(path, 0777); + + fileXioDclose(fd); + + snprintf(path, sizeof(path), "mc%d:OPL/opl.icn", mcID); + fd = fileXioOpen(path, O_RDONLY, 0666); + if (fd < 0) + writeMCIcon(); + + fileXioClose(fd); + + snprintf(path, sizeof(path), "mc%d:OPL/icon.sys", mcID); + fd = fileXioOpen(path, O_RDONLY, 0666); + if (fd < 0) + writeMCIcon(); + + fileXioClose(fd); +} + static int checkMC() { int dummy, ret; @@ -65,14 +92,12 @@ static int checkMC() if (fd < 0) { fd = fileXioDopen("mc1:OPL"); if (fd < 0) { - // No base dir found on any MC, will create the folder - if (fileXioMkdir("mc0:OPL", 0777) >= 0) { + // No base dir found on any MC, check MC is inserted + fd = sysCheckMC(); + if (fd == 0) mcID = 0x30; - writeMCIcon(); - } else if (fileXioMkdir("mc1:OPL", 0777) >= 0) { + else if (fd == 1) mcID = 0x31; - writeMCIcon(); - } } else { fileXioDclose(fd); mcID = 0x31;