Skip to content

Commit

Permalink
Fix SwiftLint failures and make all errors contain a localized descri…
Browse files Browse the repository at this point in the history
…ption.
  • Loading branch information
vapidinfinity committed Jan 29, 2024
1 parent dc230fe commit 2ff73d3
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ extension Legendary {
case load
}

struct UnableToGetPlatformError: Error { }
struct UnableToGetPlatformError: LocalizedError {
var errorDescription: String? = "Mythic is unable to get the platform of this game."
}

struct IsNotLegendaryError: Error { }
struct IsNotLegendaryError: LocalizedError {
var errorDescription: String? = "This is not an epic game."
}

// GameDoesNotExistError unified!

Expand Down Expand Up @@ -86,12 +90,15 @@ extension Legendary {

/// Error when legendary is signed out on a command that enforces signin.
@available(*, message: "This error will be deprecated soon, in favor of UserValidationError")
struct NotSignedInError: Error { }
struct NotSignedInError: LocalizedError {
var errorDescription: String? = "You aren't signed in to epic games"
}

/// Installation error with a message, see ``Legendary.install()``
struct InstallationError: Error {
struct InstallationError: LocalizedError {
init(_ message: String) { self.message = message }

let message: String
var errorDescription: String? = "Unable to install game." // TODO: message
}
}
7 changes: 5 additions & 2 deletions Mythic/Controllers/Wine/Extensions/WineInterfaceExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ extension Wine {
}

/// Signifies that a wineprefix is unable to boot.
struct BootError: Error {
struct BootError: LocalizedError {

// TODO: proper implementation, see `Wine.boot(prefix: <#URL#>)`
let reason: String? = nil
var errorDescription: String? = "Bottle unable to boot." // TODO: add reason if possible
}

internal enum RegistryType: String {
Expand Down Expand Up @@ -74,5 +75,7 @@ extension Wine {
}

/// Signifies that a wineprefix does not exist at a specified location.
struct PrefixDoesNotExistError: Error { }
struct PrefixDoesNotExistError: LocalizedError {
var errorDescription: String? = "This bottle doesn't exist."
}
}
6 changes: 3 additions & 3 deletions Mythic/Controllers/Wine/WineInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
private static var runningCommands: [String: Process] = .init()

/// The directory where all wine prefixes related to Mythic are stored.
static let bottlesDirectory: URL? = { // FIXME: is optional necessary in case of dir creation failure?
static let bottlesDirectory: URL? = { // FIXME: allow force-unwrapping of bottles directory, directory creation error will be rare
let directory = Bundle.appContainer!.appending(path: "Bottles")
if files.fileExists(atPath: directory.path) {
return directory
Expand Down Expand Up @@ -286,8 +286,8 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
settings: BottleSettings = defaultBottleSettings,
completion: @escaping (Result<Bottle, Error>) -> Void
) async {
guard let baseURL = baseURL else { completion(.failure(NSError())); return }
guard files.fileExists(atPath: baseURL.path) else { completion(.failure(FileLocations.FileDoesNotExistError(nil))); return }
guard let baseURL = baseURL else { return }
guard files.fileExists(atPath: baseURL.path) else { completion(.failure(FileLocations.FileDoesNotExistError(baseURL))); return }
let bottleURL = baseURL.appending(path: name)

guard Libraries.isInstalled() else { completion(.failure(Libraries.NotInstalledError())); return }
Expand Down
3 changes: 2 additions & 1 deletion Mythic/Extensions/Global.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func placeholderGame(_ type: GameType) -> Game {
}

/// Your father.
struct GameDoesNotExistError: Error {
struct GameDoesNotExistError: LocalizedError {
init(_ game: Mythic.Game) { self.game = game }
let game: Mythic.Game
var errorDescription: String? = "This game doesn't exist."
}

// MARK: - Functions
Expand Down
11 changes: 7 additions & 4 deletions Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2289,9 +2289,6 @@
}
}
}
},
"Change Bottle..." : {

},
"Check for Updates…" : {
"localizations" : {
Expand Down Expand Up @@ -9207,7 +9204,10 @@
}
}
},
"q" : {
"raaa %@" : {

},
"raaah %@" : {

},
"RECENTLY PLAYED" : {
Expand Down Expand Up @@ -12790,6 +12790,9 @@
}
}
}
},
"You probably left this open while installing. Your install has finished." : {

}
},
"version" : "1.0"
Expand Down
6 changes: 4 additions & 2 deletions Mythic/Utilities/FileLocations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,21 @@ class FileLocations {

// MARK: - Other

struct FileDoesNotExistError: Error {
struct FileDoesNotExistError: LocalizedError {
init(_ fileURL: URL?) {
self.fileURL = fileURL
}

let fileURL: URL?
var errorDescription: String? = "The file/folder doesn't exist."
}

struct FileNotModifiableError: Error {
struct FileNotModifiableError: LocalizedError {
init(_ fileURL: URL?) {
self.fileURL = fileURL
}

let fileURL: URL?
var errorDescription: String? = "The file/folder isn't modifiable."
}
}
8 changes: 6 additions & 2 deletions Mythic/Utilities/Libraries/Extensions/LibrariesExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import Foundation

extension Libraries {
/// An error indicating that the libraries are already installed.
struct AlreadyInstalledError: Error { }
struct AlreadyInstalledError: LocalizedError {
var errorDescription: String? = "Mythic Engine is already installed."
}

/// An error indicating that the libraries are not installed.
struct NotInstalledError: Error { }
struct NotInstalledError: LocalizedError {
var errorDescription: String? = "Mythic Engine is not installed."
}
}
2 changes: 1 addition & 1 deletion Mythic/Views/GameList/GameList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ struct GameListView: View {
)
}
} else {
throw NSError()
throw Wine.PrefixDoesNotExistError()
}
} catch {
LaunchError.game = game
Expand Down
9 changes: 9 additions & 0 deletions Mythic/Views/Navigation/Wine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import SwiftUI
struct WineView: View {
var body: some View {
NotImplementedView()
if let bottles = Wine.allBottles {
List {
ForEach(Array(bottles.keys), id: \.self) { name in
Text("raaa \(name)")
Text("raaah \(bottles[name]!.url.prettyPath())")
}
}
.padding()
}
}
}

Expand Down

0 comments on commit 2ff73d3

Please sign in to comment.