Skip to content

Commit

Permalink
feature: basic settings
Browse files Browse the repository at this point in the history
  • Loading branch information
stowmyy committed Oct 26, 2023
1 parent 381dd0c commit 3ac3773
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
Binary file modified dropship/assets/icons/icon-block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dropship/assets/icons/icon-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions dropship/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <d3d11.h>

#include <string>
#include <filesystem>

// common
#include "util.hpp"
Expand Down Expand Up @@ -59,6 +60,9 @@ OPTIONS options
#else
.auto_update = true,
#endif

// TODO implement
._save_settings = true,
};

AppStore __default__appStore
Expand Down Expand Up @@ -253,8 +257,27 @@ int main(int, char**)
// https://github.com/ocornut/imgui/issues/5169

// TODO /tmp
io.IniFilename = NULL;
io.LogFilename = NULL;
// io.IniFilename = NULL;
//{
std::filesystem::path path = std::filesystem::temp_directory_path().append("dropship");
if (!std::filesystem::is_directory(path) || !std::filesystem::exists(path)) {
std::filesystem::create_directory(path);
}

path.append("dropship.ini");

std::string path_name = path.string();

io.IniFilename = path_name.c_str();
//}

io.UserData = &options;

ImGui::SaveIniSettingsToDisk(io.IniFilename);

printf("file path: %s\n", io.IniFilename);

//io.LogFilename = NULL;
// store my own data :D
//io.UserData = NULL

Expand Down
8 changes: 4 additions & 4 deletions dropship/src/DashboardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ DashboardManager::DashboardManager() :

if (__previous__application_open && !appStore.application_open)
{
// std::thread([&]() {
std::thread([&]() {
firewallManager.sync(&(this->endpoints));
// }).detach();
}).detach();

appStore.dashboard.heading = __default__appStore.dashboard.heading;

Expand Down Expand Up @@ -790,7 +790,7 @@ void DashboardManager::RenderInline()
// action
if (action)
{
// std::thread([&]() {
std::thread([&]() {
firewallManager.sync(&(this->endpoints), appStore.application_open);

bool pending_actions = false;
Expand All @@ -799,7 +799,7 @@ void DashboardManager::RenderInline()
pending_actions = true;

this->game_restart_required = pending_actions;
// }).detach();
}).detach();

// fill missing frame
w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color, 5, NULL);
Expand Down
2 changes: 0 additions & 2 deletions dropship/src/_WindowsFirewallUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,6 @@ class _WindowsFirewallUtil : public failable
if (!e.active_desired_state != ruleEnabled && (!only_unblocks || (only_unblocks && (!e.active && e.active_desired_state))))
{

printf("\n\nhere\n\n");

// if endpointDominant, set firewall to mirror endpoint state
if (endpointDominant)
{
Expand Down
24 changes: 13 additions & 11 deletions dropship/src/_windows_download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,25 @@ class _downloading : public IBindStatusCallback

static void download_file(std::string uri, std::string filename, float* progress, std::string* data = nullptr, std::filesystem::path* path = nullptr)
{
std::string directory = std::filesystem::temp_directory_path().string() + "/dropship";
std::filesystem::path _path = std::filesystem::temp_directory_path().append("dropship");

if (!std::filesystem::is_directory(directory) || !std::filesystem::exists("src")) {
std::filesystem::create_directory(directory);
if (!std::filesystem::is_directory(_path) || !std::filesystem::exists(_path)) {
std::filesystem::create_directory(_path);
}

std::filesystem::path filePath = directory + "/" + filename;
_path.append(filename);

if (std::filesystem::exists(filePath))
std::filesystem::remove(filePath);
if (std::filesystem::exists(_path))
std::filesystem::remove(_path);

DeleteUrlCacheEntry(filePath.string().c_str());
std::string _path_name = _path.string();

wprintf(filePath.c_str());
DeleteUrlCacheEntry(_path_name.c_str());

printf("downloading: %s\n", _path_name.c_str());

_downloading _progress(progress);
if (URLDownloadToFile(NULL, uri.c_str(), filePath.string().c_str(), 0, &_progress) != S_OK)
if (URLDownloadToFile(NULL, uri.c_str(), _path_name.c_str(), 0, &_progress) != S_OK)
{
printf("download failed\n");
}
Expand All @@ -154,12 +156,12 @@ static void download_file(std::string uri, std::string filename, float* progress
if (data != nullptr)
{

*data = get_file_contents(filePath.string().c_str());
*data = get_file_contents(_path_name.c_str());
}

if (path != nullptr)
{
*path = filePath;
*path = _path;
}

// std::filesystem::hash_value
Expand Down
5 changes: 3 additions & 2 deletions dropship/src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ struct Endpoint
//std::shared_ptr<int> ping = std::make_shared<int>(-9);
int display_ping = 0;

bool active;
bool active_desired_state;
bool active = true; // if no rules have been defined, default to selected
bool active_desired_state = true;

};

struct OPTIONS
{
bool auto_update;
bool _save_settings;
};


Expand Down

0 comments on commit 3ac3773

Please sign in to comment.