Skip to content

Commit

Permalink
Fix paths, solve crashs within config reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanquitas committed Dec 23, 2017
1 parent e35348a commit c60237c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 49 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ else
endif
endif


BUILD_DIR := build
OUTPUT_DIR := output
INCLUDE_DIRS := $(SOURCE_DIRS) include
SOURCE_DIRS := source source/json

EXTRA_OUTPUT_FILES :=

LIBRARY_DIRS := $(PORTLIBS) $(CTRULIB)
LIBRARY_DIRS := $(PORTLIBS) $(CTRULIB)
LIBRARIES := citro3d ctru png z m

VERSION_MAJOR := 2
VERSION_MINOR := 10
VERSION_MINOR := 11
VERSION_MICRO := 0


Expand Down Expand Up @@ -129,14 +129,14 @@ re:
@rm -rf $(BUILD_DIR)
@echo cleaned build dir

FONZD: cleanupdater
FONZD: cleanupdater
make FONZD=1

PABLOMK7: cleanupdater
PABLOMK7: cleanupdater
make PABLOMK7=1

FONZDM3: clean
FONZDM3: clean
make FONZD=1 EXTENDEDMODE=1

PABLOMK7M3: clean
PABLOMK7M3: clean
make PABLOMK7=1 EXTENDEDMODE=1
66 changes: 35 additions & 31 deletions source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ bool checkPath(void)

