2015-08-21 11:29:53 +00:00
|
|
|
ScanDialog::ScanDialog() {
|
|
|
|
scanDialog = this;
|
|
|
|
|
|
|
|
onClose(&Application::quit);
|
|
|
|
layout.setMargin(5);
|
|
|
|
pathEdit.onActivate([&] { refresh(); });
|
2015-09-28 11:56:46 +00:00
|
|
|
refreshButton.setImage(Icon::Action::Refresh).setBordered(false).onActivate([&] {
|
2015-08-21 11:29:53 +00:00
|
|
|
pathEdit.setText(settings.activePath);
|
|
|
|
refresh();
|
|
|
|
});
|
2015-09-28 11:56:46 +00:00
|
|
|
homeButton.setImage(Icon::Go::Home).setBordered(false).onActivate([&] {
|
2015-08-21 11:29:53 +00:00
|
|
|
pathEdit.setText(userpath());
|
|
|
|
refresh();
|
|
|
|
});
|
2015-09-28 11:56:46 +00:00
|
|
|
upButton.setImage(Icon::Go::Up).setBordered(false).onActivate([&] {
|
|
|
|
pathEdit.setText(dirname(settings.activePath));
|
2015-08-21 11:29:53 +00:00
|
|
|
refresh();
|
|
|
|
});
|
|
|
|
scanList.onActivate([&] { activate(); });
|
|
|
|
selectAllButton.setText("Select All").onActivate([&] {
|
|
|
|
for(auto& item : scanList.items()) item.cell(0).setChecked(true);
|
|
|
|
});
|
|
|
|
unselectAllButton.setText("Unselect All").onActivate([&] {
|
|
|
|
for(auto& item : scanList.items()) item.cell(0).setChecked(false);
|
|
|
|
});
|
|
|
|
createManifestsLabel.setChecked(settings.createManifests).setText("Create Manifests").onToggle([&] {
|
|
|
|
settings.createManifests = createManifestsLabel.checked();
|
|
|
|
});
|
|
|
|
importButton.setText("Import ...").onActivate([&] { import(); });
|
|
|
|
|
|
|
|
setTitle("icarus");
|
|
|
|
setSize({800, 480});
|
|
|
|
setCentered();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ScanDialog::show() -> void {
|
|
|
|
setVisible();
|
|
|
|
pathEdit.setText(settings.activePath);
|
|
|
|
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;
|
|
|
|
|
|
|
|
pathEdit.setText(settings.activePath = pathname);
|
|
|
|
auto contents = directory::icontents(pathname);
|
|
|
|
|
|
|
|
for(auto& name : contents) {
|
|
|
|
if(!name.endsWith("/")) continue;
|
2015-09-28 11:56:46 +00:00
|
|
|
if(gamePakType(suffixname(name))) continue;
|
|
|
|
scanList.append(ListViewItem().append(ListViewCell().setImage(Icon::Emblem::Folder).setText(name.rtrim("/"))));
|
2015-08-21 11:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(auto& name : contents) {
|
|
|
|
if(name.endsWith("/")) continue;
|
2015-09-28 11:56:46 +00:00
|
|
|
if(!gameRomType(suffixname(name).downcase())) continue;
|
|
|
|
scanList.append(ListViewItem().append(ListViewCell().setCheckable().setImage(Icon::Emblem::File).setText(name)));
|
2015-08-21 11:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::processEvents();
|
|
|
|
scanList.resizeColumns();
|
|
|
|
scanList.setFocused();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ScanDialog::activate() -> void {
|
|
|
|
if(auto item = scanList.selected()) {
|
|
|
|
string location{settings.activePath, item.cell(0).text()};
|
2015-09-28 11:56:46 +00:00
|
|
|
if(directory::exists(location) && !gamePakType(suffixname(location))) {
|
2015-08-21 11:29:53 +00:00
|
|
|
pathEdit.setText(location);
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ScanDialog::import() -> void {
|
|
|
|
lstring filenames;
|
|
|
|
for(auto& item : scanList.items()) {
|
|
|
|
if(item.cell(0).checked()) {
|
|
|
|
filenames.append(string{settings.activePath, 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";
|
|
|
|
}
|