[AltStoreCore] Adds Date, FileManager, and UIColor extensions

This commit is contained in:
Riley Testut
2020-09-14 14:12:21 -07:00
parent d1b897e212
commit 88c8d5f0f8
20 changed files with 196 additions and 157 deletions

View File

@@ -0,0 +1,34 @@
//
// Date+RelativeDate.swift
// AltStore
//
// Created by Riley Testut on 7/28/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import Foundation
public extension Date
{
func numberOfCalendarDays(since date: Date) -> Int
{
let today = Calendar.current.startOfDay(for: self)
let previousDay = Calendar.current.startOfDay(for: date)
let components = Calendar.current.dateComponents([.day], from: previousDay, to: today)
return components.day!
}
func relativeDateString(since date: Date, dateFormatter: DateFormatter) -> String
{
let numberOfDays = self.numberOfCalendarDays(since: date)
switch numberOfDays
{
case 0: return NSLocalizedString("Today", comment: "")
case 1: return NSLocalizedString("Yesterday", comment: "")
case 2...7: return String(format: NSLocalizedString("%@ days ago", comment: ""), NSNumber(value: numberOfDays))
default: return dateFormatter.string(from: date)
}
}
}

View File

@@ -0,0 +1,30 @@
//
// FileManager+SharedDirectories.swift
// AltStore
//
// Created by Riley Testut on 5/14/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import Foundation
public extension FileManager
{
var altstoreSharedDirectory: URL? {
guard let appGroup = Bundle.main.appGroups.first else { return nil }
let sharedDirectoryURL = self.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
return sharedDirectoryURL
}
var appBackupsDirectory: URL? {
let appBackupsDirectory = self.altstoreSharedDirectory?.appendingPathComponent("Backups", isDirectory: true)
return appBackupsDirectory
}
func backupDirectoryURL(for app: InstalledApp) -> URL?
{
let backupDirectoryURL = self.appBackupsDirectory?.appendingPathComponent(app.bundleIdentifier, isDirectory: true)
return backupDirectoryURL
}
}

View File

@@ -0,0 +1,24 @@
//
// UIColor+AltStore.swift
// AltStore
//
// Created by Riley Testut on 5/9/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import UIKit
public extension UIColor
{
private static let colorBundle = Bundle(for: DatabaseManager.self)
static let altPrimary = UIColor(named: "Primary", in: colorBundle, compatibleWith: nil)!
static let deltaPrimary = UIColor(named: "DeltaPrimary", in: colorBundle, compatibleWith: nil)
static let altPink = UIColor(named: "Pink", in: colorBundle, compatibleWith: nil)!
static let refreshRed = UIColor(named: "RefreshRed", in: colorBundle, compatibleWith: nil)!
static let refreshOrange = UIColor(named: "RefreshOrange", in: colorBundle, compatibleWith: nil)!
static let refreshYellow = UIColor(named: "RefreshYellow", in: colorBundle, compatibleWith: nil)!
static let refreshGreen = UIColor(named: "RefreshGreen", in: colorBundle, compatibleWith: nil)!
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.969",
"green" : "0.157",
"red" : "0.545"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.698",
"green" : "0.255",
"red" : "0.925"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.518",
"green" : "0.502",
"red" : "0.004"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.349",
"green" : "0.780",
"red" : "0.204"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.000",
"green" : "0.584",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.188",
"green" : "0.231",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.000",
"green" : "0.800",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}