Skip to content

Commit

Permalink
Fix stuff and no longer replaces stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldLoc committed Apr 27, 2022
1 parent df4aadc commit 38a4b4e
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 63 deletions.
12 changes: 8 additions & 4 deletions sm_osx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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 @@ -37,6 +38,7 @@
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 @@ -89,6 +91,7 @@
963F238227F8B211004E010E /* LauncherView.swift */,
963F238427F8B942004E010E /* DataStore.xcdatamodeld */,
963F238727F8BA01004E010E /* DataController.swift */,
9670CE8E281986B5005AA0CD /* AlertToBool.swift */,
);
path = sm_osx;
sourceTree = "<group>";
Expand Down Expand Up @@ -187,6 +190,7 @@
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 @@ -321,7 +325,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\"";
DEVELOPMENT_TEAM = 25RK3JMVLT;
ENABLE_HARDENED_RUNTIME = NO;
Expand All @@ -335,7 +339,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.1.6;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -353,7 +357,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 16;
DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\"";
DEVELOPMENT_TEAM = 25RK3JMVLT;
ENABLE_HARDENED_RUNTIME = NO;
Expand All @@ -367,7 +371,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.1.6;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
7 changes: 7 additions & 0 deletions sm_osx/AlertToBool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import SwiftUI

struct AlertToBool {


}
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 = "-j$(nproc)"
case fastest = "-j64"
}
212 changes: 189 additions & 23 deletions sm_osx/LauncherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,70 @@ struct LauncherView: View {
@FetchRequest(sortDescriptors:[SortDescriptor(\.title)]) var launcherRepos: FetchedResults<LauncherRepos>
@State var existingRepo = URL(string: "")
@State var repoTitle = ""
@State var currentVersion = "v1.1.3\n"
@State var currentVersion = "v1.1.6\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
@AppStorage("firstLaunch") var firstLaunch = true
@State var romURL = URL(string: "")
let sm64: UTType = .init(filenameExtension: "f3dex2e")!
let rom: UTType = .init(filenameExtension: "z64")!

func launcherShell(_ command: String) throws -> String {
self.crashLog = ""

let task = Process()
var output = ""
task.launchPath = "/bin/zsh"
task.arguments = ["-cl", command]

let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
let outHandle = pipe.fileHandleForReading
outHandle.waitForDataInBackgroundAndNotify()

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

if data.count > 0 {
if let str = String(data: data, encoding: .utf8) {
print("got output: \(str)")

output.append(str)

self.crashLog.append(str)
}
outHandle.waitForDataInBackgroundAndNotify()
} else {
print("EOF on stdout from process")
NotificationCenter.default.removeObserver(obs1 as Any)
}
}

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

if task.terminationStatus != 0 {
self.crashLog.append("A Crash has happend. Termination Status: \(task.terminationStatus)")

self.crashStatus = true
}

NotificationCenter.default.removeObserver(obs2 as Any)
}

try? task.run()

return(output)
}


