Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lrdsnow committed Apr 12, 2024
1 parent c395a3d commit 5a86a23
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
build
.DS_Store
PurePKG.xcodeproj/project.xcworkspace/xcuserdata
PurePKG.xcodeproj/xcuserdata
PurePKG.xcodeproj/project.xcworkspace/xcshareddata/swiftpm
4 changes: 2 additions & 2 deletions PurePKG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = uwu.lrdsnow.purepkg;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
Expand Down Expand Up @@ -938,7 +938,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = uwu.lrdsnow.purepkg;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"originHash" : "801bf6f3393523e64168ca68d1acf65391e70029e22e87bea3da25455b60b197",
"pins" : [
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "3ec0ab0bca4feb56e8b33e289c9496e89059dd08",
"version" : "7.10.2"
"revision" : "5b92f029fab2cce44386d28588098b5be0824ef5",
"version" : "7.11.0"
}
},
{
Expand Down Expand Up @@ -38,5 +37,5 @@
}
}
],
"version" : 3
"version" : 2
}
Binary file not shown.
2 changes: 1 addition & 1 deletion PurePKG/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ struct MainView: View {

HStack {
ForEach(0..<4) { index in
Button(action: { if !appData.repos.isEmpty { selectedTab = index } }) {
Button(action: { selectedTab = index }) {
HStack {
tabItemImages[tabItems[index]]?
.renderingMode(.template)
Expand Down
23 changes: 12 additions & 11 deletions PurePKG/Main/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,26 @@ struct SettingsView: View {
Spacer()
Text("\(appData.deviceInfo.major).\(appData.deviceInfo.minor)\(appData.deviceInfo.patch == 0 ? "" : ".\(appData.deviceInfo.patch)")\(appData.deviceInfo.build_number == "0" ? "" : " (\(appData.deviceInfo.build_number))")")
}.listRowBG()
#if os(macOS)
HStack {
Text("Architecture")
Spacer()
Text("darwin-\(getMacOSArchitecture() ?? "unknown")")
}
#else
#if !os(macOS)
HStack {
Text("Jailbreak Type")
Spacer()
Text(appData.jbdata.jbtype == .rootful ? "Rootful (\(appData.jbdata.jbarch))" : appData.jbdata.jbtype == .tvOS_rootful ? "Rootful (\(appData.jbdata.jbarch))" : appData.jbdata.jbtype == .rootless ? "Rootless (\(appData.jbdata.jbarch))" : appData.jbdata.jbtype == .roothide ? "Roothide (\(appData.jbdata.jbarch))" : "Jailed")
Text((appData.jbdata.jbtype == .rootful || appData.jbdata.jbtype == .tvOS_rootful) ? "Rootful" : appData.jbdata.jbtype == .rootless ? "Rootless" : appData.jbdata.jbtype == .roothide ? "Roothide" : "Jailed")
}.listRowBG()
#endif
#if !os(macOS)
HStack {
Text("Jailbreak")
Text("Architecture")
Spacer()
Text(jb ?? "Unknown")
Text("\(appData.jbdata.jbarch)")
}.listRowBG()
#if !os(macOS)
if let jb = jb {
HStack {
Text("Jailbreak")
Spacer()
Text(jb)
}.listRowBG()
}
#endif
HStack {
Text("Tweak Count")
Expand Down
8 changes: 8 additions & 0 deletions RootHelper/RootHelperMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func RootHelperMain() -> Int32 {
NSLog("error saving repo metadata file: \(error)")
return -1
}
case "clearRepoFiles":
do {
try RepoHandler.RootHelper_clearRepoFiles(CommandLine.arguments[2])
return 0
} catch {
NSLog("error clearing repo files: \(error)")
return -1
}
case "removeAllRepoFiles":
do {
try RepoHandler.RootHelper_removeAllRepoFiles();
Expand Down
14 changes: 7 additions & 7 deletions Shared/Backend/Jailbreak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func getMacOSArchitecture() -> String? {
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

if let rawArch = output?.trimmingCharacters(in: .whitespacesAndNewlines) {
if let rawArch = output?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() {
if rawArch.contains("x86") {
return "amd64"
} else if rawArch.contains("arm") {
} else if rawArch.contains("arm") || rawArch.contains("aarch") {
return "arm64"
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func getDeviceInfo() -> DeviceInfo {
let minor = versionComponents[1]
let patch = versionComponents.count >= 3 ? versionComponents[2] : 0

// Check for beta and get model and <A12 check
// get model
let systemAttributes = NSDictionary(contentsOfFile: "/System/Library/CoreServices/SystemVersion.plist")
let build_number = systemAttributes?["ProductBuildVersion"] as? String ?? "0"
let beta = build_number.count > 6
Expand Down Expand Up @@ -191,7 +191,7 @@ public class Jailbreak {
#else
if jbtype == .rootful {
jbarch = "iphoneos-arm"
} else if jbtype == .rootless {
} else if jbtype == .rootless || jbtype == .jailed {
jbarch = "iphoneos-arm64"
} else if jbtype == .roothide {
jbarch = "iphoneos-arm64e"
Expand All @@ -208,7 +208,7 @@ public class Jailbreak {
static func type(_ appData: AppData? = nil) -> (jbType) {
let filemgr = FileManager.default
#if targetEnvironment(simulator)
return .rootless
return .jailed
#elseif os(tvOS)
if filemgr.fileExists(atPath: "/private/etc/apt") {
return .tvOS_rootful
Expand Down Expand Up @@ -288,7 +288,6 @@ public class Jailbreak {
static func jailbreak() -> String? {
let jburls: [(String, URL)] = [
// iOS 15+ (semi-)Jailbreaks only
("Serotonin", URL(fileURLWithPath: "/var/mobile/Serotonin.jp2")),
("Palera1n (Nightly)", URL(fileURLWithPath: "/cores/binpack/.installed_overlay")),
("Palera1n", URL(fileURLWithPath: "/cores/jbloader")),
("Palera1n (Legacy)", URL(fileURLWithPath: "/jbin/post.sh")),
Expand All @@ -299,7 +298,8 @@ public class Jailbreak {
("PureVirus", URL(fileURLWithPath: "/var/jb/.installed_purevirus")),
("Dopamine", URL(fileURLWithPath: "/var/jb/.installed_dopamine")),
("Fugu15 Rootful", URL(fileURLWithPath: "/.Fugu15")),
("Cherimoya", URL(fileURLWithPath: "/var/jb/.installed_cherimoya"))
("Cherimoya", URL(fileURLWithPath: "/var/jb/.installed_cherimoya")),
("Serotonin", URL(fileURLWithPath: "/var/mobile/Serotonin.jp2"))
]
for (name, url) in jburls {
log("\(url.path)")
Expand Down
52 changes: 48 additions & 4 deletions Shared/Backend/RepoHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class RepoHandler {

if let fileContent = String(data: data, encoding: .utf8) {
if fileContent.isValidRepoFileFormat() || (url.pathComponents.last ?? "").contains(".gpg") {
#if !os(macOS)
if ((url.pathComponents.last ?? "").contains("Packages") || (url.pathComponents.last ?? "").contains("Release")) {
let fileName = "\(url.absoluteString.replacingOccurrences(of: "https://", with: "").replacingOccurrences(of: "http://", with: "").replacingOccurrences(of: "/", with: "_"))"
let tempFilePath = FileManager.default.temporaryDirectory.appendingPathComponent(fileName)
Expand All @@ -47,6 +48,7 @@ public class RepoHandler {

}
}
#endif

let lines = fileContent.components(separatedBy: .newlines)

Expand Down Expand Up @@ -76,6 +78,19 @@ public class RepoHandler {
task.resume()
}

public static func RootHelper_clearRepoFiles(_ url: String) throws {
let urlString = url.replacingOccurrences(of: "https://", with: "").replacingOccurrences(of: "http://", with: "").replacingOccurrences(of: "/", with: "_")
let fileManager = FileManager.default
let directoryPath = "\(Jailbreak.path())/var/lib/apt/purepkglists"
let fileURLs = try fileManager.contentsOfDirectory(atPath: directoryPath)

for fileURL in fileURLs {
if fileURL.contains(urlString) {
try fileManager.removeItem(atPath: "\(directoryPath)/\(fileURL)")
}
}
}

public static func RootHelper_saveRepoFiles(_ url: URL) throws {
try? FileManager.default.createDirectory(atPath: "\(Jailbreak.path())/var/lib/apt/purepkglists", withIntermediateDirectories: true)
let data = try Data(contentsOf: url)
Expand Down Expand Up @@ -103,12 +118,18 @@ public class RepoHandler {

if let fileContent = String(data: data, encoding: .utf8) {
do {
if (url.pathComponents.last ?? "").contains("Packages") || (url.pathComponents.last ?? "").contains("Release") {
#if !os(macOS)
if ((url.pathComponents.last ?? "").contains("Packages") || (url.pathComponents.last ?? "").contains("Release")) {
let fileName = "\(url.absoluteString.replacingOccurrences(of: "https://", with: "").replacingOccurrences(of: "http://", with: "").replacingOccurrences(of: "/", with: "_"))"
let tempFilePath = FileManager.default.temporaryDirectory.appendingPathComponent(fileName)
try data.write(to: tempFilePath)
spawnRootHelper(args: ["saveRepoFiles", tempFilePath.path])
do {
try data.write(to: tempFilePath)
spawnRootHelper(args: ["saveRepoFiles", tempFilePath.path])
} catch {

}
}
#endif

let paragraphs = fileContent.components(separatedBy: "\n\n")

Expand Down Expand Up @@ -726,8 +747,21 @@ func fixDuplicateRepos(_ repos: [Repo]) -> [Repo] {
return tempRepos
}

public var refreshingRepos = false

func refreshRepos(_ bg: Bool, _ appData: AppData) {
guard !refreshingRepos else {
return
}

refreshingRepos = true

let startTime = CFAbsoluteTimeGetCurrent()
#if os(macOS)
Task(priority: .background) {
APTWrapper.spawn(command: "\(Jailbreak.path())/bin/apt-get", args: ["apt-get", "update"])
}
#endif
let oldRepos = appData.repos
let repoCacheDir = URL.documents.appendingPathComponent("repoCache")
appData.repos = []
Expand Down Expand Up @@ -763,13 +797,23 @@ func refreshRepos(_ bg: Bool, _ appData: AppData) {
DispatchQueue.main.async {
appData.repos = fixDuplicateRepos(appData.repos)
if let AppDataRepoIndex = appData.repos.firstIndex(where: { $0.url == repo.url.appendingPathComponent("refreshing/") && $0.component == repo.component }) {
appData.repos[AppDataRepoIndex] = repo
var tempRepo = repo
if repo.tweaks.isEmpty {
spawnRootHelper(args: ["clearRepoFiles", repo.url.absoluteString])
if repo.error == nil || repo.error == "" {
tempRepo.error = "An unknown error occured getting repo packages"
}
}
appData.repos[AppDataRepoIndex] = tempRepo
appData.repos = fixDuplicateRepos(appData.repos)
appData.pkgs = appData.repos.flatMap { $0.tweaks }
let jsonEncoder = JSONEncoder()
let endTime = CFAbsoluteTimeGetCurrent()
let elapsedTime = endTime - startTime
log("Got \(appData.repos.filter { $0.error != "Refreshing..." }.count) repos in \(elapsedTime) seconds")
if (appData.repos.filter { $0.error != "Refreshing..." }.count + 2) >= appData.repos.count { // the +2 is just headroom for dead repos and bugs
refreshingRepos = false
}
do {
let jsonData = try jsonEncoder.encode(repo)
do {
Expand Down

0 comments on commit 5a86a23

Please sign in to comment.