Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarGroth committed Dec 22, 2019
1 parent 2e13fd1 commit f47fd1c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 48 deletions.
4 changes: 4 additions & 0 deletions AppMover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
75492BC723AEEF4D004823F1 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
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 = "<group>"; };
75647A2123AD659600C8E88E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -49,6 +51,7 @@
isa = PBXGroup;
children = (
75492BC523AD6711004823F1 /* AppMover.swift */,
75492BC723AEEF4D004823F1 /* Extensions.swift */,
75647A2023AD659600C8E88E /* AppMover.h */,
75647A2123AD659600C8E88E /* Info.plist */,
);
Expand Down Expand Up @@ -136,6 +139,7 @@
buildActionMask = 2147483647;
files = (
75492BC623AD6711004823F1 /* AppMover.swift in Sources */,
75492BC823AEEF4D004823F1 /* Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
48 changes: 0 additions & 48 deletions AppMover/AppMover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
56 changes: 56 additions & 0 deletions AppMover/Extensions.swift
Original file line number Diff line number Diff line change
@@ -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()
}

}

0 comments on commit f47fd1c

Please sign in to comment.