Skip to content

Commit

Permalink
Ready for 2.0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Madman10K committed Feb 25, 2024
1 parent 1609e9f commit 0566fdf
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 95 deletions.
15 changes: 15 additions & 0 deletions Source/Instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
#include <thread>
#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
Expand Down
8 changes: 2 additions & 6 deletions Source/Submenus/Edit/Delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mutex);
YAML::Node o;
try
Expand Down
13 changes: 1 addition & 12 deletions Source/Submenus/Edit/Poweroff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 1 addition & 12 deletions Source/Submenus/Edit/Poweron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 1 addition & 12 deletions Source/Submenus/Edit/Restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
27 changes: 4 additions & 23 deletions Source/Submenus/Edit/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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<std::mutex> 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<std::mutex> 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;
Expand Down
35 changes: 5 additions & 30 deletions Source/Submenus/File/NewContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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;
Expand Down

0 comments on commit 0566fdf

Please sign in to comment.