]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Importing: Better error message when .conf file is not readable
authorRoopesh Chander <roop@roopc.net>
Wed, 20 Feb 2019 10:58:33 +0000 (16:28 +0530)
committerRoopesh Chander <roop@roopc.net>
Thu, 21 Feb 2019 12:27:13 +0000 (17:57 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/Base.lproj/Localizable.strings
WireGuard/WireGuard/UI/TunnelImporter.swift

index 89f903ce90a1a3ddfdb20b4188b6d475d42e2178..29fd7cba11d5bb2c53499a64ebe1526f6a435158 100644 (file)
 "alertNoTunnelsInImportedZipArchiveTitle" = "No tunnels in zip archive";
 "alertNoTunnelsInImportedZipArchiveMessage" = "No .conf tunnel files were found inside the zip archive.";
 
+// Conf import error alerts
+
+"alertCantOpenInputConfFileTitle" = "Unable to import from file";
+"alertCantOpenInputConfFileMessage (%@)" = "The file ‘%@’ could not be read.";
+
 // Tunnel management error alerts
 
 "alertTunnelActivationFailureTitle" = "Activation failure";
index 2c8fe1d52d2c93aa55931463ecf89046bda91207..0bf76e56111f03929f6b30d0670222b6c51a70dc 100644 (file)
@@ -23,9 +23,16 @@ class TunnelImporter {
                 }
             }
         } else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
+            let fileName = url.lastPathComponent
             let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
-            if let fileContents = try? String(contentsOf: url),
-                let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) {
+            let fileContents: String
+            do {
+                fileContents = try String(contentsOf: url)
+            } catch {
+                errorPresenterType.showErrorAlert(title: tr("alertCantOpenInputConfFileTitle"), message: tr(format: "alertCantOpenInputConfFileMessage (%@)", fileName), from: sourceVC, onPresented: completionHandler)
+                return
+            }
+            if let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) {
                 tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { result in
                     if let error = result.error {
                         errorPresenterType.showErrorAlert(error: error, from: sourceVC, onPresented: completionHandler)