Importing: Assume imported files without .conf or .zip extensions to be a config file

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-07 00:35:37 +05:30
parent 33edfd3587
commit f9dcfc1b9d
1 changed files with 5 additions and 5 deletions

View File

@ -175,9 +175,9 @@ class TunnelsListTableViewController: UIViewController {
self.present(alert, animated: true, completion: nil) self.present(alert, animated: true, completion: nil)
} }
func importFromFile(url: URL) { func importFromFile(url: URL, shouldConsiderAsConfigEvenWithoutExtensionMatch: Bool = false) {
// Import configurations from a .conf or a .zip file // Import configurations from a .conf or a .zip file
if (url.pathExtension == "conf") { if (url.pathExtension == "conf" || shouldConsiderAsConfigEvenWithoutExtensionMatch) {
let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines) let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
if let fileContents = try? String(contentsOf: url), if let fileContents = try? String(contentsOf: url),
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) { let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
@ -254,9 +254,9 @@ extension TunnelsListTableViewController: UIDocumentPickerDelegate {
if (url.pathExtension == "conf" || url.pathExtension == "zip") { if (url.pathExtension == "conf" || url.pathExtension == "zip") {
importFromFile(url: url) importFromFile(url: url)
} else { } else {
// What if a file provider extension didn't respect our 'documentTypes' parameter // In case a file provider extension didn't respect our 'documentTypes' parameter,
self.showErrorAlert(title: "Invalid file extension", // we'll still assume it's a config file.
message: "Please select a WireGuard configuration file (.conf) or a zip archive (.zip) for importing") importFromFile(url: url, shouldConsiderAsConfigEvenWithoutExtensionMatch: true)
} }
} }
} }