Skip to content

Commit

Permalink
extract to user homedir
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Jan 14, 2025
1 parent 4823898 commit f781da9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/btop_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ namespace Runner {

PluginHost* pluginHost = nullptr;

static std::filesystem::path getOutputDirectory() {
const char *homedir;
if (IsWindows()) {
homedir = getenv("USERPROFILE");
} else {
homedir = getenv("HOME");
}
if (homedir == nullptr) {
return std::filesystem::temp_directory_path() / ".btop";
} else {
return std::filesystem::path(homedir) / ".btop";
}
}

void create_plugin_host() {
std::stringstream pluginName;
pluginName << "btop-";
Expand Down Expand Up @@ -302,14 +316,14 @@ void create_plugin_host() {
pluginName << ".exe";
}

// Create temp directory for btop plugin
auto tmpdir = std::filesystem::temp_directory_path() / "btop";
if (!std::filesystem::exists(tmpdir)) {
std::filesystem::create_directory(tmpdir);
// Create output directory for btop plugin
auto outdir = getOutputDirectory();
if (!std::filesystem::exists(outdir)) {
std::filesystem::create_directory(outdir);
}

// Extract btop plugin from zipos
auto pluginPath = tmpdir / pluginName.str();
auto pluginPath = outdir / pluginName.str();
auto ziposPath = std::filesystem::path("/zip/") / pluginName.str();
if (!std::filesystem::exists(ziposPath)) {
std::cerr << "Plugin not found in zipos: " << ziposPath << std::endl;
Expand Down

0 comments on commit f781da9

Please sign in to comment.