From 6179b35a177d147114e0019879e46b7ad7f0bb04 Mon Sep 17 00:00:00 2001 From: Lucki Date: Mon, 13 Apr 2020 17:23:18 +0200 Subject: [PATCH] Check if our symlink already exists and create at the first free drive letter --- src/data/compat/Proton.vala | 43 ++++++++++++++++++++++++++++++++++--- src/data/compat/Wine.vala | 43 ++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/data/compat/Proton.vala b/src/data/compat/Proton.vala index a8442713..2ae64052 100644 --- a/src/data/compat/Proton.vala +++ b/src/data/compat/Proton.vala @@ -168,17 +168,54 @@ namespace GameHub.Data.Compat var dosdevices = prefix.get_child("dosdevices"); - if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists() && !dosdevices.get_child("d::").query_exists()) + if(dosdevices.get_child("c:").query_exists() && dosdevices.get_path().has_prefix(runnable.install_dir.get_path())) { - if(dosdevices.get_path().has_prefix(runnable.install_dir.get_path())) + var has_symlink = false; + for(var letter = 'd'; letter <= 'y'; letter++) { - Utils.run({"ln", "-nsf", "../../../../../", "d:"}).dir(dosdevices.get_path()).run_sync(); + if(is_symlink_and_correct(dosdevices.get_child(@"$(letter):"))) + { + has_symlink = true; + break; + } + } + + for(var letter = 'd'; has_symlink == false && letter <= 'y'; letter++) + { + if(!dosdevices.get_child(@"$(letter):").query_exists() && !dosdevices.get_child(@"$(letter)::").query_exists()) + { + Utils.run({"ln", "-nsf", "../../../../../", @"$(letter):"}).dir(dosdevices.get_path()).run_sync(); + break; + } } } return prefix; } + private bool is_symlink_and_correct(File symlink) + { + if(!symlink.query_exists()) + { + return false; + } + + try + { + var symlink_info = symlink.query_info("*", NONE); + if(symlink_info == null || !symlink_info.get_is_symlink() || symlink_info.get_symlink_target() != "../../../../../") + { + return false; + } + } + catch (Error e) + { + return false; + } + + return true; + } + protected override string[] prepare_env(Runnable runnable, bool parse_opts=true) { var env = base.prepare_env(runnable, parse_opts); diff --git a/src/data/compat/Wine.vala b/src/data/compat/Wine.vala index 864ca61a..24880dc9 100644 --- a/src/data/compat/Wine.vala +++ b/src/data/compat/Wine.vala @@ -202,17 +202,54 @@ namespace GameHub.Data.Compat var dosdevices = prefix.get_child("dosdevices"); - if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists() && !dosdevices.get_child("d::").query_exists()) + if(dosdevices.get_child("c:").query_exists() && dosdevices.get_path().has_prefix(runnable.install_dir.get_path())) { - if(dosdevices.get_path().has_prefix(runnable.install_dir.get_path())) + var has_symlink = false; + for(var letter = 'd'; letter <= 'y'; letter++) { - Utils.run({"ln", "-nsf", "../../../../", "d:"}).dir(dosdevices.get_path()).run_sync(); + if(is_symlink_and_correct(dosdevices.get_child(@"$(letter):"))) + { + has_symlink = true; + break; + } + } + + for(var letter = 'd'; has_symlink == false && letter <= 'y'; letter++) + { + if(!dosdevices.get_child(@"$(letter):").query_exists() && !dosdevices.get_child(@"$(letter)::").query_exists()) + { + Utils.run({"ln", "-nsf", "../../../../", @"$(letter):"}).dir(dosdevices.get_path()).run_sync(); + break; + } } } return prefix; } + private bool is_symlink_and_correct(File symlink) + { + if(!symlink.query_exists()) + { + return false; + } + + try + { + var symlink_info = symlink.query_info("*", NONE); + if(symlink_info == null || !symlink_info.get_is_symlink() || symlink_info.get_symlink_target() != "../../../../") + { + return false; + } + } + catch (Error e) + { + return false; + } + + return true; + } + public override File get_install_root(Runnable runnable) { return get_wineprefix(runnable).get_child("drive_c");