@@ -29,7 +29,7 @@ import SwiftUI
2929 @State private var folderPassword : String = " "
3030 @State private var searchText : String = " "
3131 @State private var destURL : URL ? = nil
32- @State private var selection : Set < EncryptedFileEntry . ID > = [ ]
32+ @State private var selectedDecryptedPaths : Set < String > = [ ]
3333 @State private var showSuccessMessage = false
3434 @State private var keepFolderStructure = true
3535
@@ -63,7 +63,7 @@ import SwiftUI
6363 . disabled ( folderPassword. isEmpty || folderID. isEmpty || sourceURL == nil )
6464 }
6565
66- Section ( " \( selection . count) files selected " ) {
66+ Section ( " \( selectedDecryptedPaths . count) files selected " ) {
6767 LabeledContent ( " Folder " ) {
6868 HStack {
6969 Text ( destURL? . lastPathComponent ?? " " )
@@ -78,12 +78,12 @@ import SwiftUI
7878 Text ( " Recreate folder structure " )
7979 }
8080
81- Button ( " Decrypt \( selection . count) files " ) {
81+ Button ( " Decrypt \( selectedDecryptedPaths . count) files " ) {
8282 Task {
8383 await self . decryptSelection ( )
8484 }
8585 } . disabled ( destURL == nil )
86- } . disabled ( folderPassword. isEmpty || folderID. isEmpty || sourceURL == nil || selection . isEmpty)
86+ } . disabled ( folderPassword. isEmpty || folderID. isEmpty || sourceURL == nil || selectedDecryptedPaths . isEmpty)
8787 }
8888 . formStyle ( . grouped)
8989 . disabled ( loading)
@@ -104,8 +104,9 @@ import SwiftUI
104104 else if sourceURL != nil && !folderID. isEmpty && !folderPassword. isEmpty {
105105 // List of files
106106 DecrypterItemsView (
107- folderID: folderID, folderPassword: folderPassword, entries: searchText. isEmpty ? allEntries : foundEntries,
108- selection: $selection)
107+ folderID: folderID, folderPassword: folderPassword,
108+ entries: searchText. isEmpty ? allEntries : foundEntries,
109+ selectedDecryptedPaths: $selectedDecryptedPaths)
109110 }
110111 else {
111112 ContentUnavailableView {
@@ -190,18 +191,23 @@ import SwiftUI
190191 let folderID = self . folderID
191192 let folderPassword = self . folderPassword
192193 let destURL = self . destURL
193- let selection = self . selection
194+ let selectedDecryptedPaths = self . selectedDecryptedPaths
194195 let sourceURL = self . sourceURL
195196 let keepFolderStructure = self . keepFolderStructure
197+ let entries = self . allEntries
196198
197199 await Task . detached ( priority: . userInitiated) {
198200 do {
199201 // Keep a bookmark accessor alive whle we write files to the destination URL
200202 try withExtendedLifetime ( try BookmarkManager . Accessor ( url: destURL!) ) {
201203 let folderKey = SushitrainNewFolderKey ( folderID, folderPassword)
202- for fileURL in selection {
204+ for entry in entries {
205+ if !selectedDecryptedPaths. contains ( entry. decryptedPath) {
206+ continue
207+ }
208+
203209 let rootPath = sourceURL!. path ( percentEncoded: false )
204- let filePath = URL ( string : fileURL ) ! . path ( percentEncoded: false )
210+ let filePath = entry . url . path ( percentEncoded: false )
205211 let trimmedPath = String ( filePath. trimmingPrefix ( rootPath) )
206212 Log . info ( " Decrypt \( trimmedPath) \( sourceURL!) \( destURL!) " )
207213 try folderKey? . decryptFile (
@@ -289,22 +295,23 @@ import SwiftUI
289295 let folderID : String
290296 let folderPassword : String
291297 let entries : [ EncryptedFileEntry ]
298+ @State private var decryptedPaths : [ String ] = [ ]
292299
293- @Binding var selection : Set < EncryptedFileEntry . ID >
300+ @Binding var selectedDecryptedPaths : Set < String >
294301
295302 var body : some View {
296- Table (
297- of : EncryptedFileEntry . self , selection : $selection ,
298- columns : {
299- TableColumn ( " File name " ) { ( entry : EncryptedFileEntry ) in
300- Text ( entry . decryptedPath )
301- }
302- } ,
303- rows : {
304- ForEach ( entries ) { entry in
305- TableRow ( entry )
306- }
307- } )
303+ List ( selection : $selectedDecryptedPaths ) {
304+ PathsOutlineGroup ( paths : decryptedPaths ) { decryptedPath , isIntermediate in
305+ Text ( decryptedPath . lastPathComponent )
306+ }
307+ }
308+ . task {
309+ await self . update ( )
310+ }
311+ }
312+
313+ private func update ( ) async {
314+ self . decryptedPaths = self . entries . map { $0 . decryptedPath }
308315 }
309316 }
310317
0 commit comments