-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
This commit is contained in:
fix94.1 2012-04-29 15:42:35 +00:00
parent c68873071d
commit 3a3519f267
4 changed files with 95 additions and 41 deletions

View File

@ -1,3 +1,6 @@
//Enable the line below to always write SD log
//#define sd_write_log
#include <gccore.h> #include <gccore.h>
#include <malloc.h> #include <malloc.h>
#include <stdio.h> #include <stdio.h>
@ -10,6 +13,9 @@
bool geckoinit = false; bool geckoinit = false;
bool textVideoInit = false; bool textVideoInit = false;
bool bufferMessages = true;
bool WriteToSD = false;
#include <stdarg.h> #include <stdarg.h>
static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len) static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len)
@ -59,6 +65,37 @@ static void USBGeckoOutput()
devoptab_list[STD_ERR] = &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 //using the gprintf from crediar because it is smaller than mine
void gprintf( const char *format, ... ) void gprintf( const char *format, ... )
{ {
@ -67,6 +104,7 @@ void gprintf( const char *format, ... )
va_start(va, format); va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp) if((vasprintf(&tmp, format, va) >= 0) && tmp)
{ {
WriteToFile(tmp);
WifiGecko_Send(tmp, strlen(tmp)); WifiGecko_Send(tmp, strlen(tmp));
if (geckoinit) if (geckoinit)
__out_write(NULL, 0, tmp, strlen(tmp)); __out_write(NULL, 0, tmp, strlen(tmp));
@ -105,13 +143,17 @@ void ghexdump(void *d, int len) {
} }
} }
bool InitGecko() bool InitGecko()
{ {
if (geckoinit) return geckoinit; 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); u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
if (geckoattached) if (geckoattached)
{ {
@ -120,4 +162,3 @@ bool InitGecko()
} }
else return false; else return false;
} }

View File

@ -8,6 +8,8 @@ extern "C" {
#endif #endif
extern bool geckoinit; extern bool geckoinit;
extern bool bufferMessages;
extern bool WriteToSD;
//use this just like printf(); //use this just like printf();
void gprintf(const char *format, ...); void gprintf(const char *format, ...);

View File

@ -91,11 +91,15 @@ int main(int argc, char **argv)
DeviceHandler::Instance()->MountAll(); DeviceHandler::Instance()->MountAll();
sleep(1); sleep(1);
for(u8 device = SD; device <= USB8; device++) for(u8 device = USB1; device <= USB8; device++)
if(DeviceHandler::Instance()->IsInserted(device)) if(DeviceHandler::Instance()->IsInserted(device))
deviceAvailable = true; deviceAvailable = true;
} }
if(!deviceAvailable) Sys_Exit(); if(DeviceHandler::Instance()->IsInserted(SD))
deviceAvailable = true;
if(!deviceAvailable)
Sys_Exit();
bool dipOK = Disc_Init() >= 0; bool dipOK = Disc_Init() >= 0;

View File

@ -197,6 +197,13 @@ void CMenu::init(void)
m_cfg.load(sfmt("%s/" CFG_FILENAME, m_appDir.c_str()).c_str()); 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); bool onUSB = m_cfg.getBool("GENERAL", "data_on_usb", strncmp(drive, "usb", 3) == 0);
drive = check; //reset the drive variable for the check drive = check; //reset the drive variable for the check