Skip to content

Commit

Permalink
quick launch anything
Browse files Browse the repository at this point in the history
  • Loading branch information
podulator committed Feb 19, 2020
1 parent 3ff0fa1 commit cbadf49
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 95 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**1.0.11** (*Codename: SpeedRun*)

* Added
* Quick launch the last game on 1st boot - only for games that needed a rom selector to launch (currently)
* Quick launch the last game on 1st boot
* Hold left on the dpad down to bypass
* Toggle on / off in Settings menu
* Fast cache load option
Expand Down
8 changes: 4 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string Config::toString() {
vec.push_back(StringUtils::stringFormat("externalAppPath=\"%s\"", this->externalAppPath().c_str()));
vec.push_back(StringUtils::stringFormat("cpuMenu=\"%s\"", this->cpuMenu().c_str()));
vec.push_back(StringUtils::stringFormat("defaultCpuSpeed=\"%s\"", this->defaultCpuSpeed().c_str()));
vec.push_back(StringUtils::stringFormat("selectedRom=\"%s\"", this->selectedRom().c_str()));
vec.push_back(StringUtils::stringFormat("quickStartPath=\"%s\"", this->quickStartPath().c_str()));

// ints
vec.push_back(StringUtils::stringFormat("buttonRepeatRate=%i", this->buttonRepeatRate()));
Expand Down Expand Up @@ -117,7 +117,7 @@ void Config::reset() {
this->sectionFilter_ = "";
this->cpuMenu_ = "";
this->defaultCpuSpeed_ = "";
this->selectedRom_ = "";
this->quickStartPath_ = "";

if (FileUtils::dirExists(EXTERNAL_LAUNCHER_PATH)) {
this->launcherPath(EXTERNAL_LAUNCHER_PATH);
Expand Down Expand Up @@ -245,8 +245,8 @@ bool Config::fromFile() {
this->cpuMenu(StringUtils::stripQuotes(value));
} else if (name == "defaultcpuspeed") {
this->defaultCpuSpeed(StringUtils::stripQuotes(value));
} else if (name == "selectedrom") {
this->selectedRom(StringUtils::stripQuotes(value));
} else if (name == "quickstartpath") {
this->quickStartPath(StringUtils::stripQuotes(value));
}

// ints
Expand Down
10 changes: 5 additions & 5 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ class Config {
this->isDirty = true;
}
}
std::string selectedRom() const { return this->selectedRom_; }
void selectedRom(std::string val) {
if (val != this->selectedRom_) {
this->selectedRom_ = val;
std::string quickStartPath() const { return this->quickStartPath_; }
void quickStartPath(std::string val) {
if (val != this->quickStartPath_) {
this->quickStartPath_ = val;
this->isDirty = true;
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ class Config {
std::string launcherPath_; // = "/media/sdcard/ROMS"
std::string cpuMenu_; // =600 || On demand
std::string defaultCpuSpeed_; // = 1000 || Performance
std::string selectedRom_; // = {int:section}:{int:link}:{int:rom}
std::string quickStartPath_; // = {int:section}:{int:link}:{string:rom}

int buttonRepeatRate_; // = 10
int resolutionX_; // = 320
Expand Down
77 changes: 32 additions & 45 deletions src/esoteric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,64 +596,51 @@ bool Esoteric::restoreState() {
// we can only get here if we're not on 1st run
if (FileUtils::dirExists(this->lastSelectorDir)) {
TRACE("recoverSession happening");
this->menu->selLinkApp()->selector(
std::string romFile = this->menu->selLinkApp()->selectRom(
this->lastSelectorElement,
this->lastSelectorDir,
true);
this->lastSelectorDir);

this->menu->selLinkApp()->runWithRom(romFile);
}
}
} else {

bool isFirstRun = Loader::isFirstRun();
bool quickStartGame = this->config->quickStartGame();
TRACE("is first run : %i", isFirstRun);
TRACE("quick start game : %i", quickStartGame);

std::string romPath = this->config->quickStartPath();
// we only care about quick starting a game on first boot
if (Loader::isFirstRun() && this->config->quickStartGame()) {
if (this->inputManager->isActive(LEFT)) {
this->inputManager->dropEvents();
TRACE("quickStartGame bypassed by button over ride");
return true;
} else if (Loader::isFirstRun() && this->config->quickStartGame() && !romPath.empty()) {

TRACE("first run and quickStartGame tests have passed");
std::string launchDir = this->config->launcherPath();
TRACE("launcherPath : '%s'", launchDir.c_str());
std::vector<std::string> launchParts;
std::string romPath = this->config->selectedRom();
TRACE("romPath : '%s'", romPath.c_str());
StringUtils::split(launchParts, romPath, ":", true);
if (3 != launchParts.size()) return true;

// minimum required for a quick launch
if (launchParts.size() < 2) return true;
int sectionId = atoi(launchParts[0].c_str());
int linkId = atoi(launchParts[1].c_str());
int selectorId = atoi(launchParts[2].c_str());

this->config->selectedRom("");

if (sectionId >= 0 && linkId >= 0 && selectorId >= 0 and FileUtils::dirExists(launchDir)) {
TRACE("potential quickStartGame scenario");
TRACE("restore section : %i", sectionId);
this->menu->setSectionIndex(sectionId);
TRACE("restore link : %i", linkId);
this->menu->setLinkIndex(linkId);

// don't do anything if we have the left dpad down
if (!this->inputManager->isActive(LEFT)) {

TRACE("a quickStartGame is happening");
TRACE("selectedRom : %i", selectorId);

this->menu->selLinkApp()->selector(
selectorId,
launchDir,
false);

this->quit();
quit_all(0);
return false;

} else {
this->inputManager->dropEvents();
TRACE("quickStartGame bypassed by button over ride");
}
} else {
TRACE("quickStartGame skipped for <= 0 index value or missing dir");

if (sectionId >= 0 && linkId >= 0) {
TRACE("restore section : %i", sectionId);
this->menu->setSectionIndex(sectionId);
TRACE("restore link : %i", linkId);
this->menu->setLinkIndex(linkId);
} else return true;

if (launchParts.size() >= 3) {
std::string romFile = launchParts[2];
this->config->quickStartPath("");
TRACE("a quickStartGame is happening");
TRACE("selectedRom : '%s'", romFile.c_str());
this->menu->selLinkApp()->runWithRom(romFile);
return false;
} else {
this->config->quickStartPath("");
this->menu->selLinkApp()->run();
return false;
}
} else if (this->config->saveSelection()) {
TRACE("save selection is set");
Expand Down
103 changes: 64 additions & 39 deletions src/linkapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "constants.h"
#include "stringutils.h"

static std::array<const char *, 4> tokens = { "%f", "%F", "%u", "%U", };
//static std::array<const char *, 4> tokens = { "%f", "%F", "%u", "%U", };
const std::string LinkApp::FAVOURITE_FOLDER = "favourites";

LinkApp::LinkApp(Esoteric *app, const char* linkfile, bool deletable_) :
Expand Down Expand Up @@ -393,19 +393,34 @@ void LinkApp::makeFavourite() {
void LinkApp::run() {
TRACE("enter");
if (!selectordir.empty()) {
selector();
std::string romFile = this->selectRom();
this->runWithRom(romFile);
} else {
std::string launchArgs = resolveArgs();
launch(launchArgs);
std::string launchArgs = this->resolveArgs();
this->launch(launchArgs);
}
TRACE("exit");
}

// takes a full path to a rom file
void LinkApp::runWithRom(const std::string &romFile) {

// turn this into a pub func and call it from quickstart eso
if (!FileUtils::fileExists(romFile)) {
TRACE("supporting rom file doesn't exist : '%s'", romFile.c_str());
return;
}
std::string launchArgs = this->resolveArgs(romFile);
this->launch(launchArgs);
}

/*
* lauches a supporting file selector if needed
*/
void LinkApp::selector(int startSelection, const std::string &selectorDir, const bool &choose) {
std::string LinkApp::selectRom(int startSelection, const std::string &selectorDir) {

TRACE("enter - startSelection = %i, selectorDir = %s", startSelection, selectorDir.c_str());
std::string result;

// Run selector interface - this is the order of dir specificity
// - directly requested in the call args
Expand All @@ -423,52 +438,48 @@ void LinkApp::selector(int startSelection, const std::string &selectorDir, const
}

Selector sel(app, this, myDir);
if (!choose) {
// we just want to get the file from dir and index
TRACE("resolving for quickStart: %i", selection);
sel.resolve(selection);
} else {
// we are doing a full resolve
selection = sel.exec(selection);
}
// we are doing a full resolve
selection = sel.exec(selection);

// we got a file
if (selection > -1) {
std::string launchArgs = this->resolveArgs(sel.getFile(), sel.getDir());
this->app->config->launcherPath(sel.getDir());
std::stringstream ss;
ss << this->app->menu->selSectionIndex() << ":" << this->app->menu->selLinkIndex() << ":" << selection;
std::string selectedRom = ss.str();
TRACE("storing launch combo : '%s'", selectedRom.c_str());
this->app->config->selectedRom(selectedRom);
this->app->writeTmp(selection, sel.getDir());
this->launch(launchArgs);
std::string romDir = sel.getDir();
std::string romFile = sel.getFile();
this->app->writeTmp(selection, romDir);
result = romDir + romFile;
} else {
TRACE("selector didn't get us a file");
}
TRACE("exit");
TRACE("exit : '%s'", result.c_str());
return result;
}

std::string LinkApp::resolveArgs(const std::string &selectedFile, const std::string &selectedDir) {
TRACE("enter file : '%s', dir : '%s'", selectedFile.c_str(), selectedDir.c_str());
std::string launchArgs = "";
std::string localFile = selectedFile;
std::string dir = selectedDir;

// selectedFile means a rom or some kind of data file..
if (!selectedFile.empty()) {
TRACE("we have a selected file to work with : %s", selectedFile.c_str());
if (!localFile.empty()) {
TRACE("we have a selected file to work with : %s", localFile.c_str());
// break out the dir, filename and extension
std::string selectedFileExtension;
std::string selectedFileName;
std::string dir;

selectedFileExtension = FileUtils::fileExtension(selectedFile);
selectedFileName = FileUtils::fileBaseName(selectedFile);

TRACE("name : %s, extension : %s", selectedFileName.c_str(), selectedFileExtension.c_str());
if (selectedDir.empty())
dir = getSelectorDir();
else
dir = selectedDir;

selectedFileExtension = FileUtils::fileExtension(localFile);
selectedFileName = FileUtils::fileBaseName(localFile);
TRACE("file - basename : '%s', extension : '%s'", selectedFileName.c_str(), selectedFileExtension.c_str());

if (dir.empty()) {
if (FileUtils::fileExists(selectedFile)) {
// it's alreaday fully qualified
dir = FileUtils::dirName(selectedFile);
localFile = FileUtils::pathBaseName(localFile);
} else {
dir = this->getSelectorDir();
}
}

// force a slash at the end
if (dir.length() > 0) {
Expand All @@ -478,28 +489,43 @@ std::string LinkApp::resolveArgs(const std::string &selectedFile, const std::str
TRACE("dir : %s", dir.c_str());

if (this->getParams().empty()) {
launchArgs = "\"" + dir + selectedFile + "\"";
launchArgs = "\"" + dir + localFile + "\"";
TRACE("no params, so cleaned to : %s", launchArgs.c_str());
} else {
TRACE("params need handling : %s", this->getParams().c_str());
launchArgs = StringUtils::strReplace(params, "[selFullPath]", StringUtils::cmdClean(dir + selectedFile));
launchArgs = StringUtils::strReplace(params, "[selFullPath]", StringUtils::cmdClean(dir + localFile));
launchArgs = StringUtils::strReplace(launchArgs, "[selPath]", StringUtils::cmdClean(dir));
launchArgs = StringUtils::strReplace(launchArgs, "[selFile]", StringUtils::cmdClean(selectedFileName));
launchArgs = StringUtils::strReplace(launchArgs, "[selExt]", StringUtils::cmdClean(selectedFileExtension));
// if this is true, then we've made no subs, so we still need to add the selected file
if (this->getParams() == launchArgs) {
launchArgs += " \"" + dir + selectedFile + "\"";
launchArgs += " \"" + dir + localFile + "\"";
}

}
// save the last dir
TRACE("setting the launcher path : %s", dir.c_str());
app->config->launcherPath(dir);

} else {
TRACE("no file selected");
TRACE("assigning params : '%s'", this->getParams().c_str());
launchArgs = this->getParams();
}

// save the quick start link
std::stringstream ss;
ss << this->app->menu->selSectionIndex() <<
":" <<
this->app->menu->selLinkIndex();

if (!localFile.empty()) {
ss << ":" << dir << localFile;
}
std::string quickStart = ss.str();
TRACE("storing launch combo : '%s'", quickStart.c_str());
this->app->config->quickStartPath(quickStart);

TRACE("exit : %s", launchArgs.c_str());
return launchArgs;
}
Expand Down Expand Up @@ -620,7 +646,6 @@ void LinkApp::setManual(const std::string &manual) {
const std::string &LinkApp::getSelectorDir() { return selectordir; }
void LinkApp::setSelectorDir(const std::string &selectordir) {
this->selectordir = selectordir;
// if (this->selectordir!="" && this->selectordir[this->selectordir.length()-1]!='/') this->selectordir += "/";
if (!this->selectordir.empty()) this->selectordir = FileUtils::resolvePath(this->selectordir);
edited = true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/linkapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ class LinkApp : public Link {

bool save();
void run();
std::string selectRom(int startSelection = -1, const std::string &selectorDir = "");
void runWithRom(const std::string &romFile);

void makeFavourite();
void makeFavourite(std::string dir, std::string file, std::string backdrop = "");

// void showManual();
void selector(int startSelection = 0, const std::string &selectorDir = "", const bool &choose = true);
bool targetExists();

const std::string &getFile() { return file; }
Expand Down

0 comments on commit cbadf49

Please sign in to comment.