Skip to content

Commit

Permalink
Fixed crashes and added a way to log while running.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldLoc committed Apr 28, 2022
1 parent 38a4b4e commit dc44654
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 36 deletions.
14 changes: 5 additions & 9 deletions sm_osx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
9669DC6D27D55CD200DE5FAB /* Patches.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9669DC6C27D55CD200DE5FAB /* Patches.swift */; };
9669DC6F27D55D5300DE5FAB /* PatchesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9669DC6E27D55D5300DE5FAB /* PatchesView.swift */; };
9669DC7127D55F4700DE5FAB /* RomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9669DC7027D55F4700DE5FAB /* RomView.swift */; };
9670CE8F281986B5005AA0CD /* AlertToBool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9670CE8E281986B5005AA0CD /* AlertToBool.swift */; };
96BB22E327E274F700057915 /* RepoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BB22E227E274F700057915 /* RepoView.swift */; };
96CF3D4227DBD8C7008A26F5 /* CompilationSpeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CF3D4127DBD8C7008A26F5 /* CompilationSpeed.swift */; };
96DE71D327EB9C170090E7A0 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DE71D227EB9C170090E7A0 /* SettingsView.swift */; };
Expand All @@ -38,7 +37,6 @@
9669DC6C27D55CD200DE5FAB /* Patches.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Patches.swift; sourceTree = "<group>"; };
9669DC6E27D55D5300DE5FAB /* PatchesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchesView.swift; sourceTree = "<group>"; };
9669DC7027D55F4700DE5FAB /* RomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RomView.swift; sourceTree = "<group>"; };
9670CE8E281986B5005AA0CD /* AlertToBool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertToBool.swift; sourceTree = "<group>"; };
96BB22E227E274F700057915 /* RepoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepoView.swift; sourceTree = "<group>"; };
96CF3D4127DBD8C7008A26F5 /* CompilationSpeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompilationSpeed.swift; sourceTree = "<group>"; };
96DE71D227EB9C170090E7A0 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,15 +81,14 @@
9669DC6A27D5581F00DE5FAB /* Repos.swift */,
9669DC6C27D55CD200DE5FAB /* Patches.swift */,
9669DC6E27D55D5300DE5FAB /* PatchesView.swift */,
9669DC7027D55F4700DE5FAB /* RomView.swift */,
960D46F527D6850D0056E393 /* BuildingSteps.swift */,
9669DC7027D55F4700DE5FAB /* RomView.swift */,
96CF3D4127DBD8C7008A26F5 /* CompilationSpeed.swift */,
96BB22E227E274F700057915 /* RepoView.swift */,
96DE71D227EB9C170090E7A0 /* SettingsView.swift */,
963F238227F8B211004E010E /* LauncherView.swift */,
963F238427F8B942004E010E /* DataStore.xcdatamodeld */,
963F238727F8BA01004E010E /* DataController.swift */,
9670CE8E281986B5005AA0CD /* AlertToBool.swift */,
);
path = sm_osx;
sourceTree = "<group>";
Expand Down Expand Up @@ -190,7 +187,6 @@
9669DC6B27D5581F00DE5FAB /* Repos.swift in Sources */,
96BB22E327E274F700057915 /* RepoView.swift in Sources */,
9669DC5C27D5565000DE5FAB /* sm_osxApp.swift in Sources */,
9670CE8F281986B5005AA0CD /* AlertToBool.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -325,7 +321,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\"";
DEVELOPMENT_TEAM = 25RK3JMVLT;
ENABLE_HARDENED_RUNTIME = NO;
Expand All @@ -339,7 +335,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.6;
MARKETING_VERSION = 1.1.7;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -357,7 +353,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\"";
DEVELOPMENT_TEAM = 25RK3JMVLT;
ENABLE_HARDENED_RUNTIME = NO;
Expand All @@ -371,7 +367,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.6;
MARKETING_VERSION = 1.1.7;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
7 changes: 0 additions & 7 deletions sm_osx/AlertToBool.swift

This file was deleted.

2 changes: 1 addition & 1 deletion sm_osx/CompilationSpeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ enum Speed: String {
case normal = "-j2"
case fast = "-j3"
case veryFast = "-j6"
case fastest = "-j64"
case fastest = "-j"
}
93 changes: 74 additions & 19 deletions sm_osx/LauncherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ struct LauncherView: View {
@FetchRequest(sortDescriptors:[SortDescriptor(\.title)]) var launcherRepos: FetchedResults<LauncherRepos>
@State var existingRepo = URL(string: "")
@State var repoTitle = ""
@State var currentVersion = "v1.1.6\n"
@State var currentVersion = "v1.1.7\n"
@State var updateAlert = false
@State var latestVersion = ""
@State var repoArgs = ""
@State var crashStatus = false
@State var crashLog = ""
@State var readableCrashLog = ""
@State var allowAddingRepos = true
@State var beginLogging = false
@AppStorage("firstLaunch") var firstLaunch = true
@State var romURL = URL(string: "")
let sm64: UTType = .init(filenameExtension: "f3dex2e")!
let rom: UTType = .init(filenameExtension: "z64")!
let sm64: UTType = .init(filenameExtension: "f3dex2e") ?? UTType.unixExecutable
let rom: UTType = .init(filenameExtension: "z64") ?? UTType.unixExecutable

func launcherShell(_ command: String) throws -> String {
self.crashLog = ""
Expand All @@ -44,7 +45,7 @@ struct LauncherView: View {
let outHandle = pipe.fileHandleForReading
outHandle.waitForDataInBackgroundAndNotify()

var obs1 : NSObjectProtocol!
var obs1 : NSObjectProtocol?
obs1 = NotificationCenter.default.addObserver(forName: Notification.Name.NSFileHandleDataAvailable, object: outHandle, queue: nil) { notification -> Void in
let data = outHandle.availableData

Expand All @@ -63,7 +64,7 @@ struct LauncherView: View {
}
}

var obs2 : NSObjectProtocol!
var obs2 : NSObjectProtocol?
obs2 = NotificationCenter.default.addObserver(forName: Process.didTerminateNotification, object: task, queue: nil) { notification -> Void in
print("terminated")

Expand Down Expand Up @@ -215,6 +216,23 @@ struct LauncherView: View {
Image(systemName: "trash")
}

Button(action: {

for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
}

print(try? launcherShell("\(LauncherRepo.path ?? "its broken") \(LauncherRepo.args ?? "")"))

beginLogging = true

print(LauncherRepo.path ?? "")
}) {
Text("Log")

Image(systemName: "arrow.right.circle.fill")
}

Button(action: {

for i in 0...launcherRepos.count - 1 {
Expand Down Expand Up @@ -246,8 +264,10 @@ struct LauncherView: View {
if allowAddingRepos {
Button(action:{

for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
if !launcherRepos.isEmpty {
for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
}
}

romURL = showOpenPanelForRom()
Expand All @@ -274,8 +294,10 @@ struct LauncherView: View {

Button(action:{

for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
if !launcherRepos.isEmpty {
for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
}
}

repoView = true
Expand All @@ -288,8 +310,10 @@ struct LauncherView: View {

Button("Add Existing Repo") {

for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
if !launcherRepos.isEmpty {
for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
}
}

existingRepo = showOpenPanel()
Expand Down Expand Up @@ -324,11 +348,11 @@ struct LauncherView: View {
launcherRepos[i].isEditing = false
}

print(try! shell.shell("brew install make mingw-w64 gcc sdl2 pkg-config glew glfw3 libusb audiofile coreutils"))
print(try? shell.shell("brew install make mingw-w64 gcc sdl2 pkg-config glew glfw3 libusb audiofile coreutils"))

print("its intel's turn nerd what an idiot man")

print(try! shell.intelShell("/usr/local/bin/brew install gcc gcc@9 sdl2 pkg-config glew glfw3 libusb audiofile coreutils"))
print(try? shell.intelShell("/usr/local/bin/brew install gcc gcc@9 sdl2 pkg-config glew glfw3 libusb audiofile coreutils"))

let content = UNMutableNotificationContent()
content.title = "Finished installing dependencies"
Expand All @@ -349,14 +373,24 @@ struct LauncherView: View {
}

}.onAppear {
if try! checkRom("ls ~/SM64Repos/baserom.us.z64") {
allowAddingRepos = true
do {
if try checkRom("ls ~/SM64Repos/baserom.us.z64") {
allowAddingRepos = true
}
else {
allowAddingRepos = false
}
}
else {
allowAddingRepos = false
catch {
print("Failed: \(error)")
}

latestVersion = try! shell.shell("curl https://github.com/EmeraldLoc/sm_osx/releases/latest -s | grep -o 'v[0-9].[0-9].[0-9]*' | sort -u")
do {
latestVersion = try shell.shell("curl https://github.com/EmeraldLoc/sm_osx/releases/latest -s | grep -o 'v[0-9].[0-9].[0-9]*' | sort -u")
}
catch {
print("Failed: \(error)")
}

print("Latest Version: \(latestVersion), Current Version: \(currentVersion)")

Expand All @@ -382,7 +416,7 @@ struct LauncherView: View {

}.alert("An Update is Avalible", isPresented: $updateAlert) {
Button("Update", role: .none) {
print(try! shell.shell("cd ~/Downloads && wget https://github.com/EmeraldLoc/sm_osx/releases/latest/download/sm_osx.zip && unzip sm_osx.zip && rm -rf sm_osx.zip /Applications/sm_osx.app && mv sm_osx.app /Applications && open /Applications/sm_osx.app"))
print(try? shell.shell("cd ~/Downloads && wget https://github.com/EmeraldLoc/sm_osx/releases/latest/download/sm_osx.zip && unzip sm_osx.zip && rm -rf sm_osx.zip /Applications/sm_osx.app && mv sm_osx.app /Applications && open /Applications/sm_osx.app"))

exit(0)
}
Expand All @@ -400,6 +434,8 @@ struct LauncherView: View {
readableCrashLog = crashLog
}
.onAppear {
beginLogging = false

readableCrashLog = crashLog
}
}
Expand All @@ -410,6 +446,25 @@ struct LauncherView: View {
crashStatus = false
}
}.frame(minWidth: 350, maxHeight: 350)
}.sheet(isPresented: $beginLogging) {
VStack {
TextEditor(text: $readableCrashLog)
.frame(minWidth: 350, minHeight: 350)
.onChange(of: readableCrashLog) { _ in
readableCrashLog = crashLog
}.onChange(of: crashLog) { _ in
readableCrashLog = crashLog
}
.onAppear {
readableCrashLog = crashLog
}

Spacer()

Button("Finish") {
beginLogging = false
}
}
}
}
}
Expand Down

0 comments on commit dc44654

Please sign in to comment.