Skip to content

Commit 58ea21a

Browse files
committed
Add a menu option to allow resetting the workspace.
1 parent 0fd1aa8 commit 58ea21a

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/gui2/fluxengine.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#include <hex/plugin.hpp>
22
#include <hex/api/content_registry/views.hpp>
3+
#include <hex/api/content_registry/user_interface.hpp>
34
#include <hex/helpers/logger.hpp>
45
#include <hex/api/content_registry/provider.hpp>
6+
#include <hex/api/workspace_manager.hpp>
7+
#include <hex/helpers/default_paths.hpp>
8+
#include <fonts/vscode_icons.hpp>
9+
#include <fonts/tabler_icons.hpp>
510
#include <romfs/romfs.hpp>
611
#include "globals.h"
712
#include "imageview.h"
@@ -24,6 +29,42 @@ IMHEX_PLUGIN_SETUP("FluxEngine", "David Given", "FluxEngine integration")
2429
return romfs::get(path).string();
2530
});
2631

32+
hex::ContentRegistry::UserInterface::addMenuItem(
33+
{"hex.builtin.menu.workspace", "fluxengine.menu.workspace.reset"},
34+
ICON_TA_CANCEL,
35+
10000,
36+
hex::Shortcut::None,
37+
[]
38+
{
39+
static const std::string extractFolder = "auto_extract/workspaces";
40+
for (const auto& romfsPath : romfs::list(extractFolder))
41+
{
42+
for (const auto& imhexPath : hex::paths::getDataPaths(false))
43+
{
44+
const auto path =
45+
imhexPath / std::fs::relative(romfsPath, extractFolder);
46+
hex::log::info("Extracting {} to {}",
47+
romfsPath.string(),
48+
path.string());
49+
50+
wolv::io::File file(path, wolv::io::File::Mode::Create);
51+
if (!file.isValid())
52+
continue;
53+
54+
auto data = romfs::get(romfsPath).span<u8>();
55+
file.writeBuffer(data.data(), data.size());
56+
57+
if (file.getSize() == data.size())
58+
break;
59+
}
60+
}
61+
62+
auto currentWorkspaceName =
63+
hex::WorkspaceManager::getCurrentWorkspace()->first;
64+
hex::WorkspaceManager::reload();
65+
hex::WorkspaceManager::switchWorkspace(currentWorkspaceName);
66+
});
67+
2768
hex::ContentRegistry::Provider::add<DiskProvider>();
2869

2970
hex::ContentRegistry::Views::add<ConfigView>();

0 commit comments

Comments
 (0)