Skip to content

Commit 98e6c4a

Browse files
committed
Add bypass 3 app limit
1 parent 976aa4f commit 98e6c4a

File tree

8 files changed

+847
-14
lines changed

8 files changed

+847
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ SparseBox_FILES = \
3434
include/minimuxer.swift \
3535
include/em_proxy.swift \
3636
include/SwiftBridgeCore.swift \
37+
Sources/AnyCodable/AnyCodable.swift \
38+
Sources/AnyCodable/AnyDecodable.swift \
39+
Sources/AnyCodable/AnyEncodable.swift \
3740
Sources/SparseRestore/MBDB.swift \
3841
Sources/SparseRestore/Backup.swift \
3942
Sources/SparseRestore/Restore.swift \

Sources/AnyCodable/AnyCodable.swift

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import Foundation
2+
3+
/**
4+
A type-erased `Codable` value.
5+
6+
The `AnyCodable` type forwards encoding and decoding responsibilities
7+
to an underlying value, hiding its specific underlying type.
8+
9+
You can encode or decode mixed-type values in dictionaries
10+
and other collections that require `Encodable` or `Decodable` conformance
11+
by declaring their contained type to be `AnyCodable`.
12+
13+
- SeeAlso: `AnyEncodable`
14+
- SeeAlso: `AnyDecodable`
15+
*/
16+
@frozen public struct AnyCodable: Codable {
17+
public let value: Any
18+
19+
public init(_ value: (some Any)?) {
20+
self.value = value ?? ()
21+
}
22+
}
23+
24+
extension AnyCodable: _AnyEncodable, _AnyDecodable {}
25+
26+
extension AnyCodable: Equatable {
27+
public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool {
28+
switch (lhs.value, rhs.value) {
29+
case is (Void, Void):
30+
true
31+
case let (lhs as Bool, rhs as Bool):
32+
lhs == rhs
33+
case let (lhs as Int, rhs as Int):
34+
lhs == rhs
35+
case let (lhs as Int8, rhs as Int8):
36+
lhs == rhs
37+
case let (lhs as Int16, rhs as Int16):
38+
lhs == rhs
39+
case let (lhs as Int32, rhs as Int32):
40+
lhs == rhs
41+
case let (lhs as Int64, rhs as Int64):
42+
lhs == rhs
43+
case let (lhs as UInt, rhs as UInt):
44+
lhs == rhs
45+
case let (lhs as UInt8, rhs as UInt8):
46+
lhs == rhs
47+
case let (lhs as UInt16, rhs as UInt16):
48+
lhs == rhs
49+
case let (lhs as UInt32, rhs as UInt32):
50+
lhs == rhs
51+
case let (lhs as UInt64, rhs as UInt64):
52+
lhs == rhs
53+
case let (lhs as Float, rhs as Float):
54+
lhs == rhs
55+
case let (lhs as Double, rhs as Double):
56+
lhs == rhs
57+
case let (lhs as String, rhs as String):
58+
lhs == rhs
59+
case let (lhs as Data, rhs as Data):
60+
lhs == rhs
61+
case let (lhs as Date, rhs as Date):
62+
lhs == rhs
63+
case let (lhs as [String: AnyCodable], rhs as [String: AnyCodable]):
64+
lhs == rhs
65+
case let (lhs as [AnyCodable], rhs as [AnyCodable]):
66+
lhs == rhs
67+
case let (lhs as [String: Any], rhs as [String: Any]):
68+
NSDictionary(dictionary: lhs) == NSDictionary(dictionary: rhs)
69+
case let (lhs as [Any], rhs as [Any]):
70+
NSArray(array: lhs) == NSArray(array: rhs)
71+
case is (NSNull, NSNull):
72+
true
73+
default:
74+
false
75+
}
76+
}
77+
}
78+
79+
extension AnyCodable: CustomStringConvertible {
80+
public var description: String {
81+
switch value {
82+
case is Void:
83+
String(describing: nil as Any?)
84+
case let value as CustomStringConvertible:
85+
value.description
86+
default:
87+
String(describing: value)
88+
}
89+
}
90+
}
91+
92+
extension AnyCodable: CustomDebugStringConvertible {
93+
public var debugDescription: String {
94+
switch value {
95+
case let value as CustomDebugStringConvertible:
96+
"AnyCodable(\(value.debugDescription))"
97+
default:
98+
"AnyCodable(\(description))"
99+
}
100+
}
101+
}
102+
103+
extension AnyCodable: ExpressibleByNilLiteral {}
104+
extension AnyCodable: ExpressibleByBooleanLiteral {}
105+
extension AnyCodable: ExpressibleByIntegerLiteral {}
106+
extension AnyCodable: ExpressibleByFloatLiteral {}
107+
extension AnyCodable: ExpressibleByStringLiteral {}
108+
extension AnyCodable: ExpressibleByStringInterpolation {}
109+
extension AnyCodable: ExpressibleByArrayLiteral {}
110+
extension AnyCodable: ExpressibleByDictionaryLiteral {}
111+
112+
extension AnyCodable: Hashable {
113+
public func hash(into hasher: inout Hasher) {
114+
switch value {
115+
case let value as Bool:
116+
hasher.combine(value)
117+
case let value as Int:
118+
hasher.combine(value)
119+
case let value as Int8:
120+
hasher.combine(value)
121+
case let value as Int16:
122+
hasher.combine(value)
123+
case let value as Int32:
124+
hasher.combine(value)
125+
case let value as Int64:
126+
hasher.combine(value)
127+
case let value as UInt:
128+
hasher.combine(value)
129+
case let value as UInt8:
130+
hasher.combine(value)
131+
case let value as UInt16:
132+
hasher.combine(value)
133+
case let value as UInt32:
134+
hasher.combine(value)
135+
case let value as UInt64:
136+
hasher.combine(value)
137+
case let value as Float:
138+
hasher.combine(value)
139+
case let value as Double:
140+
hasher.combine(value)
141+
case let value as String:
142+
hasher.combine(value)
143+
case let value as Data:
144+
hasher.combine(value)
145+
case let value as Date:
146+
hasher.combine(value)
147+
case let value as [String: AnyCodable]:
148+
hasher.combine(value)
149+
case let value as [AnyCodable]:
150+
hasher.combine(value)
151+
default:
152+
break
153+
}
154+
}
155+
}

