@@ -29,34 +29,21 @@ import Foundation
2929public class Configuration : NSObject , Codable
3030{
3131 @objc public dynamic var name : String
32- @objc public dynamic var swiftFormat : URL
33- @objc public dynamic var uncrustify : URL
32+ @objc public dynamic var swiftFormat : URL ?
33+ @objc public dynamic var uncrustify : URL ?
3434 @objc public dynamic var downloading = false
3535
3636 public static var defaultConfigurations : [ Configuration ]
3737 {
3838 [
39- Configuration ( name: " XS-Labs " , swiftFormat: " https://raw.githubusercontent.com/macmade/cgl/main/config/swiftformat-xs " , uncrustify: " https://raw.githubusercontent.com/macmade/cgl/main/config/uncrustify.cfg " ) ,
40- Configuration ( name: " XS-Labs (MIT) " , swiftFormat: " https://raw.githubusercontent.com/macmade/cgl/main/config/swiftformat-xs-mit " , uncrustify: " https://raw.githubusercontent.com/macmade/cgl/main/config/uncrustify.cfg " ) ,
41- Configuration ( name: " DigiDNA " , swiftFormat: " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/swiftformat-ddna " , uncrustify: " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/uncrustify.cfg " ) ,
42- Configuration ( name: " DigiDNA (MIT) " , swiftFormat: " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/swiftformat-ddna-mit " , uncrustify: " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/uncrustify.cfg " ) ,
39+ Configuration ( name: " XS-Labs " , swiftFormat: URL ( string : " https://raw.githubusercontent.com/macmade/cgl/main/config/swiftformat-xs " ) , uncrustify: URL ( string : " https://raw.githubusercontent.com/macmade/cgl/main/config/uncrustify.cfg " ) ) ,
40+ Configuration ( name: " XS-Labs (MIT) " , swiftFormat: URL ( string : " https://raw.githubusercontent.com/macmade/cgl/main/config/swiftformat-xs-mit " ) , uncrustify: URL ( string : " https://raw.githubusercontent.com/macmade/cgl/main/config/uncrustify.cfg " ) ) ,
41+ Configuration ( name: " DigiDNA " , swiftFormat: URL ( string : " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/swiftformat-ddna " ) , uncrustify: URL ( string : " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/uncrustify.cfg " ) ) ,
42+ Configuration ( name: " DigiDNA (MIT) " , swiftFormat: URL ( string : " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/swiftformat-ddna-mit " ) , uncrustify: URL ( string : " https://raw.githubusercontent.com/DigiDNA/cgl/main/config/uncrustify.cfg " ) ) ,
4343 ]
44- . compactMap { $0 }
4544 }
4645
47- public convenience init ? ( name: String , swiftFormat: String , uncrustify: String )
48- {
49- guard let swiftFormat = URL ( string: swiftFormat ) ,
50- let uncrustify = URL ( string: uncrustify )
51- else
52- {
53- return nil
54- }
55-
56- self . init ( name: name, swiftFormat: swiftFormat, uncrustify: uncrustify )
57- }
58-
59- public init ( name: String , swiftFormat: URL , uncrustify: URL )
46+ public init ( name: String , swiftFormat: URL ? , uncrustify: URL ? )
6047 {
6148 self . name = name
6249 self . swiftFormat = swiftFormat
@@ -106,8 +93,15 @@ public class Configuration: NSObject, Codable
10693
10794 DispatchQueue . global ( qos: . userInitiated ) . async
10895 {
109- self . download ( url: self . swiftFormat )
110- self . download ( url: self . uncrustify )
96+ if let url = self . swiftFormat
97+ {
98+ self . download ( url: url )
99+ }
100+
101+ if let url = self . uncrustify
102+ {
103+ self . download ( url: url )
104+ }
111105
112106 DispatchQueue . main. async
113107 {
@@ -138,30 +132,46 @@ public class Configuration: NSObject, Codable
138132 }
139133 }
140134
141- public func withConfigurations( completion: ( ( swiftFormat: URL , uncrustify: URL , finished: ( ) -> Void ) ) -> Void , error: ( ) -> Void )
135+ public func withConfigurations( completion: ( ( swiftFormat: URL ? , uncrustify: URL ? , finished: ( ) -> Void ) ) -> Void , error: ( ) -> Void )
142136 {
143- guard let swiftFormat = self . copy ( url: self . swiftFormat ) ,
144- let uncrustify = self . copy ( url: self . uncrustify )
145- else
137+ let swiftFormat = self . copy ( url: self . swiftFormat )
138+ let uncrustify = self . copy ( url: self . uncrustify )
139+
140+ if ( self . swiftFormat != nil && swiftFormat == nil ) || ( self . uncrustify != nil && uncrustify == nil )
146141 {
147- error ( )
148142 self . download ( )
143+ }
144+
145+ if swiftFormat == nil , uncrustify == nil
146+ {
147+ error ( )
149148
150149 return
151150 }
152151
153152 let finished : ( ) -> Void =
154153 {
155- try ? FileManager . default. removeItem ( at: swiftFormat )
156- try ? FileManager . default. removeItem ( at: uncrustify )
154+ [
155+ swiftFormat,
156+ uncrustify,
157+ ]
158+ . compactMap
159+ {
160+ $0
161+ }
162+ . forEach
163+ {
164+ try ? FileManager . default. removeItem ( at: $0 )
165+ }
157166 }
158167
159168 completion ( ( swiftFormat: swiftFormat, uncrustify: uncrustify, finished: finished ) )
160169 }
161170
162- private func copy( url: URL ) -> URL ?
171+ private func copy( url: URL ? ) -> URL ?
163172 {
164- guard let sha256 = url. sha256,
173+ guard let url = url,
174+ let sha256 = url. sha256,
165175 let container = FileManager . sharedContainerURL? . appendingPathComponent ( " Configurations " )
166176 else
167177 {
0 commit comments