Fix: Repair working directory on Mac and use app directory for extractor search paths (#3359)

* fix otr regen on mac release

* linux args
This commit is contained in:
Adam Bird 2023-11-06 17:46:48 -05:00 committed by GitHub
parent 460b3d02f5
commit 959b307b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -219,12 +219,14 @@ if [ ! -e "$SHIP_HOME"/oot.otr ] || [ ! -e "$SHIP_HOME"/oot-mq.otr ]; then
*)
osascript -e 'display notification "One or more invalid ROM provided" with title "Ship Of Harkinian"'
rm -r "$ASSETDIR"
cd "$SNAME"
continue;
esac
# Only generate OTR if we don't have on of this type yet
if [ -e "$SHIP_HOME"/"$OTRNAME" ]; then
rm -r "$ASSETDIR"
cd "$SNAME"
continue;
fi
@ -234,6 +236,7 @@ if [ ! -e "$SHIP_HOME"/oot.otr ] || [ ! -e "$SHIP_HOME"/oot-mq.otr ]; then
osascript -e 'display notification "OTR successfully generated" with title "Ship Of Harkinian"'
cp "$ASSETDIR"/oot.otr "$SHIP_HOME"/"$OTRNAME"
rm -r "$ASSETDIR"
cd "$SNAME"
fi
done
@ -243,6 +246,8 @@ if [ ! -e "$SHIP_HOME"/oot.otr ] || [ ! -e "$SHIP_HOME"/oot-mq.otr ]; then
fi
fi
cd "$SNAME"
arch_name="$(uname -m)"
launch_arch="arm64"
if [ "${arch_name}" = "x86_64" ] && [ "$(sysctl -in sysctl.proc_translated)" != "1" ]; then

View File

@ -225,7 +225,7 @@ void Extractor::GetRoms(std::vector<std::string>& roms) {
//}
#elif unix
// Open the directory of the app.
DIR* d = opendir(".");
DIR* d = opendir(mSearchPath.c_str());
struct dirent* dir;
if (d != NULL) {
@ -248,7 +248,7 @@ void Extractor::GetRoms(std::vector<std::string>& roms) {
}
closedir(d);
#else
for (const auto& file : std::filesystem::directory_iterator("./")) {
for (const auto& file : std::filesystem::directory_iterator(mSearchPath)) {
if (file.is_directory())
continue;
if ((file.path().extension() == ".n64") || (file.path().extension() == ".z64") ||
@ -297,7 +297,7 @@ bool Extractor::GetRomPathFromBox() {
}
mCurrentRomPath = nameBuffer;
#else
auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result();
auto selection = pfd::open_file("Select a file", mSearchPath, { "N64 Roms", "*.z64 *.n64 *.v64" }).result();
if (selection.empty()) {
return false;
@ -430,10 +430,12 @@ bool Extractor::ManuallySearchForRomMatchingType(RomSearchMode searchMode) {
return true;
}
bool Extractor::Run(RomSearchMode searchMode) {
bool Extractor::Run(std::string searchPath, RomSearchMode searchMode) {
std::vector<std::string> roms;
std::ifstream inFile;
mSearchPath = searchPath;
GetRoms(roms);
FilterRoms(roms, searchMode);

View File

@ -28,6 +28,7 @@ enum class RomSearchMode {
class Extractor {
std::unique_ptr<unsigned char[]> mRomData = std::make_unique<unsigned char[]>(MB64);
std::string mCurrentRomPath;
std::string mSearchPath;
size_t mCurRomSize = 0;
bool GetRomPathFromBox();
@ -58,7 +59,7 @@ class Extractor {
static void ShowErrorBox(const char* title, const char* text);
bool IsMasterQuest() const;
bool Run(RomSearchMode searchMode = RomSearchMode::Both);
bool Run(std::string searchPath, RomSearchMode searchMode = RomSearchMode::Both);
bool CallZapd(std::string installPath, std::string exportdir);
const char* GetZapdStr();
std::string Mkdtemp();

View File

@ -890,7 +890,7 @@ void DetectOTRVersion(std::string fileName, bool isMQ) {
}
Extractor extract;
if (!extract.Run(isMQ ? RomSearchMode::MQ : RomSearchMode::Vanilla)) {
if (!extract.Run(LUS::Context::GetAppDirectoryPath(appShortName), isMQ ? RomSearchMode::MQ : RomSearchMode::Vanilla)) {
Extractor::ShowErrorBox("Error", "An error occured, no OTR file was generated.\n\nExiting...");
exit(1);
}
@ -932,6 +932,7 @@ extern "C" void InitOTR() {
#elif defined(__WIIU__)
LUS::WiiU::Init(appShortName);
#endif
#ifdef _WIN32
char* tempVar = getenv("TEMP");
std::filesystem::path tempPath;
@ -985,7 +986,7 @@ extern "C" void InitOTR() {
bool generatedOtrIsMQ = false;
if (Extractor::ShowYesNoBox("No OTR Files", "No OTR files found. Generate one now?") == IDYES) {
Extractor extract;
if (!extract.Run()) {
if (!extract.Run(LUS::Context::GetAppDirectoryPath(appShortName))) {
Extractor::ShowErrorBox("Error", "An error occured, no OTR file was generated.\n\nExiting...");
exit(1);
}
@ -996,7 +997,7 @@ extern "C" void InitOTR() {
}
if (Extractor::ShowYesNoBox("Extraction Complete", "ROM Extracted. Extract another?") == IDYES) {
Extractor extract;
if (!extract.Run(generatedOtrIsMQ ? RomSearchMode::Vanilla : RomSearchMode::MQ)) {
if (!extract.Run(LUS::Context::GetAppDirectoryPath(appShortName), generatedOtrIsMQ ? RomSearchMode::Vanilla : RomSearchMode::MQ)) {
Extractor::ShowErrorBox("Error", "An error occured, an OTR file may have been generated by a different step.\n\nContinuing...");
} else {
extract.CallZapd(installPath, LUS::Context::GetAppDirectoryPath(appShortName));