Importing: Better error message when .conf file is not readable
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
c195760b15
commit
b0eff424f9
|
@ -199,6 +199,11 @@
|
||||||
"alertNoTunnelsInImportedZipArchiveTitle" = "No tunnels in zip archive";
|
"alertNoTunnelsInImportedZipArchiveTitle" = "No tunnels in zip archive";
|
||||||
"alertNoTunnelsInImportedZipArchiveMessage" = "No .conf tunnel files were found inside the 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
|
// Tunnel management error alerts
|
||||||
|
|
||||||
"alertTunnelActivationFailureTitle" = "Activation failure";
|
"alertTunnelActivationFailureTitle" = "Activation failure";
|
||||||
|
|
|
@ -23,9 +23,16 @@ class TunnelImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
|
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
|
||||||
|
let fileName = url.lastPathComponent
|
||||||
let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
|
let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
if let fileContents = try? String(contentsOf: url),
|
let fileContents: String
|
||||||
let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) {
|
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
|
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { result in
|
||||||
if let error = result.error {
|
if let error = result.error {
|
||||||
errorPresenterType.showErrorAlert(error: error, from: sourceVC, onPresented: completionHandler)
|
errorPresenterType.showErrorAlert(error: error, from: sourceVC, onPresented: completionHandler)
|
||||||
|
|
Loading…
Reference in New Issue