Skip to content

Commit

Permalink
Updated some files&README
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ committed Oct 6, 2023
1 parent a693443 commit 5e7c1e1
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 180 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions BAGen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@
8CCA71932ACEB7DA0008CC4A /* Maki_Collection.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CCA6F092ACEB7DA0008CC4A /* Maki_Collection.png */; };
8CCA71942ACEB7DA0008CC4A /* CH0167_Collection.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CCA6F0A2ACEB7DA0008CC4A /* CH0167_Collection.png */; };
8CCA71952ACEB7DA0008CC4A /* Citizen_Animal_1.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CCA6F0B2ACEB7DA0008CC4A /* Citizen_Animal_1.png */; };
8CCA71972ACF08B40008CC4A /* CrashReporterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CCA71962ACF08B40008CC4A /* CrashReporterView.swift */; };
8CCFEBE52ACD16B4003ADFEA /* Theme_01.wav in Resources */ = {isa = PBXBuildFile; fileRef = 8CCFEBE42ACD16B4003ADFEA /* Theme_01.wav */; };
8CCFEBE72ACD16BE003ADFEA /* title.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 8CCFEBE62ACD16BE003ADFEA /* title.mp4 */; };
8CCFEBF52ACD1931003ADFEA /* NotoSansSC-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8CCFEBE92ACD1931003ADFEA /* NotoSansSC-Regular.otf */; };
Expand Down Expand Up @@ -1353,6 +1354,7 @@
8CCA6F092ACEB7DA0008CC4A /* Maki_Collection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Maki_Collection.png; sourceTree = "<group>"; };
8CCA6F0A2ACEB7DA0008CC4A /* CH0167_Collection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = CH0167_Collection.png; sourceTree = "<group>"; };
8CCA6F0B2ACEB7DA0008CC4A /* Citizen_Animal_1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Citizen_Animal_1.png; sourceTree = "<group>"; };
8CCA71962ACF08B40008CC4A /* CrashReporterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReporterView.swift; sourceTree = "<group>"; };
8CCFEBE42ACD16B4003ADFEA /* Theme_01.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = Theme_01.wav; path = Res/BuiltIn/AudioClip/Theme_01.wav; sourceTree = SOURCE_ROOT; };
8CCFEBE62ACD16BE003ADFEA /* title.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = title.mp4; path = Res/BuiltIn/VideoClip/title.mp4; sourceTree = SOURCE_ROOT; };
8CCFEBE92ACD1931003ADFEA /* NotoSansSC-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSansSC-Regular.otf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1416,6 +1418,7 @@
8CCFEC012ACD361A003ADFEA /* PathFileChooserView.swift */,
8CFC141B2ACE8F5900DE14D7 /* FS */,
8CFC141C2ACE8F7000DE14D7 /* MT */,
8CCA71962ACF08B40008CC4A /* CrashReporterView.swift */,
6BD5A6312AC988E7004B05F9 /* Assets.xcassets */,
6BD5A6332AC988E7004B05F9 /* Preview Content */,
);
Expand Down Expand Up @@ -2905,6 +2908,7 @@
6BB0220B2AC9B67900460189 /* CodeExt.swift in Sources */,
6BD5A62E2AC988E6004B05F9 /* BAGenApp.swift in Sources */,
6B36D1482ACAEE3A0012CF1B /* FSEditChooserView.swift in Sources */,
8CCA71972ACF08B40008CC4A /* CrashReporterView.swift in Sources */,
6B36D14C2ACAFFDB0012CF1B /* FSEditorView.swift in Sources */,
8CCFEC022ACD361A003ADFEA /* PathFileChooserView.swift in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@
filePath = "BAGen/MT/MTEditorView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "327"
endingLineNumber = "327"
startingLineNumber = "375"
endingLineNumber = "375"
landmarkName = "body"
landmarkType = "24">
</BreakpointContent>
Expand Down
93 changes: 61 additions & 32 deletions BAGen/BAGenApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

import Darwin
import SwiftUI
import UserNotifications

var debugConsoleText = ""
var nowScene = NowScene.Intro
var fsEnterProjName = ""
var mtEnterProjName = ""
var mtIsHaveUnsavedChange = false
var isGlobalAlertPresented = false
var globalAlertContent: (() -> AnyView)?

@main
struct BAGenApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@Environment(\.scenePhase) var scenePhase
@State var debugConsoleContent = ""
@State var nowMainScene = NowScene.Intro
@State var isAlertPresented = false
Expand Down Expand Up @@ -47,6 +50,8 @@ struct BAGenApp: App {
MTEditorView()
case .EachCharacters:
EachCharactersView.Serika()
case .CrashReporter:
CrashReporterView()
}
}
.overlay {
Expand Down Expand Up @@ -81,28 +86,56 @@ struct BAGenApp: App {
.frame(width: 350, height: 260)
}
}
// .overlay(alignment: .topTrailing) {
// ZStack {
// RoundedRectangle(cornerRadius: 8).fill(.black).opacity(0.4)
// .frame(width: 200, height: 100)
// ScrollView {
// HStack {
// Text(debugConsoleContent)
// .foregroundColor(.white)
// .font(.system(size: 16))
// .onAppear {
// Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
// debugConsoleContent = debugConsoleText
// }
// }
// Spacer()
// }
// }
// .padding(5)
// }
// .frame(width: 200, height: 100)
// .allowsHitTesting(false)
// }
}
.onChange(of: scenePhase) { value in
switch value {
case .active:
// applicationDidFinishLaunching
if UserDefaults.standard.string(forKey: "CrashData") != nil {
nowScene = .CrashReporter
}

UIApplication.shared.isIdleTimerDisabled = true
signal(SIGABRT, { c in
CrashHander(signalStr: "SIGABRT", signalCode: c)
})
signal(SIGTRAP, { c in
CrashHander(signalStr: "SIGTRAP", signalCode: c)
})
signal(SIGILL, { c in
CrashHander(signalStr: "SIGILL", signalCode: c)
})

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
// 用户已经同意授权
} else {
// 用户拒绝了授权
}
}
case .inactive:
print("Inactive")
case .background:
// applicationDidEnterBackground
if mtIsHaveUnsavedChange {
debugPrint("Unsaved Change")
let content = UNMutableNotificationContent()
content.title = "未保存的项目"
content.body = "您刚才编辑的项目尚未保存"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
let request = UNNotificationRequest(identifier: "MTUnsavedChangeTip", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("发送通知失败:\(error.localizedDescription)")
} else {
print("通知已发送")
}
}
}
@unknown default:
break
}
}
}
}
Expand All @@ -115,6 +148,7 @@ enum NowScene {
case MTEditChooser
case MTEditor
case EachCharacters
case CrashReporter
}

func ChangeScene(to sceneName: NowScene) {
Expand All @@ -124,20 +158,13 @@ func ChangeScene(to sceneName: NowScene) {
class AppDelegate: NSObject, UIApplicationDelegate {
public static var orientationLock = UIInterfaceOrientationMask.landscape

func applicationDidFinishLaunching(_ application: UIApplication) {
UIApplication.shared.isIdleTimerDisabled = true
signal(SIGABRT, { c in
CrashHander(signalStr: "SIGABRT", signalCode: c)
})
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return AppDelegate.orientationLock
}
}

func CrashHander(signalStr: String, signalCode: Int32) {
var fullTrack = """
let fullTrack = """
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Expand All @@ -158,6 +185,8 @@ func CrashHander(signalStr: String, signalCode: Int32) {
Exception Type: (\(signalStr))
Termination Reason: (\(signalStr) \(signalCode))
\(Thread.callStackSymbols)
"""
UserDefaults.standard.set(fullTrack, forKey: "CrashData")
exit(1)
}
29 changes: 29 additions & 0 deletions BAGen/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,32 @@ extension String {
}
}
}

func captureScreenshot() -> UIImage {
return UIApplication.shared.keyWindow!.asImage()
}
extension UIView {
//将当前视图转为UIImage
func asImage() -> UIImage {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
}
}
extension View {
func snapshot() -> UIImage {
let controller = UIHostingController(rootView: self)
let view = controller.view

let targetSize = controller.view.intrinsicContentSize
view?.bounds = CGRect(origin: .zero, size: targetSize)
view?.backgroundColor = .clear

let renderer = UIGraphicsImageRenderer(size: targetSize)

return renderer.image { _ in
view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
}
}
}
29 changes: 25 additions & 4 deletions BAGen/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let globalAppVersion = 100
struct ContentView: View {
@AppStorage("ResVersion") var resVersion = 0
@AppStorage("FinishedDownloadVer") var finishedDownloadVer = 0 // After Download(But not finish unzip), Set this to serverVer
@AppStorage("IsSkippedDownload") var isSkippedDownload = false
let bgAvplayer = AVPlayer(url: Bundle.main.url(forResource: "title", withExtension: "mp4")!)
let bgAudioPlayer = try? AVAudioPlayer(contentsOf: Bundle.main.url(forResource: "Theme_01", withExtension: "wav")!)
@State var statusText = "正在检查更新..."
Expand All @@ -33,8 +34,8 @@ struct ContentView: View {
HStack {
Spacer()
BAButton(action: {
// resVersion = 100
nowScene = .EachCharacters
resVersion = 0
isSkippedDownload = false
}, label: "Test")
}
Spacer()
Expand Down Expand Up @@ -94,11 +95,31 @@ struct ContentView: View {
DarockKit.Network.shared.requestString("https://api.darock.top/bagen/update/check") { respStr, isSuccess in
if isSuccess {
if let serverVer = Int(respStr) {
if resVersion < serverVer {
if (resVersion < serverVer) && !isSkippedDownload {
if finishedDownloadVer >= serverVer, let filePath = UserDefaults.standard.string(forKey: "WaitToUnzipFilePath") {
UnzipArchive(filePath: filePath, serverVer: serverVer)
} else {
StartDownload(serverVer: serverAppVer)
globalAlertContent = {
AnyView(
VStack {
Spacer()
.frame(height: 20)
BAText("需要下载约3GB的附加资源\n跳过下载将导致部分功能不可用", fontSize: 20, isSystemd: true)
HStack {
BAButton(action: {
isSkippedDownload = true
isFinished = true
isGlobalAlertPresented = false
globalAlertContent = nil
}, label: "跳过")
BAButton(action: {
StartDownload(serverVer: serverVer)
}, label: "下载", isHighlighted: true)
}
}
)
}
isGlobalAlertPresented = true
}
} else {
isFinished = true
Expand Down
35 changes: 35 additions & 0 deletions BAGen/CrashReporterView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// CrashReporterView.swift
// BAGen
//
// Created by memz233 on 2023/10/5.
//

import SwiftUI

struct CrashReporterView: View {
var body: some View {
ScrollView {
VStack {
Text("SwiftArchive 似乎在上次运行中出现了问题")
.font(.system(size: 22, weight: .bold))
Text("以下是上次的错误信息:")
.font(.system(size: 20))
ScrollView {
Text(UserDefaults.standard.string(forKey: "CrashData")!)
}
.frame(maxHeight: 200)
Button(action: {
UserDefaults.standard.removeObject(forKey: "CrashData")
nowScene = .Intro
}, label: {
Text("返回首页")
})
}
}
}
}

#Preview {
CrashReporterView()
}
Loading

0 comments on commit 5e7c1e1

Please sign in to comment.