Back up retroarch.cfg to NSUserDefaults on tvOS.

This commit is contained in:
Eric Warmenhoven 2023-05-11 22:30:06 -04:00 committed by LibretroAdmin
parent d5a86e2363
commit 7242600a0b
3 changed files with 48 additions and 0 deletions

View File

@ -65,6 +65,10 @@
#include "switch_performance_profiles.h"
#endif
#if TARGET_OS_TV
#include "ui/drivers/cocoa/apple_platform.h"
#endif
enum video_driver_enum
{
VIDEO_GL = 0,
@ -3355,6 +3359,16 @@ static bool config_load_file(global_t *global,
conf = (path) ? config_file_new_from_path_to_string(path) : open_default_config_file();
#if TARGET_OS_TV
if (!conf && path && string_is_equal(path, path_get(RARCH_PATH_CONFIG)))
{
/* Sometimes the OS decides it needs to reclaim disk space
* by emptying the cache, which is the only disk space we
* have access to, other than NSUserDefaults. */
conf = open_userdefaults_config_file();
}
#endif
if (!conf)
{
first_load = false;
@ -5074,6 +5088,11 @@ bool config_save_file(const char *path)
ret = config_file_write(conf, path, true);
config_file_free(conf);
#if TARGET_OS_TV
if (ret && string_is_equal(path, path_get(RARCH_PATH_CONFIG)))
write_userdefaults_config_file();
#endif
return ret;
}

View File

@ -1,6 +1,14 @@
#ifndef COCOA_APPLE_PLATFORM_H
#define COCOA_APPLE_PLATFORM_H
#if TARGET_OS_TV
#include "config_file.h"
extern config_file_t *open_userdefaults_config_file(void);
extern void write_userdefaults_config_file(void);
#endif
#ifdef __OBJC__
#ifdef HAVE_METAL
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
@ -95,3 +103,5 @@ UINavigationControllerDelegate> {
#endif
#endif
#endif

View File

@ -30,6 +30,7 @@
#endif
#include "../../../configuration.h"
#include "../../../paths.h"
#include "../../../retroarch.h"
#include "../../../verbosity.h"
@ -836,3 +837,21 @@ bool cocoa_get_metrics(
return true;
}
#endif
config_file_t *open_userdefaults_config_file()
{
config_file_t *conf = NULL;
NSString *backup = [NSUserDefaults.standardUserDefaults stringForKey:@FILE_PATH_MAIN_CONFIG];
if ([backup length] >= 0)
conf = config_file_new_from_string([backup cStringUsingEncoding:NSUTF8StringEncoding], path_get(RARCH_PATH_CONFIG));
return conf;
}
void write_userdefaults_config_file()
{
NSString *conf = [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:path_get(RARCH_PATH_CONFIG)]
encoding:NSUTF8StringEncoding
error:nil];
if (conf)
[NSUserDefaults.standardUserDefaults setObject:conf forKey:@FILE_PATH_MAIN_CONFIG];
}