Skip to content

Commit

Permalink
Merge pull request #103 from minoscc/master
Browse files Browse the repository at this point in the history
custom rules save to user-rule.txt
  • Loading branch information
clowwindy committed Mar 6, 2015
2 parents b8e6f5a + 76882a3 commit 9c10e72
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ShadowsocksX/SWBAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation SWBAppDelegate {
FSEventStreamRef fsEventStream;
NSString *configPath;
NSString *PACPath;
NSString *userRulePath;
AFHTTPRequestOperationManager *manager;
}

Expand Down Expand Up @@ -111,6 +112,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

configPath = [NSString stringWithFormat:@"%@/%@", NSHomeDirectory(), @".ShadowsocksX"];
PACPath = [NSString stringWithFormat:@"%@/%@", configPath, @"gfwlist.js"];
userRulePath = [NSString stringWithFormat:@"%@/%@", configPath, @"user-rule.txt"];
[self monitorPAC:configPath];
appDelegate = self;
}
Expand Down Expand Up @@ -452,6 +454,13 @@ - (void)updatePACFromGFWList {
// Objective-C is bullshit
NSString *str2 = [[NSString alloc] initWithData:data2 encoding:NSUTF8StringEncoding];
NSArray *lines = [str2 componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

NSString *str3 = [[NSString alloc] initWithContentsOfFile:userRulePath encoding:NSUTF8StringEncoding error:nil];
if (str3) {
NSArray *rules = [str3 componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
lines = [lines arrayByAddingObjectsFromArray:rules];
}

NSMutableArray *filtered = [[NSMutableArray alloc] init];
for (NSString *line in lines) {
if ([line length] > 0) {
Expand Down

0 comments on commit 9c10e72

Please sign in to comment.