Skip to content

Commit

Permalink
Added structure to store device support build numbers, that are forma…
Browse files Browse the repository at this point in the history
…tted in a specific way

Here's a description that I based this implementation: https://tidbits.com/2020/07/08/how-to-decode-apple-version-and-build-numbers/

Unfortunately there could still be some unknowns, like what happens with some beta build numbers?
  • Loading branch information
vashpan committed Feb 15, 2022
1 parent f34bfa8 commit cba3dde
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DevCleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
7100BEE322F6E771002E82B2 /* Profiler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7100BEE122F6E771002E82B2 /* Profiler.swift */; };
71012FA9230C8A9E00FDF8ED /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71012FA8230C8A9E00FDF8ED /* main.swift */; };
71012FAC230C928600FDF8ED /* CmdLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71012FAB230C928600FDF8ED /* CmdLine.swift */; };
710C965427BBE09200A1DA6A /* AppleBuild.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710C965327BBE09200A1DA6A /* AppleBuild.swift */; };
7110B4922030F17B00EDBFA3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7110B4912030F17B00EDBFA3 /* AppDelegate.swift */; };
7110B4942030F17B00EDBFA3 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7110B4932030F17B00EDBFA3 /* MainViewController.swift */; };
7110B4962030F17B00EDBFA3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7110B4952030F17B00EDBFA3 /* Assets.xcassets */; };
Expand Down Expand Up @@ -61,6 +62,7 @@
7100BEE122F6E771002E82B2 /* Profiler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Profiler.swift; sourceTree = "<group>"; };
71012FA8230C8A9E00FDF8ED /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
71012FAB230C928600FDF8ED /* CmdLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CmdLine.swift; sourceTree = "<group>"; };
710C965327BBE09200A1DA6A /* AppleBuild.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleBuild.swift; sourceTree = "<group>"; };
7110B48E2030F17B00EDBFA3 /* DevCleaner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DevCleaner.app; sourceTree = BUILT_PRODUCTS_DIR; };
7110B4912030F17B00EDBFA3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7110B4932030F17B00EDBFA3 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -266,6 +268,7 @@
7100BEDB22F6E4D5002E82B2 /* Profiling */,
719B25DA205EF996007560C0 /* Extensions */,
719B25D8205ECA53007560C0 /* Version.swift */,
710C965327BBE09200A1DA6A /* AppleBuild.swift */,
7155325D2061AFD80025EB75 /* Logger.swift */,
71E7F837214E930500A11601 /* Alerts.swift */,
7162E1252097255C00081E4E /* Stack.swift */,
Expand Down Expand Up @@ -460,6 +463,7 @@
7140B61F2323E1F7005768A7 /* HelpViewController.swift in Sources */,
717AB6B620C71F4D0096743C /* LoadingView.swift in Sources */,
712F999E20D65229003927BC /* Donations.swift in Sources */,
710C965427BBE09200A1DA6A /* AppleBuild.swift in Sources */,
7185E5D320D0775200C1C918 /* DonationViewController.swift in Sources */,
7110B4922030F17B00EDBFA3 /* AppDelegate.swift in Sources */,
);
Expand Down
102 changes: 102 additions & 0 deletions DevCleaner/Utilities/AppleBuild.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// AppleBuild.swift
// DevCleaner
//
// Created by Konrad Kołakowski on 15/02/2022.
// Copyright © 2022 One Minute Games. All rights reserved.
//
// DevCleaner is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// DevCleaner is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with DevCleaner. If not, see <http://www.gnu.org/licenses/>.

import Foundation

// MARK: AppleBuild struct
public struct AppleBuild {
// MARK: Properties
public let textual: String

public let major: Int?
public let minor: Character?
public let daily: String?

// MARK: Constants
public static let empty = AppleBuild()

// MARK: Initialization
init() {
self.textual = String()

self.major = nil
self.minor = nil
self.daily = nil
}

init(string: String) {
self.textual = string

// parse build number according to this:
// https://tidbits.com/2020/07/08/how-to-decode-apple-version-and-build-numbers/
let scanner = Scanner(string: self.textual)
scanner.caseSensitive = false

self.major = scanner.scanInt()
self.minor = scanner.scanCharacter()
self.daily = scanner.string[scanner.currentIndex...].description
}
}

// MARK: - Comparable implementation
extension AppleBuild: Comparable {
public static func ==(lhs: AppleBuild, rhs: AppleBuild) -> Bool {
if lhs.major == rhs.major {
if lhs.minor == rhs.minor {
let lhsDaily = lhs.daily ?? ""
let rhsDaily = rhs.daily ?? ""

if lhsDaily == rhsDaily {
return true
}
}
}

return false
}

public static func <(lhs: AppleBuild, rhs: AppleBuild) -> Bool {
if lhs.major == rhs.major {
if lhs.minor == rhs.minor {
let lhsDaily = lhs.daily ?? ""
let rhsDaily = rhs.daily ?? ""

return lhsDaily.compare(rhsDaily) == .orderedAscending
} else {
let lhsMinor = lhs.minor ?? Character("")
let rhsMinor = rhs.minor ?? Character("")

return lhsMinor < rhsMinor
}
} else {
let lhsMajor = lhs.major ?? 0
let rhsMajor = rhs.major ?? 0

return lhsMajor < rhsMajor
}
}
}

// MARK: - CustomStringConvertible conformance
extension AppleBuild: CustomStringConvertible {
public var description: String {
return self.textual
}
}

0 comments on commit cba3dde

Please sign in to comment.