From ab7477de4496e585870b0a03796d12aa004048c6 Mon Sep 17 00:00:00 2001 From: Alin Date: Mon, 22 Jan 2024 16:26:25 -0700 Subject: [PATCH] v2.3 --- Pearcleaner.xcodeproj/project.pbxproj | 8 ++-- Pearcleaner/Logic/Locations.swift | 3 +- Pearcleaner/Logic/Logic.swift | 68 +++++++++++++++++++++------ Pearcleaner/Views/MiniMode.swift | 1 + 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/Pearcleaner.xcodeproj/project.pbxproj b/Pearcleaner.xcodeproj/project.pbxproj index dba5e16..913993a 100644 --- a/Pearcleaner.xcodeproj/project.pbxproj +++ b/Pearcleaner.xcodeproj/project.pbxproj @@ -543,7 +543,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 13; + CURRENT_PROJECT_VERSION = 14; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -561,7 +561,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.2; + MARKETING_VERSION = 2.3; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -578,7 +578,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 13; + CURRENT_PROJECT_VERSION = 14; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -596,7 +596,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.2; + MARKETING_VERSION = 2.3; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/Pearcleaner/Logic/Locations.swift b/Pearcleaner/Logic/Locations.swift index 6dbb0a8..ac1646a 100644 --- a/Pearcleaner/Logic/Locations.swift +++ b/Pearcleaner/Logic/Locations.swift @@ -35,10 +35,9 @@ struct Locations { "\(home)/Library/Application Support/CrashReporter", "\(home)/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments", "\(home)/Library/Containers", - "\(home)/Library/Group Containers", +// "\(home)/Library/Group Containers", // This is now handled by the function getGroupContainers() "\(home)/Library/Caches", "\(home)/Library/HTTPStorages", - "\(home)/Library/Group Containers", "\(home)/Library/Internet Plug-Ins", "\(home)/Library/LaunchAgents", "\(home)/Library/Logs", diff --git a/Pearcleaner/Logic/Logic.swift b/Pearcleaner/Logic/Logic.swift index 1b53762..84f9792 100644 --- a/Pearcleaner/Logic/Logic.swift +++ b/Pearcleaner/Logic/Logic.swift @@ -56,7 +56,7 @@ func getApplications() -> (systemApps: [URL], userApps: [URL]) { print("Error: \(error)") } } - + // Collect system applications collectAppPaths(at: systemAppsPath, isSystem: true) @@ -300,8 +300,9 @@ func findPathsForApp(appState: AppState, appInfo: AppInfo) { } dispatchGroup.enter() // Enter the dispatch group - + do { + let contents = try fileManager.contentsOfDirectory(atPath: location) for item in contents { @@ -340,11 +341,14 @@ func findPathsForApp(appState: AppState, appInfo: AppInfo) { // collection.append(itemURL) // } // Catch MS Office files since they have many random folder names and very short names - } else if itemL.contains("office") || itemL.contains("oneauth") || itemL.suffix(2).contains("ms") || itemL.contains("onenote") { - if itemL.contains(bundle) || itemL.contains(bundleIdentifierL) || (nameL.count > 4 && itemL.contains(nameL)) { - collection.append(itemURL) - } - } else { + } + // This is now covered by the group container logic, not needed anymore +// else if itemL.contains("office") || itemL.contains("oneauth") || itemL.suffix(2).contains("ms") || itemL.contains("onenote") { +// if itemL.contains(bundle) || itemL.contains(bundleIdentifierL) || (nameL.count > 4 && itemL.contains(nameL)) { +// collection.append(itemURL) +// } +// } + else { if itemL.contains(bundleIdentifierL) || itemL.contains(bundle) || (nameL.count > 3 && itemL.contains(nameL)) { collection.append(itemURL) } @@ -357,20 +361,54 @@ func findPathsForApp(appState: AppState, appInfo: AppInfo) { } dispatchGroup.leave() // Leave the dispatch group - - dispatchGroup.notify(queue: .main) { - updateOnMain { - appState.paths = collection - appState.selectedItems = Set(collection) - } - } - + } + + // Append group containers + let groupContainers = getGroupContainers(bundleURL: appState.appInfo.path) + collection.append(contentsOf: groupContainers) + let sortedCollection = collection.sorted(by: { $0.absoluteString < $1.absoluteString }) + + // Save to appState + dispatchGroup.notify(queue: .main) { + updateOnMain { + appState.paths = sortedCollection + appState.selectedItems = Set(sortedCollection) + } + } + } } +func getGroupContainers(bundleURL: URL) -> [URL] { + var staticCode: SecStaticCode? + + guard SecStaticCodeCreateWithPath(bundleURL as CFURL, [], &staticCode) == errSecSuccess else { + return [] + } + + var signingInformation: CFDictionary? + + let status = SecCodeCopySigningInformation(staticCode!, SecCSFlags(), &signingInformation) + + if status != errSecSuccess { + print("Failed to copy signing information. Status: \(status)") + return [] + } + + guard let topDict = signingInformation as? [String: Any], + let entitlementsDict = topDict["entitlements-dict"] as? [String: Any], + let appGroups = entitlementsDict["com.apple.security.application-groups"] as? [String] else { +// print("No application groups to extract from entitlements for this app.") + return [] + } + + let groupContainersPath = appGroups.map { URL(fileURLWithPath: "\(home)/Library/Group Containers/" + $0) } + + return groupContainersPath +} // Move files to trash using applescript/Finder so it asks for user password if needed diff --git a/Pearcleaner/Views/MiniMode.swift b/Pearcleaner/Views/MiniMode.swift index 52f64c1..51511b7 100644 --- a/Pearcleaner/Views/MiniMode.swift +++ b/Pearcleaner/Views/MiniMode.swift @@ -43,6 +43,7 @@ struct MiniMode: View { FilesView(showPopover: $showPopover, search: $search) .id(appState.appInfo.id) } + .interactiveDismissDisabled() .background( Rectangle() .fill(Color("pop"))