Skip to content

Commit

Permalink
Merge pull request #7244 from lioncash/error
Browse files Browse the repository at this point in the history
Qt/MenuBar: Make failures to load map and signature files more obvious
  • Loading branch information
spycrab committed Jul 12, 2018
2 parents 92f397d + 74899e4 commit 55b5a24
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
72 changes: 52 additions & 20 deletions Source/Core/DolphinQt/MenuBar.cpp
Expand Up @@ -1187,10 +1187,13 @@ void MenuBar::LoadSymbolMap()
} }
else else
{ {
g_symbolDB.LoadMap(existing_map_file); const QString existing_map_file_path = QString::fromStdString(existing_map_file);
QMessageBox::information(
this, tr("Information"), if (!TryLoadMapFile(existing_map_file_path))
tr("Loaded symbols from '%1'").arg(QString::fromStdString(existing_map_file))); return;

QMessageBox::information(this, tr("Information"),
tr("Loaded symbols from '%1'").arg(existing_map_file_path));
} }


HLE::PatchFunctions(); HLE::PatchFunctions();
Expand All @@ -1202,35 +1205,37 @@ void MenuBar::SaveSymbolMap()
std::string existing_map_file, writable_map_file; std::string existing_map_file, writable_map_file;
CBoot::FindMapFile(&existing_map_file, &writable_map_file); CBoot::FindMapFile(&existing_map_file, &writable_map_file);


g_symbolDB.SaveSymbolMap(writable_map_file); TrySaveSymbolMap(QString::fromStdString(writable_map_file));
} }


void MenuBar::LoadOtherSymbolMap() void MenuBar::LoadOtherSymbolMap()
{ {
QString file = QFileDialog::getOpenFileName(this, tr("Load map file"), const QString file = QFileDialog::getOpenFileName(
QString::fromStdString(File::GetUserPath(D_MAPS_IDX)), this, tr("Load map file"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)),
tr("Dolphin Map File (*.map)")); tr("Dolphin Map File (*.map)"));


if (file.isEmpty()) if (file.isEmpty())
return; return;


g_symbolDB.LoadMap(file.toStdString()); if (!TryLoadMapFile(file))
return;

HLE::PatchFunctions(); HLE::PatchFunctions();
emit NotifySymbolsUpdated(); emit NotifySymbolsUpdated();
} }


void MenuBar::SaveSymbolMapAs() void MenuBar::SaveSymbolMapAs()
{ {
const std::string& title_id_str = SConfig::GetInstance().m_debugger_game_id; const std::string& title_id_str = SConfig::GetInstance().m_debugger_game_id;
QString file = QFileDialog::getSaveFileName( const QString file = QFileDialog::getSaveFileName(
this, tr("Save map file"), this, tr("Save map file"),
QString::fromStdString(File::GetUserPath(D_MAPS_IDX) + "/" + title_id_str + ".map"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX) + "/" + title_id_str + ".map"),
tr("Dolphin Map File (*.map)")); tr("Dolphin Map File (*.map)"));


if (file.isEmpty()) if (file.isEmpty())
return; return;


g_symbolDB.SaveSymbolMap(file.toStdString()); TrySaveSymbolMap(file);
} }


void MenuBar::SaveCode() void MenuBar::SaveCode()
Expand All @@ -1241,28 +1246,55 @@ void MenuBar::SaveCode()
const std::string path = const std::string path =
writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map"; writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map";


g_symbolDB.SaveCodeMap(path); if (!g_symbolDB.SaveCodeMap(path))
{
QMessageBox::warning(
this, tr("Error"),
tr("Failed to save code map to path '%1'").arg(QString::fromStdString(path)));
}
} }


void MenuBar::CreateSignatureFile() bool MenuBar::TryLoadMapFile(const QString& path)
{ {
QString text = QInputDialog::getText( if (!g_symbolDB.LoadMap(path.toStdString()))
this, tr("Input"), tr("Only export symbols with prefix:\n(Blank for all symbols)")); {
QMessageBox::warning(this, tr("Error"), tr("Failed to load map file '%1'").arg(path));
return false;
}


if (text.isEmpty()) return true;
}

void MenuBar::TrySaveSymbolMap(const QString& path)
{
if (g_symbolDB.SaveSymbolMap(path.toStdString()))
return; return;


std::string prefix = text.toStdString(); QMessageBox::warning(this, tr("Error"), tr("Failed to save symbol map to path '%1'").arg(path));
}


QString file = QFileDialog::getSaveFileName(this, tr("Save signature file")); void MenuBar::CreateSignatureFile()
{
const QString text = QInputDialog::getText(
this, tr("Input"), tr("Only export symbols with prefix:\n(Blank for all symbols)"));
if (text.isEmpty())
return;


const QString file = QFileDialog::getSaveFileName(this, tr("Save signature file"));
if (file.isEmpty()) if (file.isEmpty())
return; return;


std::string save_path = file.toStdString(); const std::string prefix = text.toStdString();
const std::string save_path = file.toStdString();
SignatureDB db(save_path); SignatureDB db(save_path);
db.Populate(&g_symbolDB, prefix); db.Populate(&g_symbolDB, prefix);
db.Save(save_path);
if (!db.Save(save_path))
{
QMessageBox::warning(this, tr("Error"), tr("Failed to save signature file '%1'").arg(file));
return;
}

db.List(); db.List();
} }


Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/MenuBar.h
Expand Up @@ -150,6 +150,8 @@ class MenuBar final : public QMenuBar
void SaveSymbolMap(); void SaveSymbolMap();
void SaveSymbolMapAs(); void SaveSymbolMapAs();
void SaveCode(); void SaveCode();
bool TryLoadMapFile(const QString& path);
void TrySaveSymbolMap(const QString& path);
void CreateSignatureFile(); void CreateSignatureFile();
void PatchHLEFunctions(); void PatchHLEFunctions();
void ClearCache(); void ClearCache();
Expand Down

0 comments on commit 55b5a24

Please sign in to comment.