@@ -25,32 +25,32 @@ class ProgressVC: NSViewController {
2525 override func viewDidLoad( ) {
2626 super. viewDidLoad ( )
2727 Loader . shared. loadConfig ( )
28- let myContext = LAContext ( )
29- let myLocalizedReasonString = " unlock itself "
30-
31- var authError : NSError ? = nil
32- if #available( iOS 8 . 0 , OSX 10 . 12 , * ) {
33- if myContext. canEvaluatePolicy ( LAPolicy . deviceOwnerAuthentication, error: & authError) {
34- myContext. evaluatePolicy ( LAPolicy . deviceOwnerAuthentication, localizedReason: myLocalizedReasonString) { ( success, evaluateError) in
35- if ( success) {
36- // User authenticated successfully, take appropriate action
37- print ( " Success " )
28+ // let myContext = LAContext()
29+ // let myLocalizedReasonString = "unlock itself"
30+ //
31+ // var authError: NSError? = nil
32+ // if #available(iOS 8.0, OSX 10.12, *) {
33+ // if myContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: &authError) {
34+ // myContext.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: myLocalizedReasonString) { (success, evaluateError) in
35+ // if (success) {
36+ // // User authenticated successfully, take appropriate action
37+ // print("Success")
3838 self . primaryLink = self . generateLink ( )
3939 self . loadSignature ( )
40- } else {
41- // User did not authenticate successfully, look at error and take appropriate action
42- print ( " Failure " )
43- }
44- }
45- } else {
46- // Could not evaluate policy; look at authError and present an appropriate message to user
47- print ( " Evaluation " )
48- print ( authError)
49- }
50- } else {
51- // Fallback on earlier versions
52- print ( " Fallback " )
53- }
40+ // } else {
41+ // // User did not authenticate successfully, look at error and take appropriate action
42+ // print("Failure")
43+ // }
44+ // }
45+ // } else {
46+ // // Could not evaluate policy; look at authError and present an appropriate message to user
47+ // print("Evaluation")
48+ // print(authError)
49+ // }
50+ // } else {
51+ // // Fallback on earlier versions
52+ // print("Fallback")
53+ // }
5454 }
5555
5656 func downloadFileDestination( fileName: String ) -> DownloadRequest . DownloadFileDestination {
@@ -66,17 +66,21 @@ class ProgressVC: NSViewController {
6666
6767 func untar ( ) {
6868 let documentsPath = NSSearchPathForDirectoriesInDomains ( . applicationSupportDirectory, . userDomainMask, true ) [ 0 ]
69- let dataPath = documentsPath. appending ( " / \( Loader . shared. config. name ?? " installer " ) /file.tar.gz " )
69+ let dataPath = documentsPath. appending ( " / \( Loader . shared. config. name ?? " installer " ) " )
70+ let filePath = dataPath. appending ( " /file.tar.gz " )
7071 let toPath = documentsPath. appending ( " / \( Loader . shared. config. name ?? " installer " ) /application " )
7172 print ( toPath)
7273 print ( dataPath)
73- do {
74- try DCTar . decompressFile ( atPath: dataPath, toPath: toPath)
75- self . progressIndicator. doubleValue += 20
76- } catch ( let error) {
77- print ( error)
78- self . errorReadingResults ( question: " Ошибка " , text: error. localizedDescription)
74+
75+
76+ let script = NSAppleScript ( source: " do shell script \" cd ' " + dataPath + " ' && tar -xzvf ' " + filePath + " ' \" " )
77+ var errorInfo : NSDictionary ?
78+ script? . executeAndReturnError ( & errorInfo)
79+ if let error = errorInfo {
80+ print ( " ERROR: \( error) " )
81+ self . errorReadingResults ( question: " Ошибка " , text: " Ошибка при разархивировании " )
7982 }
83+ self . progressIndicator. doubleValue += 20
8084 }
8185
8286 func loadSignature( ) {
@@ -168,9 +172,10 @@ class ProgressVC: NSViewController {
168172 func copyAppToApplication ( ) {
169173 let documentsPath = NSSearchPathForDirectoriesInDomains ( . applicationSupportDirectory, . userDomainMask, true ) [ 0 ]
170174 let documentsURL = URL ( fileURLWithPath: documentsPath, isDirectory: true )
171- let fileURL = documentsURL. appendingPathComponent ( " \( Loader . shared. config. name ?? " installer " ) /application " )
172-
173- let destURL = URL ( fileURLWithPath: " /Applications/ " , isDirectory: true )
175+ let fileURL = documentsURL. appendingPathComponent ( " \( Loader . shared. config. name ?? " installer " ) " )
176+
177+ let applicationsPath = NSSearchPathForDirectoriesInDomains ( . applicationDirectory, . userDomainMask, true ) [ 0 ]
178+ let destURL = URL ( fileURLWithPath: applicationsPath, isDirectory: true )
174179 let completelyDestURL = destURL. appendingPathComponent ( Loader . shared. config. name ?? " Application " , isDirectory: true )
175180 print ( completelyDestURL)
176181
@@ -189,10 +194,10 @@ class ProgressVC: NSViewController {
189194 let appFilePaths = filePaths. filter { $0. contains ( kEXTENSION) }
190195 for appFilePath in appFilePaths{
191196 if String ( appFilePath. suffix ( 4 ) ) == kEXTENSION {
192-
193197 var fullNameArr = appFilePath. components ( separatedBy: " / " )
194198 let appFilePathNew = fullNameArr [ fullNameArr. count- 1 ]
195-
199+ NameStorage . shared. data. append ( appFilePathNew)
200+
196201 if !fileManager. fileExists ( atPath: completelyDestURL. appendingPathComponent ( appFilePathNew) . path) {
197202 do {
198203 try fileManager. copyItem ( at: fileURL. appendingPathComponent ( appFilePath, isDirectory: false ) , to: completelyDestURL. appendingPathComponent ( appFilePathNew) )
@@ -213,9 +218,18 @@ class ProgressVC: NSViewController {
213218 print ( destURL)
214219 }
215220 }
216- DispatchQueue . main. async {
217- self . statusLabel. stringValue = " Копирование завершено "
218- self . progressIndicator. increment ( by: 20 )
221+ self . changeProgress ( withText: " Копирование завершено " , toProgress: 20 )
222+
223+ }
224+
225+ func deleteFileAtPath ( _ file: String ) {
226+ let fileManager = FileManager . default
227+ if fileManager. fileExists ( atPath: file) {
228+ do {
229+ try fileManager. removeItem ( atPath: file)
230+ } catch let error as NSError {
231+ print ( error)
232+ }
219233 }
220234 }
221235
@@ -236,4 +250,11 @@ class ProgressVC: NSViewController {
236250 }
237251 }
238252 }
253+
254+ func changeProgress ( withText: String , toProgress: Double ) {
255+ DispatchQueue . main. async {
256+ self . statusLabel. stringValue = withText
257+ self . progressIndicator. increment ( by: toProgress)
258+ }
259+ }
239260}
0 commit comments