Sources/AnyCodable/AnyDecodable.swift

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import Foundation
2+
3+
/**
4+
A type-erased `Decodable` value.
5+
6+
The `AnyDecodable` type forwards decoding responsibilities
7+
to an underlying value, hiding its specific underlying type.
8+
9+
You can decode mixed-type values in dictionaries
10+
and other collections that require `Decodable` conformance
11+
by declaring their contained type to be `AnyDecodable`:
12+
13+
let json = """
14+
{
15+
"boolean": true,
16+
"integer": 42,
17+
"double": 3.141592653589793,
18+
"string": "string",
19+
"array": [1, 2, 3],
20+
"nested": {
21+
"a": "alpha",
22+
"b": "bravo",
23+
"c": "charlie"
24+
},
25+
"null": null
26+
}
27+
""".data(using: .utf8)!
28+
29+
let decoder = JSONDecoder()
30+
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
31+
*/
32+
@frozen public struct AnyDecodable: Decodable {
33+
public let value: Any
34+
35+
public init(_ value: (some Any)?) {
36+
self.value = value ?? ()
37+
}
38+
}
39+
40+
@usableFromInline
41+
protocol _AnyDecodable {
42+
var value: Any { get }
43+
init<T>(_ value: T?)
44+
}
45+
46+
extension AnyDecodable: _AnyDecodable {}
47+
48+
extension _AnyDecodable {
49+
public init(from decoder: Decoder) throws {
50+
let container = try decoder.singleValueContainer()
51+
52+
if container.decodeNil() {
53+
#if canImport(Foundation)
54+
self.init(NSNull())
55+
#else
56+
self.init(Self?.none)
57+
#endif
58+
} else if let bool = try? container.decode(Bool.self) {
59+
self.init(bool)
60+
} else if let int = try? container.decode(Int.self) {
61+
self.init(int)
62+
} else if let uint = try? container.decode(UInt.self) {
63+
self.init(uint)
64+
} else if let double = try? container.decode(Double.self) {
65+
self.init(double)
66+
} else if let string = try? container.decode(String.self) {
67+
self.init(string)
68+
} else if let data = try? container.decode(Data.self) {
69+
self.init(data)
70+
} else if let date = try? container.decode(Date.self) {
71+
self.init(date)
72+
} else if let array = try? container.decode([AnyDecodable].self) {
73+
self.init(array.map(\.value))
74+
} else if let dictionary = try? container.decode([String: AnyDecodable].self) {
75+
self.init(dictionary.mapValues { $0.value })
76+
} else {
77+
throw DecodingError.dataCorruptedError(in: container, debugDescription: "AnyDecodable value cannot be decoded")
78+
}
79+
}
80+
}
81+
82+
extension AnyDecodable: Equatable {
83+
public static func == (lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
84+
switch (lhs.value, rhs.value) {
85+
#if canImport(Foundation)
86+
case is (NSNull, NSNull), is (Void, Void):
87+
return true
88+
#endif
89+
case let (lhs as Bool, rhs as Bool):
90+
return lhs == rhs
91+
case let (lhs as Int, rhs as Int):
92+
return lhs == rhs
93+
case let (lhs as Int8, rhs as Int8):
94+
return lhs == rhs
95+
case let (lhs as Int16, rhs as Int16):
96+
return lhs == rhs
97+
case let (lhs as Int32, rhs as Int32):
98+
return lhs == rhs
99+
case let (lhs as Int64, rhs as Int64):
100+
return lhs == rhs
101+
case let (lhs as UInt, rhs as UInt):
102+
return lhs == rhs
103+
case let (lhs as UInt8, rhs as UInt8):
104+
return lhs == rhs
105+
case let (lhs as UInt16, rhs as UInt16):
106+
return lhs == rhs
107+
case let (lhs as UInt32, rhs as UInt32):
108+
return lhs == rhs
109+
case let (lhs as UInt64, rhs as UInt64):
110+
return lhs == rhs
111+
case let (lhs as Float, rhs as Float):
112+
return lhs == rhs
113+
case let (lhs as Double, rhs as Double):
114+
return lhs == rhs
115+
case let (lhs as String, rhs as String):
116+
return lhs == rhs
117+
case let (lhs as Data, rhs as Data):
118+
return lhs == rhs
119+
case let (lhs as Date, rhs as Date):
120+
return lhs == rhs
121+
case let (lhs as [String: AnyDecodable], rhs as [String: AnyDecodable]):
122+
return lhs == rhs
123+
case let (lhs as [AnyDecodable], rhs as [AnyDecodable]):
124+
return lhs == rhs
125+
default:
126+
return false
127+
}
128+
}
129+
}
130+
131+
extension AnyDecodable: CustomStringConvertible {
132+
public var description: String {
133+
switch value {
134+
case is Void:
135+
String(describing: nil as Any?)
136+
case let value as CustomStringConvertible:
137+
value.description
138+
default:
139+
String(describing: value)
140+
}
141+
}
142+
}
143+
144+
extension AnyDecodable: CustomDebugStringConvertible {
145+
public var debugDescription: String {
146+
switch value {
147+
case let value as CustomDebugStringConvertible:
148+
"AnyDecodable(\(value.debugDescription))"
149+
default:
150+
"AnyDecodable(\(description))"
151+
}
152+
}
153+
}
154+
155+
extension AnyDecodable: Hashable {
156+
public func hash(into hasher: inout Hasher) {
157+
switch value {
158+
case let value as Bool:
159+
hasher.combine(value)
160+
case let value as Int:
161+
hasher.combine(value)
162+
case let value as Int8:
163+
hasher.combine(value)
164+
case let value as Int16:
165+
hasher.combine(value)
166+
case let value as Int32:
167+
hasher.combine(value)
168+
case let value as Int64:
169+
hasher.combine(value)
170+
case let value as UInt:
171+
hasher.combine(value)
172+
case let value as UInt8:
173+
hasher.combine(value)
174+
case let value as UInt16:
175+
hasher.combine(value)
176+
case let value as UInt32:
177+
hasher.combine(value)
178+
case let value as UInt64:
179+
hasher.combine(value)
180+
case let value as Float:
181+
hasher.combine(value)
182+
case let value as Double:
183+
hasher.combine(value)
184+
case let value as String:
185+
hasher.combine(value)
186+
case let value as Data:
187+
hasher.combine(value)
188+
case let value as Date:
189+
hasher.combine(value)
190+
case let value as [String: AnyDecodable]:
191+
hasher.combine(value)
192+
case let value as [AnyDecodable]:
193+
hasher.combine(value)
194+
default:
195+
break
196+
}
197+
}
198+
}

0 commit comments

Comments
 (0)