Skip to content

Commit

Permalink
Support more themes, ios14
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcelocation committed Oct 21, 2022
1 parent 387effb commit 216ad19
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 30 deletions.
67 changes: 61 additions & 6 deletions TrollTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
CE2BF83C2902E14E00AD10BE /* Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = CE2BF83B2902E14E00AD10BE /* Dynamic */; };
CE2BF83F2902E18900AD10BE /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE2BF83E2902E18900AD10BE /* CoreServices.framework */; };
CE2BF8452902E21D00AD10BE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE2BF8442902E21D00AD10BE /* Assets.xcassets */; };
CEDE254429030238006078DD /* DebToIPA.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDE254329030238006078DD /* DebToIPA.swift */; };
CEDE25472903025F006078DD /* SWCompression in Frameworks */ = {isa = PBXBuildFile; productRef = CEDE25462903025F006078DD /* SWCompression */; };
CEDE254A29030277006078DD /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = CEDE254929030277006078DD /* Zip */; };
CEDE254D29030297006078DD /* ArArchiveKit in Frameworks */ = {isa = PBXBuildFile; productRef = CEDE254C29030297006078DD /* ArArchiveKit */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -47,14 +51,18 @@
CE2BF8392902E13900AD10BE /* TrollTools-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TrollTools-Bridging-Header.h"; sourceTree = "<group>"; };
CE2BF83E2902E18900AD10BE /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
CE2BF8442902E21D00AD10BE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CEDE254329030238006078DD /* DebToIPA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebToIPA.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
CE2BF7B42902DFF300AD10BE /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CEDE25472903025F006078DD /* SWCompression in Frameworks */,
CEDE254D29030297006078DD /* ArArchiveKit in Frameworks */,
CE2BF83F2902E18900AD10BE /* CoreServices.framework in Frameworks */,
CEDE254A29030277006078DD /* Zip in Frameworks */,
CE2BF83C2902E14E00AD10BE /* Dynamic in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -88,6 +96,7 @@
CE2BF8392902E13900AD10BE /* TrollTools-Bridging-Header.h */,
CE2BF81F2902E07F00AD10BE /* Private APIs */,
CE2BF8182902E07F00AD10BE /* RootView.swift */,
CEDE254329030238006078DD /* DebToIPA.swift */,
CE2BF8192902E07F00AD10BE /* TS */,
CE2BF8102902E07F00AD10BE /* Views */,
CE2BF8172902E07F00AD10BE /* WebClipTemplate.plist */,
Expand Down Expand Up @@ -162,6 +171,9 @@
name = TrollTools;
packageProductDependencies = (
CE2BF83B2902E14E00AD10BE /* Dynamic */,
CEDE25462903025F006078DD /* SWCompression */,
CEDE254929030277006078DD /* Zip */,
CEDE254C29030297006078DD /* ArArchiveKit */,
);
productName = TrollTools;
productReference = CE2BF7B72902DFF300AD10BE /* TrollTools.app */;
Expand Down Expand Up @@ -194,6 +206,9 @@
mainGroup = CE2BF7AE2902DFF300AD10BE;
packageReferences = (
CE2BF83A2902E14E00AD10BE /* XCRemoteSwiftPackageReference "Dynamic" */,
CEDE25452903025F006078DD /* XCRemoteSwiftPackageReference "SWCompression" */,
CEDE254829030277006078DD /* XCRemoteSwiftPackageReference "Zip" */,
CEDE254B29030296006078DD /* XCRemoteSwiftPackageReference "ArArchiveKit" */,
);
productRefGroup = CE2BF7B82902DFF300AD10BE /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -226,6 +241,7 @@
CE2BF8372902E10900AD10BE /* TrollToolsApp.swift in Sources */,
CE2BF8262902E07F00AD10BE /* ImagePickerView.swift in Sources */,
CE2BF8312902E07F00AD10BE /* BadgeChanger.swift in Sources */,
CEDE254429030238006078DD /* DebToIPA.swift in Sources */,
CE2BF82C2902E07F00AD10BE /* TSUtil.m in Sources */,
CE2BF8252902E07F00AD10BE /* MaterialView.swift in Sources */,
CE2BF8272902E07F00AD10BE /* BadgeChangerView.swift in Sources */,
Expand Down Expand Up @@ -361,7 +377,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 92S6JX27W2;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -371,12 +387,12 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = net.sourceloc.TrollTools;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -394,7 +410,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 92S6JX27W2;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -404,12 +420,12 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = net.sourceloc.TrollTools;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -451,6 +467,30 @@
kind = branch;
};
};
CEDE25452903025F006078DD /* XCRemoteSwiftPackageReference "SWCompression" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tsolomko/SWCompression";
requirement = {
branch = develop;
kind = branch;
};
};
CEDE254829030277006078DD /* XCRemoteSwiftPackageReference "Zip" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/marmelroy/Zip";
requirement = {
branch = master;
kind = branch;
};
};
CEDE254B29030296006078DD /* XCRemoteSwiftPackageReference "ArArchiveKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/LebJe/ArArchiveKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.3.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -459,6 +499,21 @@
package = CE2BF83A2902E14E00AD10BE /* XCRemoteSwiftPackageReference "Dynamic" */;
productName = Dynamic;
};
CEDE25462903025F006078DD /* SWCompression */ = {
isa = XCSwiftPackageProductDependency;
package = CEDE25452903025F006078DD /* XCRemoteSwiftPackageReference "SWCompression" */;
productName = SWCompression;
};
CEDE254929030277006078DD /* Zip */ = {
isa = XCSwiftPackageProductDependency;
package = CEDE254829030277006078DD /* XCRemoteSwiftPackageReference "Zip" */;
productName = Zip;
};
CEDE254C29030297006078DD /* ArArchiveKit */ = {
isa = XCSwiftPackageProductDependency;
package = CEDE254B29030296006078DD /* XCRemoteSwiftPackageReference "ArArchiveKit" */;
productName = ArArchiveKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = CE2BF7AF2902DFF300AD10BE /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"pins" : [
{
"identity" : "ararchivekit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/LebJe/ArArchiveKit",
"state" : {
"revision" : "ec33ce8bcb0be483e80ed49c95413e64e71e157b",
"version" : "0.3.0"
}
},
{
"identity" : "bitbytedata",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tsolomko/BitByteData",
"state" : {
"revision" : "b4b41619522aacd7aae7b02fa8360833e796a03d",
"version" : "2.0.2"
}
},
{
"identity" : "dynamic",
"kind" : "remoteSourceControl",
Expand All @@ -8,6 +26,24 @@
"branch" : "master",
"revision" : "772883073d044bc754d401cabb6574624eb3778f"
}
},
{
"identity" : "swcompression",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tsolomko/SWCompression",
"state" : {
"branch" : "develop",
"revision" : "5b590803b89b49c5e174f40b542df151edb3798d"
}
},
{
"identity" : "zip",
"kind" : "remoteSourceControl",
"location" : "https://github.com/marmelroy/Zip",
"state" : {
"branch" : "master",
"revision" : "67fa55813b9e7b3b9acee9c0ae501def28746d76"
}
}
],
"version" : 2
Expand Down
Binary file not shown.
95 changes: 95 additions & 0 deletions TrollTools/DebToIPA.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// DebToIPA.swift
// TrollTools
//
// Created by exerhythm on 21.10.2022.
//

