Skip to content

Commit

Permalink
fix: annoying swiftui bug with nonfunctional copyItem method + light …
Browse files Browse the repository at this point in the history
…code refactoring
  • Loading branch information
vapidinfinity committed Jan 15, 2025
1 parent 336a344 commit 661e9ba
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Mythic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3278;
CURRENT_PROJECT_VERSION = 3290;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\"";
Expand Down Expand Up @@ -852,7 +852,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3278;
CURRENT_PROJECT_VERSION = 3290;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\"";
Expand Down
20 changes: 20 additions & 0 deletions Mythic/Utilities/Extensions/Built-in/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ extension FileManager {
try files.removeItem(at: url)
}
}

func forceCopyItem(at sourceURL: URL, to destinationURL: URL) throws {
let (stderr, _) = try Process.execute(
executableURL: .init(filePath: "/bin/cp"),
arguments: [
"-f",
sourceURL.path(percentEncoded: false),
destinationURL.path(percentEncoded: false)
]
)

if !stderr.isEmpty {
throw ForceCopyFailedError()
}
}

/// An error indicating that force-copying files has failed.
struct ForceCopyFailedError: LocalizedError {
var errorDescription: String? = "Failed to force-copy files."
}
}
24 changes: 15 additions & 9 deletions Mythic/Utilities/Extensions/Built-in/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ import Foundation
import OSLog

extension Process {
static func execute(executableURL: URL, arguments: [String]) throws -> String {
static func execute(executableURL: URL, arguments: [String]) throws -> (stderr: String, stdout: String) {
let process = Process()
process.executableURL = executableURL
process.arguments = arguments

let pipe = Pipe()
process.standardOutput = pipe


let stderr = Pipe()
let stdout = Pipe()

process.standardError = stderr
process.standardOutput = stdout

try? process.run()
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(decoding: data, as: UTF8.self)

return output.trimmingCharacters(in: .whitespacesAndNewlines)
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()

let stderrOutput = String(decoding: stderrData, as: UTF8.self)
let stdoutOutput = String(decoding: stdoutData, as: UTF8.self)

return (stderr: stderrOutput, stdout: stdoutOutput)
}

static func executeAsync(executableURL: URL, arguments: [String], completion: @escaping (CommandOutput) -> Void) async throws {
Expand Down
2 changes: 1 addition & 1 deletion Mythic/Utilities/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class GameOperation: ObservableObject {
case .macOS:
workspace.runningApplications.contains(where: { $0.bundleURL?.path == gamePath }) // debounce may be necessary because macOS is slow at opening apps
case .windows:
(try? Process.execute(executableURL: .init(fileURLWithPath: "/bin/bash"), arguments: ["-c", "ps aux | grep -i '\(gamePath)' | grep -v grep"]))?.isEmpty == false
(try? Process.execute(executableURL: .init(fileURLWithPath: "/bin/bash"), arguments: ["-c", "ps aux | grep -i '\(gamePath)' | grep -v grep"]))?.stdout.isEmpty == false
}
}()

Expand Down
8 changes: 4 additions & 4 deletions Mythic/Utilities/Wine/WineInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,20 @@ final class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
}

// MARK: - Kill All Method
static func killAll(containerURL: URL? = nil) throws {
static func killAll(containerURLs urls: [URL] = .init()) throws {
let task = Process()
task.executableURL = Engine.directory.appending(path: "wine/bin/wineserver")
task.arguments = ["-k"]

let urls: [URL] = containerURL.map { [$0] } ?? .init(containerURLs)
let urls: [URL] = urls.isEmpty ? .init(containerURLs) : urls

for url in urls {
task.environment = ["WINEPREFIX": url.path(percentEncoded: false)]
task.qualityOfService = .utility
try task.run()
}
}

// MARK: - Clear Shader Cache Method
static func purgeShaderCache(game: Game? = nil) -> Bool {
let task = Process()
Expand Down
12 changes: 7 additions & 5 deletions Mythic/Views/Unified/Sheets/ContainerSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ struct ContainerSettingsView: View {
do {
withAnimation { modifyingDXVK = true }

try Wine.killAll(containerURLs: [container.url])

// x64
try files.removeItemIfExists(at: container.url.appending(path: "drive_c/windows/system32/d3d10core.dll"))
try files.removeItemIfExists(at: container.url.appending(path: "drive_c/windows/system32/d3d11.dll"))
Expand All @@ -182,21 +184,21 @@ struct ContainerSettingsView: View {
)
} else {
// x64
try files.copyItem(
try files.forceCopyItem(
at: Engine.directory.appending(path: "DXVK/x64/d3d10core.dll"),
to: container.url.appending(path: "drive_c/windows/system32")
)
try files.copyItem(
try files.forceCopyItem(
at: Engine.directory.appending(path: "DXVK/x64/d3d11.dll"),
to: container.url.appending(path: "drive_c/windows/system32")
)

// x32
try files.copyItem(
try files.forceCopyItem(
at: Engine.directory.appending(path: "DXVK/x32/d3d10core.dll"),
to: container.url.appending(path: "drive_c/windows/syswow64")
)
try files.copyItem(
try files.forceCopyItem(
at: Engine.directory.appending(path: "DXVK/x32/d3d11.dll"),
to: container.url.appending(path: "drive_c/windows/syswow64")
)
Expand Down Expand Up @@ -232,7 +234,7 @@ struct ContainerSettingsView: View {
get: { container.settings.dxvkAsync },
set: { container.settings.dxvkAsync = $0 }
))
.disabled(!container.settings.dxvk)
.disabled(!container.settings.dxvk || modifyingDXVK)

if !modifyingWindowsVersion, windowsVersionError == nil {
Picker("Windows Version", selection: Binding(
Expand Down

0 comments on commit 661e9ba

Please sign in to comment.