diff --git a/ShadowsocksX-NG/Configure.h b/ShadowsocksX-NG/Configure.h index 41ec9e6..0529d5f 100644 --- a/ShadowsocksX-NG/Configure.h +++ b/ShadowsocksX-NG/Configure.h @@ -46,5 +46,6 @@ static NSString * const USERDEFAULTS_FIXED_NETWORK_SPEED_VIEW_WIDTH = @"FIXED_NE static NSString * const USERDEFAULTS_REMOVE_NODE_AFTER_DELETE_SUBSCRIPTION = @"REMOVE_NODE_AFTER_DELETE_SUBSCRIPTION"; static NSString * const USERDEFAULTS_PROXY_EXCEPTIONS = @"ProxyExceptions"; static NSString * const USERDEFAULTS_SERVERS_LIST_SHOW_SERVER_AND_PORT = @"SERVERS_LIST_SHOW_SERVER_AND_PORT"; +static NSString * const USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1 = @"USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1"; #endif /* Configure_h */ diff --git a/ShadowsocksX-NG/PACUtils.swift b/ShadowsocksX-NG/PACUtils.swift index 273def1..0148f1f 100644 --- a/ShadowsocksX-NG/PACUtils.swift +++ b/ShadowsocksX-NG/PACUtils.swift @@ -35,6 +35,18 @@ func SyncPac() { let fileMgr = FileManager.default if !fileMgr.fileExists(atPath: PACRulesDirPath) { needGenerate = true + } else { + if let oldSha1Sum = UserDefaults.standard.object(forKey: USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1) as? String { + let newSha1 = getFileSHA1Sum(PACUserRuleFilePath) + if newSha1 != oldSha1Sum { + needGenerate = true + UserDefaults.standard.set(newSha1, forKey: USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1) + UserDefaults.standard.synchronize() + } + } else { + UserDefaults.standard.set(getFileSHA1Sum(PACUserRuleFilePath), forKey: USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1) + UserDefaults.standard.synchronize() + } } if !fileMgr.fileExists(atPath: ACLWhiteListFilePath) && !fileMgr.fileExists(atPath: ACLBackCHNFilePath) { @@ -101,6 +113,8 @@ func GeneratePACFile() -> Bool { var lines = str!.components(separatedBy: CharacterSet.newlines) do { + UserDefaults.standard.set(getFileSHA1Sum(PACUserRuleFilePath), forKey: USERDEFAULTS_SERVERS_USER_RULE_FILE_SHA1) + UserDefaults.standard.synchronize() let userRuleStr = try String(contentsOfFile: PACUserRuleFilePath, encoding: String.Encoding.utf8) let userRuleLines = userRuleStr.components(separatedBy: CharacterSet.newlines)