Skip to content

Commit

Permalink
Merge pull request #47 from ohaiibuzzle/feat/reinstall-gptk
Browse files Browse the repository at this point in the history
Feat: reinstall gptk
  • Loading branch information
ohaiibuzzle authored Jul 1, 2023
2 parents f211dca + f8f4344 commit e2327a5
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Harbor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
AB7A81022A30D2FE00AA71A6 /* HarborUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7A81012A30D2FE00AA71A6 /* HarborUtils.swift */; };
AB7D8E332A4DDE3400B55527 /* WinetricksUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7D8E322A4DDE3400B55527 /* WinetricksUtils.swift */; };
AB87CAF42A4AC67C00C32025 /* HarborShortcuts.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB87CAF32A4AC67C00C32025 /* HarborShortcuts.swift */; };
AB95D9FD2A5011C5003402D2 /* GPTKConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB95D9FC2A5011C5003402D2 /* GPTKConfigView.swift */; };
ABC0BFCE2A31627400382A42 /* BottleManagementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0BFCD2A31627400382A42 /* BottleManagementView.swift */; };
ABC0BFD12A31629300382A42 /* HarborBottle.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0BFD02A31629300382A42 /* HarborBottle.swift */; };
ABC0BFD42A31691500382A42 /* BottleOpsDropdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0BFD32A31691500382A42 /* BottleOpsDropdown.swift */; };
Expand Down Expand Up @@ -73,6 +74,7 @@
AB7A81012A30D2FE00AA71A6 /* HarborUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HarborUtils.swift; sourceTree = "<group>"; };
AB7D8E322A4DDE3400B55527 /* WinetricksUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinetricksUtils.swift; sourceTree = "<group>"; };
AB87CAF32A4AC67C00C32025 /* HarborShortcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HarborShortcuts.swift; sourceTree = "<group>"; };
AB95D9FC2A5011C5003402D2 /* GPTKConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GPTKConfigView.swift; sourceTree = "<group>"; };
ABC0BFCD2A31627400382A42 /* BottleManagementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottleManagementView.swift; sourceTree = "<group>"; };
ABC0BFD02A31629300382A42 /* HarborBottle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HarborBottle.swift; sourceTree = "<group>"; };
ABC0BFD32A31691500382A42 /* BottleOpsDropdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottleOpsDropdown.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -228,6 +230,7 @@
AB6254332A3CE30D002A6206 /* BottleCardListView.swift */,
AB0D004B2A40B8900019D62F /* DXVKInstallView.swift */,
AB0D004D2A40E3D30019D62F /* EnvironmentVarsEditor.swift */,
AB95D9FC2A5011C5003402D2 /* GPTKConfigView.swift */,
);
path = BottleManagement;
sourceTree = "<group>";
Expand Down Expand Up @@ -359,6 +362,7 @@
AB5CC6C02A308BBB00AEBB2B /* HarborApp.swift in Sources */,
AB7D8E332A4DDE3400B55527 /* WinetricksUtils.swift in Sources */,
AB7A81022A30D2FE00AA71A6 /* HarborUtils.swift in Sources */,
AB95D9FD2A5011C5003402D2 /* GPTKConfigView.swift in Sources */,
ABF5340C2A3F63BE0030677A /* BottleManagementCardView.swift in Sources */,
AB6652C42A3334E600F3FC5D /* XCLIUtils.swift in Sources */,
AB6254342A3CE30D002A6206 /* BottleCardListView.swift in Sources */,
Expand Down
74 changes: 64 additions & 10 deletions Harbor/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,12 @@
}
}
},
"setup.message.enterPassword" : {
"setup.message.removalComplete" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Please enter your admin password in order to un-quarantine the newly installed bottle"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Wpisz hasło Administratora, aby usunąć kwarantannę z nowo zainstalowanej butelki"
"value" : "Game Porting Toolkit removal complete. You can now close this window"
}
}
}
Expand Down Expand Up @@ -1012,12 +1006,12 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You can install GPTK quicker by obtaining a pre-built brew bottle of GPTK. \nThis saves your Mac from compiling Wine at the cost of potential compatibility issues.\nPlease note that this installation method excludes the shader compiler from Apple"
"value" : "You can install GPTK quicker by obtaining a pre-built brew bottle of GPTK. \nThis saves your Mac from compiling Wine at the cost of potential compatibility issues.\nPlease note that this installation method excludes the compiler from Apple"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"state" : "needs_review",
"value" : "Możesz zainstalować GPK szybciej wybierając wcześniej skompilowaną butelkę Homebrew z GPTK.\nTo oszczędza twojego Maca od kompilowania Wine kosztem potencjalnych problemów z kompatybilnością\nTa metoda instalacji nie zawiera kompilatora shaderów od Apple"
}
}
Expand Down Expand Up @@ -1135,6 +1129,66 @@
}
}
},
"sheet.GPTKConfig.removeGPTK" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Completely remove GPTK"
}
}
}
},
"sheet.GPTKConfig.removeGPTK.subtitle" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Harbor is about to completely remove GPTK from your device. You will need to reinstall it again if you want to use Harbor."
}
}
}
},
"sheet.GPTKConfig.removeGPTK.title" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "GPTK Removal"
}
}
}
},
"sheet.GPTKConfig.subtitle" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You can update the GPTK DirectX libraries \nor completely remove GPTK for reinstallation when a newer release is available"
}
}
}
},
"sheet.GPTKConfig.title" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Configure GPTK"
}
}
}
},
"sheet.GPTKConfig.updateGPTKLibs" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Update GPTK Libraries"
}
}
}
},
"sheet.HBInstall.status.installed" : {
"localizations" : {
"en" : {
Expand Down
47 changes: 45 additions & 2 deletions Harbor/Systems/GPKUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ final class GPKUtils {
let aaplScript = """
property shellScript : "clear && \(brewUtils.x64BrewPrefix)/bin/brew install gstreamer pkg-config zlib \
freetype sdl2 libgphoto2 faudio jpeg libpng mpg123 libtiff libgsm glib gnutls libusb gettext molten-vk && \
/usr/bin/xattr -r -d com.apple.quarantine \(gpkBottle.path) && \
\(brewUtils.x64BrewPrefix)/bin/brew install --ignore-dependencies \(gpkBottle.path) && \
clear && echo '\(String(localized: "setup.message.enterPassword"))' && \
sudo /usr/bin/xattr -r -d com.apple.quarantine /usr/local/opt/game-porting-toolkit/; \
clear && echo '\(String(localized: "setup.message.complete"))' && exit"
tell application "Terminal"
Expand Down Expand Up @@ -221,4 +220,48 @@ final class GPKUtils {
return false
}
}

func reinstallGPKLibraries() {
// Remove the GPK libraries
let gpkLib = URL(fileURLWithPath: "/usr/local/opt/game-porting-toolkit/lib/external")
if FileManager.default.fileExists(atPath: gpkLib.path) {
do {
try FileManager.default.removeItem(at: gpkLib)
} catch {
HarborUtils.shared.quickError(error.localizedDescription)
return
}
}
// Copy the GPK libraries
copyGPKLibraries()
}

func completelyRemoveGPK() {
// Remove the GPK bottle from Brew
let aaplScript = """
property shellScript : "/usr/local/Homebrew/bin/brew uninstall game-porting-toolkit && \
echo '\(String(localized: "setup.message.removalComplete"))' && exit"
tell application "Terminal"
activate
-- Enter x86_64 shell
do script "arch -x86_64 /bin/sh"
delay 2
-- Run removal
do script shellScript in front window
end tell
"""

if let script = NSAppleScript(source: aaplScript) {
var error: NSDictionary?
script.executeAndReturnError(&error)
if let error = error {
NSLog("Harbor: Failed to execute AppleScript: \(error)")
} else {
status = .notInstalled
}
} else {
return
}
}
}
99 changes: 99 additions & 0 deletions Harbor/UIElements/BottleManagement/GPTKConfigView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// ReinstallGPTKView.swift
// Harbor
//
// Created by Venti on 01/07/2023.
//

import SwiftUI

struct GPTKConfigView: View {
@Binding var isPresented: Bool
@State var gpkSelected = false
@Environment(\.gpkUtils) var gpkUtils

var body: some View {
VStack {
Text("sheet.GPTKConfig.title")
.font(.title)
.padding()

Text("sheet.GPTKConfig.subtitle")
.multilineTextAlignment(.center)

VStack(alignment: .center) {
HStack {
Button("btn.browse") {
let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = false
panel.allowsMultipleSelection = false
panel.allowedContentTypes = [.diskImage]
panel.begin { response in
if response == .OK {
let result = panel.url
if let result = result {
let destination = HarborUtils.shared.getContainerHome()
.appendingPathComponent("GPK.dmg")
do {
// Remove any existing GPK.dmg
if FileManager.default.fileExists(atPath: destination.path) {
try FileManager.default.removeItem(at: destination)
}
try FileManager.default.copyItem(at: result, to: destination)
gpkSelected = true
} catch {
NSLog("sheet.GPKInstall.status.failedCopy \(destination)")
}
}
}
}
}
if gpkSelected {
Text("sheet.GPKInstall.status.selected")
.foregroundColor(.green)
}
}
.padding()

Button("sheet.GPTKConfig.updateGPTKLibs") {
gpkUtils.reinstallGPKLibraries()
isPresented.toggle()
}
.disabled(!gpkSelected)

Button("sheet.GPTKConfig.removeGPTK") {
let alert = NSAlert()
alert.messageText = String(localized: "sheet.GPTKConfig.removeGPTK.title")
alert.informativeText = String(localized: "sheet.GPTKConfig.removeGPTK.subtitle")
alert.addButton(withTitle: String(localized: "home.btn.nuke"))
alert.addButton(withTitle: String(localized: "btn.cancel"))
alert.alertStyle = .warning
alert.runModal() == .alertFirstButtonReturn ? {
Task.detached {
gpkUtils.completelyRemoveGPK()
Task { @MainActor in
isPresented.toggle()
}
}
}() : ()
}
.buttonStyle(.borderedProminent)
.tint(.red)
}
.padding()
Button("btn.OK") {
isPresented.toggle()
}
}
.padding()
}
}

struct GPTKConfigView_Previews: PreviewProvider {
static var previews: some View {
GPTKConfigView(isPresented: Binding.constant(true))
.environment(\.brewUtils, .init())
.environment(\.gpkUtils, .init())
}
}
5 changes: 5 additions & 0 deletions Harbor/UIElements/Commands/HarborMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ struct HarborMenu: Commands {
@Bindable var menuUIStates: MenuUIStates
var body: some Commands {
CommandGroup(after: .appVisibility) {
Divider()
Button("menu.harbor.installDXVK") {
menuUIStates.shouldShowDXVKSheet = true
}
Button("menu.harbor.killAll") {
HarborUtils.shared.dropNukeOnWine()
}
.keyboardShortcut("k", modifiers: [.command, .option, .shift])
Button("sheet.GPTKConfig.title") {
menuUIStates.shouldShowGPTKReinstallSheet = true
}
// Divider()
}
}
}
1 change: 1 addition & 0 deletions Harbor/Utils/MenuUIStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ final class MenuUIStates {
// This class is for stuff that needs to be passed between
// the menu items and the UI elements (eg. sheets within views)
var shouldShowDXVKSheet = false
var shouldShowGPTKReinstallSheet = false
}
3 changes: 3 additions & 0 deletions Harbor/Views/BottleManagementView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ struct BottleManagementView: View {
.sheet(isPresented: $menuUIStates.shouldShowDXVKSheet) {
DXVKInstallView(isPresented: $menuUIStates.shouldShowDXVKSheet)
}
.sheet(isPresented: $menuUIStates.shouldShowGPTKReinstallSheet) {
GPTKConfigView(isPresented: $menuUIStates.shouldShowGPTKReinstallSheet)
}
}
}

Expand Down

0 comments on commit e2327a5

Please sign in to comment.