Skip to content

Commit

Permalink
Check if our symlink already exists and create at the first free driv…
Browse files Browse the repository at this point in the history
…e letter
  • Loading branch information
Lucki committed Apr 13, 2020
1 parent d3dbc7c commit 6179b35
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
43 changes: 40 additions & 3 deletions src/data/compat/Proton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 40 additions & 3 deletions src/data/compat/Wine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 6179b35

Please sign in to comment.