add error message when trying to uninstall Xcode if file not found

This commit is contained in:
Leon Wolf 2022-10-06 08:42:40 +02:00
parent 13e829ca88
commit ed2e5bfcaa
4 changed files with 31 additions and 2 deletions

View file

@ -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)
}
}
}

View file

@ -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
}
}
}

View file

@ -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?";

View file

@ -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 %@?";