Skip to content

Commit

Permalink
Delete actually deletes from the config and is thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Madman10K committed Jul 28, 2023
1 parent a2ead63 commit c59bdda
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
50 changes: 47 additions & 3 deletions Source/Submenus/Edit/Delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,60 @@ void UntitledGameSystemManager::Delete::tick(float deltaTime)
if (!inst->bWorkerActive && ImGui::Button("Delete##button"))
{
inst->bWorkerActive = true;
inst->worker = std::thread([&]() -> void
inst->worker = std::thread([inst, this]() -> void
{
if (LXDDeleteContainer(inst->selectedContainer->name.data()) != 0)
std::string name;
std::string configDir;
{
const std::lock_guard<std::mutex> lock(mutex);
name = inst->selectedContainer->name;
configDir = inst->configDir;
}

if (LXDDeleteContainer(name.data()) != 0)
{
Logger::log("Failed to delete the following container: ", UVKLog::UVK_LOG_TYPE_ERROR,
inst->selectedContainer->name, " Error: ", LXDGetError());
name, " Error: ", LXDGetError());
UImGui::Instance::shutdown();
}
const std::lock_guard<std::mutex> lock(mutex);
YAML::Node o;
try
{
o = YAML::LoadFile(configDir + "config/layout.yaml");
}
catch (YAML::BadFile&)
{
Logger::log("Couldn't open the config file at: ", UVKLog::UVK_LOG_TYPE_ERROR, configDir, "config/layout.yaml");
std::terminate();
}
YAML::Node cont = o["containers"];
if (cont)
{
std::vector<YAML::Node> containers;
for (const YAML::Node& a : cont)
{
if (a["container"] && a["pins"])
{
auto r = a["container"].as<std::string>();
if (name == r)
continue;
}

containers.push_back(a);
}
o["containers"] = containers;
}

std::ofstream file(configDir + "config/layout.yaml");
file << o;
file.close();

state = UIMGUI_COMPONENT_STATE_PAUSED;
((Instance*)UImGui::Instance::getGlobal())->bFinishedExecution = true;

inst->loadConfigData();
inst->selectedContainer = nullptr;
});
}
ImGui::SameLine();
Expand Down
2 changes: 1 addition & 1 deletion Source/Submenus/Edit/Delete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace UntitledGameSystemManager
virtual void end() override;
virtual ~Delete() override;
private:

std::mutex mutex;
};
}

0 comments on commit c59bdda

Please sign in to comment.