diff --git a/WireGuard/AppDelegate.swift b/WireGuard/AppDelegate.swift
index 2460a9f..bf9573e 100644
--- a/WireGuard/AppDelegate.swift
+++ b/WireGuard/AppDelegate.swift
@@ -32,14 +32,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
os_log("Failed to remove item from Inbox: %{public}@", log: Log.general, type: .error, url.absoluteString)
}
}
- guard url.pathExtension == "conf" else { return false }
-
- do {
- try appCoordinator.importConfig(config: url)
- } catch {
- os_log("Unable to import config: %{public}@", log: Log.general, type: .error, url.absoluteString)
- return false
+ if url.pathExtension == "conf" {
+ do {
+ try appCoordinator.importConfig(config: url)
+ } catch {
+ os_log("Unable to import config: %{public}@", log: Log.general, type: .error, url.absoluteString)
+ return false
+ }
+ return true
+ } else if url.pathExtension == "zip" {
+ do {
+ try appCoordinator.importConfigs(configZip: url)
+ } catch {
+ os_log("Unable to import config: %{public}@", log: Log.general, type: .error, url.absoluteString)
+ return false
+ }
+ return true
}
- return true
+ return false
+
}
}
diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift
index 31de8f1..7ed9025 100644
--- a/WireGuard/Coordinators/AppCoordinator.swift
+++ b/WireGuard/Coordinators/AppCoordinator.swift
@@ -99,17 +99,36 @@ class AppCoordinator: RootViewCoordinator {
func importConfig(config: URL) throws {
do {
- let configString = try String(contentsOf: config)
+ try importConfig(configString: try String(contentsOf: config), title: config.deletingPathExtension().lastPathComponent)
+ } catch {
+ throw AppCoordinatorError.configImportError(msg: "Failed")
+ }
+ }
+
+ func importConfig(configString: String, title: String) throws {
+ do {
let addContext = persistentContainer.newBackgroundContext()
let tunnel = try Tunnel.fromConfig(configString, context: addContext)
- let title = config.deletingPathExtension().lastPathComponent
tunnel.title = title
addContext.saveContext()
self.saveTunnel(tunnel)
} catch {
throw AppCoordinatorError.configImportError(msg: "Failed")
}
+ }
+ func importConfigs(configZip: URL) throws {
+ if let archive = Archive(url: configZip, accessMode: .read) {
+ for entry in archive {
+ var entryData = Data(capacity: 0)
+ _ = try archive.extract(entry) { (data) in
+ entryData.append(data)
+ }
+ if let config = String(data: entryData, encoding: .utf8) {
+ try importConfig(configString: config, title: entry.path)
+ }
+ }
+ }
}
// swiftlint:disable next function_body_length
diff --git a/WireGuard/Info.plist b/WireGuard/Info.plist
index f3d505d..0603681 100644
--- a/WireGuard/Info.plist
+++ b/WireGuard/Info.plist
@@ -79,11 +79,6 @@
UTExportedTypeDeclarations
- UTTypeTagSpecification
-
- public.filename-extension
- conf
-
UTTypeConformsTo
public.data
@@ -97,19 +92,19 @@
UTTypeIdentifier
com.wireguard.config.quick
+ UTTypeTagSpecification
+
+ public.filename-extension
+ conf
+
UTImportedTypeDeclarations
- UTTypeTagSpecification
-
- public.filename-extension
- conf
-
UTTypeConformsTo
- public.data
+ com.pkware.zip-archive
UTTypeDescription
WireGuard configuration
@@ -120,6 +115,28 @@
UTTypeIdentifier
com.wireguard.config.quick
+ UTTypeTagSpecification
+
+ public.filename-extension
+ conf
+
+
+
+ UTTypeConformsTo
+
+ public.data
+
+ UTTypeDescription
+ WireGuard configurations
+ UTTypeIconFiles
+
+ icon_20pt.png
+ icon_60pt@3x.png
+
+ UTTypeIdentifier
+ com.wireguard.config.quick.confs
+ public.filename-extension
+ zip