Program Execution Argument Extraction (#5807)

* Add function to be able to feed specific path into to process programmatically, and setup drag and drop functionality.

* Encapsulate dropped file functionality from Switch and Wii U.

* Fix dropped file detection, and fix ShowYesNowBox return checking.
This commit is contained in:
Malkierian
2025-10-09 16:51:04 -07:00
committed by GitHub
parent 57c368aa2c
commit 52a8f6c281
6 changed files with 60 additions and 7 deletions

View File

@@ -453,6 +453,34 @@ bool Extractor::ManuallySearchForRomMatchingType(RomSearchMode searchMode) {
return true;
}
bool Extractor::RunFileStandalone(std::string rom) {
if (std::filesystem::is_directory(rom)) {
return false;
}
auto file = std::filesystem::path(rom);
if ((file.extension() != ".n64") && (file.extension() != ".z64") && (file.extension() != ".v64")) {
return false;
}
SetRomInfo(rom);
if (!ValidateRomSize()) {
return false;
}
std::ifstream inFile;
inFile.open(rom, std::ios::in | std::ios::binary);
inFile.read((char*)mRomData.get(), mCurRomSize);
inFile.clear();
inFile.close();
BitConverter::RomToBigEndian(mRomData.get(), mCurRomSize);
if (!ValidateRom(true)) {
return false;
}
return true;
}
bool Extractor::Run(std::string searchPath, RomSearchMode searchMode) {
std::vector<std::string> roms;
std::ifstream inFile;

View File

@@ -59,6 +59,7 @@ class Extractor {
static void ShowErrorBox(const char* title, const char* text);
bool IsMasterQuest() const;
bool RunFileStandalone(std::string file);
bool Run(std::string searchPath, RomSearchMode searchMode = RomSearchMode::Both);
bool CallZapd(std::string installPath, std::string exportdir);
const char* GetZapdStr();

View File

@@ -3,7 +3,7 @@
// OTRTODO - this is awful
extern "C" {
void InitOTR();
void InitOTR(int argc, char* argv[]);
void Graph_ProcessFrame(void (*run_one_game_iter)(void));
void Graph_StartFrame();
void Graph_ProcessGfxCommands(Gfx* commands);

View File

@@ -1121,7 +1121,32 @@ void CheckAndCreateModFolder() {
}
}
extern "C" void InitOTR() {
extern "C" void InitOTR(int argc, char* argv[]) {
#if !defined(__SWITCH__) && !defined(__WIIU__)
if (argc > 1) {
for (int i = 1; i < argc; i++) {
std::string installPath = Ship::Context::GetAppBundlePath();
Extractor extract;
if (extract.RunFileStandalone(argv[i])) {
bool doExtract = true;
std::string archive = (extract.IsMasterQuest() ? "oot-mq.o2r" : "oot.o2r");
if (std::filesystem::exists(Ship::Context::GetAppBundlePath() + "/" + archive)) {
std::string msg = "Archive for current ROM, " + archive + ", already exists. Extract again?";
doExtract = extract.ShowYesNoBox("Confirm Re-extract", msg.c_str()) == IDYES;
}
if (doExtract) {
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName));
}
} else {
std::string msg = "File " + std::string(argv[i]) + " is not a ROM or does not match supported ROMs.";
extract.ShowErrorBox("Incompatible File", msg.c_str());
}
}
if (Extractor::ShowYesNoBox("Run Ship of Harkinian", "All files have been processed. Run SoH?") != IDYES) {
exit(0);
}
}
#endif
OTRGlobals::Instance = new OTRGlobals();
#ifdef __SWITCH__
Ship::Switch::Init(Ship::PreInitPhase);

View File

@@ -87,7 +87,7 @@ class OTRGlobals {
#endif
#ifndef __cplusplus
void InitOTR(void);
void InitOTR(int argc, char* argv[]);
void DeinitOTR(void);
void VanillaItemTable_Init();
void OTRAudio_Init();

View File

@@ -45,7 +45,7 @@ void Main_LogSystemHeap(void) {
}
#ifdef _WIN32
int SDL_main(int argc, char** argv) {
int SDL_main(int argc, char* argv[]) {
AllocConsole();
(void)freopen("CONIN$", "r", stdin);
(void)freopen("CONOUT$", "w", stdout);
@@ -57,11 +57,10 @@ int SDL_main(int argc, char** argv) {
setlocale(LC_ALL, ".UTF8");
#else //_WIN32
int main(int argc, char** argv) {
int main(int argc, char* argv[]) {
#endif
GameConsole_Init();
InitOTR();
InitOTR(argc, argv);
// TODO: Was moved to below InitOTR because it requires window to be setup. But will be late to catch crashes.
CrashHandlerRegisterCallback(CrashHandler_PrintSohData);
BootCommands_Init();