Sync with KoalaBox

This commit is contained in:
acidicoala
2025-09-19 02:14:17 +05:00
parent 3544436df7
commit a7b95fc907
16 changed files with 366 additions and 556 deletions

View File

@@ -1,8 +1,5 @@
#include <filesystem>
#include <iostream>
#include <random>
#include <regex>
#include <string>
#include <koalabox/http_client.hpp>
#include <koalabox/logger.hpp>
@@ -33,12 +30,13 @@ namespace {
}
void print_help() {
std::cout << "Steamworks SDK downloader for SmokeAPI v1.0" << std::endl
<< "Usage: steamworks_downloader version1 version2 ... versionN" << std::endl
<< "Example: steamworks_downloader 100 158a 162" << std::endl
<< "Alternative usage: steamworks_downloader C:/path/to/downloaded_sdk/"
<< "SDK version list available at: "
<< "https://partner.steamgames.com/downloads/list" << std::endl;
LOG_INFO(
"Steamworks SDK downloader for SmokeAPI v1.0\n"
"Usage: steamworks_downloader version1 version2 ... versionN\n"
"Example: steamworks_downloader 100 158a 162\n"
"Alternative usage: steamworks_downloader C:/path/to/downloaded_sdk/\n"
"SDK version list available at: https://partner.steamgames.com/downloads/list"
);
}
void unzip_sdk(const fs::path& zip_file_path, const fs::path& unzip_dir) {
@@ -62,7 +60,7 @@ namespace {
if(
name.starts_with("sdk/redistributable_bin/linux") &&
name.ends_with("libsteam_api.so")
) {
) {
return unzip_dir / "binaries" / name.substr(name.find("linux"));
}
@@ -85,7 +83,7 @@ namespace {
const auto unzip_dir = steamworks_dir / version;
unzip_sdk(zip_file_path, unzip_dir);
} catch(std::exception& e) {
std::cerr << "Unzip error: " << e.what() << std::endl;
LOG_ERROR("Unzip error: {}", e.what());
}
fs::remove(zip_file_path);
@@ -97,6 +95,8 @@ namespace {
* for further processing by other tools.
*/
int MAIN(const int argc, const TCHAR* argv[]) { // NOLINT(*-use-internal-linkage)
kb::logger::init_console_logger();
if(argc == 1) {
print_help();
return 0;

View File

@@ -1,8 +1,5 @@
#include <chrono>
#include <deque>
#include <filesystem>
#include <fstream>
#include <functional>
#include <set>
#include <BS_thread_pool.hpp>
@@ -131,7 +128,7 @@ namespace {
/**
* Certain Steam macros break C++ AST parser, if left unprocessed.
* This function does that in a very naive manner. Stupid, but works.
* This function preprocesses them in a very naive manner. Stupid, but works.
*/
std::string manually_preprocess_header(const fs::path& header_path) {
const auto header_contents = kb::io::read_file(header_path);
@@ -143,11 +140,7 @@ namespace {
return processed_contents;
}
void parse_sdk(
const fs::path& sdk_path,
nlohmann::ordered_json& lookup,
BS::thread_pool<>& pool
) {
void parse_sdk(const fs::path& sdk_path, nlohmann::ordered_json& lookup, BS::thread_pool<>& pool) {
const auto headers_dir = sdk_path / "headers\\steam";
const auto headers_dir_str = kb::path::to_str(headers_dir);
@@ -161,7 +154,8 @@ namespace {
// Go over each file in headers directory
for(const auto& entry : fs::directory_iterator(headers_dir)) {
if(const auto& header_path = entry.path(); header_path.extension() == ".h") {
const auto task = pool.submit_task( // NOLINT(*-unused-local-non-trivial-variable)
const auto task = pool.submit_task(
// NOLINT(*-unused-local-non-trivial-variable)
[&, header_path] {
try {
LOG_DEBUG("Parsing header: {}", kb::path::to_str(header_path));
@@ -178,11 +172,9 @@ namespace {
}
}
void generate_lookup_json(
const fs::path& steamworks_dir,
//
const std::set<std::string>& sdk_filter
) {
void generate_lookup_json(const fs::path& steamworks_dir, const std::set<std::string>& sdk_filter) {
// Ideally the top level lookup should be unordered json (i.e. keys sorted alphabetically).
// But the library doesn't support inserting ordered_json instances as values in json objects.
nlohmann::ordered_json lookup;
// The thread pool noticeably speeds up the overall parsing.