Tweak to error dialogs and add separate warning dialogs
(Also some error messages tweaked)
This commit is contained in:
@@ -54,7 +54,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
|
||||
// the three flags still follow that.
|
||||
FILE* file_id = fopen(file_to_load.string().c_str(), "rb");
|
||||
if(file_id == NULL) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
|
||||
n = fread(&flags, len, 1, file_id);
|
||||
if(n < 1) {
|
||||
fclose(file_id);
|
||||
giveError("This is not a Blades of Exile save file.");
|
||||
showError("This is not a Blades of Exile save file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
|
||||
case new_oboe:
|
||||
return load_party_v2(file_to_load, univ, town_restore, in_scen, maps_there);
|
||||
case unknown:
|
||||
giveError("This is not a Blades of Exile save file.");
|
||||
showError("This is not a Blades of Exile save file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
{ // Load main party data first
|
||||
std::istream& fin = partyIn.getFile("save/party.txt");
|
||||
if(!fin) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
univ.party.readFrom(fin);
|
||||
@@ -315,7 +315,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
{ // Then the "setup" array
|
||||
std::istream& fin = partyIn.getFile("save/setup.dat");
|
||||
if(!fin) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
uint16_t magic;
|
||||
@@ -334,7 +334,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
fname[7] = i + '1';
|
||||
std::istream& fin = partyIn.getFile(fname);
|
||||
if(!fin) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
univ.party[i].readFrom(fin);
|
||||
@@ -363,7 +363,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
// Load town data
|
||||
std::istream& fin = partyIn.getFile("save/town.txt");
|
||||
if(!fin) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
univ.town.readFrom(fin);
|
||||
@@ -382,7 +382,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
// Load outdoors data
|
||||
std::istream& fin = partyIn.getFile("save/out.txt");
|
||||
if(!fin) {
|
||||
giveError("Loading Blades of Exile save file failed.");
|
||||
showError("Loading Blades of Exile save file failed.");
|
||||
return false;
|
||||
}
|
||||
univ.out.readFrom(fin);
|
||||
@@ -406,7 +406,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
|
||||
spec_scen_g.party_sheet.reset(new sf::Texture);
|
||||
spec_scen_g.party_sheet->create(party_sheet.getSize().x, party_sheet.getSize().y);
|
||||
spec_scen_g.party_sheet->update(party_sheet);
|
||||
} else giveError("There was an error loading the party custom graphics.");
|
||||
} else showWarning("There was an error loading the party custom graphics.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -77,10 +77,10 @@ bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header)
|
||||
else if(fname.substr(dot) == ".exs")
|
||||
return load_scenario_v1(file_to_load, scenario, only_header);
|
||||
} catch(std::exception& x) {
|
||||
giveError("There was an error loading the scenario. The details of the error are given below; you may be able to decompress the scenario package, fix the error, and repack it.", x.what());
|
||||
showError("There was an error loading the scenario. The details of the error are given below; you may be able to decompress the scenario package, fix the error, and repack it.", x.what());
|
||||
return false;
|
||||
}
|
||||
giveError("That is not a Blades of Exile scenario.");
|
||||
showError("That is not a Blades of Exile scenario.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
// TODO: Convert this (and all the others in this file) to use C++ streams
|
||||
FILE* file_id = fopen(file_to_load.string().c_str(),"rb");
|
||||
if(file_id == NULL) {
|
||||
giveError(err_prefix + "Could not open file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not open file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
|
||||
if(fread(&scenario.format, len, 1, file_id) < 1){
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Failed to read scenario header.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Failed to read scenario header.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
}
|
||||
if(!file_ok) {
|
||||
fclose(file_id);
|
||||
giveError("This is not a legitimate Blades of Exile scenario.");
|
||||
showError("This is not a legitimate Blades of Exile scenario.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
n = fread(temp_scenario, len, 1, file_id);
|
||||
if(n < 1){
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Failed to read scenario data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Failed to read scenario data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
port_scenario(temp_scenario);
|
||||
@@ -158,7 +158,7 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
n = fread(item_data, len, 1, file_id);
|
||||
if(n < 1){
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Failed to read scenario items.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Failed to read scenario items.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
port_item_list(item_data);
|
||||
@@ -629,7 +629,7 @@ static void initialXmlRead(ticpp::Document& data, std::string root_tag, int& maj
|
||||
if(name == "boes") {
|
||||
std::tie(maj, min, rev) = parse_version(val);
|
||||
if(maj < 2) {
|
||||
giveError("This scenario specifies an invalid format version. Loading will be attempted as if it were version 2.0.0, but there is a possibility that there could be errors.");
|
||||
showError("This scenario specifies an invalid format version. Loading will be attempted as if it were version 2.0.0, but there is a possibility that there could be errors.");
|
||||
maj = 2;
|
||||
min = rev = 0;
|
||||
}
|
||||
@@ -1970,7 +1970,7 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
tarball pack;
|
||||
std::ifstream fin;
|
||||
if(!fs::exists(file_to_load)) {
|
||||
giveError("The scenario could not be found.");
|
||||
showError("The scenario could not be found.");
|
||||
return false;
|
||||
}
|
||||
if(fs::is_directory(file_to_load)) { // Unpacked
|
||||
@@ -1979,7 +1979,7 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head
|
||||
igzstream gzin(file_to_load.string().c_str());
|
||||
pack.readFrom(gzin);
|
||||
if(gzin.bad()) {
|
||||
giveError("There was an error loading the scenario.");
|
||||
showError("There was an error loading the scenario.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2155,7 +2155,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
|
||||
|
||||
FILE* file_id = fopen(scen_file.string().c_str(), "rb");
|
||||
if(file_id == NULL) {
|
||||
giveError(err_prefix + "Could not open file for reading town data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not open file for reading town data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2163,7 +2163,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
|
||||
n = fseek(file_id, len_to_jump, SEEK_SET);
|
||||
if(n != 0) {
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Failure seeking to town record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Failure seeking to town record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2171,7 +2171,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
|
||||
n = fread(&store_town, len, 1, file_id);
|
||||
if(n < 1) {
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Could not read town record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not read town record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
port_town(&store_town);
|
||||
@@ -2224,7 +2224,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
|
||||
n = fread(&store_talk, len, 1, file_id);
|
||||
if(n < 1) {
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Could not read dialogue record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not read dialogue record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
port_talk_nodes(&store_talk);
|
||||
@@ -2259,7 +2259,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
|
||||
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
giveError(err_prefix + "An error occurred while closing the file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "An error occurred while closing the file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -2293,7 +2293,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out,
|
||||
|
||||
FILE* file_id = fopen(scen_file.string().c_str(), "rb");
|
||||
if(file_id == NULL) {
|
||||
giveError(err_prefix + "Could not open file for reading outdoor data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not open file for reading outdoor data.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2301,7 +2301,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out,
|
||||
n = fseek(file_id, len_to_jump, SEEK_SET);
|
||||
if(n != 0) {
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Failure seeking to outdoor record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Failure seeking to outdoor record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2309,7 +2309,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out,
|
||||
n = fread(&store_out, len, 1, file_id);
|
||||
if(n < 1) {
|
||||
fclose(file_id);
|
||||
giveError(err_prefix + "Could not read outdoor record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Could not read outdoor record.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2335,7 +2335,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out,
|
||||
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
giveError(err_prefix + "Something went wrong when closing the file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
showError(err_prefix + "Something went wrong when closing the file.", boost::lexical_cast<std::string>(std_fmterr));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2367,7 +2367,7 @@ void load_spec_graphics_v1(fs::path scen_file) {
|
||||
if(fs::exists(gpath)) {
|
||||
if(graphics_store.loadFromFile(gpath.string()))
|
||||
foundGraphics = true;
|
||||
else giveError("An old-style .bmp graphics file was found, but there was an error reading from the file.",noGraphics);
|
||||
else showWarning("An old-style .bmp graphics file was found, but there was an error reading from the file.",noGraphics);
|
||||
}
|
||||
}
|
||||
if(foundGraphics) {
|
||||
@@ -2378,7 +2378,7 @@ void load_spec_graphics_v1(fs::path scen_file) {
|
||||
spec_scen_g.sheets = new sf::Texture[1];
|
||||
spec_scen_g.numSheets = 1;
|
||||
if(!spec_scen_g.sheets[0].loadFromImage(graphics_store)) {
|
||||
giveError("An error occurred while converting old-style graphics into the new format.",noGraphics);
|
||||
showWarning("An error occurred while converting old-style graphics into the new format.",noGraphics);
|
||||
spec_scen_g.is_old = false;
|
||||
spec_scen_g.numSheets = 0;
|
||||
delete[] spec_scen_g.sheets;
|
||||
|
@@ -45,7 +45,7 @@ template<typename T> class ptr_guard {
|
||||
void boundcheck() {
|
||||
if(the_ptr > guard) {
|
||||
std::string overflow = std::to_string(the_ptr - guard);
|
||||
giveError(err_prefix + "read pointer reached end of buffer", overflow);
|
||||
showError(err_prefix + "read pointer reached end of buffer", overflow);
|
||||
throw std::runtime_error(overflow);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
T& operator[](size_t i) {
|
||||
if(the_ptr + i > guard) {
|
||||
std::string overflow = std::to_string(i - (guard - the_ptr));
|
||||
giveError(err_prefix + "attempt to index beyond buffer", overflow);
|
||||
showError(err_prefix + "attempt to index beyond buffer", overflow);
|
||||
throw std::runtime_error(overflow);
|
||||
}
|
||||
return the_ptr[i];
|
||||
@@ -86,7 +86,7 @@ static void loadColourTable(ptr_guard<char>& picData, sf::Color(& clut)[256], in
|
||||
while(numColours >= 0) {
|
||||
int i = extract_word(picData);
|
||||
if(i > 256) {
|
||||
giveError(err_prefix + " Found too many colours in 'clut'", std::to_string(i));
|
||||
showError(err_prefix + " Found too many colours in 'clut'", std::to_string(i));
|
||||
throw std::runtime_error(std::to_string(i));
|
||||
}
|
||||
picData += 2;
|
||||
@@ -164,7 +164,7 @@ static legacy::Rect loadPixMapData(ptr_guard<char>& picData, ptr_guard<unsigned
|
||||
picData += 4 + 4; // Skip hRes and vRes
|
||||
picData += 2 + 2; // Skip pixelType and pixelSize
|
||||
if(picData[-1] != 8) {
|
||||
giveError(err_prefix + "Unsupported pixel type found.");
|
||||
showError(err_prefix + "Unsupported pixel type found.");
|
||||
throw std::runtime_error("pixelType");
|
||||
}
|
||||
picData += 2 + 2; // Skip cmpCount and cmpSize
|
||||
@@ -172,7 +172,7 @@ static legacy::Rect loadPixMapData(ptr_guard<char>& picData, ptr_guard<unsigned
|
||||
picData += 4 + 2; // Skip ctSeed and ctFlags
|
||||
int numColours = extract_word(picData);
|
||||
if(numColours >= 256) {
|
||||
giveError(err_prefix + "More than 256 colours found.");
|
||||
showError(err_prefix + "More than 256 colours found.");
|
||||
throw std::runtime_error(std::to_string(numColours));
|
||||
}
|
||||
picData += 2;
|
||||
@@ -206,12 +206,12 @@ static rectangle loadFromPictResource(Handle resHandle, unsigned char*& pixelSto
|
||||
picFrame.bottom = extract_word(picData); picData += 2;
|
||||
picFrame.right = extract_word(picData); picData += 2;
|
||||
if(strncmp(picData, "\0\x11\x02\xff", 4) != 0) { // QuickDraw version code (version 2)
|
||||
giveError("Missing QuickDraw 2 version code");
|
||||
showError("Missing QuickDraw 2 version code");
|
||||
throw std::runtime_error("QD2 version");
|
||||
}
|
||||
picData += 4; // Skip version field
|
||||
if(strncmp(picData, "\x0c\0", 2) != 0) { // Header opcode
|
||||
giveError("Missing QuickDraw 2 header opcode");
|
||||
showError("Missing QuickDraw 2 header opcode");
|
||||
throw std::runtime_error("QD2 header");
|
||||
}
|
||||
picData += 2 + 24; // Skip header opcode and payload
|
||||
@@ -466,25 +466,25 @@ bool tryLoadPictFromResourceFile(fs::path& gpath, sf::Image& graphics_store) {
|
||||
err = FSGetResourceForkName(&rsrc);
|
||||
err = FSOpenResourceFile(&file, rsrc.length, rsrc.unicode, fsRdPerm, &custRef);
|
||||
if(err != noErr) {
|
||||
giveError("An old-style .meg graphics file was found, but neither data nor resource fork could be read.",noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but neither data nor resource fork could be read.",noGraphics);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int nPicts = Count1Resources('PICT');
|
||||
if(nPicts < 1) {
|
||||
CloseResFile(custRef);
|
||||
giveError("An old-style .meg graphics file was found, but it did not contain any PICT resources.",noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but it did not contain any PICT resources.",noGraphics);
|
||||
return false;
|
||||
}
|
||||
Handle resHandle = Get1Resource('PICT', 1);
|
||||
if(ResError() == resNotFound) {
|
||||
CloseResFile(custRef);
|
||||
giveError("An old-style .meg graphics file was found, but it did not contain a PICT resource of ID 1.",noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but it did not contain a PICT resource of ID 1.",noGraphics);
|
||||
return false;
|
||||
}
|
||||
if(resHandle == NULL) {
|
||||
CloseResFile(custRef);
|
||||
giveError("An old-style .meg graphics file was found, but an error occurred while fetching the PICT resource of ID 1.",noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but an error occurred while fetching the PICT resource of ID 1.",noGraphics);
|
||||
return false;
|
||||
}
|
||||
unsigned char* data = NULL;
|
||||
@@ -495,13 +495,13 @@ bool tryLoadPictFromResourceFile(fs::path& gpath, sf::Image& graphics_store) {
|
||||
} catch(std::runtime_error&) {
|
||||
CloseResFile(custRef);
|
||||
if(data != NULL) delete[] data;
|
||||
giveError("An old-style .meg graphics file was found, but an error occurred while loading the PICT resource of ID 1.",noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but an error occurred while loading the PICT resource of ID 1.",noGraphics);
|
||||
return false;
|
||||
}
|
||||
CloseResFile(custRef);
|
||||
if(picFrame.width() <= 0 || picFrame.height() <= 0) {
|
||||
if(data != NULL) delete[] data;
|
||||
giveError("An old-style .meg graphics file was found, but an error occurred while reading it: " + errStrings[error],noGraphics);
|
||||
showError("An old-style .meg graphics file was found, but an error occurred while reading it: " + errStrings[error],noGraphics);
|
||||
return false;
|
||||
}
|
||||
graphics_store.create(picFrame.width(), picFrame.height(), data);
|
||||
|
Reference in New Issue
Block a user