Skip to content
Permalink
Browse files

Support drag and drop of games and BIOS files

  • Loading branch information...
Cydrak Cydrak
Cydrak authored and Cydrak committed Aug 3, 2013
1 parent bacf268 commit ed3c1e4324f3f210a55df86cb5ed0d82800f40e5
Showing with 70 additions and 16 deletions.
  1. +33 −3 ui/general/presentation.cpp
  2. +1 −1 ui/interface/interface.cpp
  3. +35 −11 ui/utility/utility.cpp
  4. +1 −1 ui/utility/utility.hpp
@@ -46,7 +46,9 @@ Presentation::Presentation() : active(nullptr) {
setBackgroundColor({0, 0, 0});
setMenuVisible();
setStatusVisible();

setDroppable();
viewport.setDroppable();

loadMenu.setText("Library");
loadImport.setText("Import Game ...");
settingsMenu.setText("Settings");
@@ -99,10 +101,38 @@ Presentation::Presentation() : active(nullptr) {
Application::quit();
}
};


onDrop = viewport.onDrop = [&](lstring paths) {
if(paths.size() == 1) {
// Single path - might be file or folder.
utility->loadMedia(paths[0]);
}
else {
// Don't try to import folders.
for(auto &path : paths)
if(directory::exists(path))
return;

unsigned numImported = 0;

for(auto &path : paths) {
if(auto container = utility->importMedia(path)) {
if(container != "<system>") numImported++;
}
else break;
}
if(numImported > 0)
utility->showMessage({"Imported ",numImported," titles."});
}
};

loadImport.onActivate = [&] {
string path = browser->select("Import game");
if(path) utility->importMedia(path);
if(path) {
auto e = program->emulator[0];
if(auto container = utility->importMedia(path))
utility->loadMedia(e, e->media[0], container);
}
};

shaderNone.onActivate = [&] { uiConfig->video.shader = "None"; utility->updateShader(); };
@@ -72,7 +72,7 @@ void Interface::videoRefresh(const uint32_t *data, unsigned pitch, unsigned widt
time(&current);
if(current != previous) {
previous = current;
utility->setStatusText({"FPS: ", frameCounter});
//utility->setStatusText({"FPS: ", frameCounter});
frameCounter = 0;
}
}
@@ -15,29 +15,47 @@ string Utility::libraryPath() {
return path;
}

void Utility::importMedia(string pathname) {
string Utility::importMedia(string pathname) {
string container;
print("Importing ",pathname,"\n");

if(file::exists(pathname) && file::size(pathname) <= 0x10000) {
// Check if it's one of the system ROMs
if(auto manifest = program->getUserResource("Nintendo DS.sys/manifest.bml")) {
auto elem = Markup::Document(vectorstream(manifest()).text());
auto contents = file::read(pathname);
auto hash = sha256(contents.data(), contents.size());
auto sysfolder = program->savePath("Nintendo DS.sys/");

if(hash == elem["system/memory/arm9/sha256"].text()) {
string dest = {sysfolder, elem["system/memory/arm9/data"].text()};
file::write(dest, contents);
return "<system>";
}
else if(hash == elem["system/memory/arm7/sha256"].text()) {
string dest = {sysfolder, elem["system/memory/arm7/data"].text()};
file::write(dest, contents);
return "<system>";
}
}
}

if(!NintendoDS::validateHeader(filestream(pathname, file::mode::read))) {
MessageWindow().setTitle("Import failed").setText(
{"Couldn't import ",pathname,".\n"
"\n"
"This file doesn't look like a Nintendo DS title.\n"
"If it is, the header might be damaged or ill-formed."})
"This file doesn't look like a Nintendo DS title.\n"})
.error();
return "";
}
else if(!NintendoDS::importROMImage(container, libraryPath(), pathname)) {
MessageWindow().setTitle("Import failed").setText(
{"Couldn't import ",pathname,".\n"
"\n"
"Check to see if you've got sufficient permissions and disk space."})
.error();
return "";
}
else {
auto e = program->emulator[0];
loadMedia(e, e->media[0], container);
}
return container;
}

//load from command-line, etc
@@ -46,9 +64,15 @@ void Utility::loadMedia(string pathname) {
if(pathname.endswith("/")) pathname.rtrim("/");

//if a filename was provided: convert to game folder and then load
if(!directory::exists(pathname) && file::exists(pathname))
return importMedia(pathname);

if(!directory::exists(pathname) && file::exists(pathname)) {
auto e = program->emulator[0];
if(auto container = importMedia(pathname)) {
utility->showMessage({"Imported ",pathname,"."});
if(container != "<system>")
loadMedia(e, e->media[0], container);
}
return;
}
if(!directory::exists(pathname)) return;
string type = extension(pathname);

@@ -3,7 +3,7 @@ struct Utility {

string libraryPath();

void importMedia(string pathname);
string importMedia(string pathname);

void loadMedia(string pathname);
void loadMedia(Emulator::Interface *emulator, Emulator::Interface::Media &media);

0 comments on commit ed3c1e4

Please sign in to comment.
You can’t perform that action at this time.