(buffer: Buffer)
| 178 | * @returns Extracted scheme and simulator information |
| 179 | */ |
| 180 | export function parseXcuserstateBuffer(buffer: Buffer): XcodeStateResult { |
| 181 | const result: XcodeStateResult = {}; |
| 182 | |
| 183 | try { |
| 184 | const [root] = bplistParseBuffer(buffer) as [BplistResult]; |
| 185 | |
| 186 | if (!root || root.$archiver !== 'NSKeyedArchiver' || !Array.isArray(root.$objects)) { |
| 187 | return result; |
| 188 | } |
| 189 | |
| 190 | const objects = root.$objects; |
| 191 | |
| 192 | const activeSchemeIdx = findStringIndex(objects, 'ActiveScheme'); |
| 193 | const activeRunDestIdx = findStringIndex(objects, 'ActiveRunDestination'); |
| 194 | const ideNameStringIdx = findStringIndex(objects, 'IDENameString'); |
| 195 | const targetDeviceLocationIdx = findStringIndex(objects, 'targetDeviceLocation'); |
| 196 | |
| 197 | if (activeSchemeIdx === -1 && activeRunDestIdx === -1) { |
| 198 | return result; |
| 199 | } |
| 200 | |
| 201 | const parentDict = findDictWithKey(objects, activeSchemeIdx); |
| 202 | if (!parentDict) { |
| 203 | return result; |
| 204 | } |
| 205 | |
| 206 | if (activeSchemeIdx !== -1 && ideNameStringIdx !== -1) { |
| 207 | const schemeObj = getValueForKey(objects, parentDict, activeSchemeIdx); |
| 208 | if (typeof schemeObj === 'object' && schemeObj !== null) { |
| 209 | const schemeDict = schemeObj as ArchivedDict; |
| 210 | const schemeName = getValueForKey(objects, schemeDict, ideNameStringIdx); |
| 211 | if (typeof schemeName === 'string') { |
| 212 | result.scheme = schemeName; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if (activeRunDestIdx !== -1 && targetDeviceLocationIdx !== -1) { |
| 218 | const destObj = getValueForKey(objects, parentDict, activeRunDestIdx); |
| 219 | if (typeof destObj === 'object' && destObj !== null) { |
| 220 | const destDict = destObj as ArchivedDict; |
| 221 | const location = getValueForKey(objects, destDict, targetDeviceLocationIdx); |
| 222 | if (typeof location === 'string') { |
| 223 | result.deviceLocation = location; |
| 224 | |
| 225 | const match = location.match(/dvtdevice-([a-z]+):([A-F0-9-]{36})/i); |
| 226 | if (match) { |
| 227 | result.simulatorPlatform = match[1]; |
| 228 | result.simulatorId = match[2]; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } catch (error) { |
| 234 | console.error('Failed to parse xcuserstate buffer:', error); |
| 235 | } |
| 236 | |
| 237 | return result; |
no test coverage detected