From daf8b409f325891c163f9bf69d3adaeb53579ec0 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 11 Sep 2024 17:08:20 -0700 Subject: [PATCH 1/2] FEXRootFSFetcher: Fallback to TTY if zenity isn't installed If packaged improperly or if someone has just did a source install then they may not have zenity. Fallback to TTY path if zenity isn't installed. --- Source/Tools/FEXRootFSFetcher/Main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index 897622e89b..385c466396 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -212,6 +212,7 @@ namespace WorkingAppsTester { static bool Has_Curl {false}; static bool Has_Squashfuse {false}; static bool Has_Unsquashfs {false}; +static bool Has_Zenity {false}; // EroFS specific static bool Has_EroFSFuse {false}; @@ -284,6 +285,17 @@ void CheckUnsquashfs() { } close(fd); } +void CheckZenity() { + // Check if zenity exists on the host + std::vector ExecveArgs = { + "zenity", + "-h", + nullptr, + }; + + int32_t Result = Exec::ExecAndWaitForResponseRedirect(ExecveArgs[0], const_cast(ExecveArgs.data()), -1, -1); + Has_Zenity = Result != -1; +} // EroFS specific tests void CheckEroFSFuse() { @@ -312,6 +324,7 @@ void Init() { CheckCurl(); CheckSquashfuse(); CheckUnsquashfs(); + CheckZenity(); CheckEroFSFuse(); CheckEroFSFsck(); } @@ -967,6 +980,14 @@ void CheckTTY() { IsTTY = ArgOptions::UIOption == ArgOptions::UIOverrideOption::TTY; } + if (!WorkingAppsTester::Has_Zenity) { + // Force TTY if zenity isn't installed. + if (ArgOptions::UIOption == ArgOptions::UIOverrideOption::Zenity) { + fmt::print("Zenity isn't executable. Falling back to TTY mode\n"); + } + IsTTY = true; + } + if (IsTTY) { _AskForConfirmation = TTY::AskForConfirmation; _ExecWithInfo = TTY::ExecWithInfo; @@ -1091,6 +1112,8 @@ int main(int argc, char** argv, char** const envp) { ArgOptions::ParseArguments(argc, argv); + WorkingAppsTester::Init(); + CheckTTY(); if (ArgOptions::RemainingArgs.size()) { @@ -1103,7 +1126,6 @@ int main(int argc, char** argv, char** const envp) { return 0; } - WorkingAppsTester::Init(); // Check if curl exists on the host if (!WorkingAppsTester::Has_Curl) { ExecWithInfo("curl is required to use this tool. Please install curl before using."); From 6ff073ac11754855232cb7505eb4f136f3629183 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 13 Sep 2024 11:29:44 -0700 Subject: [PATCH 2/2] FEXRootFSFetcher: convert vector usage over to array and span Most uses of vector could actually be converted to array and a lot of argument passing could actually be converted over to spans instead. --- Source/Tools/FEXRootFSFetcher/Main.cpp | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index 385c466396..50d4a4af26 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -220,7 +220,7 @@ static bool Has_EroFSFsck {false}; void CheckCurl() { // Check if curl exists on the host - std::vector ExecveArgs = { + const std::array ExecveArgs = { "curl", "-V", nullptr, @@ -231,7 +231,7 @@ void CheckCurl() { } void CheckSquashfuse() { - std::vector ExecveArgs = { + const std::array ExecveArgs = { "squashfuse", "--help", nullptr, @@ -242,7 +242,7 @@ void CheckSquashfuse() { } void CheckUnsquashfs() { - std::vector ExecveArgs = { + const std::array ExecveArgs = { "unsquashfs", "--help", nullptr, @@ -287,7 +287,7 @@ void CheckUnsquashfs() { } void CheckZenity() { // Check if zenity exists on the host - std::vector ExecveArgs = { + std::array ExecveArgs = { "zenity", "-h", nullptr, @@ -299,7 +299,7 @@ void CheckZenity() { // EroFS specific tests void CheckEroFSFuse() { - std::vector ExecveArgs = { + std::array ExecveArgs = { "erofsfuse", "--help", nullptr, @@ -310,7 +310,7 @@ void CheckEroFSFuse() { } void CheckEroFSFsck() { - std::vector ExecveArgs = { + std::array ExecveArgs = { "fsck.erofs", "-V", nullptr, @@ -499,7 +499,7 @@ struct FileTargets { const static std::string DownloadURL = "https://rootfs.fex-emu.gg/RootFS_links.json"; std::string DownloadToString(const std::string& URL) { - std::vector ExecveArgs = { + std::array ExecveArgs = { "curl", URL.c_str(), nullptr, @@ -512,7 +512,7 @@ bool DownloadToPath(const fextl::string& URL, const fextl::string& Path) { auto filename = URL.substr(URL.find_last_of('/') + 1); auto PathName = Path + filename; - std::vector ExecveArgs = { + std::array ExecveArgs = { "curl", URL.c_str(), "-o", PathName.c_str(), nullptr, }; @@ -533,7 +533,7 @@ bool DownloadToPathWithZenityProgress(const fextl::string& URL, const fextl::str // Making zenity vanish immediately const std::string ZenityBuf = "zenity --time-remaining --progress --no-cancel --title 'Downloading'"; std::string BigArgs = fmt::format("{} | {} | {} | {}", CurlPipe, StdBuf, SedBuf, ZenityBuf); - std::vector ExecveArgs = { + std::array ExecveArgs = { "/bin/sh", "-c", BigArgs.c_str(), @@ -640,7 +640,7 @@ bool AskForConfirmation(const fextl::string& Question) { return ArgOptions::AssumeYes || ExecWithQuestion(Question); } -int32_t AskForConfirmationList(const fextl::string& Text, const std::vector& Arguments) { +int32_t AskForConfirmationList(const fextl::string& Text, const std::span Arguments) { fextl::string TextArg = "--text=" + Text; std::vector ExecveArgs = { @@ -666,7 +666,7 @@ int32_t AskForConfirmationList(const fextl::string& Text, const std::vector& Arguments) { +int32_t AskForComplexConfirmationList(const std::string& Text, const std::span Arguments) { std::string TextArg = "--text=" + Text; std::vector ExecveArgs = { @@ -687,7 +687,7 @@ int32_t AskForComplexConfirmationList(const std::string& Text, const std::vector return std::stoi(Result); } -int32_t AskForDistroSelection(DistroQuery::DistroInfo& Info, std::vector& Targets) { +int32_t AskForDistroSelection(DistroQuery::DistroInfo& Info, const std::span Targets) { // Search for an exact match int32_t DistroIndex = -1; if (!Info.Unknown) { @@ -737,7 +737,7 @@ bool ValidateCheckExists(const WebFileFetcher::FileTargets& Target) { std::error_code ec; if (std::filesystem::exists(PathName, ec)) { - const std::vector Args { + const std::array Args { "Overwrite", "Validate", }; @@ -826,7 +826,7 @@ void ExecWithInfo(const fextl::string& Text) { std::cout << Text << std::endl; } -int32_t AskForConfirmationList(const fextl::string& Text, const std::vector& List) { +int32_t AskForConfirmationList(const fextl::string& Text, std::span List) { fmt::print("{}\n", Text); fmt::print("Options:\n"); fmt::print("\t0: Cancel\n"); @@ -850,7 +850,7 @@ int32_t AskForConfirmationList(const fextl::string& Text, const std::vector& Targets) { +int32_t AskForDistroSelection(DistroQuery::DistroInfo& Info, const std::span Targets) { // Search for an exact match int32_t DistroIndex = -1; if (!Info.Unknown) { @@ -895,7 +895,7 @@ bool ValidateCheckExists(const WebFileFetcher::FileTargets& Target) { std::error_code ec; if (std::filesystem::exists(PathName, ec)) { - const std::vector Args { + const std::array Args { "Overwrite", "Validate", }; @@ -967,8 +967,8 @@ bool ValidateDownloadSelection(const WebFileFetcher::FileTargets& Target) { namespace { std::function _AskForConfirmation; std::function _ExecWithInfo; -std::function& List)> _AskForConfirmationList; -std::function& Targets)> _AskForDistroSelection; +std::function List)> _AskForConfirmationList; +std::function Targets)> _AskForDistroSelection; std::function _ValidateCheckExists; std::function _ValidateDownloadSelection; @@ -1013,11 +1013,11 @@ void ExecWithInfo(const fextl::string& Text) { _ExecWithInfo(Text); } -int32_t AskForConfirmationList(const fextl::string& Text, const std::vector& Arguments) { +int32_t AskForConfirmationList(const fextl::string& Text, const std::span Arguments) { return _AskForConfirmationList(Text, Arguments); } -int32_t AskForDistroSelection(std::vector& Targets) { +int32_t AskForDistroSelection(const std::span Targets) { auto Info = DistroQuery::GetDistroInfo(); if (!ArgOptions::DistroName.empty()) { @@ -1066,7 +1066,7 @@ bool UnsquashRootFS(const fextl::string& Path, const fextl::string& RootFS, cons } } - const std::vector ExecveArgs = { + const std::array ExecveArgs = { "unsquashfs", "-f", "-d", TargetFolder.c_str(), RootFS.c_str(), nullptr, }; @@ -1092,7 +1092,7 @@ bool ExtractEroFS(const fextl::string& Path, const fextl::string& RootFS, const ExecWithInfo("Extracting Erofs. This might take a few minutes."); const auto ExtractOption = fmt::format("--extract={}", TargetFolder); - const std::vector ExecveArgs = { + const std::array ExecveArgs = { "fsck.erofs", ExtractOption.c_str(), RootFS.c_str(),