Skip to content

Commit 35ae6b7

Browse files
authored
Merge pull request #306 from leon-wolf/feature/144-add-error-on-uninstall
add error message when trying to uninstall Xcode if file not found
2 parents b9ba988 + 0e45884 commit 35ae6b7

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

Xcodes.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
36741BFD291E4FDB00A85AAE /* DownloadPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36741BFC291E4FDB00A85AAE /* DownloadPreferencePane.swift */; };
11+
36741BFF291E50F500A85AAE /* FileError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36741BFE291E50F500A85AAE /* FileError.swift */; };
1112
536CFDD2263C94DE00026CE0 /* SignedInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536CFDD1263C94DE00026CE0 /* SignedInView.swift */; };
1213
536CFDD4263C9A8000026CE0 /* XcodesSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536CFDD3263C9A8000026CE0 /* XcodesSheet.swift */; };
1314
53CBAB2C263DCC9100410495 /* XcodesAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CBAB2B263DCC9100410495 /* XcodesAlert.swift */; };
@@ -172,6 +173,7 @@
172173
15FAD1652811D15600B63259 /* hi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hi; path = hi.lproj/Localizable.strings; sourceTree = "<group>"; };
173174
25E2FA26284769A00014A318 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
174175
36741BFC291E4FDB00A85AAE /* DownloadPreferencePane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadPreferencePane.swift; sourceTree = "<group>"; };
176+
36741BFE291E50F500A85AAE /* FileError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileError.swift; sourceTree = "<group>"; };
175177
4A5AAA1D28118FAD00528958 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
176178
536CFDD1263C94DE00026CE0 /* SignedInView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignedInView.swift; sourceTree = "<group>"; };
177179
536CFDD3263C9A8000026CE0 /* XcodesSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodesSheet.swift; sourceTree = "<group>"; };
@@ -458,6 +460,7 @@
458460
CAA858C325A2BE4E00ACF8C0 /* Downloader.swift */,
459461
CABFA9B22592EEEA00380FEE /* Entry+.swift */,
460462
CABFA9A92592EEE900380FEE /* Environment.swift */,
463+
36741BFE291E50F500A85AAE /* FileError.swift */,
461464
CABFA9B82592EEEA00380FEE /* FileManager+.swift */,
462465
CAFBDB942598FE96003DCC5A /* FocusedValues.swift */,
463466
CABFA9AC2592EEE900380FEE /* Foundation.swift */,
@@ -841,6 +844,7 @@
841844
CAA1CB45255A5B60003FD669 /* SignIn2FAView.swift in Sources */,
842845
CABFA9C52592EEEA00380FEE /* FileManager+.swift in Sources */,
843846
CABFA9CD2592EEEA00380FEE /* Foundation.swift in Sources */,
847+
36741BFF291E50F500A85AAE /* FileError.swift in Sources */,
844848
CA9FF8872595607900E47BAF /* InstalledXcode.swift in Sources */,
845849
53CBAB2C263DCC9100410495 /* XcodesAlert.swift in Sources */,
846850
CA42DD6E25AEA8B200BC0B0C /* Logger.swift in Sources */,

Xcodes/Backend/FileError.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// FileError.swift
3+
// Xcodes
4+
//
5+
// Created by Leon Wolf on 06.10.22.
6+
// Copyright © 2022 Robots and Pencils. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import LegibleError
11+
12+
enum FileError: LocalizedError{
13+
case fileNotFound(_ fileName: String)
14+
}
15+
16+
extension FileError {
17+
var errorDescription: String? {
18+
switch self {
19+
case .fileNotFound(let fileName):
20+
return String(format: localizeString("Alert.Uninstall.Error.Message.FileNotFound"), fileName)
21+
}
22+
}
23+
}

Xcodes/Backend/FileManager+.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ extension FileManager {
1111
@discardableResult
1212
func trashItem(at url: URL) throws -> URL {
1313
var resultingItemURL: NSURL!
14-
try trashItem(at: url, resultingItemURL: &resultingItemURL)
14+
if fileExists(atPath: url.path) {
15+
try trashItem(at: url, resultingItemURL: &resultingItemURL)
16+
} else {
17+
throw FileError.fileNotFound(url.lastPathComponent)
18+
}
1519
return resultingItemURL as URL
1620
}
17-
}
21+
}

Xcodes/Resources/de.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"Alert.Uninstall.Title" = "Xcode %@ deinstallieren?";
160160
"Alert.Uninstall.Message" = "Die Anwendung wird in den Papierkorb verschoben, dieser wird aber nicht geleert.";
161161
"Alert.Uninstall.Error.Title" = "Die Deinstallation von Xcode ist nicht möglich";
162+
"Alert.Uninstall.Error.Message.FileNotFound" = "Datei \"%@\" konnte nicht gefunden werden.";
162163

163164
// Cancel Install
164165
"Alert.CancelInstall.Title" = "Bist du sicher, dass Du die installation von Xcode %@ anhalten möchtest?";

Xcodes/Resources/en.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"Alert.Uninstall.Title" = "Uninstall Xcode %@?";
160160
"Alert.Uninstall.Message" = "It will be moved to the Trash, but won't be emptied.";
161161
"Alert.Uninstall.Error.Title" = "Unable to uninstall Xcode";
162+
"Alert.Uninstall.Error.Message.FileNotFound" = "Could not find file \"%@\".";
162163

163164
// Cancel Install
164165
"Alert.CancelInstall.Title" = "Are you sure you want to stop the installation of Xcode %@?";

0 commit comments

Comments
 (0)