Skip to content

Commit

Permalink
removing OperatingSystemVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 14, 2025
1 parent b3b1025 commit 0c37c6f
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 33 deletions.
12 changes: 1 addition & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"originHash" : "fbb2ea6138c41c6f92d8bc2ca79baabda2b27ad45e05777925979fe74ac47b0f",
"pins" : [
{
"identity" : "openapikit",
Expand All @@ -10,15 +9,6 @@
"version" : "3.3.0"
}
},
{
"identity" : "operatingsystemversion",
"kind" : "remoteSourceControl",
"location" : "https://github.com/brightdigit/OperatingSystemVersion",
"state" : {
"revision" : "bd3c70eb38da109ec6be9958e80ee495125d3232",
"version" : "1.0.0-beta.1"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -101,5 +91,5 @@
}
}
],
"version" : 3
"version" : 2
}
5 changes: 0 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ let package = Package(
.library(name: "IPSWDownloads", targets: ["IPSWDownloads"])
],
dependencies: [
.package(
url: "https://github.com/brightdigit/OperatingSystemVersion",
from: "1.0.0-beta.1"
),
.package(
url: "https://github.com/apple/swift-openapi-generator",
from: "1.7.0"
Expand All @@ -30,7 +26,6 @@ let package = Package(
.target(
name: "IPSWDownloads",
dependencies: [
.product(name: "OperatingSystemVersion", package: "OperatingSystemVersion"),
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
],
Expand Down
5 changes: 0 additions & 5 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ let package = Package(
.library(name: "IPSWDownloads", targets: ["IPSWDownloads"])
],
dependencies: [
.package(
url: "https://github.com/brightdigit/OperatingSystemVersion",
from: "1.0.0-beta.1"
),
.package(
url: "https://github.com/apple/swift-openapi-generator",
from: "1.7.0"
Expand All @@ -55,7 +51,6 @@ let package = Package(
.target(
name: "IPSWDownloads",
dependencies: [
.product(name: "OperatingSystemVersion", package: "OperatingSystemVersion"),
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
],
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/Board.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
9 changes: 4 additions & 5 deletions Sources/IPSWDownloads/Firmware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand All @@ -28,15 +28,14 @@
//

public import Foundation
public import OperatingSystemVersion

/// A struct representing firmware details of a device.
public struct Firmware: Sendable, Codable, Hashable, Equatable {
/// The unique identifier of the firmware.
public let identifier: String

/// The version of the operating system associated with the firmware.
public let version: OperatingSystemVersion
public let version: SemVer

/// The build ID of the firmware.
public let buildid: String
Expand Down Expand Up @@ -77,7 +76,7 @@ public struct Firmware: Sendable, Codable, Hashable, Equatable {
/// - signed: A flag indicating whether the firmware is signed.
public init(
identifier: String,
version: OperatingSystemVersion,
version: SemVer,
buildid: String,
sha1sum: Data?,
md5sum: Data?,
Expand Down Expand Up @@ -109,7 +108,7 @@ extension Firmware {
internal init(component: Components.Schemas.Firmware) throws {
try self.init(
identifier: component.identifier,
version: OperatingSystemVersion(string: component.version),
version: SemVer(string: component.version),
buildid: component.buildid,
sha1sum: Data(hexString: component.sha1sum, emptyIsNil: true),
md5sum: Data(hexString: component.md5sum, emptyIsNil: true),
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/FirmwareType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/IPSWDownloads.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/RuntimeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
75 changes: 75 additions & 0 deletions Sources/IPSWDownloads/SemVer+Comparable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// SemVer+Comparable.swift
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

extension SemVer: Comparable {
// swiftlint:disable:next function_body_length cyclomatic_complexity
public static func < (lhs: SemVer, rhs: SemVer) -> Bool {
if lhs.major != rhs.major {
return lhs.major < rhs.major
}
if lhs.minor != rhs.minor {
return lhs.minor < rhs.minor
}
if lhs.patch != rhs.patch {
return lhs.patch < rhs.patch
}

// If everything else is equal, compare pre-release versions
switch (lhs.prerelease, rhs.prerelease) {
case (nil, nil):
return false

case (nil, .some):
return false // Release version is greater than pre-release
case (.some, nil):
return true // Pre-release version is less than release
case let (lhsPre?, rhsPre?):
// Compare pre-release identifiers
let lhsComponents = lhsPre.split(separator: ".")
let rhsComponents = rhsPre.split(separator: ".")

for (lhs, rhs) in zip(lhsComponents, rhsComponents) {
if let lNum = Int(lhs), let rNum = Int(rhs) {
if lNum != rNum {
return lNum < rNum
}
} else if Int(lhs) != nil {
return true // Numeric is less than non-numeric
} else if Int(rhs) != nil {
return false // Non-numeric is greater than numeric
} else {
if lhs != rhs {
return lhs.description < rhs.description
}
}
}
return lhsComponents.count < rhsComponents.count
}
}
}
41 changes: 41 additions & 0 deletions Sources/IPSWDownloads/SemVer+CustomStringConvertible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SemVer+CustomStringConvertible.swift
// IPSWDownloads
//
// Created by Leo Dion.
// Copyright © 2025 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

extension SemVer: CustomStringConvertible {
public var description: String {
var version = "\(major).\(minor).\(patch)"
if let prerelease {
version += "-\(prerelease)"
}
if let buildMetadata {
version += "+\(buildMetadata)"
}
return version
}
}
Loading

0 comments on commit 0c37c6f

Please sign in to comment.