import ArArchiveKit
import Zip
import SWCompression
import UIKit

class DebExtractor {
private static let fm = FileManager.default
private static var tempDir: URL { fm.temporaryDirectory }

/// Extracts deb
static func extractDeb(_ url: URL, to extractedDir: URL, statusUpdate: (String) -> ()) throws -> URL {
statusUpdate("Reading .deb")
let reader = try ArArchiveReader(archive: Array<UInt8>(Data(contentsOf: url)))
var foundData = false
for (header, dataInts) in reader {
guard header.name.contains("data.tar") else { continue }
let dataURL = tempDir.appendingPathComponent(header.name)

// Write data to disk
statusUpdate("Creating data from ints")
let data = Data(dataInts)
try data.write(to: dataURL, options: .atomic)

statusUpdate("Decompressing data archive")
let decompressedData: Data?
switch DecompressionMethod(rawValue: header.name.components(separatedBy: ".").last ?? "") {
case .lzma:
foundData = true
statusUpdate("Decompressing LZMA data.\nThis might take a while")
decompressedData = try LZMA.decompress(data: data)
case .gz:
foundData = true
statusUpdate("Unarchiving Gzip archive.\nThis might take a while")
decompressedData = try GzipArchive.unarchive(archive:data)
case .bzip2:
foundData = true
statusUpdate("Decompressing BZip2 data.\nThis might take a while")
decompressedData = try BZip2.decompress(data:data)
case .xz:
foundData = true
statusUpdate("Unarchiving XZ archive.\nThis might take a while")
decompressedData = try XZArchive.unarchive(archive:data)
case .none:
throw ConversionError.unsupportedCompression
}

statusUpdate("Opening .tar")
try decompressedData!.write(to: extractedDir.appendingPathExtension("tar"))
let tarContainer = try TarContainer.open(container: decompressedData!)

statusUpdate("Creating files")
for entry in tarContainer {
if entry.info.type == .directory {
try fm.createDirectory(at: extractedDir.appendingPathComponent(entry.info.name), withIntermediateDirectories: true)
} else if entry.info.type == .regular {
try entry.data?.write(to: extractedDir.appendingPathComponent(entry.info.name))
} else if entry.info.type == .symbolicLink {
try fm.createSymbolicLink(at: extractedDir.appendingPathComponent(entry.info.name), withDestinationURL: URL(fileURLWithPath: entry.info.linkName))
} else {
throw ConversionError.unknownFiletypeInsideTar
}
print(entry.info)
}
}

if !foundData {
throw ConversionError.noDataFound
}
return extractedDir
}

static func cleanup() throws {
for url in try fm.contentsOfDirectory(at: tempDir, includingPropertiesForKeys: nil) {
try fm.removeItem(at: url)
}
}
}

