Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions app-gpui/backend-route-inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1300,
"line": 1319,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -246,22 +246,22 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1092,
"line": 1111,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1126,
"line": 1145,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1163,
"line": 1182,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1197,
"line": 1216,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -343,22 +343,22 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1092,
"line": 1111,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1126,
"line": 1145,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1163,
"line": 1182,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1197,
"line": 1216,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -2004,12 +2004,12 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1038,
"line": 1057,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1394,
"line": 1413,
"kind": "literal-candidate"
}
],
Expand Down Expand Up @@ -2199,7 +2199,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 650,
"line": 669,
"kind": "literal-candidate"
}
],
Expand Down Expand Up @@ -2280,7 +2280,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 764,
"line": 783,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -2405,7 +2405,7 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 781,
"line": 800,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -2795,7 +2795,7 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 738,
"line": 757,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -2827,7 +2827,7 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 738,
"line": 757,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -3333,7 +3333,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1388,
"line": 1407,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -3595,12 +3595,12 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 824,
"line": 843,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 875,
"line": 894,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -3702,7 +3702,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 898,
"line": 917,
"kind": "literal-candidate"
}
],
Expand All @@ -3719,7 +3719,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 963,
"line": 982,
"kind": "literal-candidate"
}
],
Expand Down Expand Up @@ -3768,7 +3768,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 929,
"line": 948,
"kind": "literal-candidate"
}
],
Expand Down Expand Up @@ -3801,7 +3801,7 @@
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 689,
"line": 708,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -3872,17 +3872,17 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 809,
"line": 828,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 849,
"line": 868,
"kind": "literal-candidate"
},
{
"file": "app-gpui/src/settings_preview.rs",
"line": 979,
"line": 998,
"kind": "literal-candidate"
},
{
Expand Down Expand Up @@ -4418,7 +4418,7 @@
"literal_references": [
{
"file": "app-gpui/src/settings_preview.rs",
"line": 1335,
"line": 1354,
"kind": "literal-candidate"
},
{
Expand Down
36 changes: 32 additions & 4 deletions app-gpui/src/settings_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,25 @@ impl SettingsPreview {
== Some(true)
}

/// Whether anything of `variant`'s runtime is on disk to uninstall (installed, or only downloaded or partly set
/// up), per the last /runtime/state. A backend without "present" reports only "installed".
fn runtime_present(&self, variant: &str) -> bool {
self.runtime_state
.as_ref()
.and_then(|s| s.get(variant))
.and_then(|v| v.get("present").or_else(|| v.get("installed")))
.and_then(Value::as_bool)
== Some(true)
}

/// The runtime the backend runs on ("fex" or "regular"), per the last /runtime/state.
fn active_runtime(&self) -> Option<&str> {
self.runtime_state
.as_ref()
.and_then(|s| s.get("active"))
.and_then(Value::as_str)
}

/// Settings' "Uninstall FEX" / "Uninstall x86_64": that runtime only (the backend refuses the last one).
fn uninstall_runtime(&mut self, variant: &'static str, cx: &mut Context<Self>) {
if self.uninstalling_runtime {
Expand Down Expand Up @@ -2598,15 +2617,24 @@ impl Render for SettingsPreview {
.child(self.text_control(format!("{}%", app.update_progress.round() as u32))),
)
});
// One runtime only, for a user who wants just one of the two: offered when both are installed (the last
// one goes with "Uninstall MetalSharp").
let both_installed = self.runtime_installed("fex") && self.runtime_installed("regular");
// One runtime only, for a user who wants just one of the two. The inactive one is offered whenever anything
// of it is on disk, including a download whose setup never finished (#813); the active one only when the
// other is installed to switch to (the last one goes with "Uninstall MetalSharp").
let active = self.active_runtime().map(str::to_owned);
let offered = |variant: &str| {
let other = if variant == "fex" { "regular" } else { "fex" };
match active.as_deref() {
Some(a) if a == variant => self.runtime_installed(other),
Some(_) => self.runtime_present(variant),
None => self.runtime_installed("fex") && self.runtime_installed("regular"),
}
};
let runtime_uninstalls: Vec<_> = [
("fex", "uninstall-fex", "Uninstall FEX", "Delete the FEX Wine runtime (Arm64 with FEX) and its shader caches, keeping the x86_64 one, your prefixes and settings"),
("regular", "uninstall-x86_64", "Uninstall x86_64", "Delete the x86_64 Wine runtime (Rosetta 2) and its shader caches, keeping the FEX one, your prefixes and settings"),
]
.into_iter()
.filter(|_| both_installed)
.filter(|(variant, ..)| offered(variant))
.map(|(variant, id, label, desc)| {
self.row(
label,
Expand Down
2 changes: 2 additions & 0 deletions app/src-c/include/metalsharp_backend/wine_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ void ms_wine_reload_active_runtime(void);
/* The backend (main) follows config/active-runtime; other programs (the tests) keep the build's runtime */
void ms_wine_use_active_runtime_setting(void);
bool ms_wine_runtime_installed(const char* home, const char* variant);
/* Anything of the runtime's on disk to uninstall: installed, or only downloaded / partly set up */
bool ms_wine_runtime_present(const char* home, const char* variant);
/* Removes what an update leaves behind: an app set aside by an interrupted swap, and a download from another
* MetalSharp Wine release. */
void ms_wine_remove_superseded(const char* home);
Expand Down
23 changes: 21 additions & 2 deletions app/src-c/runtime/wine_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,22 @@ bool ms_wine_runtime_installed(const char* home, const char* variant) {
format_path(wine, sizeof(wine), "%s/%s", path, "wine") && runtime_wine_ready(wine, variant);
}

/* Anything of `variant`'s on disk that "Uninstall FEX" / "Uninstall x86_64" would remove: it installed, its app in
* runtime/, its download, or its files kept aside. A runtime downloaded but never set up (or whose setup failed) has
* only some of these, and is still worth removing. */
bool ms_wine_runtime_present(const char* home, const char* variant) {
char path[PATH_MAX];
bool fex = variant && !strcmp(variant, "fex");
const char* app = fex ? "MetalSharp-Wine.app" : WINE_X86_64_APP;
if (!home || !variant || (!fex && strcmp(variant, "regular")))
return false;
if (ms_wine_runtime_installed(home, variant))
return true;
return (format_path(path, sizeof(path), "%s/runtime/%s", home, app) && access(path, F_OK) == 0) ||
(format_path(path, sizeof(path), "%s/downloads/%s", home, app) && access(path, F_OK) == 0) ||
(runtime_stash(home, variant, path, sizeof(path)) && access(path, F_OK) == 0);
}

/* Where the runtime installs from: MetalSharp.app's own, or one downloaded into <home>/downloads */
static bool runtime_source_available(const char* variant) {
char* source = !strcmp(variant, "fex") ? ms_wine_fex_app_source() : ms_wine_x86_64_app_source();
Expand All @@ -1593,6 +1609,8 @@ static void write_runtime_state(ms_json_writer* writer, const char* home, const
ms_json_writer_object_begin(writer);
ms_json_writer_key(writer, "installed");
ms_json_writer_bool(writer, ms_wine_runtime_installed(home, variant));
ms_json_writer_key(writer, "present");
ms_json_writer_bool(writer, ms_wine_runtime_present(home, variant));
ms_json_writer_key(writer, "source");
ms_json_writer_bool(writer, runtime_source_available(variant));
/* installed from another MetalSharp Wine release, with nothing of this one to install from: switching to it
Expand Down Expand Up @@ -1793,8 +1811,9 @@ char* ms_wine_switch_runtime_json(const char* home, const char* body, size_t bod
* Settings' "Uninstall FEX" / "Uninstall x86_64": that runtime's Wine app, its laid-out files (active in runtime/ or
* kept aside), its download and its lanes' caches go; prefixes, which both runtimes share, stay. The active runtime
* goes only when the other is installed: the switch to it comes first (and the backend restarts on it). The last
* runtime stays: removing it is "Uninstall MetalSharp". MetalSharp.app still carries the apps, so either runtime can
* be set up again from the FEX | x86_64 toggle. */
* runtime stays: removing it is "Uninstall MetalSharp". The inactive one goes whatever state it is in, including a
* download whose setup never finished. MetalSharp.app still carries the apps, so either runtime can be set up again
* from the FEX | x86_64 toggle. */
bool ms_wine_uninstall_runtime(const char* home, const char* variant, bool* switched, char* error, size_t error_size) {
static const char* const fex_caches[] = {"shader-cache/fex-dxmt", "shader-cache/fex-dxmt_32",
"shader-cache/fex-vkd3d", "shader-cache/fex-dxvk",
Expand Down
30 changes: 30 additions & 0 deletions app/src-c/tests/runtime_routes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,35 @@ static void test_bottle_action_keeps_child_waits(const char* root) {
unsetenv("METALSHARP_APP_RESOURCES");
}

/* The inactive runtime downloaded but never set up (FEX's setup failing, issue 811) is still something on disk to
* remove: /runtime/state reports it present though not installed, so Settings offers "Uninstall FEX" /
* "Uninstall x86_64" for it, and uninstalling it removes the download (issue 813). */
static void test_uninstall_downloaded_runtime(const char* root) {
char home[PATH_MAX], path[PATH_MAX], downloaded[PATH_MAX], error[PATH_MAX + 128] = "";
const char* inactive = ms_wine_is_fex() ? "regular" : "fex";
const char* app = ms_wine_is_fex() ? "MetalSharp-Wine-x86_64.app" : "MetalSharp-Wine.app";
char *state, key[64];
bool switched = true;
snprintf(home, sizeof(home), "%s/uninstall-downloaded-runtime", root);
snprintf(downloaded, sizeof(downloaded), "%s/downloads/%s", home, app);
snprintf(path, sizeof(path), "mkdir -p '%s/Contents/MacOS' '%s/runtime'", downloaded, home);
assert(system(path) == 0);

assert(!ms_wine_runtime_installed(home, inactive));
assert(ms_wine_runtime_present(home, inactive));
state = ms_wine_runtimes_json(home);
snprintf(key, sizeof(key), "\"%s\":{\"installed\":false,\"present\":true", inactive);
assert(state && strstr(state, key));
free(state);

assert(ms_wine_uninstall_runtime(home, inactive, &switched, error, sizeof(error)));
assert(!switched);
assert(access(downloaded, F_OK) != 0);
assert(!ms_wine_runtime_present(home, inactive));
/* nothing of it at all */
assert(!ms_wine_runtime_present(home, "bogus") && !ms_wine_runtime_present(NULL, inactive));
}

int main(int argc, char** argv) {
if (argc >= 2 && !strcmp(argv[1], "--wine-exe-probe")) {
for (;;)
Expand Down Expand Up @@ -2970,6 +2999,7 @@ int main(int argc, char** argv) {
free(dosdevices);
legacy_ntdll_hook_refresh_test(home);
test_bottle_action_keeps_child_waits(home);
test_uninstall_downloaded_runtime(home);
puts("runtime routing regressions passed");
return 0;
}
Loading