From 6bfaa259666ff9760b3c127bbdc58113174658dc Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 6 Oct 2009 07:09:18 +0000 Subject: [PATCH] rewritten save function --- source/ngc/fileop.cpp | 45 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 8d6ceef..8d46c72 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -835,32 +835,35 @@ SaveFile (char * buffer, char *filepath, size_t datasize, bool silent) { while(!written && retry == 1) { - if(ChangeInterface(device, silent)) + if(!ChangeInterface(device, silent)) + break; + + file = fopen (filepath, "wb"); + + if(!file) { - file = fopen (filepath, "wb"); - - if (file) - { - while(written < datasize) - { - if(datasize - written > 4096) nextwrite=4096; - 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); - } + if(silent) + break; + + retry = ErrorPromptRetry("Error creating file!"); + continue; } + + while(written < datasize) + { + if(datasize - written > 4096) nextwrite=4096; + else nextwrite = datasize-written; + writesize = fwrite (buffer+written, 1, nextwrite, file); + if(writesize != nextwrite) break; // write failure + written += writesize; + } + + if(written != datasize) written = 0; + if(!written) { unmountRequired[device] = true; - if(!silent) - retry = ErrorPromptRetry("Error saving file!"); - else - retry = 0; + retry = ErrorPromptRetry("Error saving file!"); } } }