diff options
Diffstat (limited to 'StarsEx/DataLoader.cpp')
-rw-r--r-- | StarsEx/DataLoader.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/StarsEx/DataLoader.cpp b/StarsEx/DataLoader.cpp index 72eaf4b..1dcbe0e 100644 --- a/StarsEx/DataLoader.cpp +++ b/StarsEx/DataLoader.cpp @@ -26,11 +26,13 @@ DataLoader* DataLoader::loader = 0; DataLoader::DataLoader() : datapath(""), video(0), use_file_system(true), enable_media(true) -{ } +{ +} DataLoader::~DataLoader() { archives.destroy(); + sources.destroy(); } // +--------------------------------------------------------------------+ @@ -82,6 +84,37 @@ DataLoader::EnableMedia(bool enable) // +--------------------------------------------------------------------+ int +DataLoader::InsertDatafile(const char* name, int pos) +{ + FILE* f = fopen(name, "rb"); + if (!f) { + Print(" WARNING: could not open datafile '%s'\n", name); + return DATAFILE_NOTEXIST; + } + fclose(f); + auto archive = new DataArchive(name); + if (!archive || archive->NumFiles() < 1) { + Print(" WARNING: invalid data file '%s'\n", name); + if (archive) delete archive; + return DATAFILE_INVALID; + } + DataSource* source = new ArchiveDataSource(archive); + if (pos < 0) + sources.append(source); + else + sources.insert(source, pos); + return DATAFILE_OK; +} + +void +DataLoader::ClearSources() +{ + sources.destroy(); +} + +// +--------------------------------------------------------------------+ + +int DataLoader::EnableDatafile(const char* name) { int status = DATAFILE_NOTEXIST; |