mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
fix: Issues when running the updater on Linux
This commit is contained in:
@@ -98,7 +98,7 @@ namespace hex {
|
||||
[[nodiscard]] std::string toByteString(u64 bytes);
|
||||
[[nodiscard]] std::string makePrintable(u8 c);
|
||||
|
||||
void startProgram(const std::string &command);
|
||||
void startProgram(const std::vector<std::string> &command);
|
||||
int executeCommand(const std::string &command);
|
||||
void openWebpage(std::string url);
|
||||
|
||||
|
||||
@@ -1048,12 +1048,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
EventImHexClosing::subscribe([executablePath, updateTypeString] {
|
||||
hex::startProgram(
|
||||
fmt::format("\"{}\" \"{}\"",
|
||||
wolv::util::toUTF8String(executablePath),
|
||||
updateTypeString
|
||||
)
|
||||
);
|
||||
hex::startProgram({ wolv::util::toUTF8String(executablePath), updateTypeString });
|
||||
});
|
||||
|
||||
ImHexApi::System::closeImHex();
|
||||
|
||||
@@ -302,17 +302,18 @@ namespace hex {
|
||||
return std::to_string(value).substr(0, 5) + Suffixes[suffixIndex];
|
||||
}
|
||||
|
||||
void startProgram(const std::string &command) {
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
std::ignore = system(fmt::format("start \"\" {0}", command).c_str());
|
||||
#elif defined(OS_MACOS)
|
||||
std::ignore = system(fmt::format("{0}", command).c_str());
|
||||
#elif defined(OS_LINUX)
|
||||
executeCmd({"xdg-open", command});
|
||||
#elif defined(OS_WEB)
|
||||
std::ignore = command;
|
||||
#endif
|
||||
void startProgram(const std::vector<std::string> &command) {
|
||||
#if defined(OS_WINDOWS)
|
||||
std::ignore = system(fmt::format("start \"\" {0:?}", fmt::join(command, " ")).c_str());
|
||||
#elif defined(OS_MACOS)
|
||||
std::ignore = system(fmt::format("{0:?}", fmt::join(command, " ")).c_str());
|
||||
#elif defined(OS_LINUX)
|
||||
std::vector<std::string> xdgCommand = { "xdg-open" };
|
||||
xdgCommand.insert(xdgCommand.end(), command.begin(), command.end());
|
||||
executeCmd(xdgCommand);
|
||||
#elif defined(OS_WEB)
|
||||
std::ignore = command;
|
||||
#endif
|
||||
}
|
||||
|
||||
int executeCommand(const std::string &command) {
|
||||
@@ -323,19 +324,19 @@ namespace hex {
|
||||
if (!url.contains("://"))
|
||||
url = "https://" + url;
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
#elif defined(OS_MACOS)
|
||||
openWebpageMacos(url.c_str());
|
||||
#elif defined(OS_LINUX)
|
||||
executeCmd({"xdg-open", url});
|
||||
#elif defined(OS_WEB)
|
||||
EM_ASM({
|
||||
window.open(UTF8ToString($0), '_blank');
|
||||
}, url.c_str());
|
||||
#else
|
||||
#warning "Unknown OS, can't open webpages"
|
||||
#endif
|
||||
#if defined(OS_WINDOWS)
|
||||
ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
#elif defined(OS_MACOS)
|
||||
openWebpageMacos(url.c_str());
|
||||
#elif defined(OS_LINUX)
|
||||
executeCmd({ "xdg-open", url });
|
||||
#elif defined(OS_WEB)
|
||||
EM_ASM({
|
||||
window.open(UTF8ToString($0), '_blank');
|
||||
}, url.c_str());
|
||||
#else
|
||||
#warning "Unknown OS, can't open webpages"
|
||||
#endif
|
||||
}
|
||||
|
||||
std::optional<u8> hexCharToValue(char c) {
|
||||
|
||||
@@ -124,21 +124,21 @@ std::string_view getUpdateArtifactEnding() {
|
||||
return ARCH_DEPENDENT("x86_64.flatpak", "arm64.flatpak");
|
||||
} else if (hex::getEnvironmentVariable("SNAP").has_value()) {
|
||||
return ARCH_DEPENDENT("x86_64.snap", "arm64.snap");
|
||||
} else if (hex::executeCommand("grep 'ID=ubuntu' /etc/os-release") == 0) {
|
||||
} else if (hex::executeCommand("grep -q 'ID=ubuntu' /etc/os-release") == 0) {
|
||||
if (hex::executeCommand("grep 'VERSION_ID=\"24.04\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Ubuntu-24.04-x86_64.deb", "");
|
||||
else if (hex::executeCommand("grep 'VERSION_ID=\"24.10\"' /etc/os-release") == 0)
|
||||
else if (hex::executeCommand("grep -q 'VERSION_ID=\"24.10\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Ubuntu-24.10-x86_64.deb", "");
|
||||
else if (hex::executeCommand("grep 'VERSION_ID=\"25.04\"' /etc/os-release") == 0)
|
||||
else if (hex::executeCommand("grep -q 'VERSION_ID=\"25.04\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Ubuntu-25.04-x86_64.deb", "");
|
||||
} else if (hex::executeCommand("grep 'ID=fedora' /etc/os-release") == 0) {
|
||||
if (hex::executeCommand("grep 'VERSION_ID=\"41\"' /etc/os-release") == 0)
|
||||
} else if (hex::executeCommand("grep -q 'ID=fedora' /etc/os-release") == 0) {
|
||||
if (hex::executeCommand("grep -q 'VERSION_ID=\"41\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Fedora-41-x86_64.rpm", "");
|
||||
else if (hex::executeCommand("grep 'VERSION_ID=\"42\"' /etc/os-release") == 0)
|
||||
else if (hex::executeCommand("grep -q 'VERSION_ID=\"42\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Fedora-42-x86_64.rpm", "");
|
||||
else if (hex::executeCommand("grep 'VERSION_ID=\"rawhide\"' /etc/os-release") == 0)
|
||||
else if (hex::executeCommand("grep -q 'VERSION_ID=\"rawhide\"' /etc/os-release") == 0)
|
||||
return ARCH_DEPENDENT("Fedora-rawhide-x86_64.rpm", "");
|
||||
} else if (hex::executeCommand("grep '^NAME=\"Arch Linux\"' /etc/os-release") == 0) {
|
||||
} else if (hex::executeCommand("grep -q '^NAME=\"Arch Linux\"' /etc/os-release") == 0) {
|
||||
return ARCH_DEPENDENT("ArchLinux-x86_64.pkg.tar.zst", "");
|
||||
}
|
||||
#endif
|
||||
@@ -155,12 +155,12 @@ bool installUpdate(const std::fs::path &updatePath) {
|
||||
const static auto UpdateHandlers = {
|
||||
UpdateHandler { ".msi", "msiexec /i \"{}\" /qb" },
|
||||
UpdateHandler { ".dmg", "hdiutil attach -autoopen \"{}\"" },
|
||||
UpdateHandler { ".deb", "sudo apt install -y --fix-broken \"{}\"" },
|
||||
UpdateHandler { ".rpm", "sudo rpm -i \"{}\"" },
|
||||
UpdateHandler { ".pkg.tar.zst", "sudo pacman -Syy && sudo pacman -U --noconfirm \"{}\"" },
|
||||
UpdateHandler { ".AppImage", fmt::format("sudo cp \"{{}}\" \"{}\"", hex::getEnvironmentVariable("APPIMAGE").value_or("")) },
|
||||
UpdateHandler { ".flatpak", "sudo flatpak install -y --reinstall \"{}\"" },
|
||||
UpdateHandler { ".snap", "sudo snap install --dangerous \"{}\"" },
|
||||
UpdateHandler { ".deb", "zenity --password | sudo -S apt install -y --fix-broken \"{}\"" },
|
||||
UpdateHandler { ".rpm", "zenity --password | sudo -S rpm -i \"{}\"" },
|
||||
UpdateHandler { ".pkg.tar.zst", "zenity --password | sudo -S pacman -Syy && sudo pacman -U --noconfirm \"{}\"" },
|
||||
UpdateHandler { ".AppImage", fmt::format("zenity --password | sudo -S cp \"{{}}\" \"{}\"", hex::getEnvironmentVariable("APPIMAGE").value_or("")) },
|
||||
UpdateHandler { ".flatpak", "zenity --password | sudo -S flatpak install -y --reinstall \"{}\"" },
|
||||
UpdateHandler { ".snap", "zenity --password | sudo -S snap install --dangerous \"{}\"" },
|
||||
};
|
||||
|
||||
const auto updateFileName = wolv::util::toUTF8String(updatePath.filename());
|
||||
@@ -170,7 +170,7 @@ bool installUpdate(const std::fs::path &updatePath) {
|
||||
const auto command = fmt::format(fmt::runtime(handler.command), updatePath.string());
|
||||
|
||||
hex::log::info("Starting update process with command: '{}'", command);
|
||||
hex::startProgram(command);
|
||||
hex::executeCommand(command);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user