cleanup and fixes

This commit is contained in:
m 2022-12-22 07:27:28 -06:00
parent 160b5cd325
commit 56b144c48f
3 changed files with 13 additions and 38 deletions

View File

@ -355,41 +355,38 @@ namespace party
bool download_files(const game::netadr_s& target, const utils::info_string& info, bool allow_download); bool download_files(const game::netadr_s& target, const utils::info_string& info, bool allow_download);
int user_download_response(game::hks::lua_State* state) void user_download_response(bool response)
{ {
const auto response = state->m_apistack.base[0].v.boolean;
if (!response) if (!response)
{ {
return 0; return;
} }
nlohmann::json obj = get_whitelist_json_object(); nlohmann::json obj = get_whitelist_json_object();
if (obj == nullptr) if (obj == nullptr)
{ {
return 0; obj = {};
} }
obj.insert(obj.end(), target_ip_to_string(saved_info_response.host)); obj.push_back(target_ip_to_string(saved_info_response.host));
utils::io::write_file_json(get_whitelist_json_path(), obj);
utils::io::write_file(get_whitelist_json_path(), obj.dump(4));
download_files(saved_info_response.host, saved_info_response.info_string, true); download_files(saved_info_response.host, saved_info_response.info_string, true);
return 1;
} }
bool should_user_confirm(const game::netadr_s& target, const utils::info_string& info) bool should_user_confirm(const game::netadr_s& target, const utils::info_string& info)
{ {
nlohmann::json obj = get_whitelist_json_object(); nlohmann::json obj = get_whitelist_json_object();
if (obj == nullptr) if (obj != nullptr)
{ {
return false; const auto target_ip = target_ip_to_string(target);
} for (const auto& [key, value] : obj.items())
const auto target_ip = target_ip_to_string(target);
for (const auto& [key, value] : obj.items())
{
if (value.is_string() && value.get<std::string>() == target_ip)
{ {
return false; if (value.is_string() && value.get<std::string>() == target_ip)
{
return false;
}
} }
} }

View File

@ -19,27 +19,6 @@ namespace utils::io
return std::ifstream(file).good(); return std::ifstream(file).good();
} }
bool write_file_json(const std::string& file, const nlohmann::json& object)
{
const auto pos = file.find_last_of("/\\");
if (pos != std::string::npos)
{
create_directory(file.substr(0, pos));
}
std::ofstream stream(
file, std::ios::binary | std::ofstream::out);
if (stream.is_open())
{
stream << object;
stream.close();
return true;
}
return false;
}
bool write_file(const std::string& file, const std::string& data, const bool append) bool write_file(const std::string& file, const std::string& data, const bool append)
{ {
const auto pos = file.find_last_of("/\\"); const auto pos = file.find_last_of("/\\");

View File

@ -10,7 +10,6 @@ namespace utils::io
bool remove_file(const std::string& file); bool remove_file(const std::string& file);
bool move_file(const std::string& src, const std::string& target); bool move_file(const std::string& src, const std::string& target);
bool file_exists(const std::string& file); bool file_exists(const std::string& file);
bool write_file_json(const std::string& file, const nlohmann::json& object);
bool write_file(const std::string& file, const std::string& data, bool append = false); bool write_file(const std::string& file, const std::string& data, bool append = false);
bool read_file(const std::string& file, std::string* data); bool read_file(const std::string& file, std::string* data);
std::string read_file(const std::string& file); std::string read_file(const std::string& file);