Skip to content

Commit

Permalink
Test DyKnow folder size on program start
Browse files Browse the repository at this point in the history
  • Loading branch information
eschan145 committed Jan 22, 2025
1 parent 727cfe8 commit f10486e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ extern "C" {
}
}

DK_API uint64_t get_dyknow_size(const std::string& directory) {
uint64_t total = 0;
WIN32_FIND_DATAA data;
HANDLE find = FindFirstFile((directory + "\\*").c_str(), &data);

if (find = INVALID_HANDLE_VALUE) {
error("Failed to access DyKnow folder! Validating...\n");
validate();
return 0;
}

do {
std::string filename = data.cFileName;

if ((filename == ".") || (filename == "..")) {
continue;
}

std::string full_path = FOLDER_PATH + "\\" + filename;

if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// If it's a directory, recursively calculate its size
total += get_dyknow_size(directory);
} else {
LARGE_INTEGER file_size;

file_size.LowPart = data.nFileSizeLow;
file_size.HighPart = data.nFileSizeHigh;
total += file_size.QuadPart;
}
} while (FindNextFileA(find, &data) != 0);

FindClose(find);
}

DK_API void validate() {
/*
Check for the validity of the DyKnow installation. If the DyKnow
Expand Down Expand Up @@ -133,6 +168,9 @@ DK_API void validate() {
std::cout << "Successfully validated DyKnow installation and file "
<< "integrity.\n";
}

uint64_t size = get_dyknow_size();
std::cout << "DyKnow folder size: " << size << "\n";
}

bool exists(const char* path) {
Expand Down
3 changes: 3 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ extern "C" {
DK_API int get_kill_method();
DK_API void set_kill_method(int value);

DK_API uint64_t get_dyknow_size(const std::string& directory = FOLDER_PATH);

DK_API void validate();
DK_API const char* get_folder_path();

DK_API void start_monitoring(const char* folder_path = FOLDER_PATH);
DK_API void stop_monitoring();
DK_API int monitor_executables(int interval);
Expand Down

0 comments on commit f10486e

Please sign in to comment.