-
Notifications
You must be signed in to change notification settings - Fork 12
/
MODs.swift
51 lines (42 loc) · 1.11 KB
/
MODs.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
//
// MODs.swift
// my41
//
// Created by Miroslav Perovic on 2.2.21..
// Copyright © 2021 iPera. All rights reserved.
//
import Foundation
struct MODs {
private var allMODFiles = [String]()
private init() {
allMODFiles = modFilesInBundle()
removeLoadedModules()
}
private func modFilesInBundle() -> [String] {
return Bundle.main.paths(forResourcesOfType: "mod", inDirectory: nil)
.map {
NSString(string: $0)
}.filter {
$0.lastPathComponent != "nut-c.mod" && $0.lastPathComponent != "nut-cv.mod" && $0.lastPathComponent != "nut-cx.mod"
} as [String]
}
private mutating func removeLoadedModules() {
let defaults = UserDefaults.standard
HPPort.allCases.forEach {
if let path = defaults.string(forKey: $0.rawValue) {
allMODFiles.remove(path)
}
}
}
static func getModFiles() -> [String : MOD] {
let mods = MODs()
var modFiles = [String : MOD]()
mods.allMODFiles.forEach {
if let modFile = try? MOD(modName: $0, withMemoryCheck: false) {
let name = NSString(string: $0).lastPathComponent as String
modFiles[name] = modFile
}
}
return modFiles
}
}