Skip to content

Instantly share code, notes, and snippets.

@moyashi
Created May 9, 2010 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyashi/395285 to your computer and use it in GitHub Desktop.
Save moyashi/395285 to your computer and use it in GitHub Desktop.
//iPhoneのOperaのInfo.plistにURL Schemeを追加するコマンド
#import <Foundation/Foundation.h>
#include <unistd.h>
#define VERSION 0.1
extern char *optarg;
extern int optind, opterr;
void help(char *progname)
{
fprintf(stderr, "%s version %.1f by moyashi <http://moyashi.air-nifty.com/>\n", progname, VERSION);
fprintf(stderr, "Usage: %s [options...]\n", progname);
fprintf(stderr, " -i input plist file name\n");
fprintf(stderr, " -? show this help\n");
return;
}
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int opt = -1;
NSString *plistPath;
if (argc == 1) {
help(argv[0]);
[pool release];
exit(EXIT_FAILURE);
}
while ((opt = getopt(argc, argv, "i:")) != -1)
{
switch (opt)
{
case 'i':
plistPath = [NSString stringWithCString:optarg encoding:NSUTF8StringEncoding];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
NSLog(@"%@ does not found.", plistPath);
[pool release];
exit(EXIT_FAILURE);
} else {
NSMutableDictionary *readDict = [[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath] autorelease];
NSMutableDictionary *newEntry = [NSMutableDictionary dictionary];
[newEntry setObject:@"com.opera.OperaMini" forKey:@"CFBundleURLName"];
[newEntry setObject:[NSArray arrayWithObject:@"operamini"] forKey:@"CFBundleURLSchemes"];
[readDict setObject:[NSArray arrayWithObject:newEntry] forKey:@"CFBundleURLTypes"];
[readDict writeToFile:plistPath atomically:YES];
}
break;
default: /* '?' */
help(argv[0]);
}
}
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment