Skip to content

Commit

Permalink
Using AppleBuild structure in device support entries
Browse files Browse the repository at this point in the history
  • Loading branch information
vashpan committed Feb 15, 2022
1 parent cba3dde commit e4b376b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
6 changes: 3 additions & 3 deletions DevCleaner/Model/Entries/DeviceSupportFileEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ public final class DeviceSupportFileEntry: XcodeFileEntry {
public let device: String?
public let osType: OSType
public let version: Version
public let build: String?
public let build: AppleBuild?
public let date: Date
public let architecture: String?

// MARK: Initialization
public init(device: String?, osType: OSType, version: Version, build: String?, date: Date, arch: String?, selected: Bool) {
public init(device: String?, osType: OSType, version: Version, build: AppleBuild?, date: Date, arch: String?, selected: Bool) {
self.device = device
self.osType = osType
self.version = version
self.build = build
self.date = date
self.architecture = arch

let label = "\(self.osType.description) \(self.version) \(self.build ?? "")"
let label = "\(self.osType.description) \(self.version) \(self.build ?? AppleBuild.empty)"
let tooltip = label + " " + DateFormatter.localizedString(from: self.date, dateStyle: .medium, timeStyle: .none)

super.init(label: label, tooltipText: tooltip, icon: DeviceSupportFileEntry.icon(for: osType, version: version), tooltip: true, selected: selected)
Expand Down
21 changes: 14 additions & 7 deletions DevCleaner/Model/XcodeFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ final public class XcodeFiles {

let device: String?
let version: Version
let build: String?
let buildString: String?
let creationDate: Date = FileManager.default.dateCreated(for: url)
let arch: String?

Expand All @@ -208,29 +208,29 @@ final public class XcodeFiles {
version = foundVersion

if splitted.count > 1 {
build = String(splitted[1])
buildString = String(splitted[1])
if splitted.count > 2 {
arch = String(splitted[2])
} else {
arch = nil
}
} else {
build = nil
buildString = nil
arch = nil
}
} else if splitted.count > 1, let foundVersion = Version(describing: String(splitted[1])) { // if version is second, we may have extra device info
device = String(splitted[0])
version = foundVersion

if splitted.count > 2 {
build = String(splitted[2])
buildString = String(splitted[2])
if splitted.count > 3 {
arch = String(splitted[3])
} else {
arch = nil
}
} else {
build = nil
buildString = nil
arch = nil
}
} else {
Expand All @@ -241,7 +241,7 @@ final public class XcodeFiles {
return DeviceSupportFileEntry(device: device,
osType: DeviceSupportFileEntry.OSType(label: osLabel),
version: version,
build: build,
build: (buildString != nil) ? AppleBuild(string: buildString!) : nil,
date: creationDate,
arch: arch,
selected: true)
Expand Down Expand Up @@ -470,7 +470,14 @@ final public class XcodeFiles {

// sort
deviceSupportEntries = deviceSupportEntries.sorted { (lhs, rhs) -> Bool in
lhs.version > rhs.version
if lhs.version == rhs.version {
let lhsBuild = lhs.build ?? AppleBuild.empty
let rhsBuild = rhs.build ?? AppleBuild.empty

return lhsBuild > rhsBuild
} else {
return lhs.version > rhs.version
}
}

// merge (in case we have different architectures)
Expand Down
22 changes: 10 additions & 12 deletions DevCleaner/Utilities/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ public struct Version {
public let minor: UInt
public let patch: UInt?

public var description: String {
var result = "\(self.major).\(self.minor)"
if let patch = self.patch {
result += ".\(patch)"
}

return result
}

// MARK: Initialization
init(major: UInt, minor: UInt, patch: UInt? = nil) {
self.major = major
Expand Down Expand Up @@ -85,7 +76,7 @@ public struct Version {
}
}

// MARK: Comparable implementation
// MARK: - Comparable implementation
extension Version: Comparable {
public static func ==(lhs: Version, rhs: Version) -> Bool {
if lhs.major == rhs.major {
Expand Down Expand Up @@ -118,8 +109,15 @@ extension Version: Comparable {
}
}

// MARK: CustomStringConvertible conformance
// MARK: - CustomStringConvertible conformance
extension Version: CustomStringConvertible {

public var description: String {
var result = "\(self.major).\(self.minor)"
if let patch = self.patch {
result += ".\(patch)"
}

return result
}
}

0 comments on commit e4b376b

Please sign in to comment.