diff --git a/Xcodes/Backend/FileError.swift b/Xcodes/Backend/FileError.swift new file mode 100644 index 0000000..c3965bb --- /dev/null +++ b/Xcodes/Backend/FileError.swift @@ -0,0 +1,23 @@ +// +// FileError.swift +// Xcodes +// +// Created by Leon Wolf on 06.10.22. +// Copyright © 2022 Robots and Pencils. All rights reserved. +// + +import Foundation +import LegibleError + +enum FileError: LocalizedError{ + case fileNotFound(_ fileName: String) +} + +extension FileError { + var errorDescription: String? { + switch self { + case .fileNotFound(let fileName): + return String(format: localizeString("Alert.Uninstall.Error.Message.FileNotFound"), fileName) + } + } +} diff --git a/Xcodes/Backend/FileManager+.swift b/Xcodes/Backend/FileManager+.swift index 12c96e1..72fd1ee 100644 --- a/Xcodes/Backend/FileManager+.swift +++ b/Xcodes/Backend/FileManager+.swift @@ -11,7 +11,11 @@ extension FileManager { @discardableResult func trashItem(at url: URL) throws -> URL { var resultingItemURL: NSURL! - try trashItem(at: url, resultingItemURL: &resultingItemURL) + if fileExists(atPath: url.path) { + try trashItem(at: url, resultingItemURL: &resultingItemURL) + } else { + throw FileError.fileNotFound(url.lastPathComponent) + } return resultingItemURL as URL } -} \ No newline at end of file +} diff --git a/Xcodes/Resources/de.lproj/Localizable.strings b/Xcodes/Resources/de.lproj/Localizable.strings index 7b568cc..846566d 100644 --- a/Xcodes/Resources/de.lproj/Localizable.strings +++ b/Xcodes/Resources/de.lproj/Localizable.strings @@ -156,6 +156,7 @@ "Alert.Uninstall.Title" = "Xcode %@ deinstallieren?"; "Alert.Uninstall.Message" = "Die Anwendung wird in den Papierkorb verschoben, dieser wird aber nicht geleert."; "Alert.Uninstall.Error.Title" = "Die Deinstallation von Xcode ist nicht möglich"; +"Alert.Uninstall.Error.Message.FileNotFound" = "Datei \"%@\" konnte nicht gefunden werden."; // Cancel Install "Alert.CancelInstall.Title" = "Bist du sicher, dass Du die installation von Xcode %@ anhalten möchtest?"; diff --git a/Xcodes/Resources/en.lproj/Localizable.strings b/Xcodes/Resources/en.lproj/Localizable.strings index 9d45c5e..56857ff 100644 --- a/Xcodes/Resources/en.lproj/Localizable.strings +++ b/Xcodes/Resources/en.lproj/Localizable.strings @@ -156,6 +156,7 @@ "Alert.Uninstall.Title" = "Uninstall Xcode %@?"; "Alert.Uninstall.Message" = "It will be moved to the Trash, but won't be emptied."; "Alert.Uninstall.Error.Title" = "Unable to uninstall Xcode"; +"Alert.Uninstall.Error.Message.FileNotFound" = "Could not find file \"%@\"."; // Cancel Install "Alert.CancelInstall.Title" = "Are you sure you want to stop the installation of Xcode %@?";