-
Notifications
You must be signed in to change notification settings - Fork 398
Expand file tree
/
Copy pathExtensions.swift
More file actions
72 lines (63 loc) · 1.93 KB
/
Extensions.swift
File metadata and controls
72 lines (63 loc) · 1.93 KB
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
//
// Extensions.swift
// Postgres
//
// Created by Chris on 04/08/2016.
// Copyright © 2016 postgresapp. All rights reserved.
//
import Foundation
extension FileManager {
func applicationSupportDirectoryPath() -> String {
let url = self.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
let bundleName = Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as! String
let path = url.appendingPathComponent(bundleName).path
if !self.fileExists(atPath: path) {
try! self.createDirectory(atPath: path, withIntermediateDirectories: false)
}
return path
}
func applicationExists(_ appName: String) -> Bool {
var appPath = "/Applications/"
switch appName {
case "Terminal":
appPath += "Utilities/"+appName+".app"
default:
appPath += appName+".app"
}
return self.fileExists(atPath: appPath)
}
}
func is_arm_mac() -> Bool {
// first check the cpu type
var cpu_type: cpu_type_t = 0
var cpu_type_size = MemoryLayout.size(ofValue: cpu_type)
if -1 == sysctlbyname("hw.cputype", &cpu_type, &cpu_type_size, nil, 0) {
// this should never happen
return false
}
if (cpu_type & CPU_TYPE_ARM) == CPU_TYPE_ARM {
return true
}
// When the app is running under Rosetta, hw.cputype reports an Intel CPU
// We want to know the real CPU type, so we have to check for Rosetta
// If we detect Rosetta, we are running on ARM
var is_translated: Int = 0;
var is_translated_size = MemoryLayout.size(ofValue: is_translated)
if -1 == sysctlbyname("sysctl.proc_translated", &is_translated, &is_translated_size, nil, 0) {
// if this call fails we are probably running on Intel
return false
}
else if is_translated != 0 {
// process is translated with Rosetta -> we must be on ARM
return true
}
else {
return false
}
}
extension ProcessInfo {
var macosDisplayVersion: String {
let v = operatingSystemVersion
return "\(v.majorVersion).\(v.minorVersion).\(v.patchVersion)"
}
}