summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--StarsEx/DataLoader.cpp35
-rw-r--r--StarsEx/DataLoader.h7
-rw-r--r--StarsEx/Starshatter.cpp22
-rw-r--r--Starserver/StarServer.cpp9
4 files changed, 31 insertions, 42 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;
}
// +--------------------------------------------------------------------+
diff --git a/StarsEx/DataLoader.h b/StarsEx/DataLoader.h
index 92cdd11..6d83e2f 100644
--- a/StarsEx/DataLoader.h
+++ b/StarsEx/DataLoader.h
@@ -29,10 +29,9 @@ class DataLoader
public:
using Group = DataSource::Group;
+ static constexpr int FAILED {-1};
static const char* TYPENAME() { return "DataLoader"; }
- enum { DATAFILE_OK, DATAFILE_INVALID, DATAFILE_NOTEXIST };
-
DataLoader();
virtual ~DataLoader();
@@ -40,6 +39,8 @@ public:
static void Initialize();
static void Close();
+ const char* LastError() const;
+
void Reset();
void UseFileSystem(bool use=true);
void UseVideo(Video* v);
@@ -83,6 +84,8 @@ private:
Video* video;
bool enable_media;
+ Text last_error;
+
List<DataArchive> archives;
List<DataSource> sources;
DataSource* work_directory_source;
diff --git a/StarsEx/Starshatter.cpp b/StarsEx/Starshatter.cpp
index 62b728f..dc60533 100644
--- a/StarsEx/Starshatter.cpp
+++ b/StarsEx/Starshatter.cpp
@@ -171,14 +171,9 @@ chat_mode(0), exit_time(1.2), cutscene(0)
loader = DataLoader::GetLoader();
int loadstat = loader->EnableDatafile("shatter.dat");
- if (loadstat != DataLoader::DATAFILE_OK) {
- const char* err_msg = loadstat == DataLoader::DATAFILE_INVALID ?
- "The file 'shatter.dat' appears to have been damaged. Please re-install Starshatter." :
- "Starshatter cannot open the file 'shatter.dat'. Please re-install Starshatter.";
-
- ::MessageBox(hwnd, err_msg, "Starshatter - Error", MB_OK);
- ::Print(err_msg);
- ::Print("\n\nFATAL ERROR: EXIT.");
+ if (loadstat == DataLoader::FAILED) {
+ ::MessageBox(hwnd, loader->LastError(), "Starshatter - Error", MB_OK);
+ ::Print("FATAL ERROR: %s\n", loader->LastError());
exit(-1);
}
@@ -191,17 +186,6 @@ chat_mode(0), exit_time(1.2), cutscene(0)
if (loader->FindFile("content.dat"))
loader->EnableDatafile("content.dat");
- //if (loadstat != DataLoader::DATAFILE_OK) {
- // const char* err_msg = loadstat == DataLoader::DATAFILE_INVALID ?
- // "The file 'content.dat' appears to have been damaged. Please re-install the latest Starshatter update." :
- // "Starshatter cannot open the file 'content.dat'. Please re-install the latest Starshatter update.";
-
- // ::MessageBox(hwnd, err_msg, "Starshatter - Error", MB_OK);
- // ::Print(err_msg);
- // ::Print("\n\nFATAL ERROR: EXIT.");
- // exit(-1);
- //}
-
LoadVideoConfig("video.cfg");
// create the fonts
diff --git a/Starserver/StarServer.cpp b/Starserver/StarServer.cpp
index 12a3d90..ce83f81 100644
--- a/Starserver/StarServer.cpp
+++ b/Starserver/StarServer.cpp
@@ -64,13 +64,8 @@ StarServer::StarServer() :
if (!loader) throw "Could not get DataLoader instance";
int loadstat = loader->EnableDatafile("shatter.dat");
- if (loadstat != DataLoader::DATAFILE_OK) {
- if (loadstat == DataLoader::DATAFILE_INVALID) {
- throw "The file 'shatter.dat' appears to have been damaged.";
- }
- else {
- throw "Starshatter cannot open the file 'shatter.dat'. Please check current directory.";
- }
+ if (loadstat == DataLoader::FAILED) {
+ throw loader->LastError();
}
if (loader->FindFile("start.dat"))