Skip to content

Commit

Permalink
Use Windows Paths where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jun 21, 2023
1 parent 49ab131 commit 08acc0b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Whisky/Extensions/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ extension URL {
.replacingOccurrences(of: "/Users/\(NSUserName())", with: "~")
return prettyPath
}

func windowsPath() -> String {
var windowsPath = path
if let range = windowsPath.range(of: "drive_c") {
windowsPath = String(path[range.lowerBound...])
}

windowsPath = windowsPath.replacingOccurrences(of: "drive_c", with: "C:")
windowsPath = windowsPath.replacingOccurrences(of: "/", with: "\\")
return windowsPath
}
}
8 changes: 7 additions & 1 deletion Whisky/Utils/Wine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,17 @@ class Wine {
@discardableResult
static func runProgram(program: Program) async throws -> String {
let arguments = program.settings.arguments.split { $0.isWhitespace }.map(String.init)
return try await run(["start", "/unix", program.url.path] + arguments,
return try await run(["start", program.url.windowsPath()] + arguments,
bottle: program.bottle,
environment: program.settings.environment)
}

@discardableResult
static func runExternalProgram(url: URL, bottle: Bottle) async throws -> String {
return try await run(["start", "/unix", url.path],
bottle: bottle)
}

static func killBottle(bottle: Bottle) throws {
return try runWineserver(["-k"], bottle: bottle)
}
Expand Down
9 changes: 5 additions & 4 deletions Whisky/Views/Bottle Views/BottleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ struct BottleView: View {
Task(priority: .userInitiated) {
if result == .OK {
if let url = panel.urls.first {
let program = Program(name: url.lastPathComponent,
url: url,
bottle: bottle)
await program.run()
do {
try await Wine.runExternalProgram(url: url, bottle: bottle)
} catch {
print("Failed to run external program: \(error)")
}
programLoading = false
}
} else {
Expand Down
7 changes: 6 additions & 1 deletion Whisky/Views/ProgramView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ struct ProgramView: View {
Form {
Section("info.title") {
HStack {
InfoItem(label: String(localized: "info.path"), value: program.url.prettyPath())
InfoItem(label: String(localized: "info.path"), value: program.url.windowsPath())
.contextMenu {
Button("info.winPath.copy") {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(program.url.windowsPath(), forType: .string)
}
Button("info.path.copy") {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
Expand Down
1 change: 1 addition & 0 deletions Whisky/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"info.title" = "Info";
"info.path" = "Path";
"info.path.copy" = "Copy Path";
"info.winPath.copy" = "Copy Windows Path";
"info.wine" = "Wine Version";
"info.win" = "Windows Version";

Expand Down

0 comments on commit 08acc0b

Please sign in to comment.