From b0eff424f9b4a686fac539eb1b2a0d8b43f14694 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Wed, 20 Feb 2019 16:28:33 +0530 Subject: Importing: Better error message when .conf file is not readable Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/TunnelImporter.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'WireGuard/WireGuard/UI/TunnelImporter.swift') diff --git a/WireGuard/WireGuard/UI/TunnelImporter.swift b/WireGuard/WireGuard/UI/TunnelImporter.swift index 2c8fe1d..0bf76e5 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) -- cgit v1.2.3-59-g8ed1b