bsnes/icarus/ui/scan-dialog.cpp
Tim Allen 6adfe71836 Update to icarus 20151117.
byuu says:

This release adds a settings dialog that lets you control the library
path, optionally generate manifest.bml files, and optionally bypass the
internal games database (so far this is only the US SNES set.)

Also, the settings.bml file can exist in the same folder as the binary
now (portable mode). Plus it can share the same config file as
higan/tomoko itself does. This will allow you to change the library
location in either program and have it affect the other program as well.
It's a bit hackish, but it works >_>

Note: don't use this with higan v095.06 or earlier, or bad things will
happen.
2015-11-19 20:27:56 +11:00

124 lines
3.5 KiB
C++

ScanDialog::ScanDialog() {
scanDialog = this;
onClose(&Application::quit);
layout.setMargin(5);
pathEdit.onActivate([&] { refresh(); });
refreshButton.setImage(Icon::Action::Refresh).setBordered(false).onActivate([&] {
pathEdit.setText(settings["icarus/Path"].text());
refresh();
});
homeButton.setImage(Icon::Go::Home).setBordered(false).onActivate([&] {
pathEdit.setText(userpath());
refresh();
});
upButton.setImage(Icon::Go::Up).setBordered(false).onActivate([&] {
pathEdit.setText(dirname(settings["icarus/Path"].text()));
refresh();
});
scanList.onActivate([&] { activate(); });
selectAllButton.setText("Select All").onActivate([&] {
for(auto& item : scanList.items()) {
if(item.cell(0).checkable()) item.cell(0).setChecked(true);
}
});
unselectAllButton.setText("Unselect All").onActivate([&] {
for(auto& item : scanList.items()) {
if(item.cell(0).checkable()) item.cell(0).setChecked(false);
}
});
settingsButton.setText("Settings ...").onActivate([&] {
settingsDialog->setCentered(*this);
settingsDialog->setVisible();
settingsDialog->setFocused();
});
importButton.setText("Import ...").onActivate([&] { import(); });
setTitle("icarus");
setSize({800, 480});
setCentered();
}
auto ScanDialog::show() -> void {
setVisible();
pathEdit.setText(settings["icarus/Path"].text());
refresh();
}
auto ScanDialog::refresh() -> void {
scanList.reset();
scanList.append(ListViewHeader().setVisible(false).append(ListViewColumn().setExpandable()));
auto pathname = pathEdit.text().transform("\\", "/").rtrim("/").append("/");
if(!directory::exists(pathname)) return;
settings["icarus/Path"].setValue(pathname);
pathEdit.setText(pathname);
auto contents = directory::icontents(pathname);
for(auto& name : contents) {
if(!name.endsWith("/")) continue;
if(gamePakType(suffixname(name))) continue;
scanList.append(ListViewItem().append(ListViewCell().setImage(Icon::Emblem::Folder).setText(name.rtrim("/"))));
}
for(auto& name : contents) {
if(name.endsWith("/")) continue;
if(!gameRomType(suffixname(name).downcase())) continue;
scanList.append(ListViewItem().append(ListViewCell().setCheckable().setImage(Icon::Emblem::File).setText(name)));
}
Application::processEvents();
scanList.resizeColumns();
scanList.setFocused();
}
auto ScanDialog::activate() -> void {
if(auto item = scanList.selected()) {
string location{settings["icarus/Path"].text(), item.cell(0).text()};
if(directory::exists(location) && !gamePakType(suffixname(location))) {
pathEdit.setText(location);
refresh();
}
}
}
auto ScanDialog::import() -> void {
lstring filenames;
for(auto& item : scanList.items()) {
if(item.cell(0).checked()) {
filenames.append(string{settings["icarus/Path"].text(), item.cell(0).text()});
}
}
if(!filenames) {
MessageDialog().setParent(*this).setText("Nothing selected to import.").error();
return;
}
setVisible(false);
importDialog->run(filenames);
}
auto ScanDialog::gamePakType(const string& type) -> bool {
return type == ".sys"
|| type == ".fc"
|| type == ".sfc"
|| type == ".gb"
|| type == ".gbc"
|| type == ".gba"
|| type == ".bs"
|| type == ".st";
}
auto ScanDialog::gameRomType(const string& type) -> bool {
return type == ".zip"
|| type == ".fc" || type == ".nes"
|| type == ".sfc" || type == ".smc"
|| type == ".gb"
|| type == ".gbc"
|| type == ".gba"
|| type == ".bs"
|| type == ".st";
}