Rewrite plat_init_rom_paths in Qt frontend

This commit is contained in:
David Hrdlička
2022-04-08 00:58:38 +02:00
parent 8e1b14c570
commit a780d9a241
7 changed files with 28 additions and 67 deletions

View File

@@ -28,3 +28,7 @@ target_link_libraries(86Box Threads::Threads)
add_library(ui OBJECT unix_sdl.c unix_cdrom.c)
target_compile_definitions(ui PUBLIC _FILE_OFFSET_BITS=64)
target_link_libraries(ui ${CMAKE_DL_LIBS})
if(APPLE)
target_sources(plat PRIVATE macOSXGlue.m)
endif()

23
src/unix/macOSXGlue.h Normal file
View File

@@ -0,0 +1,23 @@
//
// macOSXGlue.h
// TestSDL
//
// Created by Jerome Vernet on 18/11/2021.
// Copyright © 2021 Jerome Vernet. All rights reserved.
//
#ifndef macOSXGlue_h
#define macOSXGlue_h
#include <CoreFoundation/CFBase.h>
CF_IMPLICIT_BRIDGING_ENABLED
CF_EXTERN_C_BEGIN
void getDefaultROMPath(char*);
int toto();
CF_EXTERN_C_END
CF_IMPLICIT_BRIDGING_DISABLED
#endif /* macOSXGlue_h */

43
src/unix/macOSXGlue.m Normal file
View File

@@ -0,0 +1,43 @@
//
// macOSXGlue.m
// 86BOx MacoSx Glue....
// Todo: so much
// Created by Jerome Vernet on 18/11/2021.
// Copyright © 2021 Jerome Vernet. All rights reserved.
//
#import <Foundation/Foundation.h>
void getDefaultROMPath(char* Path)
{
NSFileManager* sharedFM = [NSFileManager defaultManager];
NSArray* possibleURLs = [sharedFM URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
NSURL* appSupportDir = nil;
NSURL* appDirectory = nil;
if ([possibleURLs count] >= 1) {
// Use the first directory (if multiple are returned)
appSupportDir = [possibleURLs objectAtIndex:0];
}
// If a valid app support directory exists, add the
// app's bundle ID to it to specify the final directory.
if (appSupportDir) {
NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
appDirectory=[appDirectory URLByAppendingPathComponent:@"roms"];
}
// create ~/Library/Application Support/... stuff
NSError* theError = nil;
if (![sharedFM createDirectoryAtURL:appDirectory withIntermediateDirectories:YES
attributes:nil error:&theError])
{
// Handle the error.
NSLog(@"Error creating user library rom path");
} else NSLog(@"Create user rom path sucessfull");
strcpy(Path,[appDirectory fileSystemRepresentation]);
// return appDirectory;
}

View File

@@ -36,6 +36,10 @@
#include <86box/ui.h>
#include <86box/gdbstub.h>
#ifdef __APPLE__
#include "macOSXGlue.h"
#endif
static int first_use = 1;
static uint64_t StartingTime;
static uint64_t Frequency;
@@ -797,12 +801,9 @@ plat_init_rom_paths()
add_rom_path("/usr/share/86Box/roms/");
}
#else
char home_rom_path[1024] = { '\0' };
snprintf(home_rom_path, 1024, "%s/Documents/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir);
plat_dir_create(home_rom_path);
strcat(home_rom_path, "roms/");
plat_dir_create(home_rom_path);
add_rom_path(home_rom_path);
char default_rom_path[1024] = { '\0 '};
getDefaultROMPath(default_rom_path);
add_rom_path(default_rom_path);
#endif
}