Skip to content

Commit

Permalink
mia, desktop-ui: Emit error if database files not found (#1769)
Browse files Browse the repository at this point in the history
For each emulator core with a `.bml` file in the Database folder
packaged with ares, this PR adds a separate check in their mia `load`
functions to verify that their database file exists on disk. If it does
not, we bail out of the loading process.

Meanwhile, in desktop-ui, if loading failed, we will now throw up an
error.

This PR stops short of adding fully robust error handling to the load
routines; the error message we throw up is generalized, and will appear
for anything that causes loading to fail, not just specifically database
files not being found. I think that the database files should be by far
the most common cause of load failure, so this seems OK to me for now,
but could certainly be improved in the future to provide more specific
errors. I obviously welcome feedback on how to handle any aspect of this
better.
  • Loading branch information
jcm93 authored Jan 16, 2025
1 parent 2197df8 commit c76b87c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 9 deletions.
6 changes: 5 additions & 1 deletion desktop-ui/emulator/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ auto Emulator::region() -> string {
auto Emulator::load(const string& location) -> bool {
if(inode::exists(location)) locationQueue.append(location);

if(!load()) return false;
if(!load()) {
error("Failed to load system! Database files may have been incorrectly \n"
"installed. Make sure you have packaged or installed ares correctly.");
return false;
}
setBoolean("Color Emulation", settings.video.colorEmulation);
setBoolean("Deep Black Boost", settings.video.deepBlackBoost);
setBoolean("Interframe Blending", settings.video.interframeBlending);
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/arcade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ struct Arcade : Mame {
};

auto Arcade::load(string location) -> bool {
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
manifest = manifestDatabaseArcade(Medium::name(location));
if(!manifest) return false;

Expand Down
2 changes: 2 additions & 0 deletions mia/medium/bs-memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ auto BSMemory::load(string location) -> bool {

this->sha256 = Hash::SHA256(rom).digest();
this->location = location;
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
this->manifest = Medium::manifestDatabase(sha256);
if(!manifest) manifest = analyze(rom);
auto document = BML::unserialize(manifest);
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/famicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ auto Famicom::analyze(vector<u8>& data) -> string {
}

string digest = Hash::SHA256(data).digest();
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return {};
string manifest = Medium::manifestDatabase(digest);
if(manifest) return manifest;

Expand Down
17 changes: 10 additions & 7 deletions mia/medium/medium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ auto Medium::create(string name) -> shared_pointer<Pak> {
return {};
}

auto Medium::loadDatabase() -> void {
auto Medium::loadDatabase() -> bool {
//load the database on the first time it's needed for a given media type
bool found = false;
for(auto& database : Media::databases) {
if(database.name == name()) found = true;
if(database.name == name()) return true;
}

if(!found) {
Database database;
database.name = name();
database.list = BML::unserialize(file::read(locate({"Database/", name(), ".bml"})));
Database database;
database.name = name();
auto databaseFile = locate({"Database/", name(), ".bml"});
if(inode::exists(databaseFile)) {
database.list = BML::unserialize(file::read(databaseFile));
Media::databases.append(std::move(database));
return true;
}

return false;
}

//Retrieve all entries in game database
Expand Down
2 changes: 1 addition & 1 deletion mia/medium/medium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Database {

struct Medium : Pak {
static auto create(string name) -> shared_pointer<Pak>;
auto loadDatabase() -> void;
auto loadDatabase() -> bool;
auto database() -> Database;
auto manifestDatabase(string sha256) -> string;
auto manifestDatabaseArcade(string name) -> string;
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/msx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auto MSX::load(string location) -> bool {

this->sha256 = Hash::SHA256(rom).digest();
this->location = location;
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
this->manifest = Medium::manifestDatabase(sha256);
if(!manifest) manifest = analyze(rom);
auto document = BML::unserialize(manifest);
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/neo-geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ auto NeoGeo::load(string location) -> bool {
vector<u8> voiceAROM; //V ROM (ADPCM-A voice samples)
vector<u8> voiceBROM; //V ROM (ADPCM-B voice samples)

auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
this->info = BML::unserialize(manifestDatabaseArcade(Medium::name(location)));

if(file::exists(location)) {
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/sufami-turbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ auto SufamiTurbo::load(string location) -> bool {

this->sha256 = Hash::SHA256(rom).digest();
this->location = location;
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
this->manifest = Medium::manifestDatabase(sha256);
if(!manifest) manifest = analyze(rom);
auto document = BML::unserialize(manifest);
Expand Down
2 changes: 2 additions & 0 deletions mia/medium/super-famicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ auto SuperFamicom::load(string location) -> bool {

this->sha256 = Hash::SHA256(rom).digest();
this->location = location;
auto foundDatabase = Medium::loadDatabase();
if(!foundDatabase) return false;
this->manifest = Medium::manifestDatabase(sha256);

if(!manifest) {
Expand Down

0 comments on commit c76b87c

Please sign in to comment.