├── LICENSE ├── PkgsCleaner.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings │ └── xcuserdata │ │ └── mikael.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings ├── xcshareddata │ └── xcschemes │ │ └── PkgsCleaner.xcscheme └── xcuserdata │ └── mikael.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── PkgsCleaner ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── PkgsCleanerIconFinal-1024.png │ │ ├── PkgsCleanerIconFinal-128.png │ │ ├── PkgsCleanerIconFinal-16.png │ │ ├── PkgsCleanerIconFinal-256.png │ │ ├── PkgsCleanerIconFinal-257.png │ │ ├── PkgsCleanerIconFinal-32.png │ │ ├── PkgsCleanerIconFinal-33.png │ │ ├── PkgsCleanerIconFinal-512.png │ │ ├── PkgsCleanerIconFinal-513.png │ │ └── PkgsCleanerIconFinal-64.png │ ├── BlackText.colorset │ │ └── Contents.json │ ├── ColorText.colorset │ │ └── Contents.json │ ├── Contents.json │ └── Warning.iconset │ │ ├── icon_128x128.png │ │ ├── icon_128x128@2x.png │ │ ├── icon_16x16.png │ │ ├── icon_16x16@2x.png │ │ ├── icon_256x256.png │ │ ├── icon_256x256@2x.png │ │ ├── icon_32x32.png │ │ ├── icon_32x32@2x.png │ │ ├── icon_512x512.png │ │ └── icon_512x512@2x.png ├── Base.lproj │ └── MainMenu.xib ├── Bash.swift ├── ExtensionString.swift ├── Info.plist ├── Keychain.swift ├── PkgAndMpkg.swift ├── PkgFromRecipe.swift ├── PkgsCleaner.entitlements └── Variables.swift ├── README.md └── images ├── pkgcleaner_interface.png └── pkgscleanericon.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mikael Löfgren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 731B039B228B090C00C90A3F /* Variables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 731B039A228B090C00C90A3F /* Variables.swift */; }; 11 | 733697AE2265166A001EEA73 /* Bash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 733697AD2265166A001EEA73 /* Bash.swift */; }; 12 | 7354C15D22F565000045B6F5 /* PkgAndMpkg.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7354C15C22F565000045B6F5 /* PkgAndMpkg.swift */; }; 13 | 7362F6862265156600D07F81 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7362F6852265156600D07F81 /* AppDelegate.swift */; }; 14 | 7362F6882265156600D07F81 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7362F6872265156600D07F81 /* Assets.xcassets */; }; 15 | 7362F68B2265156600D07F81 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7362F6892265156600D07F81 /* MainMenu.xib */; }; 16 | 7367FBEC22F6E80300A0228F /* PkgFromRecipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7367FBEB22F6E80300A0228F /* PkgFromRecipe.swift */; }; 17 | 73A29AFC22DC58B000993172 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73A29AFB22DC58B000993172 /* Keychain.swift */; }; 18 | 73C1536D2269B6A100AF9D1F /* ExtensionString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73C1536C2269B6A100AF9D1F /* ExtensionString.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 731B039A228B090C00C90A3F /* Variables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Variables.swift; sourceTree = ""; }; 23 | 733697AD2265166A001EEA73 /* Bash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bash.swift; sourceTree = ""; }; 24 | 7354C15C22F565000045B6F5 /* PkgAndMpkg.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PkgAndMpkg.swift; sourceTree = ""; }; 25 | 7362F6822265156600D07F81 /* PkgsCleaner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PkgsCleaner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 7362F6852265156600D07F81 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | 7362F6872265156600D07F81 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 7362F68A2265156600D07F81 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 29 | 7362F68C2265156600D07F81 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 7362F68D2265156600D07F81 /* PkgsCleaner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PkgsCleaner.entitlements; sourceTree = ""; }; 31 | 7367FBEB22F6E80300A0228F /* PkgFromRecipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PkgFromRecipe.swift; sourceTree = ""; }; 32 | 73A29AFB22DC58B000993172 /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = ""; }; 33 | 73C1536C2269B6A100AF9D1F /* ExtensionString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionString.swift; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 7362F67F2265156600D07F81 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXFrameworksBuildPhase section */ 45 | 46 | /* Begin PBXGroup section */ 47 | 7362F6792265156600D07F81 = { 48 | isa = PBXGroup; 49 | children = ( 50 | 7362F6842265156600D07F81 /* PkgsCleaner */, 51 | 7362F6832265156600D07F81 /* Products */, 52 | ); 53 | sourceTree = ""; 54 | }; 55 | 7362F6832265156600D07F81 /* Products */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 7362F6822265156600D07F81 /* PkgsCleaner.app */, 59 | ); 60 | name = Products; 61 | sourceTree = ""; 62 | }; 63 | 7362F6842265156600D07F81 /* PkgsCleaner */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | 73C1536C2269B6A100AF9D1F /* ExtensionString.swift */, 67 | 733697AD2265166A001EEA73 /* Bash.swift */, 68 | 7362F6852265156600D07F81 /* AppDelegate.swift */, 69 | 7367FBEB22F6E80300A0228F /* PkgFromRecipe.swift */, 70 | 731B039A228B090C00C90A3F /* Variables.swift */, 71 | 7362F6872265156600D07F81 /* Assets.xcassets */, 72 | 7362F6892265156600D07F81 /* MainMenu.xib */, 73 | 7362F68C2265156600D07F81 /* Info.plist */, 74 | 7362F68D2265156600D07F81 /* PkgsCleaner.entitlements */, 75 | 73A29AFB22DC58B000993172 /* Keychain.swift */, 76 | 7354C15C22F565000045B6F5 /* PkgAndMpkg.swift */, 77 | ); 78 | path = PkgsCleaner; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 7362F6812265156600D07F81 /* PkgsCleaner */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 7362F6902265156600D07F81 /* Build configuration list for PBXNativeTarget "PkgsCleaner" */; 87 | buildPhases = ( 88 | 7362F67E2265156600D07F81 /* Sources */, 89 | 7362F67F2265156600D07F81 /* Frameworks */, 90 | 7362F6802265156600D07F81 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = PkgsCleaner; 97 | productName = PkgsCleaner; 98 | productReference = 7362F6822265156600D07F81 /* PkgsCleaner.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 7362F67A2265156600D07F81 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 1020; 108 | LastUpgradeCheck = 1020; 109 | ORGANIZATIONNAME = "Mikael Löfgren"; 110 | TargetAttributes = { 111 | 7362F6812265156600D07F81 = { 112 | CreatedOnToolsVersion = 10.2; 113 | SystemCapabilities = { 114 | com.apple.HardenedRuntime = { 115 | enabled = 1; 116 | }; 117 | com.apple.Sandbox = { 118 | enabled = 0; 119 | }; 120 | }; 121 | }; 122 | }; 123 | }; 124 | buildConfigurationList = 7362F67D2265156600D07F81 /* Build configuration list for PBXProject "PkgsCleaner" */; 125 | compatibilityVersion = "Xcode 9.3"; 126 | developmentRegion = en; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | Base, 131 | ); 132 | mainGroup = 7362F6792265156600D07F81; 133 | productRefGroup = 7362F6832265156600D07F81 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | 7362F6812265156600D07F81 /* PkgsCleaner */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXResourcesBuildPhase section */ 143 | 7362F6802265156600D07F81 /* Resources */ = { 144 | isa = PBXResourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 7362F6882265156600D07F81 /* Assets.xcassets in Resources */, 148 | 7362F68B2265156600D07F81 /* MainMenu.xib in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | 7362F67E2265156600D07F81 /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 7367FBEC22F6E80300A0228F /* PkgFromRecipe.swift in Sources */, 160 | 7362F6862265156600D07F81 /* AppDelegate.swift in Sources */, 161 | 7354C15D22F565000045B6F5 /* PkgAndMpkg.swift in Sources */, 162 | 733697AE2265166A001EEA73 /* Bash.swift in Sources */, 163 | 731B039B228B090C00C90A3F /* Variables.swift in Sources */, 164 | 73C1536D2269B6A100AF9D1F /* ExtensionString.swift in Sources */, 165 | 73A29AFC22DC58B000993172 /* Keychain.swift in Sources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXSourcesBuildPhase section */ 170 | 171 | /* Begin PBXVariantGroup section */ 172 | 7362F6892265156600D07F81 /* MainMenu.xib */ = { 173 | isa = PBXVariantGroup; 174 | children = ( 175 | 7362F68A2265156600D07F81 /* Base */, 176 | ); 177 | name = MainMenu.xib; 178 | sourceTree = ""; 179 | }; 180 | /* End PBXVariantGroup section */ 181 | 182 | /* Begin XCBuildConfiguration section */ 183 | 7362F68E2265156600D07F81 /* Debug */ = { 184 | isa = XCBuildConfiguration; 185 | buildSettings = { 186 | ALWAYS_SEARCH_USER_PATHS = NO; 187 | CLANG_ANALYZER_NONNULL = YES; 188 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 189 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 190 | CLANG_CXX_LIBRARY = "libc++"; 191 | CLANG_ENABLE_MODULES = YES; 192 | CLANG_ENABLE_OBJC_ARC = YES; 193 | CLANG_ENABLE_OBJC_WEAK = YES; 194 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 195 | CLANG_WARN_BOOL_CONVERSION = YES; 196 | CLANG_WARN_COMMA = YES; 197 | CLANG_WARN_CONSTANT_CONVERSION = YES; 198 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 199 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 200 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 201 | CLANG_WARN_EMPTY_BODY = YES; 202 | CLANG_WARN_ENUM_CONVERSION = YES; 203 | CLANG_WARN_INFINITE_RECURSION = YES; 204 | CLANG_WARN_INT_CONVERSION = YES; 205 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 206 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 207 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 210 | CLANG_WARN_STRICT_PROTOTYPES = YES; 211 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 212 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 213 | CLANG_WARN_UNREACHABLE_CODE = YES; 214 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 215 | CODE_SIGN_IDENTITY = "-"; 216 | COPY_PHASE_STRIP = NO; 217 | DEBUG_INFORMATION_FORMAT = dwarf; 218 | ENABLE_STRICT_OBJC_MSGSEND = YES; 219 | ENABLE_TESTABILITY = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu11; 221 | GCC_DYNAMIC_NO_PIC = NO; 222 | GCC_NO_COMMON_BLOCKS = YES; 223 | GCC_OPTIMIZATION_LEVEL = 0; 224 | GCC_PREPROCESSOR_DEFINITIONS = ( 225 | "DEBUG=1", 226 | "$(inherited)", 227 | ); 228 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 229 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 230 | GCC_WARN_UNDECLARED_SELECTOR = YES; 231 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 232 | GCC_WARN_UNUSED_FUNCTION = YES; 233 | GCC_WARN_UNUSED_VARIABLE = YES; 234 | MACOSX_DEPLOYMENT_TARGET = 10.14; 235 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 236 | MTL_FAST_MATH = YES; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = macosx; 239 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 240 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 241 | }; 242 | name = Debug; 243 | }; 244 | 7362F68F2265156600D07F81 /* Release */ = { 245 | isa = XCBuildConfiguration; 246 | buildSettings = { 247 | ALWAYS_SEARCH_USER_PATHS = NO; 248 | CLANG_ANALYZER_NONNULL = YES; 249 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 250 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 251 | CLANG_CXX_LIBRARY = "libc++"; 252 | CLANG_ENABLE_MODULES = YES; 253 | CLANG_ENABLE_OBJC_ARC = YES; 254 | CLANG_ENABLE_OBJC_WEAK = YES; 255 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_COMMA = YES; 258 | CLANG_WARN_CONSTANT_CONVERSION = YES; 259 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INFINITE_RECURSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 268 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 269 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 270 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 271 | CLANG_WARN_STRICT_PROTOTYPES = YES; 272 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 273 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 274 | CLANG_WARN_UNREACHABLE_CODE = YES; 275 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 276 | CODE_SIGN_IDENTITY = "-"; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu11; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | MACOSX_DEPLOYMENT_TARGET = 10.14; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | MTL_FAST_MATH = YES; 292 | SDKROOT = macosx; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | }; 296 | name = Release; 297 | }; 298 | 7362F6912265156600D07F81 /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | CODE_SIGN_IDENTITY = "Mac Developer"; 303 | CODE_SIGN_STYLE = Automatic; 304 | COMBINE_HIDPI_IMAGES = YES; 305 | DEVELOPMENT_TEAM = 543LXU387V; 306 | ENABLE_HARDENED_RUNTIME = YES; 307 | INFOPLIST_FILE = PkgsCleaner/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = ( 309 | "$(inherited)", 310 | "@executable_path/../Frameworks", 311 | ); 312 | MACOSX_DEPLOYMENT_TARGET = 10.13; 313 | PRODUCT_BUNDLE_IDENTIFIER = se.dicom.pkgscleaner; 314 | PRODUCT_NAME = "$(TARGET_NAME)"; 315 | SWIFT_VERSION = 5.0; 316 | }; 317 | name = Debug; 318 | }; 319 | 7362F6922265156600D07F81 /* Release */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 323 | CODE_SIGN_IDENTITY = "Mac Developer"; 324 | CODE_SIGN_STYLE = Automatic; 325 | COMBINE_HIDPI_IMAGES = YES; 326 | DEVELOPMENT_TEAM = 543LXU387V; 327 | ENABLE_HARDENED_RUNTIME = YES; 328 | INFOPLIST_FILE = PkgsCleaner/Info.plist; 329 | LD_RUNPATH_SEARCH_PATHS = ( 330 | "$(inherited)", 331 | "@executable_path/../Frameworks", 332 | ); 333 | MACOSX_DEPLOYMENT_TARGET = 10.13; 334 | PRODUCT_BUNDLE_IDENTIFIER = se.dicom.pkgscleaner; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | SWIFT_VERSION = 5.0; 337 | }; 338 | name = Release; 339 | }; 340 | /* End XCBuildConfiguration section */ 341 | 342 | /* Begin XCConfigurationList section */ 343 | 7362F67D2265156600D07F81 /* Build configuration list for PBXProject "PkgsCleaner" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | 7362F68E2265156600D07F81 /* Debug */, 347 | 7362F68F2265156600D07F81 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | 7362F6902265156600D07F81 /* Build configuration list for PBXNativeTarget "PkgsCleaner" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 7362F6912265156600D07F81 /* Debug */, 356 | 7362F6922265156600D07F81 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | /* End XCConfigurationList section */ 362 | }; 363 | rootObject = 7362F67A2265156600D07F81 /* Project object */; 364 | } 365 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.xcworkspace/xcuserdata/mikael.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner.xcodeproj/project.xcworkspace/xcuserdata/mikael.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/project.xcworkspace/xcuserdata/mikael.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | EnabledFullIndexStoreVisibility 12 | 13 | IssueFilterStyle 14 | ShowActiveSchemeOnly 15 | LiveSourceIssuesEnabled 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/xcshareddata/xcschemes/PkgsCleaner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/xcuserdata/mikael.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /PkgsCleaner.xcodeproj/xcuserdata/mikael.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | PkgsCleaner.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 7362F6812265156600D07F81 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /PkgsCleaner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // PkgsCleaner 4 | // 5 | // Created by Mikael Löfgren on 2019-04-15. 6 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | @IBOutlet var showTempfolder: NSMenuItem! 15 | @IBOutlet var pkgsPopup: NSPopUpButton! 16 | @IBOutlet var window: NSWindow! 17 | @IBOutlet var exportPopup: NSPopUpButton! 18 | @IBOutlet var finalOutPutTextField: NSTextView! 19 | @IBOutlet var openMenu: NSMenuItem! 20 | @IBOutlet var preferences: NSMenuItem! 21 | @IBOutlet var certificateCheckbox: NSButton! 22 | @IBOutlet var certificatePopup: NSPopUpButton! 23 | 24 | 25 | 26 | // START pkgDirOutputFunctionPrint 27 | func pkgDirOutputFunctionPrint () { 28 | if globalVariables.PkgsDirFinal.isEmpty == false { 29 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"DIR_PATHS=( ", attributes: blackText)) 30 | for (idx, element) in globalVariables.PkgsDirFinal.enumerated() { 31 | if idx == globalVariables.PkgsDirFinal.endIndex-1 { 32 | // For last element in array add a ) at the end of the output 33 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\" )\n", attributes: blackText)) 34 | } else { 35 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\"\n", attributes: blackText)) 36 | } 37 | } 38 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 39 | 40 | for ALL in "${DIR_PATHS[@]}"; do 41 | if [ -d "$ALL" ]; then 42 | /bin/rm -rf "$ALL" 43 | fi 44 | done 45 | \n 46 | """, attributes: blackText)) 47 | } 48 | } 49 | // END pkgDirOutputFunctionPrint 50 | 51 | // START pkgFilesOutputFunctionPrint 52 | func pkgFilesOutputFunctionPrint () { 53 | if globalVariables.PkgsFiles.isEmpty == false { 54 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"FILES_PATHS=( ", attributes: blackText)) 55 | for (idx, element) in globalVariables.PkgsFiles.enumerated() { 56 | if idx == globalVariables.PkgsFiles.endIndex-1 { 57 | // For last element in array add a ) at the end of the output 58 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\" )\n", attributes: blackText)) 59 | } else { 60 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\"\n", attributes: blackText)) 61 | } 62 | } 63 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 64 | 65 | for ALL in "${FILES_PATHS[@]}"; do 66 | if [ -f "$ALL" ]; then 67 | /bin/rm "$ALL" 68 | fi 69 | done 70 | \n 71 | """, attributes: blackText)) 72 | } 73 | } 74 | // END pkgFilesOutputFunctionPrint 75 | 76 | // START pkgutilForgetPrint 77 | func pkgutilForgetPrint () { 78 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 79 | /usr/sbin/pkgutil --forget \"\(globalVariables.SelectedPkg)\"\n 80 | exit 0\n 81 | """, attributes: blackText)) 82 | } 83 | // END pkgutilForgetPrint 84 | 85 | // START RawDirOutputFunction 86 | func rawDirOutputFunction () { 87 | // Clean Arrays using globalVariables.PkgsDirAndFilesRemoveRaw remove empty value for nice output of Raw output 88 | // Raw Directories Output 89 | if globalVariables.PkgsDirRaw.isEmpty == false { 90 | // Remove empty values for nice output 91 | globalVariables.PkgsDirRaw.removeAll(where: { globalVariables.PkgsDirAndFilesRemoveRaw.contains($0) }) 92 | // Insert like a header 93 | globalVariables.PkgsDirRaw.insert("# Raw Directories Output #", at: 0) 94 | // Insert linebreaks and bash comment # 95 | let pkgsDirRawWithSeparator = globalVariables.PkgsDirRaw.joined(separator: "\n# ") 96 | 97 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 98 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\(pkgsDirRawWithSeparator)", attributes: colorText)) 99 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 100 | 101 | } 102 | } 103 | // END rawDirOutputFunction 104 | 105 | // START rawFilesOutputFunction 106 | func rawFilesOutputFunction () { 107 | // Raw Files Output 108 | if globalVariables.PkgsFilesRaw.isEmpty == false { 109 | // Remove empty values for nice output 110 | globalVariables.PkgsFilesRaw.removeAll(where: { globalVariables.PkgsDirAndFilesRemoveRaw.contains($0) }) 111 | // Insert like a header 112 | globalVariables.PkgsFilesRaw.insert("# Raw Files Output #", at: 0) 113 | // Insert linebreaks and bash comment # 114 | let pkgsFilesRawWithSeparator = globalVariables.PkgsFilesRaw.joined(separator: "\n# ") 115 | 116 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 117 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\(pkgsFilesRawWithSeparator)", attributes: colorText)) 118 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 119 | } 120 | } 121 | //END rawFilesOutputFunction 122 | 123 | 124 | @IBAction func pkgsPopUpSelected(_ sender: NSPopUpButtonCell) { 125 | 126 | // Pkg info ///////////////////////// 127 | func pkginfoFunction () { 128 | let pkgInfoOutput = bash.execute(commandName: "/usr/sbin/pkgutil", arguments: ["--pkg-info",(globalVariables.SelectedPkg)]) 129 | 130 | // Create a Array called globalVariables.PkgsInfo, where we store all output 131 | globalVariables.PkgsInfo = (pkgInfoOutput?.components(separatedBy: "\n"))! 132 | 133 | 134 | // Installation time from PkgsInfo (like bash date -r) Converted to day 135 | let InstallDateString = globalVariables.PkgsInfo[4].components(separatedBy: ":").last! as NSString 136 | let InstallDateDouble = InstallDateString.doubleValue 137 | let InstallDateFormat = Date(timeIntervalSince1970: InstallDateDouble ) 138 | // Call function to convert to right Dateformat 139 | let InstallDate = dateToString(InstallDateFormat)! 140 | 141 | // Output Pkginfo 142 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"#!/bin/bash\n", attributes: blackText)) 143 | finalOutPutTextField.textStorage?.append(NSAttributedString(string: """ 144 | # Uninstall script created by PkgsCleaner \(globalVariables.DateNow) 145 | # \(globalVariables.PkgsInfo[0]) 146 | # \(globalVariables.PkgsInfo[3]) 147 | # \(globalVariables.PkgsInfo[1]) 148 | # install-time: \(InstallDate) 149 | \n 150 | """, attributes: colorText)) 151 | } 152 | 153 | // END pkginfoFunction 154 | 155 | // START locationFunction 156 | func locationFunction () { 157 | // Get Locations path, clean empty space in beginning 158 | let locationSeparated = globalVariables.PkgsInfo[3].components(separatedBy: ":").last! 159 | globalVariables.Location = String(locationSeparated.dropFirst()) 160 | 161 | // Get location path if empty just add a slash otherwise add slash at beginning and end 162 | if globalVariables.Location == "" { 163 | globalVariables.Location.insert("/", at: globalVariables.Location.startIndex) 164 | } 165 | 166 | // Check that Location starts with slash otherwise add it 167 | let LocationFirst = globalVariables.Location.first! 168 | if LocationFirst == "/" { 169 | } 170 | else { 171 | globalVariables.Location.insert("/", at: globalVariables.Location.startIndex) 172 | } 173 | 174 | // Check that Location ends with slash otherwise add it 175 | let LocationLast = globalVariables.Location.last! 176 | if LocationLast == "/" { 177 | } 178 | else { 179 | globalVariables.Location.insert("/", at: globalVariables.Location.endIndex) 180 | } 181 | } 182 | 183 | // END locationFunction 184 | 185 | 186 | 187 | 188 | // Start main script calling functions ///////////////////// 189 | //SelectedPkg as String 190 | globalVariables.SelectedPkg = pkgsPopup.titleOfSelectedItem! 191 | 192 | // Remove Selected from file PKG from Popup everytime 193 | if globalVariables.SelectedPkgFromFile.isEmpty { 194 | } else { 195 | pkgsPopup.removeItem(withTitle: "\(globalVariables.SelectedPkgFromFile)" ) 196 | globalVariables.SelectedPkgFromFile = "" 197 | } 198 | 199 | 200 | // Clear everything in finalOutPutTextField 201 | finalOutPutTextField.string = "" 202 | // If default is choosen dont do anything 203 | if globalVariables.SelectedPkg.contains("Please select a PKGs recipe"){ 204 | // Dont do anything 205 | return 206 | } 207 | 208 | pkginfoFunction () 209 | locationFunction () 210 | 211 | // If Location contains tmp, private or var exit 212 | for all in globalVariables.TmpFolders { 213 | if globalVariables.Location.contains(all){ 214 | //finalOutPutTextField.string += """ 215 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"# This installer seems to install to a temp directory, check the installer scripts from original pkg.\n", attributes: colorText)) 216 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 217 | 218 | /usr/sbin/pkgutil --forget \"\(globalVariables.SelectedPkg)\"\n 219 | exit 0 220 | """, attributes: blackText)) 221 | return } 222 | } 223 | 224 | 225 | pkgFilesFunction () 226 | pkgDirFunction () 227 | 228 | // If Pkgs is equal to tmp, var and private remove all 229 | if globalVariables.PkgsDir.isEmpty == false { 230 | for all in globalVariables.TmpFolders { 231 | if globalVariables.PkgsDir[0].contains(all){ 232 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"# This installer seems to install to a temp directory, check the installer scripts from original pkg.\n", attributes: colorText)) 233 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 234 | 235 | /usr/sbin/pkgutil --forget \"\(globalVariables.SelectedPkg)\"\n 236 | exit 0 237 | """, attributes: blackText)) 238 | return 239 | } 240 | } 241 | 242 | } 243 | 244 | 245 | // If PkgsDir and PkgsFiles is Empty the installer is probably a nopayload pkg installer 246 | if globalVariables.PkgsDir.isEmpty == true && globalVariables.PkgsFiles.isEmpty == true { 247 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"# This installer doesnt seems to install anything, probably a nopayload pkg, check the installer scripts from original pkg.\n", attributes: colorText)) 248 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 249 | 250 | /usr/sbin/pkgutil --forget \"\(globalVariables.SelectedPkg)\"\n 251 | exit 0 252 | """, attributes: blackText)) 253 | return 254 | } 255 | 256 | pkgDirOutputFunction () 257 | pkgDirOutputFunctionPrint () 258 | pkgFilesOutputFunction () 259 | pkgFilesOutputFunctionPrint () 260 | pkgutilForgetPrint () 261 | rawDirOutputFunction () 262 | rawFilesOutputFunction () 263 | 264 | } 265 | 266 | @IBAction func openDialog(_ sender: Any) { 267 | let dialog = NSOpenPanel(); 268 | dialog.allowsMultipleSelection = false; 269 | dialog.canChooseFiles = true; 270 | dialog.allowedFileTypes = ["pkg", "mpkg"] 271 | 272 | if (dialog.runModal() == NSApplication.ModalResponse.OK) { 273 | let result = dialog.url // Pathname of the file 274 | if (result != nil) { 275 | let path = result!.path 276 | 277 | // Remove Selected PKG from files everytime 278 | if globalVariables.SelectedPkgFromFile.isEmpty { 279 | globalVariables.DocumentDirURL = URL(fileURLWithPath: path) 280 | let fileURL = globalVariables.DocumentDirURL 281 | globalVariables.SelectedPkgFromFile = fileURL.lastPathComponent 282 | } else { 283 | // Remove 284 | pkgsPopup.removeItem(withTitle: "\(globalVariables.SelectedPkgFromFile)" ) 285 | // Generate new 286 | globalVariables.DocumentDirURL = URL(fileURLWithPath: path) 287 | let fileURL = globalVariables.DocumentDirURL 288 | globalVariables.SelectedPkgFromFile = fileURL.lastPathComponent 289 | } 290 | dialog.close() 291 | 292 | } 293 | } else { 294 | print("Cancel") 295 | return 296 | } 297 | 298 | 299 | func printClassPackagesInfo(packagesinfo: [ClassPackagesInfo]) 300 | { 301 | for pkgsNameEntry in packagesinfo { 302 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"# package-id: \(pkgsNameEntry.pkgsName)\n# location: \(pkgsNameEntry.pkgsInstallationPath)\n# version: \(pkgsNameEntry.pkgsVersion)\n", attributes: colorText)) 303 | } 304 | } 305 | 306 | // START IdentifierArrayPrint 307 | func identifierArrayPrint () { 308 | if globalVariables.IdentifierArray.isEmpty == false { 309 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"PKGS=( ", attributes: blackText)) 310 | for (idx, element) in globalVariables.IdentifierArray.enumerated() { 311 | if idx == globalVariables.IdentifierArray.endIndex-1 { 312 | // For last element in array add a ) at the end of the output 313 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\" )\n", attributes: blackText)) 314 | } else { 315 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\"\(element)\"\n", attributes: blackText)) 316 | } 317 | } 318 | finalOutPutTextField.textStorage?.append(NSAttributedString(string: """ 319 | 320 | for ALL in "${PKGS[@]}"; do 321 | /usr/sbin/pkgutil --forget "$ALL" 322 | done\n 323 | exit 0\n 324 | """, attributes: blackText)) 325 | } 326 | } 327 | // END IdentifierArrayPrint 328 | 329 | removeTempDir () 330 | expandPKG () 331 | // Create variable to get expandPKGchecker status 332 | var expandPKGsuccess:Bool 333 | expandPKGsuccess = expandPKGchecker() 334 | if expandPKGsuccess == true { 335 | pkgAndMpkg () 336 | pkgDirOutputFunction () 337 | pkgFilesOutputFunction() 338 | pkgsPopup.addItem(withTitle: "\(globalVariables.SelectedPkgFromFile)" ) 339 | pkgsPopup.selectItem(withTitle: "\(globalVariables.SelectedPkgFromFile)") 340 | // Clear everything in finalOutPutTextField 341 | finalOutPutTextField.string = "" 342 | finalOutPutTextField.textStorage?.append(NSAttributedString(string: "#!/bin/bash\n", attributes: blackText)) 343 | finalOutPutTextField.textStorage?.append(NSAttributedString(string: "# Uninstall script created by PkgsCleaner \(globalVariables.DateNow)\n", attributes: colorText)) 344 | 345 | if globalVariables.PkgsFiles.isEmpty == true && globalVariables.PkgsDir.isEmpty == true { 346 | if globalVariables.PkgsOrMpkg == "Pkg" { 347 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 348 | # package-id: \(globalVariables.Identifier) 349 | # location: \(globalVariables.Location) 350 | # version: \(globalVariables.Version)\n 351 | # This installer doesnt seems to install anything, probably a nopayload pkg. 352 | # Check the installer scripts: \(globalVariables.pkgsTemp)/Scripts 353 | \n 354 | """, attributes: colorText)) 355 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 356 | /usr/sbin/pkgutil --forget "\(globalVariables.Identifier)"\n 357 | exit 0 358 | """, attributes: blackText)) } else { 359 | printClassPackagesInfo(packagesinfo: packagesinfo) 360 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 361 | 362 | # This installer doesnt seems to install anything, probably a nopayload pkg. Check the installer scripts. 363 | \n 364 | """, attributes: colorText)) 365 | identifierArrayPrint () 366 | 367 | } 368 | return } 369 | 370 | 371 | if globalVariables.PkgsOrMpkg == "Pkg" { 372 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 373 | # package-id: \(globalVariables.Identifier) 374 | # location: \(globalVariables.Location) 375 | # version: \(globalVariables.Version)\n 376 | 377 | """, attributes: colorText)) 378 | pkgDirOutputFunctionPrint () 379 | pkgFilesOutputFunctionPrint () 380 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:""" 381 | /usr/sbin/pkgutil --forget "\(globalVariables.Identifier)"\n 382 | exit 0 383 | 384 | """, attributes: blackText)) 385 | rawDirOutputFunction () 386 | rawFilesOutputFunction () 387 | } else { 388 | printClassPackagesInfo(packagesinfo: packagesinfo) 389 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 390 | pkgDirOutputFunctionPrint () 391 | pkgFilesOutputFunctionPrint () 392 | identifierArrayPrint () 393 | rawDirOutputFunction () 394 | rawFilesOutputFunction () 395 | } 396 | finalOutPutTextField.textStorage?.append(NSAttributedString(string:"\n", attributes: colorText)) 397 | 398 | } else { 399 | // Reset pkgsPopup and SelectedPkgFromfile and Clear Textfield 400 | pkgsPopup.selectItem(at: 0) 401 | globalVariables.SelectedPkgFromFile.removeAll() 402 | finalOutPutTextField.string = "" 403 | 404 | // Show warning 405 | let fileURL = globalVariables.DocumentDirURL.path 406 | let warning = NSAlert() 407 | warning.messageText = "Expand pkg file failed" 408 | warning.informativeText = """ 409 | Try to expand manually with this command in terminal: 410 | /usr/sbin/pkgutil --expand "\(fileURL)" "\(fileURL)expanded" 411 | """ 412 | warning.runModal() 413 | 414 | 415 | return 416 | } 417 | } 418 | 419 | 420 | 421 | 422 | @IBAction func ExportNopayload(_ sender: Any) { 423 | // If globalVariables.SelectedPkgFromFile is not empty change it to globalVariables.SelectedPkg 424 | // so it works with export options 425 | if globalVariables.SelectedPkgFromFile.isEmpty { 426 | } else { 427 | globalVariables.SelectedPkg = globalVariables.SelectedPkgFromFile 428 | } 429 | 430 | // If default is choosen dont do anything 431 | if globalVariables.SelectedPkg.contains("Please select a PKGs recipe"){ 432 | // Dont do anything and reset Export as option 433 | exportPopup.selectItem(at: 0) 434 | return 435 | } 436 | 437 | 438 | 439 | // Save Dialog 440 | let dialog = NSSavePanel(); 441 | dialog.message = "Select location for output"; 442 | dialog.showsTagField = false; 443 | dialog.showsResizeIndicator = true; 444 | dialog.showsHiddenFiles = false; 445 | dialog.canCreateDirectories = true; 446 | 447 | 448 | 449 | // Default Save value, add .pkg or not 450 | let endsWithPkg = globalVariables.SelectedPkg.suffix(4) 451 | if endsWithPkg == ".pkg" { 452 | dialog.nameFieldStringValue = "Uninstaller_\(globalVariables.SelectedPkg)"; 453 | } else { 454 | dialog.nameFieldStringValue = "Uninstaller_\(globalVariables.SelectedPkg).pkg"; 455 | } 456 | 457 | if (dialog.runModal() == NSApplication.ModalResponse.OK) { 458 | let result = dialog.url // Pathname of the file 459 | if (result != nil) { 460 | let path = result!.path 461 | 462 | 463 | // Call function for creating tempdirectories 464 | let scriptsFolder = (createTempDirectory(folderName: "se.pkgscleaner/scripts")!) 465 | let nopayloadFolder = (createTempDirectory(folderName: "se.pkgscleaner/nopayload")!) 466 | 467 | // Convert scriptsFolder to URL 468 | let DocumentDirURL = URL(fileURLWithPath: scriptsFolder) 469 | 470 | 471 | // Get the text in textview to output to a tmp file for calling from pkgsbuild 472 | // Save data to file 473 | let fileName = "postinstall" 474 | let fileURL = DocumentDirURL.appendingPathComponent(fileName) 475 | let writeString = (finalOutPutTextField.textStorage as NSAttributedString?)!.string 476 | do { 477 | // Write to the file 478 | try writeString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) 479 | } catch let error as NSError { 480 | print("Failed writing to URL: \(fileURL), Error: " + error.localizedDescription) 481 | } 482 | 483 | // Remove Extended attributs and Chmod on tempfile 484 | _ = bash.execute(commandName: "/usr/bin/xattr", arguments: ["-c","\(fileURL.path)"]) 485 | _ = bash.execute(commandName: "/bin/chmod", arguments: ["a+x","\(fileURL.path)"]) 486 | 487 | // Output Signed pkg 488 | if globalVariables.StatusCertificateCheckbox == 1 { 489 | globalVariables.SelectedCertificate = certificatePopup.titleOfSelectedItem! 490 | 491 | 492 | // Output variables for root and scriptsfolders needs to be like "/Users/username/Desktop/" "--version","1.0" 493 | // If no Version is added then no pkginfo is written to package database 494 | globalVariables.Signed = bash.execute(commandName: "/usr/bin/pkgbuild", arguments: ["--sign","\(globalVariables.SelectedCertificate)","--identifier","se.pkgscleaner","--root","\(nopayloadFolder)","--scripts","\(scriptsFolder)","\(path)"])! 495 | 496 | globalVariables.Output = globalVariables.Signed as String 497 | } else { 498 | // Output UnSigned pkg 499 | 500 | globalVariables.UnSigned = bash.execute(commandName: "/usr/bin/pkgbuild", arguments: ["--identifier","se.pkgscleaner","--root","\(nopayloadFolder)","--scripts","\(scriptsFolder)","\(path)"])! 501 | 502 | globalVariables.Output = globalVariables.UnSigned as String 503 | } 504 | if globalVariables.Output.contains("Wrote") { 505 | 506 | // Create the notification and setup information (depricated should be updated) 507 | let notification = NSUserNotification() 508 | notification.identifier = "se.dicom.pkgscleaner" 509 | notification.title = "Successfully exported to:" 510 | notification.subtitle = "\(path)" 511 | notification.soundName = NSUserNotificationDefaultSoundName 512 | let notificationCenter = NSUserNotificationCenter.default 513 | notificationCenter.deliver(notification) 514 | 515 | let warning = NSAlert() 516 | warning.addButton(withTitle: "OK") 517 | warning.alertStyle = NSAlert.Style.informational 518 | warning.messageText = "Successfully exported to" 519 | warning.informativeText = "\(path)" 520 | warning.runModal() 521 | 522 | // Reset Export as option 523 | exportPopup.selectItem(at: 0) 524 | } else { 525 | 526 | let warning = NSAlert() 527 | warning.icon = NSImage(named: "Warning") 528 | warning.addButton(withTitle: "OK") 529 | warning.messageText = "Something went wrong" 530 | warning.alertStyle = NSAlert.Style.warning 531 | // Show warning dialog with differents output depending if signed or not 532 | if globalVariables.StatusCertificateCheckbox == 1 { 533 | warning.informativeText = """ 534 | Before you quit the app, try it manually by copy this command into terminal: 535 | 536 | /usr/bin/pkgbuild --sign \"\(globalVariables.SelectedCertificate)\" --identifier se.pkgscleaner --root \(nopayloadFolder) --scripts \(scriptsFolder) \(path) 537 | """ 538 | } else { 539 | warning.informativeText = """ 540 | Before you quit the app, try it manually by copy this command into terminal: 541 | 542 | /usr/bin/pkgbuild --identifier se.pkgscleaner --root \(nopayloadFolder) --scripts \(scriptsFolder) \(path) 543 | """ 544 | } 545 | 546 | warning.runModal() 547 | 548 | // Reset Export as option 549 | exportPopup.selectItem(at: 0) 550 | } 551 | } 552 | } else { 553 | // User clicked on "Cancel" 554 | // Dont do anything and reset Export as option 555 | exportPopup.selectItem(at: 0) 556 | return 557 | } 558 | // End Save Dialog 559 | 560 | } 561 | 562 | 563 | 564 | @IBAction func ExportScript(_ sender: Any) { 565 | // If globalVariables.SelectedPkgFromFile is not empty change it to globalVariables.SelectedPkg 566 | // so it works with export options 567 | if globalVariables.SelectedPkgFromFile.isEmpty { 568 | } else { 569 | globalVariables.SelectedPkg = globalVariables.SelectedPkgFromFile 570 | } 571 | 572 | // If default is choosen dont do anything 573 | if globalVariables.SelectedPkg.contains("Please select a PKGs recipe"){ 574 | // Dont do anything and reset Export as option 575 | exportPopup.selectItem(at: 0) 576 | return 577 | } 578 | // Save Dialog 579 | let dialog = NSSavePanel(); 580 | dialog.showsResizeIndicator = true; 581 | dialog.showsHiddenFiles = false; 582 | dialog.canCreateDirectories = true; 583 | 584 | 585 | // Default Save value, add .sh and remove .pkg 586 | let endsWithPkg = globalVariables.SelectedPkg.suffix(4) 587 | if endsWithPkg == ".pkg" { 588 | dialog.nameFieldStringValue = "Uninstaller_\(globalVariables.SelectedPkg.dropLast(4)).sh"; 589 | } else { 590 | dialog.nameFieldStringValue = "Uninstaller_\(globalVariables.SelectedPkg).sh"; 591 | } 592 | 593 | if (dialog.runModal() == NSApplication.ModalResponse.OK) { 594 | let result = dialog.url // Pathname of the file 595 | if (result != nil) { 596 | let path = result!.path 597 | 598 | let documentDirURL = URL(fileURLWithPath: path) 599 | // Save data to file 600 | let fileURL = documentDirURL 601 | let writeString = (finalOutPutTextField.textStorage as NSAttributedString?)!.string 602 | do { 603 | // Write to the file 604 | try writeString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) 605 | } catch let error as NSError { 606 | print("Failed writing to URL: \(fileURL), Error: " + error.localizedDescription) 607 | } 608 | 609 | // Remove Extended attributs and Chmod on tempfile 610 | _ = bash.execute(commandName: "/usr/bin/xattr", arguments: ["-c","\(fileURL.path)"]) 611 | _ = bash.execute(commandName: "/bin/chmod", arguments: ["a+x","\(fileURL.path)"]) 612 | 613 | // Reset Export as option 614 | exportPopup.selectItem(at: 0) 615 | 616 | // Create the notification and setup information (depricated should be updated) 617 | let notification = NSUserNotification() 618 | notification.identifier = "se.dicom.pkgscleaner" 619 | notification.title = "Succesfully exported to:" 620 | notification.subtitle = "\(path)" 621 | notification.soundName = NSUserNotificationDefaultSoundName 622 | let notificationCenter = NSUserNotificationCenter.default 623 | notificationCenter.deliver(notification) 624 | } 625 | } else { 626 | // User clicked on "Cancel" 627 | // Dont do anything and reset Export as option 628 | exportPopup.selectItem(at: 0) 629 | return 630 | } 631 | // End Save Dialog 632 | 633 | 634 | 635 | 636 | 637 | } 638 | 639 | 640 | 641 | 642 | @IBAction func shellSheck(sender: AnyObject) { 643 | if globalVariables.SelectedPkgFromFile.isEmpty { 644 | } else { 645 | globalVariables.SelectedPkg = globalVariables.SelectedPkgFromFile 646 | } 647 | // If default is choosen dont do anything 648 | if globalVariables.SelectedPkg.contains("Please select a PKGs recipe"){ 649 | return 650 | } 651 | 652 | // Copy finalOutPutTextField to pasteboard and open Shellcheck.net 653 | let pasteBoard = NSPasteboard.general 654 | pasteBoard.clearContents() 655 | let writeString = (finalOutPutTextField.textStorage as NSAttributedString?)!.string 656 | pasteBoard.writeObjects([writeString as NSPasteboardWriting]) 657 | 658 | let url = URL(string: "https:/www.shellcheck.net")! 659 | if NSWorkspace.shared.open(url) { 660 | } 661 | 662 | } 663 | 664 | 665 | @IBAction func CertificateButtom(_ sender: NSButton) { 666 | 667 | func CreateCertificatePopup() { 668 | let myIdentities = getAllKeyChainIdentityItems() 669 | var developerIdentities:Array = [String]() 670 | for items in myIdentities { 671 | let lastItems = items.components(separatedBy: ":").last! 672 | let lastItemsClean = String(lastItems.dropFirst()) 673 | developerIdentities.append(lastItemsClean) 674 | } 675 | 676 | 677 | if developerIdentities.isEmpty == false { 678 | certificatePopup.isEnabled = true 679 | certificatePopup.removeAllItems() 680 | // Add an item to the list 681 | certificatePopup.addItems(withTitles: developerIdentities) 682 | certificatePopup.selectItem(at: 0) 683 | } else { 684 | // If no certificate is found Checkbox to Off and variable to 0 685 | certificatePopup.addItems(withTitles: ["No Developer Certificates found"]) 686 | // Set the state to Off 687 | certificateCheckbox.state = NSControl.StateValue.off 688 | globalVariables.StatusCertificateCheckbox = 0 689 | 690 | 691 | } 692 | 693 | } 694 | 695 | 696 | globalVariables.StatusCertificateCheckbox = sender.state.rawValue 697 | certificatePopup.removeAllItems() 698 | 699 | // If Checkbox is ON (1) try get Certificates 700 | if globalVariables.StatusCertificateCheckbox == 1 { 701 | CreateCertificatePopup() 702 | globalVariables.SelectedCertificate = certificatePopup.titleOfSelectedItem! 703 | } else { 704 | // Set the state to Off 705 | certificateCheckbox.state = NSControl.StateValue.off 706 | globalVariables.StatusCertificateCheckbox = 0 707 | } 708 | } 709 | 710 | 711 | 712 | 713 | func applicationDidFinishLaunching(_ aNotification: Notification) { 714 | // Insert code here to initialize your application 715 | 716 | // List all PKGS 717 | var pkgsOutput = bash.execute(commandName: "/usr/sbin/pkgutil", arguments: ["--pkgs"]) 718 | 719 | // Create a Array called PkgsTemp, where we store all output 720 | var pkgsTemp:Array = (pkgsOutput?.components(separatedBy: "\n"))! 721 | 722 | // Remove com.apple pkgs cause we dont want to uninstall Apple systemfiles, and they are sometimes to complex to parse 723 | var pkgs:Array = [String]() 724 | for elements in pkgsTemp { 725 | // Remove items contains com.apple 726 | pkgs.append(elements.deletingPrefix("com.apple")) 727 | } 728 | 729 | // Clean Array using this Set 730 | let cleanPkgsArray: Set = [""] 731 | pkgs.removeAll(where: { cleanPkgsArray.contains($0) }) 732 | 733 | // Sort Pkgs Array 734 | pkgs.sort() 735 | 736 | // Create PkgsPopup 737 | func createPkgsPopup() { 738 | pkgsPopup.removeAllItems() 739 | // Add an item to the list 740 | pkgsPopup.addItem(withTitle: "Please select a PKGs recipe [ of total \(pkgs.count) ]") 741 | pkgsPopup.addItems(withTitles: pkgs) 742 | pkgsPopup.selectItem(at: 0) 743 | globalVariables.SelectedPkg = pkgsPopup.titleOfSelectedItem! 744 | 745 | } 746 | 747 | createPkgsPopup() 748 | 749 | 750 | // Get date 751 | globalVariables.DateNow = dateToString(Date())! 752 | 753 | } 754 | 755 | @IBAction func showTempfolders(_ sender: Any) { 756 | // Create and open the temp folder in Finder 757 | _ = globalVariables.pkgsTemp 758 | NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: "\(globalVariables.pkgsTemp)") 759 | } 760 | 761 | 762 | 763 | func applicationWillTerminate(_ aNotification: Notification) { 764 | } 765 | 766 | @IBAction func myQuitButtom(_ sender: NSButton) { 767 | // Delete tempfolder if exist 768 | if FileManager.default.fileExists(atPath: globalVariables.MainTempFolder) { 769 | // Delete folder 770 | try? FileManager.default.removeItem(atPath: globalVariables.MainTempFolder) 771 | } 772 | exit(0); 773 | } 774 | 775 | } 776 | 777 | -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "PkgsCleanerIconFinal-16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "PkgsCleanerIconFinal-33.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "PkgsCleanerIconFinal-32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "PkgsCleanerIconFinal-64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "PkgsCleanerIconFinal-128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "PkgsCleanerIconFinal-256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "PkgsCleanerIconFinal-257.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "PkgsCleanerIconFinal-513.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "PkgsCleanerIconFinal-512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "PkgsCleanerIconFinal-1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-1024.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-128.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-16.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-256.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-257.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-257.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-32.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-33.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-512.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-513.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-513.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/AppIcon.appiconset/PkgsCleanerIconFinal-64.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/BlackText.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | }, 6 | "colors" : [ 7 | { 8 | "idiom" : "universal", 9 | "color" : { 10 | "reference" : "textColor" 11 | } 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "appearances" : [ 16 | { 17 | "appearance" : "luminosity", 18 | "value" : "light" 19 | } 20 | ], 21 | "color" : { 22 | "reference" : "textColor" 23 | } 24 | }, 25 | { 26 | "idiom" : "universal", 27 | "appearances" : [ 28 | { 29 | "appearance" : "luminosity", 30 | "value" : "dark" 31 | } 32 | ], 33 | "color" : { 34 | "color-space" : "srgb", 35 | "components" : { 36 | "red" : "1.000", 37 | "alpha" : "1.000", 38 | "blue" : "1.000", 39 | "green" : "1.000" 40 | } 41 | } 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/ColorText.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | }, 6 | "colors" : [ 7 | { 8 | "idiom" : "universal", 9 | "color" : { 10 | "color-space" : "srgb", 11 | "components" : { 12 | "red" : "0.580", 13 | "alpha" : "1.000", 14 | "blue" : "0.694", 15 | "green" : "0.498" 16 | } 17 | } 18 | }, 19 | { 20 | "idiom" : "universal", 21 | "appearances" : [ 22 | { 23 | "appearance" : "luminosity", 24 | "value" : "light" 25 | } 26 | ], 27 | "color" : { 28 | "color-space" : "srgb", 29 | "components" : { 30 | "red" : "0.580", 31 | "alpha" : "1.000", 32 | "blue" : "0.694", 33 | "green" : "0.498" 34 | } 35 | } 36 | }, 37 | { 38 | "idiom" : "universal", 39 | "appearances" : [ 40 | { 41 | "appearance" : "luminosity", 42 | "value" : "dark" 43 | } 44 | ], 45 | "color" : { 46 | "color-space" : "srgb", 47 | "components" : { 48 | "red" : "1.000", 49 | "alpha" : "1.000", 50 | "blue" : "1.000", 51 | "green" : "0.094" 52 | } 53 | } 54 | } 55 | ] 56 | } -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_128x128.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_128x128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_128x128@2x.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_16x16.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_16x16@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_16x16@2x.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_256x256.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_256x256@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_256x256@2x.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_32x32.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_32x32@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_32x32@2x.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_512x512.png -------------------------------------------------------------------------------- /PkgsCleaner/Assets.xcassets/Warning.iconset/icon_512x512@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/PkgsCleaner/Assets.xcassets/Warning.iconset/icon_512x512@2x.png -------------------------------------------------------------------------------- /PkgsCleaner/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | Default 553 | 554 | 555 | 556 | 557 | 558 | 559 | Left to Right 560 | 561 | 562 | 563 | 564 | 565 | 566 | Right to Left 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | Default 578 | 579 | 580 | 581 | 582 | 583 | 584 | Left to Right 585 | 586 | 587 | 588 | 589 | 590 | 591 | Right to Left 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 739 | 740 | 741 | 742 | 743 | 744 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | -------------------------------------------------------------------------------- /PkgsCleaner/Bash.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Bash.swift 3 | // PkgsCleaner 4 | // 5 | // 6 | // Code from: 7 | // https://gist.github.com/andreacipriani/8c3af3719da31c8fae2cdfa8c21e17ba 8 | // Thanks Andrea 9 | 10 | import Foundation 11 | protocol CommandExecuting { 12 | func execute(commandName: String) -> String? 13 | func execute(commandName: String, arguments: [String]) -> String? 14 | } 15 | 16 | final class Bash: CommandExecuting { 17 | 18 | // MARK: - CommandExecuting 19 | 20 | func execute(commandName: String) -> String? { 21 | return execute(commandName: commandName, arguments: []) 22 | } 23 | 24 | func execute(commandName: String, arguments: [String]) -> String? { 25 | guard var bashCommand = execute(command: "/bin/bash" , arguments: ["-l", "-c", "which \(commandName)"]) else { return "\(commandName) not found" } 26 | bashCommand = bashCommand.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines) 27 | return execute(command: bashCommand, arguments: arguments) 28 | } 29 | 30 | // MARK: Private 31 | 32 | private func execute(command: String, arguments: [String] = []) -> String? { 33 | let process = Process() 34 | process.launchPath = command 35 | process.arguments = arguments 36 | 37 | let pipe = Pipe() 38 | process.standardOutput = pipe 39 | process.launch() 40 | 41 | let data = pipe.fileHandleForReading.readDataToEndOfFile() 42 | let output = String(data: data, encoding: String.Encoding.utf8) 43 | return output 44 | 45 | } 46 | } 47 | 48 | let bash: CommandExecuting = Bash() 49 | -------------------------------------------------------------------------------- /PkgsCleaner/ExtensionString.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExtensionString.swift 3 | // PkgsCleaner 4 | // 5 | // Created by Mikael Löfgren on 2019-04-19. 6 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | // https://stackoverflow.com/questions/28323848/removing-from-array-during-enumeration-in-swift 11 | 12 | 13 | // Deleting Prefix from Array strings 14 | extension String { 15 | func deletingPrefix(_ prefix: String) -> String { 16 | guard self.hasPrefix(prefix) else { return self } 17 | return String() 18 | } 19 | } 20 | 21 | 22 | // Function to Sort Arrays by length 23 | func length(value1: String, value2: String) -> Bool { 24 | // Compare character count of the strings. 25 | return value1.count < value2.count 26 | } 27 | 28 | 29 | // Get Pkgs name from Distribution file 30 | extension String 31 | { 32 | func pkgref() -> [String] 33 | { 34 | if let regex = try? NSRegularExpression(pattern: "#.+\\.pkg", options: .caseInsensitive) 35 | { 36 | let string = self as NSString 37 | 38 | return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map { 39 | string.substring(with: $0.range).replacingOccurrences(of: "#", with: "") 40 | } 41 | } 42 | 43 | return [] 44 | } 45 | } 46 | 47 | // Get Install Location from PackageInfo file 48 | extension String 49 | { 50 | func installLocation() -> [String] 51 | { 52 | if let regex = try? NSRegularExpression(pattern: "install-location=(\"([^\"]|\"\")*\")", options: .caseInsensitive) 53 | { 54 | let string = self as NSString 55 | 56 | return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map { 57 | string.substring(with: $0.range).replacingOccurrences(of: "\"", with: "") 58 | } 59 | } 60 | 61 | return [] 62 | } 63 | } 64 | 65 | // Get Identifier from PackageInfo file 66 | extension String 67 | { 68 | func identifier() -> [String] 69 | { 70 | if let regex = try? NSRegularExpression(pattern: "identifier=(\"([^\"]|\"\")*\")", options: .caseInsensitive) 71 | { 72 | let string = self as NSString 73 | 74 | return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map { 75 | string.substring(with: $0.range).replacingOccurrences(of: "\"", with: "") 76 | } 77 | } 78 | 79 | return [] 80 | } 81 | } 82 | 83 | // Get Version from PackageInfo file 84 | extension String 85 | { 86 | func version() -> [String] 87 | { 88 | if let regex = try? NSRegularExpression(pattern: "\" version=(\"([^\"]|\"\")*\")", options: .caseInsensitive) 89 | { 90 | let string = self as NSString 91 | 92 | return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map { 93 | string.substring(with: $0.range).replacingOccurrences(of: "\"", with: "") 94 | } 95 | } 96 | 97 | return [] 98 | 99 | } 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /PkgsCleaner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSApplicationCategoryType 24 | public.app-category.utilities 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2019 Mikael Löfgren. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /PkgsCleaner/Keychain.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Keychain.swift 3 | // PkgsCleaner 4 | // 5 | // Created by Mikael Löfgren on 2019-07-15. 6 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | public func getAllKeyChainIdentityItems() -> [String] { 11 | 12 | let query: [String: Any] = [ 13 | kSecClass as String : kSecClassIdentity, 14 | kSecReturnData as String : kCFBooleanTrue!, 15 | kSecReturnAttributes as String : kCFBooleanTrue!, 16 | kSecReturnRef as String : kCFBooleanTrue!, 17 | kSecMatchLimit as String: kSecMatchLimitAll 18 | ] 19 | 20 | var result: AnyObject? 21 | 22 | let lastResultCode = withUnsafeMutablePointer(to: &result) { 23 | SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) 24 | } 25 | 26 | var values = [String]() 27 | 28 | if lastResultCode == noErr { 29 | let array = result as? Array> 30 | 31 | for item in array! { 32 | let label = item[kSecAttrLabel as String] as? String 33 | if label!.contains("Developer") { 34 | values.append(label!) 35 | 36 | } 37 | 38 | } 39 | } 40 | 41 | return values 42 | } 43 | 44 | -------------------------------------------------------------------------------- /PkgsCleaner/PkgAndMpkg.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PkgAndMpkg.swift 3 | // PkgsCleaner 4 | // 5 | // Created by Mikael Löfgren on 2019-08-03. 6 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 7 | // 8 | 9 | 10 | import Foundation 11 | 12 | 13 | // START removeTempDir 14 | func removeTempDir () { 15 | if FileManager.default.fileExists(atPath: globalVariables.pkgsTemp) { 16 | // Delete folder 17 | try? FileManager.default.removeItem(atPath: globalVariables.pkgsTemp) 18 | } 19 | } 20 | // END removeTempDir 21 | 22 | // START expandPKG 23 | func expandPKG() { 24 | // Get fileURL in this format /Users/username/Desktop/nameOfPkg.pkg 25 | let fileURL = globalVariables.DocumentDirURL.path 26 | _ = bash.execute(commandName: "/usr/sbin/pkgutil", arguments: ["--expand","\(fileURL)","\(globalVariables.pkgsTemp)"]) 27 | } 28 | // END expandPKG 29 | 30 | // START expandPKGchecker, return true if exist else false 31 | func expandPKGchecker() -> Bool { 32 | if FileManager.default.fileExists(atPath: globalVariables.pkgsTemp) { 33 | return true 34 | } else { 35 | return false 36 | } 37 | } 38 | // END expandPKGchecker 39 | 40 | 41 | 42 | // START Class for PackagesInfo 43 | class ClassPackagesInfo { 44 | let pkgsName : String 45 | let pkgsInstallationPath : String 46 | let pkgsVersion : String 47 | 48 | init(pkgsName: String, pkgsInstallationPath: String, pkgsVersion : String) { 49 | self.pkgsName = pkgsName 50 | self.pkgsInstallationPath = pkgsInstallationPath 51 | self.pkgsVersion = pkgsVersion 52 | } 53 | } 54 | 55 | var packagesinfo:[ClassPackagesInfo] = [] 56 | // END Class for PackagesInfo 57 | 58 | // START locationCheckerFunction 59 | func locationCheckerFunction () { 60 | 61 | // Get location path if empty just add a slash otherwise add slash at beginning and end 62 | if globalVariables.Location == "" { 63 | globalVariables.Location.insert("/", at: globalVariables.Location.startIndex) 64 | } 65 | 66 | // Check that Location starts with slash otherwise add it 67 | let locationFirst = globalVariables.Location.first! 68 | if locationFirst == "/" { 69 | } 70 | else { 71 | globalVariables.Location.insert("/", at: globalVariables.Location.startIndex) 72 | } 73 | 74 | // Check that Location ends with slash otherwise add it 75 | let locationLast = globalVariables.Location.last! 76 | if locationLast == "/" { 77 | } 78 | else { 79 | globalVariables.Location.insert("/", at: globalVariables.Location.endIndex) 80 | } 81 | for all in globalVariables.TmpFolders { 82 | if globalVariables.Location.contains(all){ 83 | globalVariables.Location = "tmp" 84 | return 85 | } 86 | } 87 | } 88 | // END LocationCheckerFunction 89 | 90 | 91 | 92 | // START PkgAndMpkg 93 | func pkgAndMpkg () { 94 | 95 | // If distribution file exist, grep all pkgs references from distribution file using "function pkgref" 96 | // add results to DistroPKGS array, use that to grep file and folders info from Bom files. 97 | 98 | // Clear arrays before we start 99 | globalVariables.PkgsFiles = [String]() 100 | globalVariables.PkgsDir = [String]() 101 | globalVariables.PkgsFilesRaw = [String]() 102 | globalVariables.PkgsDirRaw = [String]() 103 | globalVariables.IdentifierArray = [String]() 104 | packagesinfo.removeAll() 105 | 106 | let fileManager = FileManager.default 107 | // Set the file path 108 | let FilePath = "\(globalVariables.pkgsTemp)/Distribution" 109 | 110 | pkgFilesDirs: if fileManager.fileExists(atPath: "\(globalVariables.pkgsTemp)/Distribution") { 111 | globalVariables.PkgsOrMpkg = "Mpkg" 112 | print("Mpkg format") 113 | 114 | // Get the Contents 115 | do { 116 | let FileContents = try String(contentsOfFile: FilePath, encoding: .utf8) 117 | // Create array from every pkgref from Distributionfile 118 | globalVariables.DistroPKGS = FileContents.pkgref() 119 | 120 | } catch { 121 | //handle error 122 | print(error) 123 | return 124 | } 125 | 126 | 127 | 128 | // If Distropkgs refs filepath includes %20 for spaces in filepath remove the Percent Encoding 129 | for elements in globalVariables.DistroPKGS { 130 | // Empty Strings before we start 131 | globalVariables.Identifier.removeAll() 132 | globalVariables.Location.removeAll() 133 | globalVariables.Version.removeAll() 134 | globalVariables.LocationRaw.removeAll() 135 | 136 | let filePathLocation = "\(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/PackageInfo" 137 | do { 138 | let fileContents = try String(contentsOfFile: filePathLocation, encoding: .utf8) 139 | 140 | // Get identifier and version and location 141 | if fileContents.identifier().isEmpty { 142 | } else { 143 | globalVariables.Identifier = fileContents.identifier()[0].replacingOccurrences(of: "identifier=", with: "") 144 | // Add globalVariables.Identifier to an array to use for multiple output later on 145 | globalVariables.IdentifierArray.append(globalVariables.Identifier) 146 | } 147 | 148 | if fileContents.version().isEmpty { 149 | } else { 150 | globalVariables.Version = fileContents.version()[0].replacingOccurrences(of: " version=", with: "") 151 | } 152 | 153 | if fileContents.installLocation().isEmpty { 154 | globalVariables.Location = "/" 155 | } else { 156 | globalVariables.Location = fileContents.installLocation()[0].replacingOccurrences(of: "install-location=", with: "") as String 157 | } 158 | 159 | // Make a new LocationVariable from raw value to use to inform if files installs to tmp folders 160 | globalVariables.LocationRaw = globalVariables.Location 161 | locationCheckerFunction () 162 | 163 | } catch { 164 | //handle error 165 | print(error) 166 | } 167 | 168 | 169 | if fileManager.fileExists(atPath: "\(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/Bom") { 170 | // List PkgsFiles 171 | globalVariables.PkgsOutput = bash.execute(commandName: "/usr/bin/lsbom", arguments: ["-f","-s","\(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/Bom"])! 172 | 173 | // List PkgsDir 174 | globalVariables.PkgsOutputDirs = bash.execute(commandName: "/usr/bin/lsbom", arguments: ["-d","-s","\(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/Bom"])! 175 | 176 | // Add output to two arrays 177 | globalVariables.FileTemp = (globalVariables.PkgsOutput.components(separatedBy: "\n")) 178 | globalVariables.DirTemp = (globalVariables.PkgsOutputDirs.components(separatedBy: "\n")) 179 | 180 | // Make a copy for RAW output 181 | globalVariables.PkgsFilesRaw += globalVariables.FileTemp 182 | globalVariables.PkgsDirRaw += globalVariables.DirTemp 183 | 184 | // Clean Raw arrays from . and empty 185 | globalVariables.PkgsFilesRaw.removeAll(where: { globalVariables.CleanRawArray.contains($0) }) 186 | globalVariables.PkgsDirRaw.removeAll(where: { globalVariables.CleanRawArray.contains($0) }) 187 | 188 | // Remove two first characthers ./ 189 | globalVariables.FileTemp = globalVariables.FileTemp.map({ String($0.dropFirst(2)) }) 190 | globalVariables.DirTemp = globalVariables.DirTemp.map({ String($0.dropFirst(2)) }) 191 | 192 | // Clean temp arrays 193 | globalVariables.FileTemp.removeAll(where: { CleanArray.contains($0) }) 194 | globalVariables.DirTemp.removeAll(where: { CleanArray.contains($0) }) 195 | 196 | 197 | 198 | // If Location contains tmp skip files, but inform in output comments 199 | if globalVariables.Location == "tmp" { 200 | let tempPkgsinfo = ClassPackagesInfo(pkgsName: "\(globalVariables.Identifier)", pkgsInstallationPath: "\(globalVariables.LocationRaw)\n# Installs to a temp folder, check installerscripts: \(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/Scripts", pkgsVersion: "\(globalVariables.Version)") 201 | packagesinfo.append(tempPkgsinfo) 202 | } else { 203 | // Add Location before files and Dirs 204 | globalVariables.PkgsFiles += globalVariables.FileTemp.map({ globalVariables.Location + $0 }) 205 | globalVariables.PkgsDir += globalVariables.DirTemp.map({ globalVariables.Location + $0 }) 206 | let tempPkgsinfo = ClassPackagesInfo(pkgsName: "\(globalVariables.Identifier)", pkgsInstallationPath: globalVariables.LocationRaw, pkgsVersion: "\(globalVariables.Version)") 207 | packagesinfo.append(tempPkgsinfo) 208 | } 209 | 210 | 211 | // And when we are done, empty temp arrays 212 | globalVariables.FileTemp.removeAll() 213 | globalVariables.DirTemp.removeAll() 214 | 215 | } 216 | else { print("We got a nopayload package") 217 | if globalVariables.Location == "tmp" { 218 | let tempPkgsinfo = ClassPackagesInfo(pkgsName: "\(globalVariables.Identifier)", pkgsInstallationPath: "\(globalVariables.LocationRaw)\n# Installs to a temp folder, check installerscripts: \(globalVariables.pkgsTemp)/\(elements.removingPercentEncoding!)/Scripts", pkgsVersion: "\(globalVariables.Version)") 219 | packagesinfo.append(tempPkgsinfo) 220 | } 221 | 222 | break pkgFilesDirs 223 | } 224 | } 225 | 226 | } else { 227 | globalVariables.PkgsOrMpkg = "Pkg" 228 | print("Pkg format") 229 | 230 | // Empty Strings before we start 231 | globalVariables.Identifier.removeAll() 232 | globalVariables.Location.removeAll() 233 | 234 | let filePathLocation = "\(globalVariables.pkgsTemp)/PackageInfo" 235 | do { 236 | // Get identifier and version and location 237 | let fileContents = try String(contentsOfFile: filePathLocation, encoding: .utf8) 238 | 239 | if fileContents.identifier().isEmpty { 240 | } else { 241 | globalVariables.Identifier = fileContents.identifier()[0].replacingOccurrences(of: "identifier=", with: "") 242 | // Add globalVariables.Identifier only to an array to use for output later on 243 | globalVariables.IdentifierArray.append(globalVariables.Identifier) 244 | } 245 | 246 | if fileContents.version().isEmpty { 247 | } else { 248 | globalVariables.Version = fileContents.version()[0].replacingOccurrences(of: " version=", with: "") 249 | } 250 | 251 | if fileContents.installLocation().isEmpty { 252 | globalVariables.Location = "/" 253 | } else { 254 | globalVariables.Location = fileContents.installLocation()[0].replacingOccurrences(of: "install-location=", with: "") as String 255 | } 256 | 257 | locationCheckerFunction () 258 | 259 | } catch { 260 | //handle error 261 | print(error) 262 | } 263 | 264 | 265 | if fileManager.fileExists(atPath: "\(globalVariables.pkgsTemp)/Bom") { 266 | globalVariables.PkgsOutput = bash.execute(commandName: "/usr/bin/lsbom", arguments: ["-f","-s","\(globalVariables.pkgsTemp)/Bom"])! 267 | globalVariables.PkgsOutputDirs = bash.execute(commandName: "/usr/bin/lsbom", arguments: ["-d","-s","\(globalVariables.pkgsTemp)/Bom"])! 268 | 269 | // Add output to two arrays 270 | globalVariables.FileTemp = (globalVariables.PkgsOutput.components(separatedBy: "\n")) 271 | globalVariables.DirTemp = (globalVariables.PkgsOutputDirs.components(separatedBy: "\n")) 272 | 273 | // Make a copy for RAW output 274 | globalVariables.PkgsFilesRaw += globalVariables.FileTemp 275 | globalVariables.PkgsDirRaw += globalVariables.DirTemp 276 | 277 | // Clean Raw arrays from only dots . and empty 278 | globalVariables.PkgsFilesRaw.removeAll(where: { globalVariables.CleanRawArray.contains($0) }) 279 | globalVariables.PkgsDirRaw.removeAll(where: { globalVariables.CleanRawArray.contains($0) }) 280 | 281 | // Remove two first characthers ./ 282 | globalVariables.FileTemp = globalVariables.FileTemp.map({ String($0.dropFirst(2)) }) 283 | globalVariables.DirTemp = globalVariables.DirTemp.map({ String($0.dropFirst(2)) }) 284 | 285 | // Clean temp arrays 286 | globalVariables.FileTemp.removeAll(where: { CleanArray.contains($0) }) 287 | globalVariables.DirTemp.removeAll(where: { CleanArray.contains($0) }) 288 | 289 | // Add Location to a new array 290 | globalVariables.PkgsFiles += globalVariables.FileTemp.map({ globalVariables.Location + $0 }) 291 | globalVariables.PkgsDir += globalVariables.DirTemp.map({ globalVariables.Location + $0 }) 292 | 293 | // When we are done, empty temp arrays 294 | globalVariables.FileTemp.removeAll() 295 | globalVariables.DirTemp.removeAll() 296 | 297 | } else { 298 | break pkgFilesDirs 299 | } 300 | } 301 | 302 | // Call funtion to sort by length 303 | globalVariables.PkgsDir.sort(by: length) 304 | 305 | } 306 | // END pkgAndMpkg 307 | -------------------------------------------------------------------------------- /PkgsCleaner/PkgFromRecipe.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PkgFromPkgRecipe.swift 3 | // PkgsCleaner 4 | // 5 | // Created by Mikael Löfgren on 2019-08-04. 6 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | 13 | // START pkgFilesFunction 14 | func pkgFilesFunction () { 15 | 16 | let pkgsOutputOnlyFiles = bash.execute(commandName: "/usr/sbin/pkgutil", arguments: ["--only-files","--files",(globalVariables.SelectedPkg)]) 17 | 18 | //Create Array PkgsFiles 19 | globalVariables.PkgsFiles = (pkgsOutputOnlyFiles?.components(separatedBy: "\n"))! 20 | 21 | //Create Array thats a copy of PkgsFiles use for RAW output 22 | globalVariables.PkgsFilesRaw = globalVariables.PkgsFiles 23 | 24 | 25 | // Add globalVariables.Location to a every elements in globalVariables.PkgsFiles using .map 26 | // Clean using set CleanArray but not for suffix .app 27 | if globalVariables.Location.suffix(5) == ".app/" { 28 | globalVariables.PkgsFiles = globalVariables.PkgsFiles.map({ globalVariables.Location + $0 }) 29 | } else { 30 | //// Clean Array 31 | globalVariables.PkgsFiles.removeAll(where: { CleanArray.contains($0) }) 32 | globalVariables.PkgsFiles = globalVariables.PkgsFiles.map({ globalVariables.Location + $0 }) 33 | } 34 | 35 | } 36 | // END pkgFilesFunction 37 | 38 | 39 | 40 | 41 | // START pkgDirFunction 42 | func pkgDirFunction () { 43 | 44 | let pkgsOutputOnlyDir = bash.execute(commandName: "/usr/sbin/pkgutil", arguments: ["--only-dirs","--files",(globalVariables.SelectedPkg)]) 45 | 46 | 47 | // Create a Arry called PkgsDir, where we store all output 48 | globalVariables.PkgsDir = (pkgsOutputOnlyDir?.components(separatedBy: "\n"))! 49 | 50 | //Create Array thats a copy of PkgsDir use for RAW output 51 | globalVariables.PkgsDirRaw = globalVariables.PkgsDir 52 | 53 | // Add globalVariables.Location to a every elements in globalVariables.PkgsDir using .map 54 | // Clean using set CleanArray but not for suffix .app or .plugin 55 | if globalVariables.Location.suffix(5) == ".app/" || globalVariables.Location.suffix(8) == ".plugin/" { 56 | globalVariables.PkgsDir = globalVariables.PkgsDir.map({ globalVariables.Location + $0 }) 57 | } else { 58 | // Clean Array 59 | globalVariables.PkgsDir.removeAll(where: { CleanArray.contains($0) }) 60 | globalVariables.PkgsDir = globalVariables.PkgsDir.map({ globalVariables.Location + $0 }) 61 | } 62 | 63 | // Call funtion and sort by length 64 | globalVariables.PkgsDir.sort(by: length) 65 | } 66 | // END pkgDirFunction 67 | 68 | 69 | // START pkgDirOutputFunction 70 | func pkgDirOutputFunction () { 71 | var firstPkgsDir = "" 72 | 73 | 74 | // Empty Array globalVariables.PkgsDirFinal where we store final output from Directories 75 | globalVariables.PkgsDirFinal = [String]() 76 | globalVariables.PkgsDirAndFilesRemove.removeAll() 77 | 78 | // Get first/shortest elements from PkgsDir 79 | // add that to a new array and a variable FirstPkgsDir 80 | // Repeat for all elements in PkgsDir until its empty 81 | // Using PkgsDirAndFilesRemove array for the removing 82 | if globalVariables.PkgsDir.isEmpty == false { 83 | repeat { 84 | firstPkgsDir = globalVariables.PkgsDir[0] 85 | globalVariables.PkgsDirFinal.append(firstPkgsDir) 86 | for elements in globalVariables.PkgsDir { 87 | if elements.contains(firstPkgsDir) { 88 | globalVariables.PkgsDirAndFilesRemove.insert(elements) 89 | } 90 | } 91 | globalVariables.PkgsDir.removeAll(where: { globalVariables.PkgsDirAndFilesRemove.contains($0) }) 92 | } while (globalVariables.PkgsDir.isEmpty == false) 93 | } 94 | } 95 | // END pkgDirOutputFunction 96 | 97 | // START pkgFilesOutputFunction 98 | func pkgFilesOutputFunction () { 99 | // Output Pkgsfiles START, clean Files array using globalVariables.PkgsDirAndFilesRemove 100 | if globalVariables.PkgsDirFinal.isEmpty == false { 101 | for all in globalVariables.PkgsDirFinal { 102 | for elements in globalVariables.PkgsFiles { 103 | if elements.contains(all) { 104 | globalVariables.PkgsDirAndFilesRemove.insert(elements) 105 | 106 | } 107 | } 108 | } 109 | globalVariables.PkgsFiles.removeAll(where: { globalVariables.PkgsDirAndFilesRemove.contains($0) }) 110 | } 111 | } 112 | // END pkgFilesOutputFunction 113 | -------------------------------------------------------------------------------- /PkgsCleaner/PkgsCleaner.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PkgsCleaner/Variables.swift: -------------------------------------------------------------------------------- 1 | // Variables.swift 2 | // PkgsCleaner 3 | // 4 | // Created by Mikael Löfgren on 2019-05-14. 5 | // Copyright © 2019 Mikael Löfgren. All rights reserved. 6 | // 7 | import Foundation 8 | import Cocoa 9 | // Disable Smart Quotes for the output FinalOutPutTextField 10 | // https://stackoverflow.com/questions/19801601/nstextview-with-smart-quotes-disabled-still-replaces-quotes 11 | // Add this to the InterfaceBuilder File (IB) 12 | // automaticQuoteSubstitutionEnabled Boolean Value Unchecked 13 | // automaticDashSubstitutionEnabled Boolean Value Unchecked 14 | // automaticTextReplacementEnabled Boolean Value Unchecked 15 | 16 | // Function for creating TempDirectories 17 | func createTempDirectory(folderName: String) -> String? { 18 | guard let tempDirURL = NSURL(fileURLWithPath:NSTemporaryDirectory()).appendingPathComponent(folderName) else { 19 | return nil 20 | } 21 | do { 22 | try FileManager.default.createDirectory(at: tempDirURL, withIntermediateDirectories: true, attributes: nil) 23 | } catch { 24 | return nil 25 | } 26 | 27 | return (tempDirURL.path) 28 | } 29 | 30 | struct globalVariables { 31 | static var SelectedPkg = "" 32 | static var SelectedPkgFromFile = "" 33 | // Date right now 34 | static var DateNow = "" 35 | static var PkgsInfo:Array = [String]() 36 | static var PkgsFilesRaw:Array = [String]() 37 | static var PkgsFiles:Array = [String]() 38 | static var PkgsDirRaw:Array = [String]() 39 | static var PkgsDir:Array = [String]() 40 | static var PkgsDirFinal:Array = [String]() 41 | static var PkgsDirAndFilesRemove = Set([""]) 42 | static var PkgsDirAndFilesRemoveRaw = Set([""]) 43 | static var StatusCertificateCheckbox: Int = 0 44 | static var SelectedCertificate = "" 45 | static var Location = "" 46 | static var LocationRaw = "" 47 | static var Identifier = "" 48 | static var Version = "" 49 | static var IdentifierArray:Array = [String]() 50 | static var MainTempFolder = (createTempDirectory(folderName: "se.pkgscleaner")!) 51 | static var Signed = "" 52 | static var UnSigned = "" 53 | static var Output = "" 54 | // URL 55 | static var DocumentDirURL = URL(fileURLWithPath: "") 56 | // Tempfolders Variables 57 | static var TmpFolders = Set(["tmp","private","var"]) 58 | // Variables PkgAndMpkg 59 | static var pkgsTemp = (createTempDirectory(folderName: "se.pkgscleaner/temp")!) 60 | static var DistroPKGS:Array = [String]() 61 | static var PkgsOrMpkg = "" 62 | static var PkgsOutput = "" 63 | static var PkgsOutputDirs = "" 64 | static var DirTemp:Array = [String]() 65 | static var FileTemp:Array = [String]() 66 | static var CleanRawArray: Set = ["","."] 67 | } 68 | 69 | // Clean Arrays using this Set, Its only Cleans exactly match, this paths wont get uninstalled 70 | var CleanArray = Set(["","Applications","Applications/GRAPHISOFT","Applications/Graphisoft","Applications/Utilities","System", "System/Library","System/Library/Sandbox","System/Library/Extensions","System/Library/CoreServices","System/Library/LaunchAgents","System/Library/LaunchDaemons","System/Library/PrivateFrameworks","/System/Library/Video","/System/Library/Frameworks","Library","Library/Extensions","Library/LaunchAgents","Library/LaunchDaemons","Library/Application Support","Library/Application Support/Adobe","Adobe","Library/Documentation","Library/Documentation/Applications","Printers","Library/Frameworks","Library/Logs","Library/Java/JavaVirtualMachines","Library/Printers","Library/Printers/PPDs","Printers/PPDs","PPDs","PPDs/Contents","Printers/PPDs/Contents/Resources","Printers/PPDs/Contents","Library/Printers/RICOH/Profiles","Profiles","Library/Printers/RICOH/Icons","Icons","PPDs/Contents/Resources","Library/Printers/PPDs/Contents","Library/Printers/Sharp","Sharp","Printers/KONICAMINOLTA","Library/Printers/Sharp/PDEs","Library/Printers/Sharp/Icons","Library/Printers/Sharp/Filters","Sharp/PDEs","Sharp/Icons","Sharp/Filters","Library/Printers/PPDs/Contents/Resources","Library/Printers/toshiba","Library/Printers/hp","hp","Library/Printers/hp/Frameworks","hp/Frameworks","Library/Printers/hp/PDEs","Library/Printers/hp/Fax","Library/Printers/hp/filter","Library/Printers/hp/cups","Library/Printers/hp/cups/filters","Library/Printers/hp/Icons","Library/Printers/hp/Profiles","Library/Printers/hp/Utilities","Library/Printers/hp/Utilities/Handlers","Library/PrivilegedHelperTools","Library/Internet Plug-Ins","Library/ColorSync","Library/ColorSync/Profiles", "Library/PreferencePanes","Library/Java","Library/Java/Extensions","Application Support", "Library/Preferences","Library/Widgets","Library/Image Capture","Library/Image Capture/Devices","Application Support/KONICAMINOLTA","Library/Application Support/Adobe","Library/Application Support/Microsoft","Library/Application Support/Microsoft/Office365","Library/Application Support/Microsoft/Office365/User Content.localized","Library/Application Support/Microsoft/Office365/User Content.localized/Templates","Library/Caches", "LaunchAgents","LaunchDaemons","etc","etc/newsyslog.d","bin","usr","usr/standalone/firmware","usr/standalone/i386","usr/libexec/cups","usr/libexec/cups/backend","usr/bin","usr/lib","usr/libexec","usr/sbin","usr/share","usr/standalone","usr/share/man","usr/share/man/man1", "usr/local","usr/local/lib","usr/local/libexec","usr/local/bin","usr/local/sbin","usr/local/share","usr/local/share/doc","usr/local/share/man","opt","opt/local","sbin","private","private/etc","private/tmp","private/var", "private/etc/paths.d","private/var/db","private/var/db/dslocal","private/var/db/dslocal/nodes","private/var/db/dslocal/nodes/Default","private/var/db/dslocal/nodes/Default/users","Library/Application Support/com.apple.TCC", "Library/CoreAnalytics", "Library/Filesystems/NetFSPlugins/Staged", "Library/Filesystems/NetFSPlugins/Valid", "Library/Frameworks/iTunesLibrary.framework", "Library/GPUBundles", "Library/MessageTracer", "Library/Preferences/SystemConfiguration/com.apple.Boot.plist", "Library/StagedExtensions", "Library/Updates", "System", "System/Library/Assets", "System/Library/AssetsV2", "System/Library/Caches", "System/Library/Caches/com.apple.kext.caches", "System/Library/Extensions","System/Library/LaunchDaemons/com.apple.UpdateSettings.plist","System/Library/PreinstalledAssets", "System/Library/PreinstalledAssetsV2", "System/Library/User Template", "bin", "private/var/db/ConfigurationProfiles/Settings", "private/var/db/CVMS", "private/var/db/SystemPolicyConfiguration", "private/var/db/com.apple.xpc.roleaccountd.staging", "private/var/db/datadetectors", "private/var/db/dyld", "private/var/db/timezone","private/var/folders", "private/var/install", "sbin", "usr", "usr/libexec/cups", "usr/local", "usr/share/man", "usr/share/snmp", "etc", "tmp", "var"]) 71 | 72 | // Color for output text from Assets.xcassets 73 | // https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface 74 | let colorText: [NSAttributedString.Key: Any] = [ 75 | .foregroundColor: NSColor(named: NSColor.Name("ColorText"))! 76 | ] 77 | 78 | let blackText: [NSAttributedString.Key: Any] = [ 79 | .foregroundColor: NSColor(named: NSColor.Name("BlackText"))! 80 | ] 81 | 82 | // Function for get right dateformat back to string 83 | func dateToString(_ Date: Date) -> String? { 84 | let dateFormat = ISO8601DateFormatter() 85 | dateFormat.formatOptions = [.withFullDate, .withDashSeparatorInDate] 86 | dateFormat.timeZone = TimeZone.current 87 | return dateFormat.string(from: Date) 88 | } 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | # PkgsCleaner
3 | Read PKG and PKG recipe files, return uninstall-script for easy export as nopayload pkg or script.
4 | Use the Open menu to read from a PKG file.
5 |
6 | In my testing in returns a script in 10 sec for a big PKGs (like Microsoft Office).
7 | 8 | Always test your uninstall script before deploy.
9 | 10 | Hopefully its this saves your time when you want to uninstall any app or just to get a overview 11 | over what a PKG install.
12 | 13 | Use Help menu - Open temp folder to see the open/expanded PKG included files.
14 | 15 | System requirements: 10.13 or newer 16 | 17 | 18 | 19 | This is my first attempt to do a Swift app...Its open source so if anyone want to join, Im happy with that.
20 | 21 | ## Todo
22 | - CLI version (to return a uninstallscript)
23 | - Drag n drop
24 | - Undo in textfield
25 | - Better Notification after export
26 | -------------------------------------------------------------------------------- /images/pkgcleaner_interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/images/pkgcleaner_interface.png -------------------------------------------------------------------------------- /images/pkgscleanericon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaellofgren/PkgsCleaner/d06deab7ccd4b8419ca43053d24f4127a1b58e5c/images/pkgscleanericon.png --------------------------------------------------------------------------------