import ADV settings, platform files

This commit is contained in:
Ondřej Novák 2025-01-30 20:43:42 +01:00
parent 9b86bed2d8
commit ccebc91f0d
17 changed files with 244 additions and 14 deletions

View file

@ -1,14 +1,48 @@
SET(files error.cpp
)
# Základní knihovna mylib
add_library(skeldal_platform STATIC)
# Přidejte soubory společné pro všechny platformy
target_sources(skeldal_platform PRIVATE
legacy_coroutines.cpp
platform.cpp
int2ascii.c
istr.c
file_access.cpp
config.cpp
error.cpp
timer.cpp
)
add_library(skeldal_platform_libs ${files})
set_property(TARGET skeldal_platform_libs PROPERTY CXX_STANDARD 20)
# Podmínky pro platformu Windows
if(WIN32)
target_sources(skeldal_platform PRIVATE
windows/save_folder.cpp
)
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_WINDOWS)
message(STATUS "Building for Windows")
# Podmínky pro platformu Linux
elseif(UNIX AND NOT APPLE)
target_sources(skeldal_platform PRIVATE
linux/save_folder.cpp
linux/map_file.cpp
)
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_LINUX)
message(STATUS "Building for Linux")
# Podmínky pro platformu macOS
elseif(APPLE)
target_sources(skeldal_platform PRIVATE
mac_os/save_folder.cpp
)
target_compile_definitions(mylib PRIVATE PLATFORM_MACOS)
message(STATUS "Building for macOS")
else()
error("Platform not detected, please add new platform here")
endif()
set_property(TARGET skeldal_platform PROPERTY CXX_STANDARD 20)
add_subdirectory(sdl)
add_subdirectory(linux)

View file

@ -1,6 +1,7 @@
#include "config.h"
#include "platform.h"
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <string_view>
@ -50,7 +51,7 @@ void parseIniStream(std::istream& input, Callback &&callback) {
}
const INI_CONFIG* ini_open(const char *filename) {
INI_CONFIG* ini_open(const char *filename) {
INI_CONFIG *c = new INI_CONFIG;
std::fstream input(filename);
@ -168,3 +169,28 @@ int ini_get_boolean(const INI_CONFIG_SECTION *section, const char *key,
}
return defval;
}
void ini_replace_key( INI_CONFIG_SECTION *section, const char *key, const char *value) {
auto s = reinterpret_cast<INI_CONFIG::Section *>(section);
(*s)[std::string(key)] = std::string(value);
}
INI_CONFIG_SECTION* ini_create_section(INI_CONFIG *cfg, const char *section_name) {
auto &sect = cfg->data[std::string(section_name)];
return reinterpret_cast<INI_CONFIG_SECTION *>(&sect);
}
INI_CONFIG* ini_create_empty(void) {
INI_CONFIG *c = new INI_CONFIG;
return c;
}
void ini_store_to_file(const INI_CONFIG *config, const char *filename) {
std::ofstream out(filename,std::ios::out|std::ios::trunc);
for (const auto &[sname, s]: config->data) {
out << '[' << sname << ']' << std::endl;
for (const auto &[k,v]: s) {
out << k << '=' << v << std::endl;
}
}
}

View file

@ -7,9 +7,9 @@ typedef struct ini_config_tag INI_CONFIG;
typedef struct ini_config_section_tag INI_CONFIG_SECTION;
///Opens config, returns handle
const INI_CONFIG *ini_open(const char *filename);
INI_CONFIG *ini_open(const char *filename);
///closes the config and frees memory
void ini_close(const INI_CONFIG *config);
void ini_close(INI_CONFIG *config);
///Opens section
/**
@ -54,6 +54,15 @@ double ini_get_value_double(const char *value, int *conv_ok);
*/
int ini_get_value_boolean(const char *value);
INI_CONFIG_SECTION* ini_create_section(INI_CONFIG *cfg, const char *section_name);
INI_CONFIG *ini_create_empty(void);
void ini_store_to_file(const INI_CONFIG *cfg, const char *filename);
///Replace existing key with different value
void ini_replace_key(INI_CONFIG_SECTION *section, const char *key, const char *value);
///retrieve string from ini
/**

View file

@ -9,9 +9,8 @@ extern "C" {
void display_error(const char *text) {
char failed_because_error = 0;
std::cerr << "ERROR:" << text << std::endl;
assert(failed_because_error);
abort();
}

View file

@ -1,2 +0,0 @@
add_library(skeldal_linux map_file.cpp timer.cpp)

View file

@ -0,0 +1,25 @@
#include "../save_folder.h"
#include "../error.h"
#include <filesystem>
static std::string get_default_savegame_dir() {
// Linux
char* home = std::getenv("HOME");
if (home) {
return std::filesystem::path(home) / ".local/share/" SAVEGAME_FOLDERNAME;
} else {
display_error("$HOME has no value (user with no home)");
abort();
}
}
const char *get_default_savegame_directory() {
static std::string dir = get_default_savegame_dir();
return dir.c_str();
}

View file

@ -0,0 +1,25 @@
#include "../save_folder.h"
#include "../error.h"
#include <filesystem>
static std::string get_default_savegame_dir() {
// Linux
char* home = std::getenv("HOME");
if (home) {
return std::filesystem::path(home) / ".local/share/" SAVEGAME_FOLDERNAME;
} else {
display_error("$HOME has no value (user with no home)");
abort();
}
}
const char *get_default_savegame_directory() {
static std::string dir = get_default_savegame_dir();
return dir.c_str();
}

1
platform/mac_os/todo.txt Normal file
View file

@ -0,0 +1 @@
Platform files are not complete

11
platform/save_folder.h Normal file
View file

@ -0,0 +1,11 @@
#ifdef __cplusplus__
extern "C" {
#endif
#define SAVEGAME_FOLDERNAME "Skeldal";
const char *get_default_savegame_directory();
#ifdef __cplusplus__
}
#endif

View file

@ -1,6 +1,6 @@
#include "timer.h"
#include <chrono>
#include "../platform.h"
#include "platform.h"
#include <thread>
int get_timer_value() {

View file

@ -0,0 +1,31 @@
#include "../save_folder.h"
#include "../error.h"
#include <iostream>
#include <filesystem>
#include <windows.h>
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "ole32.lib")
// Pro získání uživatelské složky
namespace fs = std::filesystem;
// Funkce pro získání složky "Saved Games"
std::string getSavedGamesDirectory() {
PWSTR path = nullptr;
// Použití identifikátoru složky FOLDERID_SavedGames
if (SUCCEEDED(SHGetKnownFolderPathA(FOLDERID_SavedGames, 0, NULL, &path))) {
fs::path savedGamesPath(path);
CoTaskMemFree(path); // Uvolnění paměti
return savedGamesPath / SAVEGAME_FOLDERNAME
} else {
display_error("Failed to retrieve FOLDEROD_SavedGames");
abort();
}
}
const char *get_default_savegame_directory() {
static std::string dir = get_default_savgetSavedGamesDirectoryegame_dir();
return dir.c_str();
}

View file

@ -0,0 +1 @@
Platform files are not complete