forked from 2009-Nissan-Cube/About-This-Hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HardwareCollector.swift
154 lines (131 loc) · 5.31 KB
/
HardwareCollector.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// HardwareCollector.swift
// HardwareCollector
//
import Foundation
class HardwareCollector {
static var macInfo: String = "Hackintosh Extreme Plus"
static var SMBios: String = ""
static var GPUstring: String = "Radeon Pro 560 4GB"
static var DisplayString: String = "Generic LCD"
static var SerialNumberString: String = "XXXXXXXXXXX"
static var BootloaderString: String = ""
static var BootloaderInfo: String = ""
static var numberOfDisplays: Int = 1
static var dataHasBeenSet: Bool = false
static var displayRes: [String] = []
static var displayNames: [String] = []
static var storageType: Bool = false
static var storageData: String = ""
static var storagePercent: Double = 0.0
static var qhasBuiltInDisplay: Bool = (macType == .LAPTOP)
static var macType: macType = .LAPTOP
static func getAllData() {
if (dataHasBeenSet) {return}
let queue = DispatchQueue(label: "ga.0xCUBE.athqueue", attributes: .concurrent)
queue.async {
numberOfDisplays = getNumDisplays()
print("Number of Displays: \(numberOfDisplays)")
qhasBuiltInDisplay = hasBuiltInDisplay()
print("Has built-in display: \(qhasBuiltInDisplay)")
// getDisplayDiagonal() Having some issues, removing for now
}
queue.async {
storageType = getStorageType()
print("Storage Type: \(storageType)")
storageData = getStorageData()[0]
print("Storage Data: \(storageData)")
storagePercent = Double(getStorageData()[1])!
print("Storage Percent: \(storagePercent)")
}
// For some reason these don't work in groups, to be fixed
displayRes = getDisplayRes()
displayNames = getDisplayNames()
dataHasBeenSet = true
}
static func getDisplayDiagonal() -> Float {
return 13.3
}
static func getDisplayRes() -> [String] {
let numDispl = getNumDisplays()
if numDispl == 1 {
return [run("""
echo "$(cat ~/.ath/scrXml.txt | grep -A2 _spdisplays_resolution | grep string | cut -c 15- | cut -f1 -d"<")"
""") ]
}
else if (numDispl == 2) {
let tmp = run("cat ~/.ath/scr.txt | grep Resolution | cut -c 23-")
let tmpParts = tmp.components(separatedBy: "\n")
return tmpParts
}
else if (numDispl == 3) {
let tmp = run("cat ~/.ath/scr.txt | grep Resolution | cut -c 23-")
let tmpParts = tmp.components(separatedBy: "\n")
return tmpParts
}
return []
}
static func getDisplayNames() -> [String] {
let numDispl = getNumDisplays()
if numDispl == 1 {
if(qhasBuiltInDisplay) {
return [run("""
echo "$(cat ~/.ath/scr.txt | grep "Display Type" | cut -c 25-)"
echo "$(cat ~/.ath/scrXml.txt | grep -A2 "</data>" | awk -F'>|<' '/_name/{getline; print $3}')" | tr -d '\n'
""")] }
else {
return [run("""
echo "$(cat ~/.ath/scr.txt | grep " " | cut -c 9- | grep "^[A-Za-z]" | cut -f 1 -d ":")"
""")]
}
}
else if (numDispl == 2 || numDispl == 3) {
print("2 or 3 displays found")
let tmp = run("""
echo "$(cat ~/.ath/scr.txt | grep "Display Type" | cut -c 25-)"
echo "$(cat ~/.ath/scr.txt | grep " " | cut -c 9- | grep "^[A-Za-z]" | cut -f 1 -d ":")"
""")
let tmpParts = tmp.components(separatedBy: "\n")
var toSend: [String] = []
if(qhasBuiltInDisplay) {
toSend.append(tmpParts[0])
for i in 2...tmpParts.count-1 {
toSend.append(tmpParts[i])
}
return toSend
}
else {
return [String](tmpParts.dropFirst())
}
}
return []
}
static func getNumDisplays() -> Int {
return Int(run("cat ~/.ath/scr.txt | grep -c Resolution | tr -d '\n'")) ?? 0x0
}
static func hasBuiltInDisplay() -> Bool {
let tmp = run("cat ~/.ath/scr.txt | grep Built-In | tr -d '\n'")
return !(tmp == "")
}
static func getStorageType() -> Bool {
let name = "\(HCStartupDisk.getStartupDisk())"
print("Startup Disk Name " + name)
let storageType = run("grep 'Solid State' ~/.ath/sysvolname.txt")
return storageType.contains("Yes")
}
static func getStorageData() -> [String] {
let name = "\(HCStartupDisk.getStartupDisk())"
let size = run("diskutil info \"\(name)\" | grep 'Disk Size' | sed 's/.*:[[:space:]]*//' | cut -f1 -d'(' | tr -d '\n'")
let available = run("diskutil info \"\(name)\" | Grep 'Container Free Space' | sed 's/.*:[[:space:]]*//' | cut -f1 -d'(' | tr -d '\n'")
let sizeTrimmed = run("echo \"\(size)\" | cut -f1 -d\" \"").dropLast(1)
let availableTrimmed = run("echo \"\(available)\" | cut -f1 -d\" \"").dropLast(1)
print("Size: \(sizeTrimmed)")
print("Available: \(availableTrimmed)")
let percent = (Double(availableTrimmed)!) / Double(sizeTrimmed)!
print("%: \(1 - percent)")
return ["""
\(name)
\(size)(\(available)Available)
""", String(1 - percent)]
}
}