From 0332e496347f6b563abb86d4ef9650bbd6ebc3e1 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 28 May 2014 15:05:57 +0200 Subject: Port server to hugin. --- src/file.cc | 72 ++++++++++++++++++++----------------------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) (limited to 'src/file.cc') diff --git a/src/file.cc b/src/file.cc index 9d86c1c..0f5d0bf 100644 --- a/src/file.cc +++ b/src/file.cc @@ -24,38 +24,33 @@ * along with MIaV; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include #include "file.h" -#include "miav_config.h" - #include #include #include #include #include - #include - -// For ntoh* #include - #include -File::File(Info *i) + +#include + +#include "miav_config.h" + +File::File() { - info = i; fd = 0; savestate = NO_CHANGE; filename = new char[1]; extension = new char[1]; } -File::File(const char *fn, const char* ext, Info *i) +File::File(const char *fn, const char* ext) { char path[256]; - info = i; - savestate = SAVE; filename = new char[strlen(fn) + 1]; @@ -88,9 +83,9 @@ File::~File() { close(fd); - info->info("This session contains the following files..."); + INFO(file, "This session contains the following files..."); for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { - info->info("[%s]", filelist[cnt].c_str()); + INFO(file, "[%s]", filelist[cnt].c_str()); } std::string *trash = config->readString("server_trash"); @@ -98,20 +93,20 @@ File::~File() switch(savestate) { case NO_CHANGE: - info->warn("File had no savestate!"); + WARN(file, "File had no savestate!"); break; case SAVE: - info->info("Files in this session is to be saved."); + INFO(file, "Files in this session is to be saved."); break; case DELETE: - info->info("Files in this session is to be deleted (moved to trash)."); + INFO(file, "Files in this session is to be deleted (moved to trash)."); Move((char*)trash->c_str()); break; case LATER: - info->info("Files in this session is stored for later decisson."); + INFO(file, "Files in this session is stored for later decisson."); Move((char*)later->c_str()); break; } @@ -133,11 +128,10 @@ int File::Move(char *destination) // TODO: Move file filelist[cnt] to the destination folder. strcpy(filename, (char*)filelist[cnt].c_str()); sprintf(newfile, "%s%s", destination, strrchr(filename, '/')); - if(rename((char*)filelist[cnt].c_str(), newfile) == -1) - info->error("Error moving file %s to %s:", - (char*)filelist[cnt].c_str(), - newfile, - strerror(errno)); + if(rename((char*)filelist[cnt].c_str(), newfile) == -1) { + ERR(file, "Error moving file %s to %s: %s", (char*)filelist[cnt].c_str(), + newfile, strerror(errno)); + } } return 0; } @@ -165,7 +159,7 @@ int File::Open() // If more than 100 files are created in one day, something is terribly wrong! if(num > 100) { - info->error("Something is wrong with the path [%s]!", fname); + ERR(file, "Something is wrong with the path [%s]!", fname); exit(1); } @@ -176,7 +170,7 @@ int File::Open() seqnum ++; - info->info("Output file: %s", fname); + INFO(file, "Output file: %s", fname); return 0; } @@ -188,11 +182,11 @@ int File::Write(void* data, int size) w = write(fd, data, size); if(w != size) { - info->info("Wrapping file."); + INFO(file, "Wrapping file."); Open(); w = write(fd, data, size); if(w != size) { - info->error("Out of diskspace!"); + ERR(file, "Out of diskspace!"); return -1; } } @@ -213,7 +207,7 @@ int File::createPath(char* path) if(strlen(subpath) > 0) createPath(subpath); - info->info("Checking and/or generating directory: %s", path); + INFO(file, "Checking and/or generating directory: %s", path); // stat(path, &stats); //if(!S_ISDIR(stats.st_mode) && S_ISREG(stats.st_mode)) @@ -228,25 +222,5 @@ int File::createPath(char* path) void File::setSaveState(n_savestate s) { savestate = s; - info->info("SETTING SAVESTATE TO: %d", savestate); -} - -#ifdef __TEST_FILE -#include "info_simple.h" - -int main(int argc, char *argv[]) { - if(argc < 3) { - fprintf(stderr, "usage:\n\ttest_file [filename] [extension]\n"); - return 1; - } - - - InfoSimple info; - File file(argv[1], argv[2], &info); - - unsigned int val = 0x01234567; - file.Write(val); - + INFO(file, "SETTING SAVESTATE TO: %d", savestate); } - -#endif/* __TEST_FILE*/ -- cgit v1.2.3