@@ -14,6 +14,11 @@ internal import Synchronization
1414@available ( FoundationPreview 6 . 2 , * )
1515extension ProgressManager {
1616
17+ internal enum CountType {
18+ case total
19+ case completed
20+ }
21+
1722 //MARK: Methods to get updated summary of properties
1823 internal func getUpdatedIntSummary( property: MetatypeWrapper < Int > ) -> Int {
1924 return state. withLock { state in
@@ -167,11 +172,6 @@ extension ProgressManager {
167172 }
168173 }
169174
170- internal enum CountType {
171- case total
172- case completed
173- }
174-
175175 internal func getUpdatedFileCount( type: CountType ) -> Int {
176176 switch type {
177177 case . total:
@@ -369,4 +369,194 @@ extension ProgressManager {
369369 return value
370370 }
371371 }
372+
373+ //MARK: Methods to set dirty bit recursively
374+ internal func markSelfDirty( property: MetatypeWrapper < Int > , parents: [ ParentState ] ) {
375+ for parentState in parents {
376+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
377+ }
378+ }
379+
380+ internal func markSelfDirty( property: MetatypeWrapper < Double > , parents: [ ParentState ] ) {
381+ for parentState in parents {
382+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
383+ }
384+ }
385+
386+ internal func markSelfDirty( property: MetatypeWrapper < String > , parents: [ ParentState ] ) {
387+ for parentState in parents {
388+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
389+ }
390+ }
391+
392+ internal func markSelfDirty( property: ProgressManager . Properties . TotalFileCount . Type , parents: [ ParentState ] ) {
393+ for parentState in parents {
394+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
395+ }
396+ }
397+
398+ internal func markSelfDirty( property: ProgressManager . Properties . CompletedFileCount . Type , parents: [ ParentState ] ) {
399+ for parentState in parents {
400+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
401+ }
402+ }
403+
404+ internal func markSelfDirty( property: ProgressManager . Properties . TotalByteCount . Type , parents: [ ParentState ] ) {
405+ for parentState in parents {
406+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
407+ }
408+ }
409+
410+ internal func markSelfDirty( property: ProgressManager . Properties . CompletedByteCount . Type , parents: [ ParentState ] ) {
411+ for parentState in parents {
412+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
413+ }
414+ }
415+
416+ internal func markSelfDirty( property: ProgressManager . Properties . Throughput . Type , parents: [ ParentState ] ) {
417+ for parentState in parents {
418+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
419+ }
420+ }
421+
422+ internal func markSelfDirty( property: ProgressManager . Properties . EstimatedTimeRemaining . Type , parents: [ ParentState ] ) {
423+ for parentState in parents {
424+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
425+ }
426+ }
427+
428+ internal func markSelfDirty( property: ProgressManager . Properties . FileURL . Type , parents: [ ParentState ] ) {
429+ for parentState in parents {
430+ parentState. parent. markChildDirty ( property: property, at: parentState. positionInParent)
431+ }
432+ }
433+
434+ internal func markChildDirty( property: MetatypeWrapper < Int > , at position: Int ) {
435+ let parents = state. withLock { state in
436+ state. children [ position] . childPropertiesInt [ property] ? . isDirty = true
437+ return state. parents
438+ }
439+ markSelfDirty ( property: property, parents: parents)
440+ }
441+
442+ internal func markChildDirty( property: MetatypeWrapper < Double > , at position: Int ) {
443+ let parents = state. withLock { state in
444+ state. children [ position] . childPropertiesDouble [ property] ? . isDirty = true
445+ return state. parents
446+ }
447+ markSelfDirty ( property: property, parents: parents)
448+ }
449+
450+ internal func markChildDirty( property: MetatypeWrapper < String > , at position: Int ) {
451+ let parents = state. withLock { state in
452+ state. children [ position] . childPropertiesString [ property] ? . isDirty = true
453+ return state. parents
454+ }
455+ markSelfDirty ( property: property, parents: parents)
456+ }
457+
458+ internal func markChildDirty( property: ProgressManager . Properties . TotalFileCount . Type , at position: Int ) {
459+ let parents = state. withLock { state in
460+ state. children [ position] . totalFileCount. isDirty = true
461+ return state. parents
462+ }
463+ markSelfDirty ( property: property, parents: parents)
464+ }
465+
466+ internal func markChildDirty( property: ProgressManager . Properties . CompletedFileCount . Type , at position: Int ) {
467+ let parents = state. withLock { state in
468+ state. children [ position] . completedFileCount. isDirty = true
469+ return state. parents
470+ }
471+ markSelfDirty ( property: property, parents: parents)
472+ }
473+
474+ internal func markChildDirty( property: ProgressManager . Properties . TotalByteCount . Type , at position: Int ) {
475+ let parents = state. withLock { state in
476+ state. children [ position] . totalByteCount. isDirty = true
477+ return state. parents
478+ }
479+ markSelfDirty ( property: property, parents: parents)
480+ }
481+
482+ internal func markChildDirty( property: ProgressManager . Properties . CompletedByteCount . Type , at position: Int ) {
483+ let parents = state. withLock { state in
484+ state. children [ position] . completedByteCount. isDirty = true
485+ return state. parents
486+ }
487+ markSelfDirty ( property: property, parents: parents)
488+ }
489+
490+ internal func markChildDirty( property: ProgressManager . Properties . Throughput . Type , at position: Int ) {
491+ let parents = state. withLock { state in
492+ state. children [ position] . throughput. isDirty = true
493+ return state. parents
494+ }
495+ markSelfDirty ( property: property, parents: parents)
496+ }
497+
498+ internal func markChildDirty( property: ProgressManager . Properties . EstimatedTimeRemaining . Type , at position: Int ) {
499+ let parents = state. withLock { state in
500+ state. children [ position] . estimatedTimeRemaining. isDirty = true
501+ return state. parents
502+ }
503+ markSelfDirty ( property: property, parents: parents)
504+ }
505+
506+ internal func markChildDirty( property: ProgressManager . Properties . FileURL . Type , at position: Int ) {
507+ let parents = state. withLock { state in
508+ state. children [ position] . fileURL. isDirty = true
509+ return state. parents
510+ }
511+ markSelfDirty ( property: property, parents: parents)
512+ }
513+
514+ //MARK: Methods to preserve values of properties upon deinit
515+ internal func setChildRemainingPropertiesInt( _ properties: [ MetatypeWrapper < Int > : Int ] , at position: Int ) {
516+ state. withLock { state in
517+ state. children [ position] . remainingPropertiesInt = properties
518+ }
519+ }
520+
521+ internal func setChildRemainingPropertiesDouble( _ properties: [ MetatypeWrapper < Double > : Double ] , at position: Int ) {
522+ state. withLock { state in
523+ state. children [ position] . remainingPropertiesDouble = properties
524+ }
525+ }
526+
527+ internal func setChildRemainingPropertiesString( _ properties: [ MetatypeWrapper < String > : String ] , at position: Int ) {
528+ state. withLock { state in
529+ state. children [ position] . remainingPropertiesString = properties
530+ }
531+ }
532+
533+ internal func setChildTotalFileCount( value: Int , at position: Int ) {
534+ state. withLock { state in
535+ state. children [ position] . totalFileCount = PropertyStateInt ( value: value, isDirty: false )
536+ }
537+ }
538+
539+ internal func setChildCompletedFileCount( value: Int , at position: Int ) {
540+ state. withLock { state in
541+ state. children [ position] . completedFileCount = PropertyStateInt ( value: value, isDirty: false )
542+ }
543+ }
544+
545+ internal func setChildTotalByteCount( value: Int64 , at position: Int ) {
546+ state. withLock { state in
547+ state. children [ position] . totalByteCount = PropertyStateInt64 ( value: value, isDirty: false )
548+ }
549+ }
550+
551+ internal func setChildCompletedByteCount( value: Int64 , at position: Int ) {
552+ state. withLock { state in
553+ state. children [ position] . completedByteCount = PropertyStateInt64 ( value: value, isDirty: false )
554+ }
555+ }
556+
557+ internal func setChildThroughput( value: ProgressManager . Properties . Throughput . AggregateThroughput , at position: Int ) {
558+ state. withLock { state in
559+ state. children [ position] . throughput = PropertyStateThroughput ( value: value, isDirty: false )
560+ }
561+ }
372562}
0 commit comments