mirror of
https://github.com/qinyuhang/ShadowsocksX-NG-R.git
synced 2026-10-20 06:24:32 +00:00
Finish import function
Finish import function TODO: export function & show example config function
This commit is contained in:
@@ -92,6 +92,7 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
085641E71D711AEF00116B27 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = "<group>"; };
|
||||
0880CE3F1D6FE6D900BD39E2 /* example-gui-config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "example-gui-config.json"; sourceTree = "<group>"; };
|
||||
0880CE411D6FF7F600BD39E2 /* BunchImportUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BunchImportUtils.swift; sourceTree = "<group>"; };
|
||||
088EC3961D5F5B8600E40791 /* whitelist.pac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = whitelist.pac; sourceTree = "<group>"; };
|
||||
@@ -119,7 +120,6 @@
|
||||
9B0BFFF41D0460A70040E62B /* ShadowsocksX-NGTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ShadowsocksX-NGTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
9B0BFFF81D0460A70040E62B /* ShadowsocksX_NGTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowsocksX_NGTests.swift; sourceTree = "<group>"; };
|
||||
9B0BFFFA1D0460A70040E62B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
9B0D55451D2CC1B800A4A8E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = "<group>"; };
|
||||
9B0D554A1D2CC85E00A4A8E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/ProxyPreferencesController.strings"; sourceTree = "<group>"; };
|
||||
9B0D554B1D2CC87400A4A8E2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ProxyPreferencesController.xib; sourceTree = "<group>"; };
|
||||
9B172A5D1D0ACEA100B87B9A /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/AdvPreferencesWindowController.strings"; sourceTree = "<group>"; };
|
||||
@@ -689,7 +689,7 @@
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
9B0BFFED1D0460A70040E62B /* Base */,
|
||||
9B0D55451D2CC1B800A4A8E2 /* zh-Hans */,
|
||||
085641E71D711AEF00116B27 /* zh-Hans */,
|
||||
);
|
||||
name = MainMenu.xib;
|
||||
sourceTree = "<group>";
|
||||
|
||||
@@ -36,9 +36,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
@IBOutlet weak var serversMenuItem: NSMenuItem!
|
||||
@IBOutlet var showQRCodeMenuItem: NSMenuItem!
|
||||
@IBOutlet var scanQRCodeMenuItem: NSMenuItem!
|
||||
@IBOutlet var showBunchJsonExampleFile: NSMenuItem!
|
||||
@IBOutlet var importBunchJsonFile: NSMenuItem!
|
||||
@IBOutlet weak var exportAllServerProfile: NSMenuItem!
|
||||
@IBOutlet var showBunchJsonExampleFileItem: NSMenuItem!
|
||||
@IBOutlet var importBunchJsonFileItem: NSMenuItem!
|
||||
@IBOutlet var exportAllServerProfileItem: NSMenuItem!
|
||||
@IBOutlet var serversPreferencesMenuItem: NSMenuItem!
|
||||
|
||||
@IBOutlet weak var lanchAtLoginMenuItem: NSMenuItem!
|
||||
@@ -265,6 +265,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
}
|
||||
|
||||
@IBAction func importBunchJsonFile(sender: NSMenuItem) {
|
||||
importConfigFile()
|
||||
updateServersMenu()//not working
|
||||
}
|
||||
|
||||
@IBAction func exportAllServerProfile(sender: NSMenuItem) {
|
||||
@@ -449,6 +451,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
let showQRItem = showQRCodeMenuItem
|
||||
let scanQRItem = scanQRCodeMenuItem
|
||||
let preferencesItem = serversPreferencesMenuItem
|
||||
let showBunch = showBunchJsonExampleFileItem
|
||||
let importBuntch = importBunchJsonFileItem
|
||||
let exportAllServer = exportAllServerProfileItem
|
||||
|
||||
var i = 0
|
||||
for p in mgr.profiles {
|
||||
@@ -475,6 +480,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
}
|
||||
serversMenuItem.submenu?.addItem(showQRItem)
|
||||
serversMenuItem.submenu?.addItem(scanQRItem)
|
||||
serversMenuItem.submenu?.addItem(showBunch)
|
||||
serversMenuItem.submenu?.addItem(importBuntch)
|
||||
serversMenuItem.submenu?.addItem(exportAllServer)
|
||||
serversMenuItem.submenu?.addItem(NSMenuItem.separatorItem())
|
||||
serversMenuItem.submenu?.addItem(preferencesItem)
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
<connections>
|
||||
<outlet property="RunningStatusMenuItem" destination="fzk-mE-CEV" id="R4x-gK-Qcw"/>
|
||||
<outlet property="autoModeMenuItem" destination="r07-Gu-aEz" id="9aH-pQ-Rgi"/>
|
||||
<outlet property="exportAllServerProfile" destination="6k0-gn-DQv" id="Wft-VL-ZV2"/>
|
||||
<outlet property="exportAllServerProfileItem" destination="6k0-gn-DQv" id="1xA-cd-5Ia"/>
|
||||
<outlet property="globalModeMenuItem" destination="Mw3-Jm-eXA" id="ar5-Yx-3ze"/>
|
||||
<outlet property="importBunchJsonFile" destination="T9g-gy-gvv" id="0ua-U7-lUK"/>
|
||||
<outlet property="importBunchJsonFileItem" destination="T9g-gy-gvv" id="GW7-ii-U1j"/>
|
||||
<outlet property="lanchAtLoginMenuItem" destination="eUq-p7-ICK" id="w4p-0c-DZn"/>
|
||||
<outlet property="manualModeMenuItem" destination="8PR-gs-c5N" id="9qz-mU-5kt"/>
|
||||
<outlet property="proxyMenuItem" destination="diI-fB-Rss" id="Qjk-9U-3Qy"/>
|
||||
@@ -25,7 +25,7 @@
|
||||
<outlet property="scanQRCodeMenuItem" destination="Qe6-bF-paT" id="XHa-pa-nCa"/>
|
||||
<outlet property="serversMenuItem" destination="u5M-hQ-VSc" id="8gp-SY-Y4U"/>
|
||||
<outlet property="serversPreferencesMenuItem" destination="M5r-E7-44f" id="voe-SX-k6a"/>
|
||||
<outlet property="showBunchJsonExampleFile" destination="pdy-JE-50Q" id="L2a-tN-4fq"/>
|
||||
<outlet property="showBunchJsonExampleFileItem" destination="pdy-JE-50Q" id="aWi-DB-deq"/>
|
||||
<outlet property="showQRCodeMenuItem" destination="R6A-96-Zcb" id="XHz-pz-nCz"/>
|
||||
<outlet property="statusMenu" destination="Hob-KD-bx9" id="clA-ZW-0pT"/>
|
||||
<outlet property="toggleRunningMenuItem" destination="GSu-Tf-StS" id="XHw-pU-nCa"/>
|
||||
|
||||
@@ -8,4 +8,63 @@
|
||||
|
||||
import Foundation
|
||||
//Todo: function 1 showExampleFile, 调用fileManager 拷贝 json 到Downloads文件夹,然后打开Downloads文件夹
|
||||
// function 2 ImportJsonFile, 调用fileManager,读取json文件,对configs for循环调用 profileManager 生成 profile并保存
|
||||
|
||||
//Function 3 导出json配置文件
|
||||
func showExampleConfigFile() {
|
||||
let savePanel = NSSavePanel()
|
||||
savePanel.canCreateDirectories = true
|
||||
savePanel.beginWithCompletionHandler { (result) -> Void in
|
||||
}
|
||||
}
|
||||
|
||||
//importConfigFile, String->void
|
||||
//调用fileManager,读取json文件,对configs for循环调用 profileManager 生成 profile并保存
|
||||
func importConfigFile() {
|
||||
let openPanel = NSOpenPanel()
|
||||
openPanel.allowsMultipleSelection = false
|
||||
openPanel.canChooseDirectories = false
|
||||
openPanel.canCreateDirectories = false
|
||||
openPanel.canChooseFiles = true
|
||||
openPanel.beginWithCompletionHandler { (result) -> Void in
|
||||
if (result == NSFileHandlingPanelOKButton && (openPanel.URL) != nil) {
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
let filePath:String = (openPanel.URL?.path!)!
|
||||
if (fileManager.fileExistsAtPath(filePath) && filePath.hasSuffix("json")) {
|
||||
let data = fileManager.contentsAtPath(filePath)
|
||||
let readString = NSString(data: data!, encoding: NSUTF8StringEncoding)!
|
||||
let readStringData = readString.dataUsingEncoding(NSUTF8StringEncoding)
|
||||
if (NSJSONSerialization.isValidJSONObject(readString)) {
|
||||
print("is not a valid json object")
|
||||
}
|
||||
let jsonArr1 = try! NSJSONSerialization.JSONObjectWithData(readStringData!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
|
||||
|
||||
for item in jsonArr1.objectForKey("configs") as! [[String: AnyObject]]{
|
||||
let profile = ServerProfile()
|
||||
var profileMgr: ServerProfileManager!
|
||||
profileMgr = ServerProfileManager.instance
|
||||
profile.serverHost = item["server"] as! String
|
||||
profile.serverPort = UInt16((item["server_port"]?.integerValue)!)
|
||||
profile.method = item["method"] as! String
|
||||
profile.password = item["password"] as! String
|
||||
profile.remark = item["remarks"] as! String
|
||||
if (item["obfs"] != nil) {
|
||||
profile.ssrObfs = item["obfs"] as! String
|
||||
profile.ssrObfsParam = item["obfsparam"] as! String
|
||||
profile.ssrProtocol = item["protocol"] as! String
|
||||
profile.ssrProtocolParam = ""
|
||||
}
|
||||
profileMgr.profiles.append(profile)
|
||||
profileMgr.save()
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil)
|
||||
}
|
||||
}else{
|
||||
//todo not close view and shake or alert
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func exportConfigFile(FilePath:String) {
|
||||
//读取example文件,删掉configs里面的配置,再用NSDictionary填充到configs里面
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
/* Class = "NSMenuItem"; title = "应用用户自定规则到 PAC"; ObjectID = "6qf-cg-HXc"; */
|
||||
"6qf-cg-HXc.title" = "应用用户自定规则到 PAC";
|
||||
/* Class = "NSMenuItem"; title = "Export All Server To Json..."; ObjectID = "6k0-gn-DQv"; */
|
||||
"6k0-gn-DQv.title" = "导出全部服务器配置";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "手动模式"; ObjectID = "8PR-gs-c5N"; */
|
||||
"8PR-gs-c5N.title" = "手动模式";
|
||||
@@ -17,68 +17,74 @@
|
||||
/* Class = "NSMenuItem"; title = "显示日志..."; ObjectID = "Jfy-sf-Fhl"; */
|
||||
"Jfy-sf-Fhl.title" = "显示日志...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "White List Domain"; ObjectID = "L27-aH-Wwl"; */
|
||||
"L27-aH-Wwl.title" = "域名白名单";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "关于"; ObjectID = "LgB-6g-Gba"; */
|
||||
"LgB-6g-Gba.title" = "关于";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "服务器设置..."; ObjectID = "M5r-E7-44f"; */
|
||||
/* Class = "NSMenuItem"; title = "Server Preferences..."; ObjectID = "M5r-E7-44f"; */
|
||||
"M5r-E7-44f.title" = "服务器设置...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "全局模式"; ObjectID = "Mw3-Jm-eXA"; */
|
||||
/* Class = "NSMenuItem"; title = "Global Mode"; ObjectID = "Mw3-Jm-eXA"; */
|
||||
"Mw3-Jm-eXA.title" = "全局模式";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "扫描屏幕上的二维码..."; ObjectID = "Qe6-bF-paT"; */
|
||||
/* Class = "NSMenuItem"; title = "Scan QR Code From Screen..."; ObjectID = "Qe6-bF-paT"; */
|
||||
"Qe6-bF-paT.title" = "扫描屏幕上的二维码...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "显示当前服务器的二维码..."; ObjectID = "R6A-96-Zcb"; */
|
||||
/* Class = "NSMenuItem"; title = "Show QR Code For Current Server..."; ObjectID = "R6A-96-Zcb"; */
|
||||
"R6A-96-Zcb.title" = "显示当前服务器的二维码...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "从 GFW List 更新PAC"; ObjectID = "TFc-Ec-duM"; */
|
||||
/* Class = "NSMenuItem"; title = "White List Mode"; ObjectID = "RvZ-Zn-29U"; */
|
||||
"RvZ-Zn-29U.title" = "白名单模式";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Import Bunch Json File..."; ObjectID = "T9g-gy-gvv"; */
|
||||
"T9g-gy-gvv.title" = "批量导入...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Update PAC from GFW List"; ObjectID = "TFc-Ec-duM"; */
|
||||
"TFc-Ec-duM.title" = "从 GFW List 更新PAC";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "反馈"; ObjectID = "W7u-7g-Gv4"; */
|
||||
/* Class = "NSMenuItem"; title = "Feedback"; ObjectID = "W7u-7g-Gv4"; */
|
||||
"W7u-7g-Gv4.title" = "反馈";
|
||||
|
||||
/* Class = "NSMenu"; title = "代理"; ObjectID = "YZp-bf-L40"; */
|
||||
/* Class = "NSMenuItem"; title = "White List IP"; ObjectID = "Xbu-Kq-BSR"; */
|
||||
"Xbu-Kq-BSR.title" = "IP白名单";
|
||||
|
||||
/* Class = "NSMenu"; title = "Proxy"; ObjectID = "YZp-bf-L40"; */
|
||||
"YZp-bf-L40.title" = "代理";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "高级设置..."; ObjectID = "bZ3-fy-34d"; */
|
||||
/* Class = "NSMenuItem"; title = "Advance Preference ..."; ObjectID = "bZ3-fy-34d"; */
|
||||
"bZ3-fy-34d.title" = "高级设置...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "代理"; ObjectID = "diI-fB-Rss"; */
|
||||
/* Class = "NSMenuItem"; title = "Proxy"; ObjectID = "diI-fB-Rss"; */
|
||||
"diI-fB-Rss.title" = "代理";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "登录时自动启动"; ObjectID = "eUq-p7-ICK"; */
|
||||
/* Class = "NSMenuItem"; title = "Launch At Login"; ObjectID = "eUq-p7-ICK"; */
|
||||
"eUq-p7-ICK.title" = "登录时自动启动";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Showsocks: On"; ObjectID = "fzk-mE-CEV"; */
|
||||
"fzk-mE-CEV.title" = "Showsocks: On";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "PAC自动模式"; ObjectID = "r07-Gu-aEz"; */
|
||||
"r07-Gu-aEz.title" = "PAC自动模式";
|
||||
/* Class = "NSMenuItem"; title = "Update All Wihte List"; ObjectID = "gde-ZE-086"; */
|
||||
"gde-ZE-086.title" = "更新全部白名单";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "编辑PAC用户自定规则..."; ObjectID = "rms-p0-CvB"; */
|
||||
"rms-p0-CvB.title" = "编辑PAC用户自定规则...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "高级设置..."; ObjectID = "sbx-yz-3lO"; */
|
||||
"sbx-yz-3lO.title" = "高级设置...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "服务器"; ObjectID = "u5M-hQ-VSc"; */
|
||||
"u5M-hQ-VSc.title" = "服务器";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "退出"; ObjectID = "vJS-JW-byz"; */
|
||||
"vJS-JW-byz.title" = "退出";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "域名白名单"; ObjectID = "L27-aH-Wwl"; */
|
||||
"L27-aH-Wwl.title" = "域名白名单";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "IP白名单"; ObjectID = "Xbu-Kq-BSR"; */
|
||||
"Xbu-Kq-BSR.title" = "IP白名单";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "白名单模式"; ObjectID = "nAe-c2-Q79"; */
|
||||
/* Class = "NSMenu"; title = "White List Mode"; ObjectID = "nAe-c2-Q79"; */
|
||||
"nAe-c2-Q79.title" = "白名单模式";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "白名单模式"; ObjectID = "RvZ-Zn-29U"; */
|
||||
"RvZ-Zn-29U.title" = "白名单模式";
|
||||
/* Class = "NSMenuItem"; title = "Show Bunch Json Example File..."; ObjectID = "pdy-JE-50Q"; */
|
||||
"pdy-JE-50Q.title" = "显示示范配置文件";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "更新全部白名单"; ObjectID = "gde-ZE-086"; */
|
||||
"gde-ZE-086.title" = "更新全部白名单";
|
||||
/* Class = "NSMenuItem"; title = "Auto Mode By PAC"; ObjectID = "r07-Gu-aEz"; */
|
||||
"r07-Gu-aEz.title" = "PAC自动模式";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Edit User Rules For PAC..."; ObjectID = "rms-p0-CvB"; */
|
||||
"rms-p0-CvB.title" = "编辑PAC用户自定规则...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Advance Proxy Preference..."; ObjectID = "sbx-yz-3lO"; */
|
||||
"sbx-yz-3lO.title" = "高级设置...";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Servers"; ObjectID = "u5M-hQ-VSc"; */
|
||||
"u5M-hQ-VSc.title" = "服务器";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Quit"; ObjectID = "vJS-JW-byz"; */
|
||||
"vJS-JW-byz.title" = "退出";
|
||||
|
||||
Reference in New Issue
Block a user