* setting.txt and SYSCONF for temp region nand emulation are now readed from nand (not written to)

* It will now create the path to setting.txt and SYSCONF if they don't exist
* It will now create setting.txt and SYSCONF if they don't exist
This commit is contained in:
overjoy.psm 2012-03-14 21:09:29 +00:00
parent 36f75ca434
commit a6709f71cf
3 changed files with 82 additions and 31 deletions

View File

@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2011 by Miigotu * Copyright (C) 2011 by Miigotu for wiiflow 2011
* (C) 2012 by OverjoY for Wiiflow-mod * (C) 2012 by OverjoY for Wiiflow-mod
* *
* Rewritten code from Mighty Channels and Triiforce * Rewritten code from Mighty Channels and Triiforce
@ -25,7 +25,6 @@
* *
* Nand/Emulation Handling Class * Nand/Emulation Handling Class
* *
* for wiiflow 2011
***************************************************************************/ ***************************************************************************/
#include <stdio.h> #include <stdio.h>
@ -33,16 +32,21 @@
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <cstdlib> #include <cstdlib>
#include <stdarg.h>
#include <dirent.h>
#include "nand.hpp" #include "nand.hpp"
#include "utils.h" #include "utils.h"
#include "gecko.h" #include "gecko.h"
#include "mem2.hpp" #include "mem2.hpp"
u8 *confbuffer; #define SYSCONFPATH "/shared2/sys/SYSCONF"
#define TXTPATH "/title/00000001/00000002/data/setting.txt"
u8 *confbuffer ATTRIBUTE_ALIGN(32);
u8 CCode[0x1008]; u8 CCode[0x1008];
char SCode[4]; char SCode[4];
char *txtbuffer; char *txtbuffer ATTRIBUTE_ALIGN(32);
config_header *cfg_hdr; config_header *cfg_hdr;
@ -232,21 +236,28 @@ s32 Nand::__configread(void)
txtbuffer = (char *)MEM2_alloc(0x100); txtbuffer = (char *)MEM2_alloc(0x100);
cfg_hdr = (config_header *)NULL; cfg_hdr = (config_header *)NULL;
FILE *f = fopen(cfgpath, "rb"); ISFS_Deinitialize();
if(f) ISFS_Initialize();
{
fread(confbuffer, 1, 0x4000, f);
gprintf("SYSCONF readed from: %s \n", cfgpath);
fclose(f);
}
f = fopen(settxtpath, "rb"); s32 fd = IOS_Open(SYSCONFPATH, IPC_OPEN_READ);
if(f) if(fd < 0)
{ return 0;
fread(txtbuffer, 1, 0x100, f);
gprintf("setting.txt readed from: %s \n", settxtpath); s32 ret = IOS_Read(fd, confbuffer, 0x4000);
fclose(f); if(ret < 0)
} return 0;
IOS_Close(fd);
fd = IOS_Open(TXTPATH, IPC_OPEN_READ);
if(fd < 0)
return 0;
ret = IOS_Read(fd, txtbuffer, 0x100);
if(ret < 0)
return 0;
IOS_Close(fd);
cfg_hdr = (config_header *)confbuffer; cfg_hdr = (config_header *)confbuffer;
@ -272,7 +283,7 @@ s32 Nand::__configwrite(void)
if(f) if(f)
{ {
fwrite(confbuffer, 1, 0x4000, f); fwrite(confbuffer, 1, 0x4000, f);
gprintf("SYSCONF written to: %s \n", cfgpath); gprintf("SYSCONF written to:\"%s\"\n", cfgpath);
fclose(f); fclose(f);
} }
@ -280,7 +291,7 @@ s32 Nand::__configwrite(void)
if(f) if(f)
{ {
fwrite(txtbuffer, 1, 0x100, f); fwrite(txtbuffer, 1, 0x100, f);
gprintf("setting.txt written to: %s \n", settxtpath); gprintf("setting.txt written to: \"%s\"\n", settxtpath);
fclose(f); fclose(f);
} }
@ -360,13 +371,50 @@ u32 Nand::__configsetsetting(const char *item, const char *val)
return 0; return 0;
} }
s32 Nand::Do_Region_Change(string id, char *path) void Nand::__CreatePath(const char *path, ...)
{ {
bzero(cfgpath, MAX_FAT_PATH); char *folder = NULL;
bzero(settxtpath, MAX_FAT_PATH); va_list args;
va_start(args, path);
if((vasprintf(&folder, path, args) >= 0) && folder)
{
DIR *d;
snprintf(cfgpath, sizeof(cfgpath), "%s/shared2/sys/SYSCONF", path); d = opendir(folder);
snprintf(settxtpath, sizeof(settxtpath), "%s/title/00000001/00000002/data/setting.txt", path); if(!d)
{
gprintf("Creating folder: \"%s\"\n", folder);
makedir(folder);
}
else
{
gprintf("Folder \"%s\" exists\n", folder);
closedir(d);
}
}
va_end(args);
SAFE_FREE(folder);
}
s32 Nand::CreateConfig(const char *path)
{
__CreatePath(path);
__CreatePath("%s/shared2", path);
__CreatePath("%s/shared2/sys", path);
__CreatePath("%s/title", path);
__CreatePath("%s/title/00000001", path);
__CreatePath("%s/title/00000001/00000002", path);
__CreatePath("%s/title/00000001/00000002/data", path);
return 0;
}
s32 Nand::Do_Region_Change(string id, const char *path)
{
bzero(cfgpath, ISFS_MAXPATH);
bzero(settxtpath, ISFS_MAXPATH);
snprintf(cfgpath, sizeof(cfgpath), "%s%s", path, SYSCONFPATH);
snprintf(settxtpath, sizeof(settxtpath), "%s%s", path, TXTPATH);
if(__configread()) if(__configread())
{ {

View File

@ -56,7 +56,8 @@ class Nand
void Set_NandPath(string path); void Set_NandPath(string path);
s32 Do_Region_Change(string id, char *path); s32 CreateConfig(const char *path);
s32 Do_Region_Change(string id, const char *path);
private: private:
Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {} Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {}
@ -74,6 +75,8 @@ class Nand
u32 __configsetbyte(const char *item, u8 val); u32 __configsetbyte(const char *item, u8 val);
u32 __configsetbigarray(const char *item, void *val, u32 size); u32 __configsetbigarray(const char *item, void *val, u32 size);
u32 __configsetsetting(const char *item, const char *val); u32 __configsetsetting(const char *item, const char *val);
void __CreatePath(const char *path, ...);
u32 MountedDevice; u32 MountedDevice;
u32 EmuDevice; u32 EmuDevice;

View File

@ -1014,7 +1014,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
if(emuSave > 2) if(emuSave > 2)
{ {
//Nand::Instance()->CreateConfig(basepath); // TODO: Write config files if they don't excist Nand::Instance()->CreateConfig(basepath);
Nand::Instance()->Do_Region_Change(id, basepath); Nand::Instance()->Do_Region_Change(id, basepath);
} }
} }