Skip to content

Commit

Permalink
fix #5025:
Browse files Browse the repository at this point in the history
don't try to load non-existing archive in menu
  • Loading branch information
abma committed Jan 4, 2016
1 parent 2a7b9f5 commit 997e639
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions rts/Menu/SelectionWidget.cpp
Expand Up @@ -23,6 +23,17 @@ CONFIG(std::string, LastSelectedMod).defaultValue(SelectionWidget::NoModSelect).
CONFIG(std::string, LastSelectedMap).defaultValue(SelectionWidget::NoMapSelect).description("Stores the previously played map.");
CONFIG(std::string, LastSelectedScript).defaultValue(SelectionWidget::NoScriptSelect).description("Stores the previously played AI.");

// returns absolute filename for given archive name, empty if not found
static const std::string GetFileName(const std::string& name){
if (name.empty())
return name;
const std::string& filename = archiveScanner->ArchiveFromName(name);
if (filename == name)
return "";
const std::string& path = archiveScanner->GetArchivePath(filename);
return path + filename;
}

SelectionWidget::SelectionWidget(agui::GuiElement* parent) : agui::GuiElement(parent)
{
SetPos(0.5f, 0.2f);
Expand All @@ -36,15 +47,15 @@ SelectionWidget::SelectionWidget(agui::GuiElement* parent) : agui::GuiElement(pa
mod->Clicked.connect(boost::bind(&SelectionWidget::ShowModList, this));
mod->SetSize(0.1f, 0.00f, true);
userMod = configHandler->GetString("LastSelectedMod");
if (archiveScanner->GetSingleArchiveChecksum(archiveScanner->ArchiveFromName(userMod)) == 0)
if (GetFileName(userMod).empty())
userMod = NoModSelect;
modT = new agui::TextElement(userMod, modL);
agui::HorizontalLayout* mapL = new agui::HorizontalLayout(vl);
map = new agui::Button("Select", mapL);
map->Clicked.connect(boost::bind(&SelectionWidget::ShowMapList, this));
map->SetSize(0.1f, 0.00f, true);
userMap = configHandler->GetString("LastSelectedMap");
if (archiveScanner->GetSingleArchiveChecksum(archiveScanner->ArchiveFromName(userMap)) == 0)
if (GetFileName(userMap).empty())
userMap = NoMapSelect;
mapT = new agui::TextElement(userMap, mapL);
agui::HorizontalLayout* scriptL = new agui::HorizontalLayout(vl);
Expand Down Expand Up @@ -105,24 +116,18 @@ void SelectionWidget::ShowMapList()
}


static const std::string GetFileName(const std::string& name){
if (name.empty())
return name;
const std::string filename = archiveScanner->ArchiveFromName(name);
const std::string path = archiveScanner->GetArchivePath(filename);
return path + filename;
}

static void AddArchive(const std::string& name) {
if (!name.empty()) {
vfsHandler->AddArchive(GetFileName(name), true);
}
const std::string& filename = GetFileName(name);
if (filename.empty())
return;
vfsHandler->AddArchive(filename, true);
}

static void RemoveArchive(const std::string& name) {
if (!name.empty()) {
vfsHandler->RemoveArchive(GetFileName(name));
}
const std::string& filename = GetFileName(name);
if (filename.empty())
return;
vfsHandler->RemoveArchive(filename);
}

void SelectionWidget::UpdateAvailableScripts()
Expand Down

0 comments on commit 997e639

Please sign in to comment.