RetroArch/apple/common/utility.m

121 lines
3.6 KiB
Mathematica
Raw Normal View History

2013-06-14 04:45:35 +00:00
/* 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 <http://www.gnu.org/licenses/>.
*/
2013-06-22 03:39:01 +00:00
#include <sys/stat.h>
#include "RetroArch_Apple.h"
2013-06-22 03:39:01 +00:00
#include "general.h"
2013-06-22 01:39:36 +00:00
#include "file.h"
2013-06-14 04:45:35 +00:00
void apple_display_alert(NSString* message, NSString* title)
2013-06-22 17:09:38 +00:00
{
#ifdef IOS
2013-06-22 17:09:38 +00:00
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title ? title : @"RetroArch"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
2013-07-07 18:46:16 +00:00
#else
NSAlert* alert = [NSAlert new];
alert.messageText = title ? title : @"RetroArch";
alert.informativeText = message;
alert.alertStyle = NSInformationalAlertStyle;
[alert beginSheetModalForWindow:RetroArch_OSX.get->window
2013-07-09 22:38:49 +00:00
modalDelegate:apple_platform
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
2013-07-07 18:46:16 +00:00
contextInfo:nil];
2013-07-09 22:38:49 +00:00
[NSApplication.sharedApplication runModalForWindow:alert.window];
#endif
}
2013-06-22 17:09:38 +00:00
2013-06-22 03:39:01 +00:00
// Little nudge to prevent stale values when reloading the confg file
void objc_clear_config_hack()
2013-06-22 03:39:01 +00:00
{
g_extern.block_config_read = false;
memset(g_settings.input.overlay, 0, sizeof(g_settings.input.overlay));
memset(g_settings.video.shader_path, 0, sizeof(g_settings.video.shader_path));
}
2013-06-14 04:45:35 +00:00
// Fetch a value from a config file, returning defaultValue if the value is not present
NSString* objc_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue)
2013-06-14 04:45:35 +00:00
{
char* data = 0;
if (config)
config_get_string(config, [name UTF8String], &data);
NSString* result = data ? [NSString stringWithUTF8String:data] : defaultValue;
free(data);
return result;
}
2013-06-22 01:39:36 +00:00
// Ensures a directory exists and has correct permissions
bool path_make_and_check_directory(const char* path, mode_t mode, int amode)
{
if (!path_is_directory(path) && mkdir(path, mode) != 0)
return false;
return access(path, amode) == 0;
}
#ifdef IOS
char* ios_get_rarch_system_directory()
{
return strdup([RetroArch_iOS.get.systemDirectory UTF8String]);
}
#include "../iOS/views.h"
2013-06-14 04:45:35 +00:00
// Simple class to reduce code duplication for fixed table views
@implementation RATableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
self.sections = [NSMutableArray array];
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
return self.sections.count;
}
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
return self.hidesHeaders ? nil : self.sections[section][0];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.sections[section] count] - 1;
}
- (id)itemForIndexPath:(NSIndexPath*)indexPath
{
return self.sections[indexPath.section][indexPath.row + 1];
}
- (void)reset
{
self.sections = [NSMutableArray array];
[self.tableView reloadData];
}
2013-06-14 04:45:35 +00:00
@end
#endif