CloverBootloader/CloverApp/Clover/Shared.swift
vectorsigma72 66f30d4dc0 Clover.app v1.05 Beta
Added Serbian translation by  crusher and Indonesian bu Badruzeus.
Changing boot1 boot sectors installation to use boo1-intsall only.
Rework on how the nvram get dumped for CloverEFI.
2019-11-17 18:06:44 +01:00

73 lines
2.2 KiB
Swift

//
// Shared.swift
// Clover
//
// Created by vector sigma on 19/10/2019.
// Copyright © 2019 CloverHackyColor. All rights reserved.
//
import Cocoa
// MARK: Paths
let Cloverv2Path : String = Bundle.main.sharedSupportPath! + "/CloverV2"
let kDaemonPath = "/Library/Application Support/Clover/CloverDaemonNew"
let kLaunchPlistPath = "/Library/LaunchDaemons/com.slice.CloverDaemonNew.plist"
// MARK: Run At Login
let gHelperID : CFString = "org.slice.CloverRunAtLogin" as CFString
let kRunAtLogin = "runAtLogin"
// MARK: File Manager
let fm = FileManager.default
// MARK: Standard users defaults
let UDs = UserDefaults.standard
// MARK: Update search interval
enum UpdateInterval: Double {
case never = 0
case daily = 86400
case weekly = 604800
case monthly = 18144000
}
// MARK: Timer interval since last update check keys
let kLastSearchUpdateDateKey = "LastSearchUpdateDate"
let kUpdateSearchInterval = "UpdateSearchInterval"
let kLastUpdateLink = "LastUpdateLink"
let kLastUpdateRevision = "LastUpdateRevision"
// MARK: find Clover Revision
func findCloverRevision(at EFIdir: String) -> String? {
let bootfiles : [String] = ["/BOOT/BOOTX64.efi",
"/CLOVER/CLOVERX64.efi",
"/BOOT/BOOTXIA32.efi",
"/CLOVER/CLOVERIA32.efi"]
let preMatchString = "Clover revision: "
let terminatingCharacter = " "
for b in bootfiles {
if fm.fileExists(atPath: EFIdir + b) {
do {
var rev : NSString? = nil
let stringToSearch : String = try String(contentsOfFile: EFIdir + b, encoding: String.Encoding.ascii)
let scanner : Scanner = Scanner(string: stringToSearch)
scanner.scanUpTo(preMatchString, into: nil)
scanner.scanString(preMatchString, into: nil)
scanner.scanUpTo(terminatingCharacter, into: &rev)
if (rev != nil), let revision = String(cString: (rev?.utf8String)!,
encoding: String.Encoding.utf8)/*&& rev?.length == 4 */{
if revision.count == 4 {
return revision
}
}
} catch {
print(error.localizedDescription)
}
}
}
return nil
}