Skip to content

Commit

Permalink
fix: writing mc icon (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
KrahJohlito authored and Tupakaveli committed Sep 29, 2019
1 parent cf40031 commit f9fcca5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ int gFadeDelay;
int toggleSfx;

int showCfgPopup;
int showThmPopup;
int showLngPopup;
int popupSfxPlayed;

#ifdef IGS
#define IGS_VERSION "0.1"
Expand Down
1 change: 1 addition & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -2216,7 +2225,7 @@ void guiIntroLoop(void)
void guiMainLoop(void)
{
guiResetNotifications();
guiBootNotifications();
guiCheckNotifications(1, 1);

while (!gTerminate) {
guiStartFrame();
Expand Down
13 changes: 5 additions & 8 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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';
Expand Down
37 changes: 31 additions & 6 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "include/opl.h"
#include "include/util.h"
#include "include/ioman.h"
#include "include/system.h"
#include <io_common.h>
#include <string.h>
#include <malloc.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f9fcca5

Please sign in to comment.