From 0566fdfaaa5bb46cc341265e6f44ffc779dbbb70 Mon Sep 17 00:00:00 2001 From: Madman10K Date: Sun, 25 Feb 2024 20:35:17 +0200 Subject: [PATCH] Ready for 2.0.1.0 --- Source/Instance.hpp | 15 ++++++++++++ Source/Submenus/Edit/Delete.cpp | 8 ++---- Source/Submenus/Edit/Poweroff.cpp | 13 +--------- Source/Submenus/Edit/Poweron.cpp | 13 +--------- Source/Submenus/Edit/Restart.cpp | 13 +--------- Source/Submenus/Edit/Update.cpp | 27 +++------------------ Source/Submenus/File/NewContainer.cpp | 35 ++++----------------------- 7 files changed, 29 insertions(+), 95 deletions(-) diff --git a/Source/Instance.hpp b/Source/Instance.hpp index d4fbdbd..e856094 100644 --- a/Source/Instance.hpp +++ b/Source/Instance.hpp @@ -6,6 +6,21 @@ #include #include "IncusBindings/libUGM_Incus_InternalFuncs.h" +#define INCUS_RUN(x, y, z, ...) \ + if (x(y __VA_OPT__(,) __VA_ARGS__) != 0) \ + { \ + Logger::log("Failed to " z " the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, y, \ + " Error: ", IncusGetError()); \ + UImGui::Instance::shutdown(); \ + } + + +#define INCUS_RUN_AND_CLOSE(x, y) inst->bWorkerActive = true; \ + inst->worker = std::thread([&]() -> void { INCUS_RUN(x, inst->selectedContainer->name.data(), y); \ + state = UIMGUI_COMPONENT_STATE_PAUSED; \ + ((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true; \ +}); + namespace UntitledGameSystemManager { struct Container diff --git a/Source/Submenus/Edit/Delete.cpp b/Source/Submenus/Edit/Delete.cpp index a24a903..47a40b0 100644 --- a/Source/Submenus/Edit/Delete.cpp +++ b/Source/Submenus/Edit/Delete.cpp @@ -37,12 +37,8 @@ void UntitledGameSystemManager::Delete::tick(float deltaTime) configDir = inst->configDir; } - if (IncusDeleteContainer(name.data()) != 0) - { - Logger::log("Failed to delete the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, - name, " Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusDeleteContainer, name.data(), "delete"); + const std::lock_guard lock(mutex); YAML::Node o; try diff --git a/Source/Submenus/Edit/Poweroff.cpp b/Source/Submenus/Edit/Poweroff.cpp index 0c29415..748c8b0 100644 --- a/Source/Submenus/Edit/Poweroff.cpp +++ b/Source/Submenus/Edit/Poweroff.cpp @@ -27,18 +27,7 @@ void UntitledGameSystemManager::Poweroff::tick(float deltaTime) if (!inst->bWorkerActive && ImGui::Button("Power off##button")) { - inst->bWorkerActive = true; - inst->worker = std::thread([&]() -> void - { - if (IncusStopContainer(inst->selectedContainer->name.data()) != 0) - { - Logger::log("Failed to power off the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, - inst->selectedContainer->name, " Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } - state = UIMGUI_COMPONENT_STATE_PAUSED; - ((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true; - }); + INCUS_RUN_AND_CLOSE(IncusStopContainer, "power off"); } ImGui::SameLine(); if (!inst->bWorkerActive && ImGui::Button("Close##info")) diff --git a/Source/Submenus/Edit/Poweron.cpp b/Source/Submenus/Edit/Poweron.cpp index c29fa93..1728fc0 100644 --- a/Source/Submenus/Edit/Poweron.cpp +++ b/Source/Submenus/Edit/Poweron.cpp @@ -27,18 +27,7 @@ void UntitledGameSystemManager::Poweron::tick(float deltaTime) if (!inst->bWorkerActive && ImGui::Button("Power on##button")) { - inst->bWorkerActive = true; - inst->worker = std::thread([&]() -> void - { - if (IncusStartContainer(inst->selectedContainer->name.data()) != 0) - { - Logger::log("Failed to power on the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, - inst->selectedContainer->name, " Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } - state = UIMGUI_COMPONENT_STATE_PAUSED; - ((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true; - }); + INCUS_RUN_AND_CLOSE(IncusStartContainer, "power on"); } ImGui::SameLine(); if (!inst->bWorkerActive && ImGui::Button("Close##info")) diff --git a/Source/Submenus/Edit/Restart.cpp b/Source/Submenus/Edit/Restart.cpp index e630cf3..98195bb 100644 --- a/Source/Submenus/Edit/Restart.cpp +++ b/Source/Submenus/Edit/Restart.cpp @@ -26,18 +26,7 @@ void UntitledGameSystemManager::Restart::tick(float deltaTime) if (!inst->bWorkerActive && ImGui::Button("Restart##button")) { - inst->bWorkerActive = true; - inst->worker = std::thread([&]() -> void - { - if (IncusRestartContainer(inst->selectedContainer->name.data()) != 0) - { - Logger::log("Failed to restart the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, - inst->selectedContainer->name, " Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } - state = UIMGUI_COMPONENT_STATE_PAUSED; - ((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true; - }); + INCUS_RUN_AND_CLOSE(IncusRestartContainer, "restart"); } ImGui::SameLine(); if (!inst->bWorkerActive && ImGui::Button("Close##info")) diff --git a/Source/Submenus/Edit/Update.cpp b/Source/Submenus/Edit/Update.cpp index 0cbd253..ed313ec 100644 --- a/Source/Submenus/Edit/Update.cpp +++ b/Source/Submenus/Edit/Update.cpp @@ -63,44 +63,25 @@ void UntitledGameSystemManager::Update::tick(float deltaTime) name = container->name; } - if (IncusStartContainer(name.data()) != 0) - { - Logger::log("Failed to start the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusStartContainer, name.data(), "start"); { const std::lock_guard lock(mutex); currentEvent = "Copying update script to container!"; } - if (IncusPushFile(name.data(), (char*)"/root/ugm-cli-update.sh", dir.data()) != 0) - { - Logger::log("Failed to copy file to the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusPushFile, name.data(), "copy file", (char*)"/root/ugm-cli-update.sh", dir.data()); { const std::lock_guard lock(mutex); currentEvent = "Copying update script to container!"; } - if (IncusExec(name.data(), ("bash{{b}}-c{{b}}/root/ugm-cli-update.sh " + type + " " + version + " &> /root/out.txt").data(), true) != 0) - {Logger::log("Failed to copy file to the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusExec, name.data(), "execute command", ("bash{{b}}-c{{b}}/root/ugm-cli-update.sh " + type + " " + version + " &> /root/out.txt").data(), true); { const std::lock_guard lock(mutex); currentEvent = "Restarting container, finalising installation!"; } - if (IncusRestartContainer(name.data()) != 0) - { - Logger::log("Failed to restart the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusRestartContainer, name.data(), "restart") state = UIMGUI_COMPONENT_STATE_PAUSED; ((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true; diff --git a/Source/Submenus/File/NewContainer.cpp b/Source/Submenus/File/NewContainer.cpp index e7e7428..e5d2bd4 100644 --- a/Source/Submenus/File/NewContainer.cpp +++ b/Source/Submenus/File/NewContainer.cpp @@ -53,63 +53,38 @@ void UntitledGameSystemManager::NewContainer::tick(float deltaTime) UImGui::FString dir = inst->configDir; UImGui::FString conf = dir; UImGui::FString type; - //UImGui::FString type = inst->gpuType; dir += "scripts/ugm-cli-install.sh"; - bStartExecuting = true; - UImGui::FString version; - //type; { const std::lock_guard lock(mutex); currentEvent = "Creating a new container!"; version = UImGui::Renderer::getDriverVersion(); type = UImGui::Renderer::getGPUName()[0] == 'N' ? "N" : "M"; - //type = inst->gpuType; - } - if (IncusNewContainer(name.data(), (char*)"archlinux") != 0) - { - Logger::log("Failed to create the following container: ", UVKLog::UVK_LOG_TYPE_ERROR, - name, " Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - return; } + INCUS_RUN(IncusNewContainer, name.data(), "create", (char*)"archlinux"); { const std::lock_guard lock(mutex); currentEvent = "Uploading installation script to container!"; } - if (IncusPushFile(name.data(), (char*)"/root/ugm-cli-install.sh", dir.data()) != 0) - { - Logger::log("Failed to copy file to the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusPushFile, name.data(), "copy file", (char*)"/root/ugm-cli-install.sh", dir.data()); IncusExec(name.data(), (char*)"bash{{b}}-c{{b}}ping -c 5 google.com || ping -c 5 google.com", true); IncusRestartContainer(name.data()); + { const std::lock_guard lock(mutex); currentEvent = "Running installation script, may take more than 20 minutes!"; } - if (IncusExec(name.data(), ("bash{{b}}-c{{b}}/root/ugm-cli-install.sh " + type + " " + version).data(), true) != 0) - { - Logger::log("Failed to execute installation script of the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusExec, name.data(), "execute installation script", ("bash{{b}}-c{{b}}/root/ugm-cli-install.sh " + type + " " + version).data(), true); { const std::lock_guard lock(mutex); currentEvent = "Restarting container, finalising installation!"; } - if (IncusRestartContainer(name.data()) != 0) - { - Logger::log("Failed to restart the following container: ", UVK_LOG_TYPE_ERROR, name, - "Error: ", IncusGetError()); - UImGui::Instance::shutdown(); - } + INCUS_RUN(IncusRestartContainer, name.data(), "restart"); YAML::Node out; out["container"] = name;