diff options
author | Roopesh Chander <roop@roopc.net> | 2018-10-31 14:30:25 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-10-31 14:30:25 +0530 |
commit | 059a989fc96ac6bb37d1db345f630e2f1621d5ea (patch) | |
tree | a670f7dae9acb369cc68631f36bfdbf3bf663e28 /WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift | |
parent | VPN: Support adding multiple configurations in one shot (diff) | |
download | wireguard-apple-059a989fc96ac6bb37d1db345f630e2f1621d5ea.tar.xz wireguard-apple-059a989fc96ac6bb37d1db345f630e2f1621d5ea.zip |
Tunnel list: Fix importing zip with multiple configurations
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index 209ada8..9763b92 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -160,21 +160,27 @@ class TunnelsListTableViewController: UITableViewController { print("Error opening zip archive: \(error)") } var numberOfConfigFilesWithErrors = 0 + var tunnelConfigurationsToAdd: [TunnelConfiguration] = [] for unarchivedFile in unarchivedFiles { if let fileBaseName = URL(string: unarchivedFile.fileName)?.deletingPathExtension().lastPathComponent, let fileContents = String(data: unarchivedFile.contents, encoding: .utf8), let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) { - tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in - if (error != nil) { - print("Error adding configuration: \(tunnelConfiguration.interface.name)") - } - } + tunnelConfigurationsToAdd.append(tunnelConfiguration) } else { numberOfConfigFilesWithErrors = numberOfConfigFilesWithErrors + 1 } } + var numberOfTunnelsRemainingAfterError = 0 + tunnelsManager?.addMultiple(tunnelConfigurations: tunnelConfigurationsToAdd) { (numberOfTunnelsRemaining, error) in + if (error != nil) { + numberOfTunnelsRemainingAfterError = numberOfTunnelsRemaining + } else { + assert(numberOfTunnelsRemaining == 0) + } + } if (numberOfConfigFilesWithErrors > 0) { - showErrorAlert(title: "Could not import \(numberOfConfigFilesWithErrors) files", message: "\(numberOfConfigFilesWithErrors) of \(unarchivedFiles.count) files contained errors and were not imported") + showErrorAlert(title: "Could not import \(numberOfConfigFilesWithErrors + numberOfTunnelsRemainingAfterError) files", + message: "\(numberOfConfigFilesWithErrors) of \(unarchivedFiles.count) files contained errors and were not imported") } } } |