00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #include "FileManager.hpp" 00023 #include "../encode/EncodeManager.hpp" 00024 #include "../schema/IoSchema.hpp" 00025 #include "util/error/Log.hpp" 00026 #include <cstdio> 00027 #include <cstring> 00028 00029 00030 00031 namespace se_core { 00032 00033 FileManager 00034 ::FileManager() { 00035 } 00036 00037 00038 FileManager 00039 ::~FileManager() { 00040 } 00041 00042 00043 void FileManager 00044 ::load(const char* filename) { 00045 InputStream* is = 0; 00046 if((is = IoSchema::fileManager->open(filename)) != 0) { 00047 bool success = IoSchema::parser().parse(*is); 00048 AssertWarning(success, "Failed loading " << filename); 00049 close(is); 00050 } 00051 } 00052 00053 void FileManager 00054 ::save(const char* filename) { 00055 OutputStream* os = 0; 00056 if((os = IoSchema::fileManager->openOutput(filename)) != 0) { 00057 IoSchema::encoder().encode(*os); 00058 closeOutput(os); 00059 } 00060 } 00061 00062 void FileManager 00063 ::loadDirectory(const char* directory) { 00064 int len = static_cast<int>(strlen(directory)); 00065 for(int i = 0; i < IoSchema::fileManager->fileCount(); ++i) { 00066 const char* filename = IoSchema::fileManager->filename(i); 00067 if(strncmp(filename, directory, len) == 0) { 00068 InputStream* is = 0; 00069 if((is = IoSchema::fileManager->open(filename)) != 0) { 00070 bool success = IoSchema::parser().parse(*is); 00071 AssertWarning(success, "Failed parsing " << filename); 00072 close(is); 00073 } 00074 } 00075 } 00076 } 00077 00078 00079 void FileManager 00080 ::loadBatch(const char* batchFilename) { 00081 InputStream* initIs = IoSchema::fileManager->open(batchFilename); 00082 char filename[256]; 00083 00084 while(true) { 00085 initIs->readLine(filename, 256); 00086 if(filename[0] == 0 || filename[0] == 'Q') { 00087 break; 00088 } 00089 if(filename[0] == 0 || filename[0] == '\n' || filename[0] == ' ') { 00090 continue; 00091 } 00092 00093 InputStream* is = 0; 00094 if((is = IoSchema::fileManager->open(filename)) != 0) { 00095 bool success = IoSchema::parser().parse(*is); 00096 AssertWarning(success, "Failed parsing " << filename); 00097 IoSchema::fileManager->close(is); 00098 LogDetail("Finished loading batch: " << filename); 00099 continue; 00100 } 00101 00102 LogFatal("Couldn't open file: " << filename); 00103 } 00104 close(initIs); 00105 } 00106 00107 00108 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.