Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macos folder changes #1373

Merged
merged 3 commits into from
Jun 27, 2024
Merged
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
12 changes: 6 additions & 6 deletions macos_init_amiberry.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 29 additions & 14 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 <mach-o/dyld.h>
void macos_copy_amiberry_files_to_userdir(std::string macos_amiberry_directory)
Expand Down Expand Up @@ -3965,22 +3967,31 @@ 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;
data_dir.append("/");
whdboot_path.append("/Whdboot/");
whdload_arch_path.append("/Lha/");
floppy_path.append("/Floppies/");
Expand All @@ -3997,6 +4008,9 @@ static void init_amiberry_paths(void)
nvram_dir.append("/Nvram/");
plugins_dir.append("/Plugins/");
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 =
Expand All @@ -4022,9 +4036,10 @@ static void init_amiberry_paths(void)
nvram_dir.append("/nvram/");
plugins_dir.append("/plugins/");
video_dir.append("/videos/");
#endif

amiberry_conf_file = config_path;
amiberry_conf_file.append("amiberry.conf");
#endif

retroarch_file = config_path;
retroarch_file.append("retroarch.cfg");
Expand Down