From 4f15a7d77c97ae81b28b13c38b2e6db679a503c9 Mon Sep 17 00:00:00 2001 From: meancoot Date: Wed, 20 Mar 2013 19:07:00 -0400 Subject: [PATCH] (iOS) Remove config file wrapper all together. --- ios/RetroArch.xcodeproj/project.pbxproj | 6 -- ios/RetroArch/RAModuleInfoList.m | 25 ++++++--- ios/RetroArch/RetroArch_iOS.m | 3 +- ios/RetroArch/browser/RADirectoryGrid.m | 22 +++++--- ios/RetroArch/config_file_helper.c | 64 ---------------------- ios/RetroArch/config_file_helper.h | 31 ----------- ios/RetroArch/settings/RASettingsList.m | 23 ++++++-- ios/RetroArch/settings/RASettingsSubList.m | 23 ++++---- ios/RetroArch/views.h | 2 +- 9 files changed, 63 insertions(+), 136 deletions(-) delete mode 100644 ios/RetroArch/config_file_helper.c delete mode 100644 ios/RetroArch/config_file_helper.h diff --git a/ios/RetroArch.xcodeproj/project.pbxproj b/ios/RetroArch.xcodeproj/project.pbxproj index 8bb9b01034..1221bd5b91 100644 --- a/ios/RetroArch.xcodeproj/project.pbxproj +++ b/ios/RetroArch.xcodeproj/project.pbxproj @@ -43,7 +43,6 @@ 96AFAE3016C1D4EA009DE44C /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2F16C1D4EA009DE44C /* GLKit.framework */; }; 96AFAE3216C1D4EA009DE44C /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE3116C1D4EA009DE44C /* OpenGLES.framework */; }; 96AFAE3816C1D4EA009DE44C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96AFAE3616C1D4EA009DE44C /* InfoPlist.strings */; }; - 96C19C3016D7045700FE8D5A /* config_file_helper.c in Sources */ = {isa = PBXBuildFile; fileRef = 96C19C2F16D7045700FE8D5A /* config_file_helper.c */; }; 96F9C26A16F7D9E2002455B3 /* btdynamic.c in Sources */ = {isa = PBXBuildFile; fileRef = 96F9C26816F7D9E2002455B3 /* btdynamic.c */; }; D48581DE16F823F9004BEB17 /* griffin.c in Sources */ = {isa = PBXBuildFile; fileRef = D48581DD16F823F9004BEB17 /* griffin.c */; }; /* End PBXBuildFile section */ @@ -108,8 +107,6 @@ 96AFAF4516C1E00A009DE44C /* bitmap.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = bitmap.bin; sourceTree = ""; }; 96AFAF4616C1E00A009DE44C /* bitmap.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = bitmap.bmp; sourceTree = ""; }; 96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarch_wrapper.h; sourceTree = ""; }; - 96C19C2E16D7045600FE8D5A /* config_file_helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config_file_helper.h; sourceTree = ""; }; - 96C19C2F16D7045700FE8D5A /* config_file_helper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = config_file_helper.c; sourceTree = ""; }; 96F9C26816F7D9E2002455B3 /* btdynamic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = btdynamic.c; sourceTree = ""; }; 96F9C26916F7D9E2002455B3 /* btdynamic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = btdynamic.h; sourceTree = ""; }; D48581DD16F823F9004BEB17 /* griffin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = griffin.c; path = ../griffin/griffin.c; sourceTree = ""; }; @@ -256,8 +253,6 @@ 966B9C8516E40D44005B61E1 /* input */, 96366C6F16CAF62200D64A22 /* settings */, 96297A0E16C5AEA100E6DCE0 /* main.m */, - 96C19C2E16D7045600FE8D5A /* config_file_helper.h */, - 96C19C2F16D7045700FE8D5A /* config_file_helper.c */, 963F5AC516CC523B009BBD19 /* RAGameView.m */, 96096DD716D1ABAF00BF4499 /* RAModuleInfoList.m */, 96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */, @@ -408,7 +403,6 @@ 963F5AC316CC522F009BBD19 /* RASettingsList.m in Sources */, 963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */, 96096DD816D1ABAF00BF4499 /* RAModuleInfoList.m in Sources */, - 96C19C3016D7045700FE8D5A /* config_file_helper.c in Sources */, 966B9CA216E418B7005B61E1 /* BTDevice.m in Sources */, 966B9CA416E418B7005B61E1 /* BTstackManager.m in Sources */, 966B9CA616E418B7005B61E1 /* wiimote.c in Sources */, diff --git a/ios/RetroArch/RAModuleInfoList.m b/ios/RetroArch/RAModuleInfoList.m index 33d48f64a8..6be73622d2 100644 --- a/ios/RetroArch/RAModuleInfoList.m +++ b/ios/RetroArch/RAModuleInfoList.m @@ -18,18 +18,24 @@ { RAModuleInfo* new = [RAModuleInfo new]; - char* dispname = ios_config_get_string(theData, "display_name", [[[thePath lastPathComponent] stringByDeletingPathExtension] UTF8String]); - char* confpath = ios_config_get_string(theData, "supported_extensions", ""); + char* dispname = 0; + char* extensions = 0; + + if (theData) + { + config_get_string(theData, "display_name", &dispname); + config_get_string(theData, "supported_extensions", &extensions); + } - new.displayName = [NSString stringWithUTF8String:dispname]; + new.displayName = dispname ? [NSString stringWithUTF8String:dispname] : [[thePath lastPathComponent] stringByDeletingPathExtension]; new.path = thePath; new.configPath = [NSString stringWithFormat:@"%@/%@.cfg", [RetroArch_iOS get].system_directory, [[thePath lastPathComponent] stringByDeletingPathExtension]]; new.data = theData; - new.supportedExtensions = [[NSString stringWithUTF8String:confpath] componentsSeparatedByString:@"|"]; + new.supportedExtensions = extensions ? [[NSString stringWithUTF8String:extensions] componentsSeparatedByString:@"|"] : [NSArray array]; free(dispname); - free(confpath); + free(extensions); return new; } @@ -47,7 +53,7 @@ @end static NSString* const labels[3] = {@"Emulator Name", @"Manufacturer", @"Name"}; -static NSString* const keys[3] = {@"emuname", @"manufacturer", @"systemname"}; +static const char* const keys[3] = {"emuname", "manufacturer", "systemname"}; static NSString* const sectionNames[2] = {@"Emulator", @"Hardware"}; static const uint32_t sectionSizes[2] = {1, 2}; @@ -92,8 +98,11 @@ static const uint32_t sectionSizes[2] = {1, 2}; cell.textLabel.text = labels[sectionBase + indexPath.row]; - char* val = ios_config_get_string(_data.data, [keys[sectionBase + indexPath.row] UTF8String], "Unspecified"); - cell.detailTextLabel.text = [NSString stringWithUTF8String:val]; + char* val = 0; + if (_data.data) + config_get_string(_data.data, keys[sectionBase + indexPath.row], &val); + + cell.detailTextLabel.text = val ? [NSString stringWithUTF8String:val] : @"Unspecified"; free(val); return cell; diff --git a/ios/RetroArch/RetroArch_iOS.m b/ios/RetroArch/RetroArch_iOS.m index 62136e56e9..cb2767e4de 100644 --- a/ios/RetroArch/RetroArch_iOS.m +++ b/ios/RetroArch/RetroArch_iOS.m @@ -126,7 +126,8 @@ // Read load time settings config_file_t* conf = config_file_new([self.moduleInfo.configPath UTF8String]); - if (ios_config_get_bool(conf, "ios_auto_bluetooth", false)) + bool autoStartBluetooth = false; + if (conf && config_get_bool(conf, "ios_auto_bluetooth", &autoStartBluetooth) && autoStartBluetooth) [self startBluetooth]; config_file_free(conf); diff --git a/ios/RetroArch/browser/RADirectoryGrid.m b/ios/RetroArch/browser/RADirectoryGrid.m index 31bd15c371..d0f7eab792 100644 --- a/ios/RetroArch/browser/RADirectoryGrid.m +++ b/ios/RetroArch/browser/RADirectoryGrid.m @@ -13,27 +13,36 @@ * If not, see . */ -#import "config_file_helper.h" +#import "conf/config_file.h" #import "browser.h" @implementation RADirectoryGrid { NSString* _path; NSArray* _list; - config_file_t* _config; } - (id)initWithPath:(NSString*)path { _path = path; - _config = config_file_new([[path stringByAppendingPathComponent:@".raconfig"] UTF8String]); _list = ra_ios_list_directory(_path); [self setTitle: [_path lastPathComponent]]; + unsigned tileWidth = 100; + unsigned tileHeight = 100; + + config_file_t* config = config_file_new([[path stringByAppendingPathComponent:@".raconfig"] UTF8String]); + if (config) + { + config_get_uint(config, "cover_width", &tileWidth); + config_get_uint(config, "cover_height", &tileHeight); + config_file_free(config); + } + // Init collection view UICollectionViewFlowLayout* layout = [UICollectionViewFlowLayout new]; - layout.itemSize = CGSizeMake(ios_config_get_uint(_config, "cover_width", 100), ios_config_get_uint(_config, "cover_height", 100)); + layout.itemSize = CGSizeMake(tileWidth, tileHeight); self = [super initWithCollectionViewLayout:layout]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"dircell"]; @@ -43,11 +52,6 @@ return self; } -- (void)dealloc -{ - config_file_free(_config); -} - - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; diff --git a/ios/RetroArch/config_file_helper.c b/ios/RetroArch/config_file_helper.c deleted file mode 100644 index 06da3034fe..0000000000 --- a/ios/RetroArch/config_file_helper.c +++ /dev/null @@ -1,64 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include -#import "config_file_helper.h" - -bool ios_config_get_bool(config_file_t* config, const char* name, bool default_) -{ - if (!config) return default_; - - bool result = default_; - config_get_bool(config, name, &result); - return result; -} - -unsigned ios_config_get_uint(config_file_t* config, const char* name, unsigned default_) -{ - if (!config) return default_; - - unsigned result = default_; - config_get_uint(config, name, &result); - return result; -} - -double ios_config_get_double(config_file_t* config, const char* name, double default_) -{ - if (!config) return default_; - - double result = default_; - config_get_double(config, name, &result); - return result; -} - -char* ios_config_get_string(config_file_t* config, const char* name, const char* default_) -{ - if (config) - { - char* result = 0; - if (config_get_string(config, name, &result)) - return result; - } - - return default_ ? strdup(default_) : 0; -} - -void ios_config_set_string(config_file_t* config, const char* name, const char* value) -{ - if (!config) - return; - - config_set_string(config, name, value); -} diff --git a/ios/RetroArch/config_file_helper.h b/ios/RetroArch/config_file_helper.h deleted file mode 100644 index 36c82dafbe..0000000000 --- a/ios/RetroArch/config_file_helper.h +++ /dev/null @@ -1,31 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef __IOS_RARCH_CONFIG_H__ -#define __IOS_RARCH_CONFIG_H__ - -#include "conf/config_file.h" - -bool ios_config_get_bool(config_file_t* config, const char* name, bool default_); -unsigned ios_config_get_uint(config_file_t* config, const char* name, unsigned default_); -double ios_config_get_double(config_file_t* config, const char* name, double default_); - -// You must free the result, even if it returns default_! -char* ios_config_get_string(config_file_t* config, const char* name, const char* default_); - -void ios_config_set_string(config_file_t* config, const char* name, const char* value); - -#endif - diff --git a/ios/RetroArch/settings/RASettingsList.m b/ios/RetroArch/settings/RASettingsList.m index 0611173e74..2d2e11cc93 100644 --- a/ios/RetroArch/settings/RASettingsList.m +++ b/ios/RetroArch/settings/RASettingsList.m @@ -28,8 +28,11 @@ static NSString* get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue) { - char* data = ios_config_get_string(config, [name UTF8String], [defaultValue UTF8String]); - NSString* result = [NSString stringWithUTF8String:data]; + char* data = 0; + if (config) + config_get_string(config, [name UTF8String], &data); + + NSString* result = data ? [NSString stringWithUTF8String:data] : defaultValue; free(data); return result; } @@ -88,9 +91,16 @@ static RASettingData* aspect_setting(config_file_t* config, NSString* label) RASettingData* result = [[RASettingData alloc] initWithType:AspectSetting label:label name:@"fram"]; result.subValues = [NSArray arrayWithObjects:@"Fill Screen", @"Game Aspect", @"Pixel Aspect", @"4:3", @"16:9", nil]; - bool videoForceAspect = ios_config_get_bool(config, "video_force_aspect", true); - bool videoAspectAuto = ios_config_get_bool(config, "video_aspect_ratio_auto", false); - double videoAspect = ios_config_get_double(config, "video_aspect_ratio", 0.0); + bool videoForceAspect = true; + bool videoAspectAuto = false; + double videoAspect = -1.0; + + if (config) + { + config_get_bool(config, "video_force_aspect", &videoForceAspect); + config_get_bool(config, "video_aspect_auto", &videoAspectAuto); + config_get_double(config, "video_aspect_ratio", &videoAspect); + } if (!videoForceAspect) result.value = @"Fill Screen"; @@ -200,7 +210,8 @@ static RASettingData* custom_action(NSString* action) if (!config) config = config_file_new(0); - ios_config_set_string(config, "system_directory", [[RetroArch_iOS get].system_directory UTF8String]); + + config_set_string(config, "system_directory", [[RetroArch_iOS get].system_directory UTF8String]); [self writeSettings:nil toConfig:config]; if (config) config_file_write(config, [[RetroArch_iOS get].moduleInfo.configPath UTF8String]); diff --git a/ios/RetroArch/settings/RASettingsSubList.m b/ios/RetroArch/settings/RASettingsSubList.m index ce7a91641c..5342134ee9 100644 --- a/ios/RetroArch/settings/RASettingsSubList.m +++ b/ios/RetroArch/settings/RASettingsSubList.m @@ -39,6 +39,9 @@ static const char* const SETTINGID = "SETTING"; - (void)writeSettings:(NSArray*)settingList toConfig:(config_file_t*)config { + if (!config) + return; + NSArray* list = settingList ? settingList : settings; for (int i = 0; i != [list count]; i ++) @@ -57,33 +60,33 @@ static const char* const SETTINGID = "SETTING"; case FileListSetting: if ([setting.value length] > 0) - ios_config_set_string(config, [setting.name UTF8String], [[setting.path stringByAppendingPathComponent:setting.value] UTF8String]); + config_set_string(config, [setting.name UTF8String], [[setting.path stringByAppendingPathComponent:setting.value] UTF8String]); else - ios_config_set_string(config, [setting.name UTF8String], ""); + config_set_string(config, [setting.name UTF8String], ""); break; case ButtonSetting: if (setting.msubValues[0] && [setting.msubValues[0] length]) - ios_config_set_string(config, [setting.name UTF8String], [setting.msubValues[0] UTF8String]); + config_set_string(config, [setting.name UTF8String], [setting.msubValues[0] UTF8String]); if (setting.msubValues[1] && [setting.msubValues[1] length]) - ios_config_set_string(config, [[setting.name stringByAppendingString:@"_btn"] UTF8String], [setting.msubValues[1] UTF8String]); + config_set_string(config, [[setting.name stringByAppendingString:@"_btn"] UTF8String], [setting.msubValues[1] UTF8String]); break; case AspectSetting: - ios_config_set_string(config, "video_force_aspect", [@"Fill Screen" isEqualToString:setting.value] ? "false" : "true"); - ios_config_set_string(config, "video_aspect_ratio_auto", [@"Game Aspect" isEqualToString:setting.value] ? "true" : "false"); - ios_config_set_string(config, "video_aspect_ratio", "-1.0"); + config_set_string(config, "video_force_aspect", [@"Fill Screen" isEqualToString:setting.value] ? "false" : "true"); + config_set_string(config, "video_aspect_ratio_auto", [@"Game Aspect" isEqualToString:setting.value] ? "true" : "false"); + config_set_string(config, "video_aspect_ratio", "-1.0"); if([@"4:3" isEqualToString:setting.value]) - ios_config_set_string(config, "video_aspect_ratio", "1.33333333"); + config_set_string(config, "video_aspect_ratio", "1.33333333"); else if([@"16:9" isEqualToString:setting.value]) - ios_config_set_string(config, "video_aspect_ratio", "1.77777777"); + config_set_string(config, "video_aspect_ratio", "1.77777777"); break; case CustomAction: break; default: - ios_config_set_string(config, [setting.name UTF8String], [setting.value UTF8String]); + config_set_string(config, [setting.name UTF8String], [setting.value UTF8String]); break; } } diff --git a/ios/RetroArch/views.h b/ios/RetroArch/views.h index b019f826e6..f41833969e 100644 --- a/ios/RetroArch/views.h +++ b/ios/RetroArch/views.h @@ -16,7 +16,7 @@ #import #import -#import "config_file_helper.h" +#include "conf/config_file.h" @interface RAGameView : UIViewController + (RAGameView*)get;