From 0695e04b428e4f5887f1b11876d22b1437ab0ffd Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 5 May 2009 22:32:58 +0000 Subject: [PATCH] file code suggestions from rodries --- source/ngc/fileop.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index be0aa49..31dc781 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -62,6 +62,7 @@ lwp_t devicethread = LWP_THREAD_NULL; static void * devicecallback (void *arg) { + sleep(1); while (1) { #ifdef HW_RVL @@ -76,7 +77,7 @@ devicecallback (void *arg) if(isMounted[METHOD_USB]) { - if(!usb->isInserted()) // check if the device was removed - doesn't work on USB! + if(!usb->isInserted()) // check if the device was removed { unmountRequired[METHOD_USB] = true; isMounted[METHOD_USB] = false; @@ -103,7 +104,7 @@ devicecallback (void *arg) } } #endif - usleep(500000); // suspend thread for 1/2 sec + sleep(1); // suspend thread for 1 sec } return NULL; } @@ -572,8 +573,17 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) if (file > 0) { - written = fwrite (savebuffer, 1, datasize, file); - if(written < datasize) written = 0; + u32 writesize, nextwrite; + while(written < datasize) + { + if(datasize - written > 16*1024) nextwrite=16*1024; + else nextwrite = datasize-written; + writesize = fwrite (buffer+written, 1, nextwrite, file); + if(writesize != nextwrite) break; // write failure + written += writesize; + } + + if(written != datasize) written = 0; fclose (file); } }