bool loadConfigFromFile(config_t *config)
{
FILE *file;
FILE *file = NULL;

file = NULL;
if (!config) goto error;
if (!fileExists(configPath)) goto error;
//if (!fileExists(configPath)) goto error;
file = fopen(configPath, "rb");
if (!file) goto error;
fread(config, sizeof(config_t), 1, file);
Expand All @@ -50,7 +49,7 @@ bool loadConfigFromFile(config_t *config)
{
memset(config, 0, sizeof(config_t));
config->version = CURRENT_CONFIG_VERSION;
bnConfig->checkForUpdate = true;
g_bnConfig.checkForUpdate = true;
goto error;
}

Expand All @@ -61,16 +60,18 @@ bool loadConfigFromFile(config_t *config)

bool saveConfig(void)
{
FILE *file;
config_t *config;
FILE *file = 0;
config_t *config = g_bnConfig.config;

config = g_bnConfig.config;
if (!config)
goto error;
if (!fileExists(configDir))
createDir(configDir);
if (!fileExists(configDir)) goto error;
file = fopen(configPath, "wb");
if (!file) goto error;
fwrite(config, sizeof(config_t), 1, file);
fflush(file);
fclose(file);
return (true);
error:
Expand All @@ -81,9 +82,9 @@ void resetConfig(void)
{
char path[0x100];
config_t *config = NULL;
bool binPath = false;
//bool binPath = false;
u32 keys;
u32 size;
//u32 size;

do
{
Expand All @@ -93,11 +94,12 @@ void resetConfig(void)

if (!fileExists(configPath)) goto exit;
config = (config_t *)calloc(1, sizeof(config_t));
if (config)
binPath = loadConfigFromFile(config);
if (!config)
goto exit;
//binPath = loadConfigFromFile(config);
remove(configPath);
rmdir(configDir);
if (!binPath) goto exit;
/* if (!binPath) goto exit;
size = strlen(config->binariesPath);
if (!size) goto exit;
memset(path, 0, 0x100);
Expand All @@ -108,8 +110,8 @@ void resetConfig(void)
remove(path);
memset(path, 0, 0x100);
strJoin(path, config->binariesPath + 5, "ntr_3_6.bin");
remove(path);
remove(path); */

exit:
if (config)
free(config);
Expand All @@ -119,12 +121,13 @@ void resetConfig(void)
void configInit(void)
{
config_t *config;
Handle fsuHandle;
Handle fsuHandle = *fsGetSessionHandle();
bool isNew3DS = false;;


srvGetServiceHandle(&fsuHandle, "fs:USER");
FSUSER_Initialize(fsuHandle);
// srvGetServiceHandle(&fsuHandle, "fs:USER");
// FSUSER_Initialize(fsuHandle);

APT_CheckNew3DS(&isNew3DS);

memset(&g_ntrConfig, 0, sizeof(g_ntrConfig));
Expand All @@ -138,10 +141,11 @@ void configInit(void)
g_bnConfig.isNew3DS = isNew3DS;

config = (config_t *)calloc(1, sizeof(config_t));
if (!config) goto error;
bnConfig->config = config;
if (!config) goto error;
g_bnConfig.config = config;
if (!loadConfigFromFile(config))
{
saveConfig();
firstLaunch();
if (!saveConfig())
newAppTop(DEFAULT_COLOR, 0, "A problem occured while saving the settings.");
Expand All @@ -150,30 +154,29 @@ void configInit(void)
}
else
{

time_t current = time(NULL);
time_t last;

if (envIsHomebrew())
last = config->lastUpdateTime3dsx;
else
last = g_bnConfig.isMode3 ? config->lastUpdateTime3 : config->lastUpdateTime;

if (current - last >= SECONDS_IN_WEEK)
bnConfig->checkForUpdate = true;
if (current - last >= SECONDS_IN_WEEK)
g_bnConfig.checkForUpdate = true;
else
bnConfig->checkForUpdate = false;
g_bnConfig.checkForUpdate = false;
}

if (g_bnConfig.isMode3)
{
bnConfig->versionToLaunch = V36;
g_bnConfig.versionToLaunch = V36;
}
else
{
if (config->flags & LV32) bnConfig->versionToLaunch = V32;
else if (config->flags & LV33) bnConfig->versionToLaunch = V33;
else if (config->flags & LV36) bnConfig->versionToLaunch = V36;
if (config->flags & LV32) g_bnConfig.versionToLaunch = V32;
else if (config->flags & LV33) g_bnConfig.versionToLaunch = V33;
else if (config->flags & LV36) g_bnConfig.versionToLaunch = V36;
}
error:
return;
Expand All @@ -185,17 +188,18 @@ void configExit(void)
config_t *config;
u32 flags;

version = bnConfig->versionToLaunch;
config = bnConfig->config;
version = g_bnConfig.versionToLaunch;
config = g_bnConfig.config;
if (!g_bnConfig.isMode3)
{
if (version == V32) flags = LV32;
else if (version == V33) flags = LV33;
else if (version == V36) flags = LV36;
else flags = 0;
config->flags = flags;
config->flags = flags;
}

saveConfig();
free(config);
g_bnConfig.config = NULL;
}
6 changes: 3 additions & 3 deletions source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define CONFIG_H

#include "main.h"
#include <time.h>
#include <time.h>

#ifndef SYSTEM_VERSION
#define SYSTEM_VERSION(major, minor, revision) \
(((major)<<24)|((minor)<<16)|((revision)<<8))
#endif

#define CURRENT_CONFIG_VERSION SYSTEM_VERSION(1, 0, 9)
#define CURRENT_CONFIG_VERSION SYSTEM_VERSION(1, 0, 10)

#define SECONDS_IN_WEEK 604800
#define SECONDS_IN_DAY 86400
Expand Down Expand Up @@ -96,4 +96,4 @@ bool checkPath(void);

void firstLaunch(void);

#endif
#endif
5 changes: 3 additions & 2 deletions source/firstLaunchMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void exitSettingsMenu(void)
{
clearBottomScreen();
clearTopScreen();
updateUI();
destroyButton(binariesPathButton);
destroyButton(pluginsPathButton);
destroyButton(createCustomButton);
Expand Down Expand Up @@ -399,8 +400,9 @@ static void setFiles(void)

newAppTop(COLOR_LIMEGREEN, 0, "Finished");
updateUI();
wait(2);
clearTop(1);
wait(3);
//wait(3);
}

void firstLaunch(void)
Expand Down Expand Up @@ -435,4 +437,3 @@ void firstLaunch(void)
appInfoEnableAutoUpdate();
updateUI();
}

8 changes: 4 additions & 4 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(void)
{
newAppStatus(DEFAULT_COLOR, CENTER | BOLD | NEWLINE, "Updated !");
goto waitForExit;
}
}

}
}
Expand All @@ -64,7 +64,7 @@ int main(void)
newAppStatus(DEFAULT_COLOR, CENTER | BOLD | NEWLINE, "Success !");

#if EXTENDEDMODE

newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY | NEWLINE, "Press Home to launch");
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "your game.");
updateUI();
Expand All @@ -86,7 +86,7 @@ int main(void)
goto exit;
#endif

}
}
}
if (g_exit || ret)
{
Expand All @@ -104,7 +104,7 @@ int main(void)
}
else
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#%s", g_primary_error);
}
}
if (g_secondary_error != NULL)
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#%s", g_secondary_error);
if (g_third_error != NULL)
Expand Down
3 changes: 1 addition & 2 deletions source/pathPatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ Result loadAndPatch(version_t version)
binPath = bnConfig->config->binariesPath;
plgPath = bnConfig->config->pluginPath;

if (version == V36)
strJoin(inPath, "romfs:/", ntrVersionStrings[version + isNew3DS]);
strJoin(inPath, "romfs:/", ntrVersionStrings[version + (version == V36 && isNew3DS)]);

if (!strncmp("sdmc:", binPath, 5)) binPath += 5;
if (!strncmp("sdmc:", plgPath, 5)) plgPath += 5;
Expand Down

0 comments on commit c60237c

Please sign in to comment.