1#include "Logger/Logger.h"
2#include "..\Private\IBaseApi.h"
3#include "..\Private\Ark\ArkBaseApi.h"
13 const DWORD InvalidParentProcessId = 0;
16 PROCESSENTRY32 ProcessEntry;
17 DWORD PID = GetCurrentProcessId();
19 Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
20 if (Snapshot == INVALID_HANDLE_VALUE)
21 return InvalidParentProcessId;
23 ZeroMemory(&ProcessEntry,
sizeof(ProcessEntry));
24 ProcessEntry.dwSize =
sizeof(ProcessEntry);
26 if (!Process32First(Snapshot, &ProcessEntry))
27 return InvalidParentProcessId;
31 if (ProcessEntry.th32ProcessID == PID)
32 return ProcessEntry.th32ParentProcessID;
33 }
while (Process32Next(Snapshot, &ProcessEntry));
35 return InvalidParentProcessId;
40 const std::string config_path = AsaApi::Tools::GetCurrentDir() +
"/config.json";
41 std::ifstream file{ config_path };
45 nlohmann::json config;
49 return config[
"settings"].value(
"AttachToParent",
true);
56 if (GetConsoleWindow())
58 if (attachToParent && parentProcessId && AttachConsole(parentProcessId))
62 freopen_s(&p_cout,
"conout$",
"w", stdout);
63 SetConsoleOutputCP(CP_UTF8);
68 const std::string config_path = AsaApi::Tools::GetCurrentDir() +
"/config.json";
69 std::ifstream file{ config_path };
73 nlohmann::json config;
77 if (config.value(
"DeleteOldLogs", nlohmann::json::object()).value(
"Enabled",
false) ==
false)
80 const std::string folderPath = API::Tools::GetCurrentDir() +
"\\logs";
81 const int maxAgeInSeconds = config.value(
"DeleteOldLogs", nlohmann::json::object()).value(
"MaxAge", 24) * 3600;
83 for (
const auto& entry : std::filesystem::directory_iterator(folderPath)) {
84 if (entry.is_regular_file()) {
87 std::filesystem::file_time_type file_time = std::filesystem::last_write_time(entry);
88 auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(file_time - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now());
89 std::time_t tt = std::chrono::system_clock::to_time_t(sctp);
91 if (std::difftime(std::time(
nullptr), tt) > maxAgeInSeconds) {
92 Log::GetLog()->info(
"Deleted log file: {}", entry.path().filename().string());
94 std::filesystem::remove(entry.path());
97 catch (std::exception& error)
99 Log::GetLog()->error(
"Error: {}", error.what());
108 namespace fs = std::filesystem;
112 const std::string current_dir = API::Tools::GetCurrentDir();
114 if (!fs::exists(current_dir +
"/logs"))
116 fs::create_directory(current_dir +
"/logs");
123 API::game_api = std::make_unique<API::ArkBaseApi>();
124 API::game_api->Init();
DWORD GetParentProcessId()