enum DecompressionMethod: String {
case gz, lzma, bzip2, xz
}

enum ConversionError: Error {
case noDataFound
case noPermission
case unknownFiletypeInsideTar
case unsupportedCompression
}
25 changes: 24 additions & 1 deletion TrollTools/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension View {
}

extension UIApplication {
public func respring() {
func respring() {
let app = self
// Credit to Amy While for this respring bug
guard let window = app.windows.first else { return }
Expand All @@ -50,3 +50,26 @@ extension UIApplication {
}
}
}


extension UIColor {
var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
getRed(&red, green: &green, blue: &blue, alpha: &alpha)

return (red, green, blue, alpha)
}
}


extension Color {
init(uiColor14: UIColor) {
self.init(red: Double(uiColor14.rgba.red),
green: Double(uiColor14.rgba.green),
blue: Double(uiColor14.rgba.blue),
opacity: Double(uiColor14.rgba.alpha))
}
}
1 change: 1 addition & 0 deletions TrollTools/Private APIs/BadgeChanger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Dynamic

class BadgeChanger {
static func change(to color: UIColor, with radius: CGFloat) throws {
let radius = max(1, radius)
let badge: UIImage = try UIImage.circle(radius: UIDevice.current.userInterfaceIdiom == .pad ? radius * 2 : radius, color: color)
let badgeBitmapPath = "/var/mobile/Library/Caches/MappedImageCache/Persistent/SBIconBadgeView.BadgeBackground:26:26.cpbitmap"
try? FileManager.default.removeItem(atPath: badgeBitmapPath)
Expand Down
18 changes: 13 additions & 5 deletions TrollTools/Private APIs/ThemeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,21 @@ class ThemeManager {
}

static func importTheme(from importURL: URL) throws -> Theme {
if !fm.fileExists(atPath: themesDir.path) {
try fm.createDirectory(at: themesDir, withIntermediateDirectories: true)
let rawIcons = !fm.fileExists(atPath: importURL.appendingPathExtension("IconBundles").path)
let name = importURL.deletingPathExtension().lastPathComponent
if rawIcons {
let themeURL = themesDir.appendingPathComponent(name)
try fm.createDirectory(at: themeURL, withIntermediateDirectories: true)
try fm.copyItem(at: importURL, to: themeURL.appendingPathComponent("IconBundles"))
} else {
if !fm.fileExists(atPath: themesDir.path) {
try fm.createDirectory(at: themesDir, withIntermediateDirectories: true)
}

try fm.copyItem(at: importURL, to: themesDir.appendingPathComponent(name))
}
let targetURL = themesDir.appendingPathComponent(importURL.deletingPathExtension().lastPathComponent)
try fm.copyItem(at: importURL, to: targetURL)
print(themesDir)

let targetURL = themesDir.appendingPathComponent(name)
return Theme(name: targetURL.deletingPathExtension().lastPathComponent, iconCount: try fm.contentsOfDirectory(at: targetURL.appendingPathComponent("IconBundles"), includingPropertiesForKeys: nil).count)
}

Expand Down
Loading

0 comments on commit 216ad19

Please sign in to comment.