From 3a3519f267983d410cbf23443d48ca0d7331e884 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sun, 29 Apr 2012 15:42:35 +0000 Subject: [PATCH] -added gecko output writing to sd card, enable "sd_write_log" in the wiiflow.ini or in the gecko.c, file will be called "wiiflow.log", you'll find it on sd card root --- source/gecko/gecko.c | 117 +++++++++++++++++++++++++++++-------------- source/gecko/gecko.h | 2 + source/main.cpp | 8 ++- source/menu/menu.cpp | 9 +++- 4 files changed, 95 insertions(+), 41 deletions(-) diff --git a/source/gecko/gecko.c b/source/gecko/gecko.c index f86ce3fb..2c472b6c 100644 --- a/source/gecko/gecko.c +++ b/source/gecko/gecko.c @@ -1,3 +1,6 @@ +//Enable the line below to always write SD log +//#define sd_write_log + #include #include #include @@ -10,53 +13,87 @@ bool geckoinit = false; bool textVideoInit = false; +bool bufferMessages = true; +bool WriteToSD = false; + #include static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len) { - if(geckoinit && ptr) - { - u32 level; - level = IRQ_Disable(); - usb_sendbuffer(1, ptr, len); - IRQ_Restore(level); - } + if(geckoinit && ptr) + { + u32 level; + level = IRQ_Disable(); + usb_sendbuffer(1, ptr, len); + IRQ_Restore(level); + } - return len; + return len; } static const devoptab_t gecko_out = { - "stdout", // device name - 0, // size of file structure - NULL, // device open - NULL, // device close - __out_write,// device write - NULL, // device read - NULL, // device seek - NULL, // device fstat - NULL, // device stat - NULL, // device link - NULL, // device unlink - NULL, // device chdir - NULL, // device rename - NULL, // device mkdir - 0, // dirStateSize - NULL, // device diropen_r - NULL, // device dirreset_r - NULL, // device dirnext_r - NULL, // device dirclose_r - NULL, // device statvfs_r - NULL, // device ftruncate_r - NULL, // device fsync_r - NULL, // device deviceData - NULL, // device chmod_r - NULL, // device fchmod_r + "stdout", // device name + 0, // size of file structure + NULL, // device open + NULL, // device close + __out_write,// device write + NULL, // device read + NULL, // device seek + NULL, // device fstat + NULL, // device stat + NULL, // device link + NULL, // device unlink + NULL, // device chdir + NULL, // device rename + NULL, // device mkdir + 0, // dirStateSize + NULL, // device diropen_r + NULL, // device dirreset_r + NULL, // device dirnext_r + NULL, // device dirclose_r + NULL, // device statvfs_r + NULL, // device ftruncate_r + NULL, // device fsync_r + NULL, // device deviceData + NULL, // device chmod_r + NULL, // device fchmod_r }; static void USBGeckoOutput() { - devoptab_list[STD_OUT] = &gecko_out; - devoptab_list[STD_ERR] = &gecko_out; + devoptab_list[STD_OUT] = &gecko_out; + devoptab_list[STD_ERR] = &gecko_out; +} + + +char *tmpfilebuffer = NULL; +void WriteToFile(char* tmp) +{ + if(bufferMessages) + { + if(strlen(tmpfilebuffer) + strlen(tmp) <= 1024) + strcat(tmpfilebuffer, tmp); + } + else + { + if(tmpfilebuffer != NULL) + { + free(tmpfilebuffer); + tmpfilebuffer = NULL; + } + return; + } + + if(WriteToSD) + { + FILE *outfile = fopen("sd:/wiiflow.log", "a"); + if(outfile) + { + fwrite(tmpfilebuffer, 1, strlen(tmpfilebuffer), outfile); + memset(tmpfilebuffer, 0, strlen(tmpfilebuffer)); + fclose(outfile); + } + } } //using the gprintf from crediar because it is smaller than mine @@ -67,6 +104,7 @@ void gprintf( const char *format, ... ) va_start(va, format); if((vasprintf(&tmp, format, va) >= 0) && tmp) { + WriteToFile(tmp); WifiGecko_Send(tmp, strlen(tmp)); if (geckoinit) __out_write(NULL, 0, tmp, strlen(tmp)); @@ -105,12 +143,16 @@ void ghexdump(void *d, int len) { } } - bool InitGecko() { if (geckoinit) return geckoinit; - USBGeckoOutput(); + USBGeckoOutput(); + + tmpfilebuffer = (char*)malloc(sizeof(char[1024])); + #ifdef sd_write_log + WriteToSD = true; + #endif u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); if (geckoattached) @@ -120,4 +162,3 @@ bool InitGecko() } else return false; } - diff --git a/source/gecko/gecko.h b/source/gecko/gecko.h index 36bafe95..6f136157 100644 --- a/source/gecko/gecko.h +++ b/source/gecko/gecko.h @@ -8,6 +8,8 @@ extern "C" { #endif extern bool geckoinit; + extern bool bufferMessages; + extern bool WriteToSD; //use this just like printf(); void gprintf(const char *format, ...); diff --git a/source/main.cpp b/source/main.cpp index 3ec238f9..25485aaf 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -91,11 +91,15 @@ int main(int argc, char **argv) DeviceHandler::Instance()->MountAll(); sleep(1); - for(u8 device = SD; device <= USB8; device++) + for(u8 device = USB1; device <= USB8; device++) if(DeviceHandler::Instance()->IsInserted(device)) deviceAvailable = true; } - if(!deviceAvailable) Sys_Exit(); + if(DeviceHandler::Instance()->IsInserted(SD)) + deviceAvailable = true; + + if(!deviceAvailable) + Sys_Exit(); bool dipOK = Disc_Init() >= 0; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index d9ae197b..04bb66ec 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -197,8 +197,15 @@ void CMenu::init(void) m_cfg.load(sfmt("%s/" CFG_FILENAME, m_appDir.c_str()).c_str()); + //Gecko Output to SD + if(!WriteToSD) + { + WriteToSD = m_cfg.getBool("GENERAL", "sd_write_log", false); + bufferMessages = WriteToSD; + } + bool onUSB = m_cfg.getBool("GENERAL", "data_on_usb", strncmp(drive, "usb", 3) == 0); - + drive = check; //reset the drive variable for the check if (onUSB)