diff --git a/src/options.c b/src/options.c index bae9870c..be035707 100644 --- a/src/options.c +++ b/src/options.c @@ -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); diff --git a/src/replay.c b/src/replay.c index 38a36a46..995279ab 100644 --- a/src/replay.c +++ b/src/replay.c @@ -801,6 +801,16 @@ 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); @@ -808,7 +818,11 @@ int save_recorded_replay_dialog() { #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?? diff --git a/src/screenshot.c b/src/screenshot.c index a3bb596a..537a6907 100644 --- a/src/screenshot.c +++ b/src/screenshot.c @@ -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. diff --git a/src/seg000.c b/src/seg000.c index 17a24718..8e70d346 100644 --- a/src/seg000.c +++ b/src/seg000.c @@ -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; }