-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
39 lines (36 loc) · 1.71 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// main.m
// jsonplist
//
// Copyright © 2017 Project V2Ray. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc < 2) {
printf("Please provide at least one input file!\n");
return 1;
}
NSString* imputFile = [NSString stringWithFormat:@"%s", argv[1]];
NSInteger length = [imputFile length];
if ([[[imputFile substringFromIndex:length - 4] lowercaseString] isEqualToString:@"json"]) {
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:
[NSData dataWithContentsOfFile:imputFile] options:NSJSONReadingMutableLeaves error:nil];
NSString* targetFile = [[imputFile substringToIndex:length - 4] stringByAppendingString:@"plist"];
[dict writeToFile:targetFile atomically:NO];
printf("%s\n", [targetFile cStringUsingEncoding:NSUTF8StringEncoding]);
return 0;
} else if ([[[imputFile substringFromIndex:length - 5] lowercaseString] isEqualToString:@"plist"]) {
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:imputFile];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
NSString* targetFile = [[imputFile substringToIndex:length - 5] stringByAppendingString:@".plist"];
[jsonData writeToFile:targetFile atomically:NO];
printf("%s\n", [targetFile cStringUsingEncoding:NSUTF8StringEncoding]);
return 0;
} else {
printf("Only json and plist are supported!\n");
return 1;
}
}
return 0;
}