From 4d1eafda524ebbe6c4d59b423f7f1c7c7e7eefbc Mon Sep 17 00:00:00 2001 From: WindowsMEMZ Date: Sun, 3 Mar 2024 17:30:43 +0800 Subject: [PATCH] feat: zipped dylib for networking --- DarockBili.xcodeproj/project.pbxproj | 64 ++++------------- .../DarockBili.dynamic.watch.xcscheme | 18 +++++ .../xcschemes/DarockBili.dynamic.xcscheme | 18 +++++ Localizable.xcstrings | 3 + MeowBili/DylibDownloadView.swift | 70 ++++++++++++------- MeowBili/InMain/MainView.swift | 6 +- MeowBili/Others/SettingsView.swift | 30 ++++---- 7 files changed, 113 insertions(+), 96 deletions(-) diff --git a/DarockBili.xcodeproj/project.pbxproj b/DarockBili.xcodeproj/project.pbxproj index 7e25fd73a..69b57e76d 100644 --- a/DarockBili.xcodeproj/project.pbxproj +++ b/DarockBili.xcodeproj/project.pbxproj @@ -1041,7 +1041,6 @@ 8CA68EF62B93224B00870AAA /* Sources */, 8CA68EF72B93224B00870AAA /* Frameworks */, 8CA68EF82B93224B00870AAA /* CopyFiles */, - 8CA638D62B93946A0041BF92 /* Code Signing */, ); buildRules = ( ); @@ -1221,7 +1220,6 @@ 8CE523B82B935D6100C89318 /* Sources */, 8CE523B92B935D6100C89318 /* Frameworks */, 8CE523BA2B935D6100C89318 /* CopyFiles */, - 8CA638D72B9396510041BF92 /* Code Signing */, ); buildRules = ( ); @@ -1415,44 +1413,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 8CA638D62B93946A0041BF92 /* Code Signing */ = { - isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - name = "Code Signing"; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "codesign -fs \"${EXPANDED_CODE_SIGN_IDENTITY_NAME}\" \"${BUILT_PRODUCTS_DIR}/DarockBili.dynamic.dylib\"\n"; - }; - 8CA638D72B9396510041BF92 /* Code Signing */ = { - isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - name = "Code Signing"; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "codesign -fs \"${EXPANDED_CODE_SIGN_IDENTITY_NAME}\" \"${BUILT_PRODUCTS_DIR}/DarockBili.dynamic.watch.dylib\"\n"; - }; 8CA97C2D2B945F670008A99B /* Export Dylibs */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -1762,7 +1722,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_TEAM = B57D8PP775; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = SafariExtension/Info.plist; @@ -1793,7 +1753,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_TEAM = B57D8PP775; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = SafariExtension/Info.plist; @@ -1829,7 +1789,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Vision App.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -1864,7 +1824,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Vision App.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -1945,7 +1905,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -1992,7 +1952,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -2036,7 +1996,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -2072,7 +2032,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_PREVIEWS = YES; @@ -2133,7 +2093,7 @@ CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Mac App.entitlements"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_HARDENED_RUNTIME = YES; @@ -2166,7 +2126,7 @@ CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Mac App.entitlements"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\""; DEVELOPMENT_TEAM = B57D8PP775; ENABLE_HARDENED_RUNTIME = YES; @@ -2195,7 +2155,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_TEAM = B57D8PP775; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 16.0; @@ -2218,7 +2178,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 932; + CURRENT_PROJECT_VERSION = 942; DEVELOPMENT_TEAM = B57D8PP775; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 16.0; diff --git a/DarockBili.xcodeproj/xcshareddata/xcschemes/DarockBili.dynamic.watch.xcscheme b/DarockBili.xcodeproj/xcshareddata/xcschemes/DarockBili.dynamic.watch.xcscheme index 59bb3ce85..c90ef894a 100644 --- a/DarockBili.xcodeproj/xcshareddata/xcschemes/DarockBili.dynamic.watch.xcscheme +++ b/DarockBili.xcodeproj/xcshareddata/xcschemes/DarockBili.dynamic.watch.xcscheme @@ -5,6 +5,24 @@ + + + + + + + + + + + + + + + + + + + + ") - } + Text("有资源包更新可用") }) } } diff --git a/MeowBili/Others/SettingsView.swift b/MeowBili/Others/SettingsView.swift index 609a6b4af..4760afd7a 100644 --- a/MeowBili/Others/SettingsView.swift +++ b/MeowBili/Others/SettingsView.swift @@ -21,6 +21,7 @@ import SwiftUI import SwiftDate import DarockKit import Alamofire +import ZipArchive import AuthenticationServices #if os(watchOS) import WatchKit @@ -919,20 +920,20 @@ struct SoftwareUpdateView: View { isDownloadingRes = true let destination: DownloadRequest.Destination = { _, _ in let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] - let fileURL = documentsURL.appendingPathComponent("mainnew.dylib") + let fileURL = documentsURL.appendingPathComponent("mainnew.zip") return (fileURL, [.removePreviousFile, .createIntermediateDirectories]) } #if targetEnvironment(simulator) #if os(watchOS) - let link = "https://cd.darock.top:32767/meowbili/res/dylib/watchsimulator.dylib" + let link = "https://cd.darock.top:32767/meowbili/res/dylib/watchsimulator.zip" #elseif os(iOS) - let link = "https://cd.darock.top:32767/meowbili/res/dylib/iphonesimulator.dylib" + let link = "https://cd.darock.top:32767/meowbili/res/dylib/iphonesimulator.zip" #endif #else #if os(watchOS) - let link = "https://cd.darock.top:32767/meowbili/res/dylib/watchos.dylib" + let link = "https://cd.darock.top:32767/meowbili/res/dylib/watchos.zip" #elseif os(iOS) - let link = "https://cd.darock.top:32767/meowbili/res/dylib/iphoneos.dylib" + let link = "https://cd.darock.top:32767/meowbili/res/dylib/iphoneos.zip" #endif #endif AF.download(link, to: destination) @@ -989,17 +990,16 @@ struct SoftwareUpdateView: View { .navigationBarHidden(true) .navigationBarBackButtonHidden() .onAppear { - let fileManager = FileManager.default - let documentsDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) - let mainDylibPath = documentsDirectory.appendingPathComponent("main.dylib") - let mainNewDylibPath = documentsDirectory.appendingPathComponent("mainnew.dylib") - do { - try fileManager.removeItem(at: mainDylibPath) - try fileManager.moveItem(at: mainNewDylibPath, to: mainDylibPath) - sleep(2) + DispatchQueue(label: "com.darock.DarockBili.updateInstall", qos: .background).async { + let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] + let zipPath = documentsURL.appendingPathComponent("mainnew.zip").path() + let libPath = documentsURL.appendingPathComponent("main.dylib").path() + if FileManager.default.fileExists(atPath: libPath) { + try! FileManager.default.removeItem(atPath: libPath) + } + try! SSZipArchive.unzipFile(atPath: zipPath, toDestination: zipPath.split(separator: "/").dropLast().joined(separator: "/"), overwrite: true, password: nil) + try! FileManager.default.removeItem(atPath: zipPath) isFinishedInstall = true - } catch { - print("错误:\(error)") } } } else {