From 2ef7adde6e3cece1a5c28e71098fc82ca8a667c0 Mon Sep 17 00:00:00 2001 From: Charlie Qiu Date: Sat, 25 Jun 2016 09:44:51 +0800 Subject: [PATCH] Fix wrong spell in path. --- ShadowsocksX-NG/LaunchAgentUtils.swift | 4 ++-- ShadowsocksX-NG/PACUtils.swift | 27 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ShadowsocksX-NG/LaunchAgentUtils.swift b/ShadowsocksX-NG/LaunchAgentUtils.swift index 65fafca..6deda10 100644 --- a/ShadowsocksX-NG/LaunchAgentUtils.swift +++ b/ShadowsocksX-NG/LaunchAgentUtils.swift @@ -9,9 +9,9 @@ import Foundation let SS_LOCAL_VERSION = "2.4.6" -let APP_SUPPORT_DIR = "/Library/Application Support/ShadowsocksX-NE/" +let APP_SUPPORT_DIR = "/Library/Application Support/ShadowsocksX-NG/" let LAUNCH_AGENT_DIR = "/Library/LaunchAgents/" -let LAUNCH_AGENT_CONF_NAME = "com.qiuyuzhou.shadowsocksX-NE.local.plist" +let LAUNCH_AGENT_CONF_NAME = "com.qiuyuzhou.shadowsocksX-NG.local.plist" func getFileSHA1Sum(filepath: String) -> String { diff --git a/ShadowsocksX-NG/PACUtils.swift b/ShadowsocksX-NG/PACUtils.swift index 5e9fad9..592b756 100644 --- a/ShadowsocksX-NG/PACUtils.swift +++ b/ShadowsocksX-NG/PACUtils.swift @@ -9,7 +9,9 @@ import Foundation import Alamofire -let PACRulesDirPath = NSHomeDirectory() + "/.ShadowsocksX-NE/" +let OldErrorPACRulesDirPath = NSHomeDirectory() + "/.ShadowsocksX-NE/" + +let PACRulesDirPath = NSHomeDirectory() + "/.ShadowsocksX-NG/" let PACUserRuleFilePath = PACRulesDirPath + "user-rule.txt" let PACFilePath = PACRulesDirPath + "gfwlist.js" let GFWListFilePath = PACRulesDirPath + "gfwlist.txt" @@ -17,12 +19,23 @@ let GFWListFilePath = PACRulesDirPath + "gfwlist.txt" // Because of LocalSocks5.ListenPort may be changed func SyncPac() { + var needGenerate = false + let nowSocks5Port = NSUserDefaults.standardUserDefaults().integerForKey("LocalSocks5.ListenPort") let oldSocks5Port = NSUserDefaults.standardUserDefaults().integerForKey("LocalSocks5.ListenPort.Old") if nowSocks5Port != oldSocks5Port { - GeneratePACFile() + needGenerate = true NSUserDefaults.standardUserDefaults().setInteger(nowSocks5Port, forKey: "LocalSocks5.ListenPort.Old") } + + let fileMgr = NSFileManager.defaultManager() + if !fileMgr.fileExistsAtPath(PACRulesDirPath) { + needGenerate = true + } + + if needGenerate { + GeneratePACFile() + } } @@ -30,8 +43,12 @@ func GeneratePACFile() -> Bool { let fileMgr = NSFileManager.defaultManager() // Maker the dir if rulesDirPath is not exesited. if !fileMgr.fileExistsAtPath(PACRulesDirPath) { - try! fileMgr.createDirectoryAtPath(PACRulesDirPath - , withIntermediateDirectories: true, attributes: nil) + if fileMgr.fileExistsAtPath(OldErrorPACRulesDirPath) { + try! fileMgr.moveItemAtPath(OldErrorPACRulesDirPath, toPath: PACRulesDirPath) + } else { + try! fileMgr.createDirectoryAtPath(PACRulesDirPath + , withIntermediateDirectories: true, attributes: nil) + } } // If gfwlist.txt is not exsited, copy from bundle @@ -40,7 +57,7 @@ func GeneratePACFile() -> Bool { try! fileMgr.copyItemAtPath(src!, toPath: GFWListFilePath) } - // If gfwlist.txt is not exsited, copy from bundle + // If user-rule.txt is not exsited, copy from bundle if !fileMgr.fileExistsAtPath(PACUserRuleFilePath) { let src = NSBundle.mainBundle().pathForResource("user-rule", ofType: "txt") try! fileMgr.copyItemAtPath(src!, toPath: PACUserRuleFilePath)