diff options
author | Aki <please@ignore.pl> | 2022-04-12 18:33:34 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-12 18:33:34 +0200 |
commit | 9c1439b0e5e1c90723c0f2f6e22a24a935623542 (patch) | |
tree | f1999c9dc2e62c576fcc14f326992514ea20e016 /StarsEx/DataLoader.cpp | |
parent | 220f110e298a211d0f508ed33bae0fa9e9bf4689 (diff) | |
download | starshatter-9c1439b0e5e1c90723c0f2f6e22a24a935623542.zip starshatter-9c1439b0e5e1c90723c0f2f6e22a24a935623542.tar.gz starshatter-9c1439b0e5e1c90723c0f2f6e22a24a935623542.tar.bz2 |
Changed error returning in DataLoader
This is to allow meaningful return values for identification of unique
sources.
Diffstat (limited to 'StarsEx/DataLoader.cpp')
-rw-r--r-- | StarsEx/DataLoader.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/StarsEx/DataLoader.cpp b/StarsEx/DataLoader.cpp index c5ad9bd..12a6c67 100644 --- a/StarsEx/DataLoader.cpp +++ b/StarsEx/DataLoader.cpp @@ -73,6 +73,14 @@ DataLoader::Reset() // +--------------------------------------------------------------------+ +const char* +DataLoader::LastError() const +{ + return last_error; +} + +// +--------------------------------------------------------------------+ + void DataLoader::UseFileSystem(bool use) { @@ -100,22 +108,22 @@ DataLoader::InsertDatafile(const char* name, Group group, int pos) { FILE* f = fopen(name, "rb"); if (!f) { - Print(" WARNING: could not open datafile '%s'\n", name); - return DATAFILE_NOTEXIST; + last_error = Text::format("Could not open datafile '%s'", name); + return FAILED; } fclose(f); auto archive = new DataArchive(name); if (!archive || archive->NumFiles() < 1) { - Print(" WARNING: invalid data file '%s'\n", name); + last_error = Text::format("Invalid datafile '%s'", name); if (archive) delete archive; - return DATAFILE_INVALID; + return FAILED; } DataSource* source = new ArchiveDataSource(archive, group); if (pos < 0) sources.append(source); else sources.insert(source, pos); - return DATAFILE_OK; + return 0; } void @@ -133,7 +141,7 @@ DataLoader::ClearSources() int DataLoader::EnableDatafile(const char* name) { - int status = DATAFILE_NOTEXIST; + int status = FAILED; FILE* f; fopen_s(&f, name, "rb"); @@ -144,7 +152,7 @@ DataLoader::EnableDatafile(const char* name) DataArchive* a = new DataArchive(name); if (a && a->NumFiles() >= 1) { - status = DATAFILE_OK; + status = 0; bool found = false; ListIter<DataArchive> iter = archives; @@ -159,17 +167,16 @@ DataLoader::EnableDatafile(const char* name) archives.append(a); } else { - Print(" WARNING: invalid data file '%s'\n", name); - status = DATAFILE_INVALID; - + last_error = Text::format("Invalid datafile '%s'", name); + status = FAILED; delete a; } loader = this; } else { - Print(" WARNING: could not open datafile '%s'\n", name); - status = DATAFILE_NOTEXIST; + last_error = Text::format("Could not open datafile '%s'", name); + status = FAILED; } return status; @@ -183,11 +190,11 @@ DataLoader::DisableDatafile(const char* name) DataArchive* a = iter.value(); if (!strcmp(a->Name(), name)) { delete iter.removeItem(); - return DATAFILE_OK; + return 0; } } - return DATAFILE_NOTEXIST; + return FAILED; } // +--------------------------------------------------------------------+ |