mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-22 15:14:49 -04:00
compile and run in windows (improvements needed)
This commit is contained in:
parent
f55f92a88b
commit
f70b29abab
83 changed files with 415 additions and 3747 deletions
73
platform/windows/app_start.cpp
Normal file
73
platform/windows/app_start.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "../../game/skeldal.h"
|
||||
#include "../getopt.h"
|
||||
#include "../platform.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void show_help(const char *arg0) {
|
||||
printf(
|
||||
"Brany Skeldalu (Gates of Skeldal) portable game player\n"
|
||||
"Copyright (c) 2025 Ondrej Novak. All rights reserved.\n\n"
|
||||
"This work is licensed under the terms of the MIT license.\n"
|
||||
"For a copy, see <https://opensource.org/licenses/MIT>.\n"
|
||||
"\n"
|
||||
"Usage:"
|
||||
);
|
||||
printf("%s [-f <file>] [-a <file>] [-l <lang>] [-s <dir>] [-h]\n\n", arg0);
|
||||
|
||||
printf("-f <file> path to configuration file\n"
|
||||
"-a <adv> path for adventure file (.adv)\n"
|
||||
"-l <lang> set language (cz|en)"
|
||||
"-s <directory> generate string-tables (for localization) and exit\n"
|
||||
"-h this help\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void show_help_short() {
|
||||
printf("Use -h for help\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string config_name = SKELDALINI;
|
||||
std::string adv_config_file;
|
||||
std::string gen_stringtable_path;
|
||||
std::string lang;
|
||||
for (int optchr = -1; (optchr = getopt(argc, argv, "hf:a:s:l:")) != -1; ) {
|
||||
switch (optchr) {
|
||||
case 'f': config_name = optarg;break;
|
||||
case 'a': adv_config_file = optarg;break;
|
||||
case 'h': show_help(argv[0]);break;
|
||||
case 'l': lang = optarg;break;
|
||||
case 's': gen_stringtable_path = optarg;break;
|
||||
default: show_help_short();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKELDAL_CONFIG cfg;
|
||||
cfg.short_help = show_help_short;
|
||||
cfg.show_error = [](const char *txt) {
|
||||
std::cerr << "ERROR: " << txt << std::endl;
|
||||
};
|
||||
cfg.adventure_path = adv_config_file.empty()?NULL:adv_config_file.c_str();
|
||||
cfg.config_path = config_name.c_str();
|
||||
cfg.lang_path = lang.empty()?NULL:lang.c_str();
|
||||
try {
|
||||
|
||||
if (!gen_stringtable_path.empty()) {
|
||||
skeldal_gen_string_table_entry_point(&cfg, gen_stringtable_path.c_str());
|
||||
return 0;
|
||||
} else {
|
||||
return skeldal_entry_point(&cfg);
|
||||
}
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
55
platform/windows/map_file.cpp
Normal file
55
platform/windows/map_file.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
|
||||
extern "C" {
|
||||
#include "map_file.h"
|
||||
}
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdexcept>
|
||||
|
||||
// Funkce pro mapování souboru do paměti
|
||||
void* map_file_to_memory_cpp(const char *name, size_t *sz) {
|
||||
if (!name || !sz) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANDLE h = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) throw std::runtime_error(std::string("Failed to open file for mapping: ").append(name));
|
||||
|
||||
LARGE_INTEGER fsize;
|
||||
if (!GetFileSizeEx(h, &fsize)) {
|
||||
CloseHandle(h);
|
||||
throw std::runtime_error(std::string("failed to get size of file:").append(name));
|
||||
}
|
||||
|
||||
|
||||
|
||||
HANDLE hMapping = CreateFileMapping(h,NULL,PAGE_READONLY,0,0,NULL);
|
||||
if (hMapping == NULL || hMapping == INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(h);
|
||||
throw std::runtime_error(std::string("Failed to create mapping of file:").append(name));
|
||||
}
|
||||
|
||||
void *mappedData = MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0);
|
||||
CloseHandle(h);
|
||||
CloseHandle(hMapping);
|
||||
if (mappedData == NULL) {
|
||||
throw std::runtime_error(std::string("Failed to map file:").append(name));
|
||||
}
|
||||
|
||||
*sz = fsize.LowPart;
|
||||
return mappedData;
|
||||
}
|
||||
|
||||
void* map_file_to_memory(const char *name, size_t *sz) {
|
||||
return map_file_to_memory_cpp(name, sz);
|
||||
}
|
||||
|
||||
// Funkce pro zrušení mapování
|
||||
void unmap_file(void *ptr, size_t) {
|
||||
UnmapViewOfFile(ptr);
|
||||
}
|
4
platform/windows/map_file.h
Normal file
4
platform/windows/map_file.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
void *map_file_to_memory(const char *name, size_t *sz);
|
||||
void unmap_file(void *ptr, size_t sz);
|
|
@ -1,23 +1,22 @@
|
|||
#include "../platform.h"
|
||||
#include "../save_folder.h"
|
||||
#include "../error.h"
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <windows.h>
|
||||
#include <ShlObj.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))) {
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SavedGames, 0, NULL, &path))) {
|
||||
fs::path savedGamesPath(path);
|
||||
CoTaskMemFree(path); // Uvolnění paměti
|
||||
return savedGamesPath / SAVEGAME_FOLDERNAME
|
||||
CoTaskMemFree(path);
|
||||
return (savedGamesPath / SAVEGAME_FOLDERNAME).string();
|
||||
} else {
|
||||
display_error("Failed to retrieve FOLDEROD_SavedGames");
|
||||
abort();
|
||||
|
@ -25,7 +24,7 @@ std::string getSavedGamesDirectory() {
|
|||
}
|
||||
const char *get_default_savegame_directory() {
|
||||
|
||||
static std::string dir = get_default_savgetSavedGamesDirectoryegame_dir();
|
||||
static std::string dir = getSavedGamesDirectory();
|
||||
return dir.c_str();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue