aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-20 16:28:33 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-21 17:57:13 +0530
commitb0eff424f9b4a686fac539eb1b2a0d8b43f14694 (patch)
tree36acb1ea917d4230c87bee04e3bfa856187cdb7c /WireGuard/WireGuard
parentmacOS: Specify crypto compliance (diff)
downloadwireguard-apple-b0eff424f9b4a686fac539eb1b2a0d8b43f14694.tar.xz
wireguard-apple-b0eff424f9b4a686fac539eb1b2a0d8b43f14694.zip
Importing: Better error message when .conf file is not readable
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r--WireGuard/WireGuard/Base.lproj/Localizable.strings5
-rw-r--r--WireGuard/WireGuard/UI/TunnelImporter.swift11
2 files changed, 14 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings
index 89f903ce..29fd7cba 100644
--- a/WireGuard/WireGuard/Base.lproj/Localizable.strings
+++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings
@@ -199,6 +199,11 @@
"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";
diff --git a/WireGuard/WireGuard/UI/TunnelImporter.swift b/WireGuard/WireGuard/UI/TunnelImporter.swift
index 2c8fe1d5..0bf76e56 100644
--- a/WireGuard/WireGuard/UI/TunnelImporter.swift
+++ b/WireGuard/WireGuard/UI/TunnelImporter.swift
@@ -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)