Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,17 @@ static int global_ini_callback(const char *section, const char *name, const char
#ifdef USE_MENU
process_boolean("enable_pause_menu", &enable_pause_menu);
#endif
if (strcasecmp(name, "mods_folder") == 0) {
if (value[0] != '\0' && strcasecmp(value, "default") != 0) {
snprintf_check(mods_folder, sizeof(mods_folder), "%s", locate_file(value));
if (strcasecmp(name, "mods_folder") == 0) {
if (value[0] != '\0' && strcasecmp(value, "default") != 0) {
const char* home_path = getenv("HOME");
if (home_path != NULL && home_path[0] != '\0') {
snprintf_check(mods_folder, sizeof(mods_folder), "%s/prince/mods/%s", home_path, value);
} else {
snprintf_check(mods_folder, sizeof(mods_folder), "./prince/mods/%s", value);
}
return 1;
}
return 1;
}
process_boolean("enable_copyprot", &enable_copyprot);
process_boolean("enable_music", &enable_music);
process_boolean("enable_fade", &enable_fade);
Expand Down
16 changes: 15 additions & 1 deletion src/replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,28 @@ int save_recorded_replay_dialog() {
return 0; // Escape was pressed -> discard the replay
}

// Получаем домашнюю директорию текущего пользователя для replays
const char *home_dir = getenv("HOME");
if (home_dir == NULL) {
home_dir = "."; // fallback на текущую директорию
}

// Создаём путь к папке replays внутри prince
char replays_folder[POP_MAX_PATH];
snprintf_check(replays_folder, sizeof(replays_folder), "%s/prince/replays", home_dir);

char full_filename[POP_MAX_PATH] = "";
snprintf_check(full_filename, sizeof(full_filename), "%s/%s.p1r", replays_folder, input_filename);

// create the "replays" folder if it does not exist already
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (replays_folder);
#else
mkdir (replays_folder, 0700);
// Создаём промежуточные папки если их нет
char prince_dir[POP_MAX_PATH];
snprintf_check(prince_dir, sizeof(prince_dir), "%s/prince", home_dir);
mkdir(prince_dir, 0700); // Создаём папку prince
mkdir(replays_folder, 0700); // Создаём папку replays
#endif

// NOTE: We currently overwrite the replay file if it exists already. Maybe warn / ask for confirmation??
Expand Down
37 changes: 23 additions & 14 deletions src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,37 @@ The authors of this program may be contacted at https://forum.princed.org

#ifdef USE_SCREENSHOT

char screenshots_folder[POP_MAX_PATH] = "screenshots";
char screenshots_folder[POP_MAX_PATH];
char screenshot_filename[POP_MAX_PATH] = "screenshot.png";
int screenshot_index = 0;

// Use incrementing numbers and a separate folder, like DOSBox.
void make_screenshot_filename(void) {
// Create the screenshots directory in SDLPoP's directory, even if the current directory is something else.
snprintf_check(screenshots_folder, sizeof(screenshots_folder), "%s", locate_file("screenshots"));
// Create the folder if it doesn't exist yet:
const char *home_dir = getenv("HOME");
if (home_dir == NULL) {
home_dir = ".";
}

snprintf_check(screenshots_folder, sizeof(screenshots_folder), "%s/prince/screenshots", home_dir);

// Create the folder if it doesn't exist yet:
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (screenshots_folder);
mkdir (screenshots_folder);
#else
mkdir (screenshots_folder, 0700);
char prince_path[POP_MAX_PATH];
snprintf_check(prince_path, sizeof(prince_path), "%s/prince", home_dir);
mkdir(prince_path, 0700);
mkdir(screenshots_folder, 0700);
#endif
// Find the first unused filename:
for (;;) {
snprintf_check(screenshot_filename, sizeof(screenshot_filename), "%s/screenshot_%03d.png", screenshots_folder, screenshot_index);
if (! file_exists(screenshot_filename)) {
return;
}
screenshot_index++;
}

// Find the first unused filename:
for (;;) {
snprintf_check(screenshot_filename, sizeof(screenshot_filename), "%s/screenshot_%03d.png", screenshots_folder, screenshot_index);
if (! file_exists(screenshot_filename)) {
return;
}
screenshot_index++;
}
}

#define EVENT_OFFSET 0 // Add this number to displayed event numbers. Use 1 for Apoplexy compatibility.
Expand Down
58 changes: 24 additions & 34 deletions src/seg000.c
Original file line number Diff line number Diff line change
Expand Up @@ -2461,46 +2461,36 @@ void show_splash() {
}

const char* get_writable_file_path(char* custom_path_buffer, size_t max_len, const char* file_name) {
// If the SDLPOP_SAVE_PATH environment variable is set, put all saves into the directory it points to.
// Otherwise, save to the home directory
// Используем домашнюю папку текущего пользователя Linux
const char* home_path = getenv("HOME");
if (home_path == NULL || home_path[0] == '\0') {
// Если HOME не установлен, используем текущую директорию
home_path = ".";
}

// Путь для сохранений: домашняя_папка/prince
char save_path[POP_MAX_PATH];
snprintf_check(save_path, max_len, "%s/prince", home_path);

// Создаем директорию, если она не существует
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
const char* save_path = getenv("SDLPOP_SAVE_PATH");
mkdir(save_path);
#else
char save_path[POP_MAX_PATH];
const char* custom_save_path = getenv("SDLPOP_SAVE_PATH");
const char* home_path = getenv("HOME");
if (custom_save_path != NULL && custom_save_path[0] != '\0')
snprintf_check(save_path, max_len, "%s", custom_save_path);
else if (home_path != NULL && home_path[0] != '\0')
snprintf_check(save_path, max_len, "%s/.%s", home_path, POP_DIR_NAME);
mkdir(save_path, 0700);
#endif

if (save_path != NULL && save_path[0] != '\0') {
if (use_custom_levelset) {
// Сначала создаем поддиректорию для набора уровней...
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, levelset_name);
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (save_path);
mkdir(custom_path_buffer);
#else
mkdir (save_path, 0700);
mkdir(custom_path_buffer, 0700);
#endif
if (use_custom_levelset) {
// First create the directory...
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, levelset_name);
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (custom_path_buffer);
#else
mkdir (custom_path_buffer, 0700);
#endif
snprintf_check(custom_path_buffer, max_len, "%s/%s/%s", save_path, levelset_name, file_name);
} else {
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, file_name);
}
return custom_path_buffer;
}

if (!use_custom_levelset) {
return file_name;
}
// if playing a custom levelset, try to use the mod folder
snprintf_check(custom_path_buffer, max_len, "%s/%s", mod_data_path, file_name);
return custom_path_buffer;
snprintf_check(custom_path_buffer, max_len, "%s/%s/%s", save_path, levelset_name, file_name);
} else {
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, file_name);
}
return custom_path_buffer;
}