func showOpenPanel() -> URL? {
let openPanel = NSOpenPanel()
Expand All @@ -34,6 +92,40 @@ struct LauncherView: View {
return response == .OK ? openPanel.url : nil
}

func showOpenPanelForRom() -> URL? {
let openPanel = NSOpenPanel()
openPanel.allowedContentTypes = [rom]
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = false
openPanel.canChooseFiles = true
let response = openPanel.runModal()
return response == .OK ? openPanel.url : nil
}

func checkRom(_ command: String) throws -> Bool {
let task = Process()
var output = false
task.launchPath = "/bin/zsh"
task.arguments = ["-cl", command]

let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
let outHandle = pipe.fileHandleForReading
outHandle.waitForDataInBackgroundAndNotify()

try? task.run()
task.waitUntilExit()
if task.terminationStatus != 0 {
output = true
}
else {
output = false
}

return(output)
}

var body: some View {
ZStack {
VStack {
Expand Down Expand Up @@ -87,6 +179,16 @@ struct LauncherView: View {
print("Its broken \(error)")
}
}

Button("Change Repo") {
existingRepo = showOpenPanel()

launcherRepos[i].path = existingRepo?.path

for i in 0...launcherRepos.count - 1 {
launcherRepos[i].isEditing = false
}
}
}.onAppear {
repoTitle = launcherRepos[i].title ?? ""
repoArgs = launcherRepos[i].args ?? ""
Expand All @@ -95,6 +197,10 @@ struct LauncherView: View {

Button(action: {

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

let launcherRepo = launcherRepos[i]

moc.delete(launcherRepo)
Expand All @@ -110,7 +216,12 @@ struct LauncherView: View {
}

Button(action: {
try? print(shell.asyncShell("\(LauncherRepo.path ?? "its broken") \(LauncherRepo.args ?? "")", waitTillExit: false))

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

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

print(LauncherRepo.path ?? "")
}) {
Expand All @@ -132,23 +243,62 @@ struct LauncherView: View {

Spacer()

if allowAddingRepos {
Button(action:{

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

romURL = showOpenPanelForRom()

romURL? = URL(fileURLWithPath: romURL?.path.replacingOccurrences(of: " ", with: "\\ ") ?? "")

print(romURL?.path ?? "")
print(romURL?.pathExtension ?? "")

print(try? shell.shell("cp \(romURL?.path ?? "") ~/SM64Repos/baserom.us.z64") ?? "")

if let doesExist = try? checkRom("ls ~/SM64Repos/baserom.us.z64") {
if doesExist {
allowAddingRepos = true
}
else {
allowAddingRepos = false
}
}
}) {
Text("Select Rom")
}
}

Button(action:{

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

repoView = true
}) {
Text("Add New Repo")
}.buttonStyle(.borderedProminent).sheet(isPresented: $repoView) {
RepoView(repoView: $repoView)
.frame(minWidth: 750, minHeight: 500)
}
}.disabled(allowAddingRepos)

Button("Add Existing Repo") {

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

existingRepo = showOpenPanel()

if existingRepo != nil {

let repo = LauncherRepos(context: moc)

repo.title = "Repo \(launcherRepos.count)"
repo.title = "New Repo \(launcherRepos.count)"
repo.path = existingRepo?.path
repo.args = ""
repo.id = UUID()
Expand All @@ -162,31 +312,18 @@ struct LauncherView: View {
}
}

Button("Install Homebrew") {
print(shell.installBrew("/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""))

let content = UNMutableNotificationContent()
content.title = "Finished installing homebrew"
content.subtitle = "Homebrew is now installed. If this is your first time with homebrew, please hit the install dependencies button."
content.sound = UNNotificationSound.default

// show this notification instantly
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false)

// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)

// add our notification request
UNUserNotificationCenter.current().add(request)
}

Text("Homebrew is REQUIRED for this software to work, please install homebrew at brew.sh")
.padding(.horizontal)

Text("\nOptional: Homebrew Intel version is nice to have. Install by launching terminal with Rosetta and installing at brew.sh")
.padding(.horizontal)

Button(action:{

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

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")
Expand All @@ -210,7 +347,14 @@ struct LauncherView: View {
Text("Install Dependencies")
}.buttonStyle(.bordered).padding(.vertical)
}

}.onAppear {
if try! checkRom("ls ~/SM64Repos/baserom.us.z64") {
allowAddingRepos = true
}
else {
allowAddingRepos = false
}

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")

Expand Down Expand Up @@ -238,12 +382,34 @@ 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"))
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)
}

Button("Not now", role: .cancel) {}
}.sheet(isPresented: $crashStatus) {
VStack {
Text("Your Game Crashed")

ScrollView {

TextEditor(text: $readableCrashLog)
.frame(minWidth: 350, minHeight: 350)
.onChange(of: readableCrashLog) { _ in
readableCrashLog = crashLog
}
.onAppear {
readableCrashLog = crashLog
}
}

Button("Close") {
crashLog = ""

crashStatus = false
}
}.frame(minWidth: 350, maxHeight: 350)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions sm_osx/Patches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ enum Patches: String {
case extData = "External Data"
case timeTrials = "Time Trials"
case captainToadStars = "Captain Toad Stars"
case qolFixes = "Quality of Life Fixes"
case qolFeatures = "Quality of Life Features"
case star_road = "Super Mario Star Road"
case nothing = ""
}
Loading

0 comments on commit 38a4b4e

Please sign in to comment.