Skip to content

Commit 4f0f6ef

Browse files
committed
alr
1 parent a24c699 commit 4f0f6ef

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

lara/classes/laramgr.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -564,31 +564,34 @@ final class laramgr: ObservableObject {
564564
func setplistvalue(path: String, key: (key: String, value: Any?), force: Bool = false) -> (ok: Bool, message: String) {
565565
do {
566566
let fm = FileManager.default
567-
if !fm.fileExists(atPath: path) && !force {
568-
return (false, "file at \(path) does not exist or couldn't be found")
569-
}
570-
if var dict = NSMutableDictionary(contentsOf: URL(fileURLWithPath: path)) ?? [:] {
571-
if let value = key.value {
572-
dict[key.key] = value
573-
} else {
574-
dict.removeObject(forKey: key.key)
575-
}
576-
let data = try PropertyListSerialization.data(
577-
fromPropertyList: dict,
578-
format: .binary,
579-
options: 0
580-
)
581-
let result = self.lara_overwritefile(
582-
target: path,
583-
data: data
584-
)
585-
if result.ok {
586-
return (true, "overwrote plist at path \(path)")
567+
var dict = NSMutableDictionary()
568+
if !fm.fileExists(atPath: path) {
569+
if !force { return (false, "file at \(path) does not exist or couldn't be found") }
570+
} else {
571+
if let dictfromplist = NSMutableDictionary(contentsOf: URL(fileURLWithPath: path)) {
572+
dict = dictfromplist
587573
} else {
588-
return(false, "overwrite failed: \(result.message)")
574+
return (false, "could not convert plist at \(path) to readable data")
589575
}
576+
}
577+
if let value = key.value {
578+
dict[key.key] = value
579+
} else {
580+
dict.removeObject(forKey: key.key)
581+
}
582+
let data = try PropertyListSerialization.data(
583+
fromPropertyList: dict,
584+
format: .binary,
585+
options: 0
586+
)
587+
let result = self.lara_overwritefile(
588+
target: path,
589+
data: data
590+
)
591+
if result.ok {
592+
return (true, "overwrote plist at path \(path)")
590593
} else {
591-
return(false, "could not convert plist at \(path) to readable data")
594+
return(false, "overwrite failed: \(result.message)")
592595
}
593596
} catch {
594597
return (false, "an error occured: \(error)")
@@ -599,7 +602,7 @@ final class laramgr: ObservableObject {
599602
do {
600603
let fm = FileManager.default
601604
if fm.fileExists(atPath: path) {
602-
if let dict = try NSDictionary(contentsOf: URL(fileURLWithPath: path)) {
605+
if let dict = NSDictionary(contentsOf: URL(fileURLWithPath: path)) {
603606
if let value = dict[key] {
604607
return (true, "success", value)
605608
} else {

0 commit comments

Comments
 (0)