diff --git a/AppMover.xcodeproj/project.pbxproj b/AppMover.xcodeproj/project.pbxproj index 71fd215..01f9178 100644 --- a/AppMover.xcodeproj/project.pbxproj +++ b/AppMover.xcodeproj/project.pbxproj @@ -8,11 +8,13 @@ /* Begin PBXBuildFile section */ 75492BC623AD6711004823F1 /* AppMover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75492BC523AD6711004823F1 /* AppMover.swift */; }; + 75492BC823AEEF4D004823F1 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75492BC723AEEF4D004823F1 /* Extensions.swift */; }; 75647A2223AD659600C8E88E /* AppMover.h in Headers */ = {isa = PBXBuildFile; fileRef = 75647A2023AD659600C8E88E /* AppMover.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 75492BC523AD6711004823F1 /* AppMover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppMover.swift; sourceTree = ""; }; + 75492BC723AEEF4D004823F1 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 75647A1D23AD659600C8E88E /* AppMover.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AppMover.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 75647A2023AD659600C8E88E /* AppMover.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppMover.h; sourceTree = ""; }; 75647A2123AD659600C8E88E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -49,6 +51,7 @@ isa = PBXGroup; children = ( 75492BC523AD6711004823F1 /* AppMover.swift */, + 75492BC723AEEF4D004823F1 /* Extensions.swift */, 75647A2023AD659600C8E88E /* AppMover.h */, 75647A2123AD659600C8E88E /* Info.plist */, ); @@ -136,6 +139,7 @@ buildActionMask = 2147483647; files = ( 75492BC623AD6711004823F1 /* AppMover.swift in Sources */, + 75492BC823AEEF4D004823F1 /* Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AppMover/AppMover.swift b/AppMover/AppMover.swift index 23c34d3..e29a210 100644 --- a/AppMover/AppMover.swift +++ b/AppMover/AppMover.swift @@ -9,54 +9,6 @@ import AppKit import Security -extension URL { - - var representsBundle: Bool { - pathExtension == "app" - } - - var isValid: Bool { - !path.trimmingCharacters(in: .whitespaces).isEmpty - } - - var numberOfFilesInDirectory: Int { - (try? FileManager.default.contentsOfDirectory(atPath: path))?.count ?? 0 - } - -} - -extension Bundle { - - var localizedName: String { - NSRunningApplication.current.localizedName ?? "The App" - } - - var isInstalled: Bool { - NSSearchPathForDirectoriesInDomains(.applicationDirectory, .allDomainsMask, true).contains(where: { $0.hasPrefix(bundlePath) - }) || bundlePath.split(separator: "/").contains("Applications") - } - - func copy(to url: URL) throws { - try FileManager.default.copyItem(at: bundleURL, to: url) - } - -} - -extension Process { - - static func runTask(command: String, arguments: [String] = [], completion: ((Int32) -> Void)? = nil) { - let task = Process() - task.launchPath = command - task.arguments = arguments - task.terminationHandler = { task in - completion?(task.terminationStatus) - } - task.launch() - } - -} - - public enum AppMover { public static func moveIfNecessary() { diff --git a/AppMover/Extensions.swift b/AppMover/Extensions.swift new file mode 100644 index 0000000..cfca8fd --- /dev/null +++ b/AppMover/Extensions.swift @@ -0,0 +1,56 @@ +// +// Extensions.swift +// AppMover +// +// Created by Oskar Groth on 2019-12-22. +// Copyright © 2019 Oskar Groth. All rights reserved. +// + +import Foundation + +extension URL { + + var representsBundle: Bool { + pathExtension == "app" + } + + var isValid: Bool { + !path.trimmingCharacters(in: .whitespaces).isEmpty + } + + var numberOfFilesInDirectory: Int { + (try? FileManager.default.contentsOfDirectory(atPath: path))?.count ?? 0 + } + +} + +extension Bundle { + + var localizedName: String { + NSRunningApplication.current.localizedName ?? "The App" + } + + var isInstalled: Bool { + NSSearchPathForDirectoriesInDomains(.applicationDirectory, .allDomainsMask, true).contains(where: { $0.hasPrefix(bundlePath) + }) || bundlePath.split(separator: "/").contains("Applications") + } + + func copy(to url: URL) throws { + try FileManager.default.copyItem(at: bundleURL, to: url) + } + +} + +extension Process { + + static func runTask(command: String, arguments: [String] = [], completion: ((Int32) -> Void)? = nil) { + let task = Process() + task.launchPath = command + task.arguments = arguments + task.terminationHandler = { task in + completion?(task.terminationStatus) + } + task.launch() + } + +}