From 4a17fe84846303290300e0ffd73df79c78e35d26 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 27 Jun 2024 22:37:36 +0200 Subject: [PATCH 1/3] refactor: use separate dir for amiberry.conf and data under macOS (#1372) Moving the contents of the data folder and amiberry.conf, under /Library/Application Support/Amiberry for macOS platforms --- macos_init_amiberry.zsh | 12 ++++++------ src/osdep/amiberry.cpp | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/macos_init_amiberry.zsh b/macos_init_amiberry.zsh index 6f15f0b5d..c8c62055e 100644 --- a/macos_init_amiberry.zsh +++ b/macos_init_amiberry.zsh @@ -3,17 +3,17 @@ CWD_VAR=$(cd "$(dirname "$0")"; pwd) USERDIR=`echo ~` -if [[ ! -f "$USERDIR/Documents/Amiberry/Configurations/amiberry.conf" ]]; then - cat $CWD_VAR/../Resources/Configurations/amiberry-osx.conf | sed -e "s#USERDIR#$USERDIR#g" > "$USERDIR/Documents/Amiberry/Configurations/amiberry.conf" +if [[ ! -f "$USERDIR/Library/Application Support/Amiberry/amiberry.conf" ]]; then + cat $CWD_VAR/../Resources/Configurations/amiberry-osx.conf | sed -e "s#USERDIR#$USERDIR#g" > "$USERDIR/Library/Application Support/Amiberry/amiberry.conf" fi for file in $CWD_VAR/../Resources/Configurations/**/*(.); do if [[ "$file" != "$CWD_VAR/../Resources/Configurations/amiberry-osx.conf" ]]; then if [[ "$file" != "$CWD_VAR/../Resources/Configurations/amiberry.conf" ]]; then - if [[ ! -f "$USERDIR/Documents/Amiberry/Configurations${file##*/Configurations}" ]]; then - echo "Copying $file to $USERDIR/Documents/Amiberry/Configurations${file##*/Configurations}" - mkdir -p $(dirname "$USERDIR/Documents/Amiberry/Configurations${file##*/Configurations}") - cp $file "$USERDIR/Documents/Amiberry/Configurations${file##*/Configurations}" + if [[ ! -f "$USERDIR/Library/Application Support/Amiberry${file##*/Configurations}" ]]; then + echo "Copying $file to $USERDIR/Library/Application Support/Amiberry${file##*/Configurations}" + mkdir -p $(dirname "$USERDIR/Library/Application Support/Amiberry${file##*/Configurations}") + cp $file "$USERDIR/Library/Application Support/Amiberry${file##*/Configurations}" fi fi fi diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index 4f9ab1999..36ef7b518 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -3910,14 +3910,6 @@ void init_macos_amiberry_folders(const std::string& macos_amiberry_directory) if (!my_existsdir(directory.c_str())) my_mkdir(directory.c_str()); - directory = macos_amiberry_directory + "/Data"; - if (!my_existsdir(directory.c_str())) - my_mkdir(directory.c_str()); - - directory = macos_amiberry_directory + "/Data/floppy_sounds"; - if (!my_existsdir(directory.c_str())) - my_mkdir(directory.c_str()); - directory = macos_amiberry_directory + "/Savestates"; if (!my_existsdir(directory.c_str())) my_mkdir(directory.c_str()); @@ -3935,6 +3927,16 @@ void init_macos_amiberry_folders(const std::string& macos_amiberry_directory) my_mkdir(directory.c_str()); } +void init_macos_library_folders(const std::string& macos_amiberry_directory) +{ + if (!my_existsdir(macos_amiberry_directory.c_str())) + my_mkdir(macos_amiberry_directory.c_str()); + + std::string directory = macos_amiberry_directory + "/floppy_sounds"; + if (!my_existsdir(directory.c_str())) + my_mkdir(directory.c_str()); +} + #ifdef __MACH__ #include void macos_copy_amiberry_files_to_userdir(std::string macos_amiberry_directory) @@ -3965,22 +3967,30 @@ static void init_amiberry_paths(void) { current_dir = start_path_data; #ifdef __MACH__ - // MacOS stores these files under the user Documents/Amiberry folder + // On MacOS, we these files under the user Documents/Amiberry folder by default + // If the folder is missing, we create it and copy the files from the app bundle + // The exception is the Data folder and amiberry.conf, which live in the user Library/Application Support/Amiberry folder const std::string macos_home_directory = getenv("HOME"); + const std::string macos_library_directory = macos_home_directory + "/Library/Application Support/Amiberry"; const std::string macos_amiberry_directory = macos_home_directory + "/Documents/Amiberry"; - if (!my_existsdir(macos_amiberry_directory.c_str())) + + if (!my_existsdir(macos_amiberry_directory.c_str()) || !my_existsdir(macos_library_directory.c_str())) { - // Amiberry home dir is missing, generate it and all directories under it + //If Amiberry library dir is missing, generate it + init_macos_library_folders(macos_library_directory); + + // If Amiberry home dir is missing, generate it and all directories under it init_macos_amiberry_folders(macos_amiberry_directory); macos_copy_amiberry_files_to_userdir(macos_amiberry_directory); } - config_path = controllers_path = data_dir = whdboot_path = whdload_arch_path = floppy_path = harddrive_path = cdrom_path = + + config_path = controllers_path = whdboot_path = whdload_arch_path = floppy_path = harddrive_path = cdrom_path = logfile_path = rom_path = rp9_path = saveimage_dir = savestate_dir = ripper_path = input_dir = screenshot_dir = nvram_dir = plugins_dir = video_dir = macos_amiberry_directory; config_path.append("/Configurations/"); controllers_path.append("/Controllers/"); - data_dir.append("/Data/"); + data_dir = macos_library_directory; whdboot_path.append("/Whdboot/"); whdload_arch_path.append("/Lha/"); floppy_path.append("/Floppies/"); @@ -3997,6 +4007,8 @@ static void init_amiberry_paths(void) nvram_dir.append("/Nvram/"); plugins_dir.append("/Plugins/"); video_dir.append("/Videos/"); + + amiberry_conf_file = data_dir; #else config_path = controllers_path = data_dir = whdboot_path = whdload_arch_path = floppy_path = harddrive_path = cdrom_path = logfile_path = rom_path = rp9_path = saveimage_dir = savestate_dir = ripper_path = @@ -4022,8 +4034,9 @@ static void init_amiberry_paths(void) nvram_dir.append("/nvram/"); plugins_dir.append("/plugins/"); video_dir.append("/videos/"); -#endif + amiberry_conf_file = config_path; +#endif amiberry_conf_file.append("amiberry.conf"); retroarch_file = config_path; From 7951eaecb0040cf6ef966d2db215e5a3278258bf Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 27 Jun 2024 22:47:22 +0200 Subject: [PATCH 2/3] fix path trailing slash was missing --- src/osdep/amiberry.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index 36ef7b518..9379440e4 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -3990,7 +3990,7 @@ static void init_amiberry_paths(void) config_path.append("/Configurations/"); controllers_path.append("/Controllers/"); - data_dir = macos_library_directory; + data_dir = macos_library_directory.append("/"); whdboot_path.append("/Whdboot/"); whdload_arch_path.append("/Lha/"); floppy_path.append("/Floppies/"); @@ -4009,6 +4009,7 @@ static void init_amiberry_paths(void) video_dir.append("/Videos/"); amiberry_conf_file = data_dir; + amiberry_conf_file.append("amiberry.conf"); #else config_path = controllers_path = data_dir = whdboot_path = whdload_arch_path = floppy_path = harddrive_path = cdrom_path = logfile_path = rom_path = rp9_path = saveimage_dir = savestate_dir = ripper_path = @@ -4036,8 +4037,8 @@ static void init_amiberry_paths(void) video_dir.append("/videos/"); amiberry_conf_file = config_path; -#endif amiberry_conf_file.append("amiberry.conf"); +#endif retroarch_file = config_path; retroarch_file.append("retroarch.cfg"); From 6cb7b632967ba18624c1d7da4f5ed7037fdcc84d Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 27 Jun 2024 22:48:50 +0200 Subject: [PATCH 3/3] actually fix the trailing slash --- src/osdep/amiberry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index 9379440e4..04ed38647 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -3990,7 +3990,8 @@ static void init_amiberry_paths(void) config_path.append("/Configurations/"); controllers_path.append("/Controllers/"); - data_dir = macos_library_directory.append("/"); + data_dir = macos_library_directory; + data_dir.append("/"); whdboot_path.append("/Whdboot/"); whdload_arch_path.append("/Lha/"); floppy_path.append("/Floppies/");