Skip to content

Commit

Permalink
Linux aware "Project Drive"
Browse files Browse the repository at this point in the history
  • Loading branch information
jetelain committed Aug 23, 2023
1 parent 3bf6c49 commit 7d5b65a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>grma3</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions GameRealisticMap.Arma3.Test/IO/ProjectDriveTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using GameRealisticMap.Arma3.IO;

namespace GameRealisticMap.Arma3.Test.IO
{
public class ProjectDriveTest
{
[Fact]
public void GetFullPath()
{
if (OperatingSystem.IsWindows())
{
var drive = new ProjectDrive("c:\\temp\\pdrive");
drive.AddMountPoint("m", "c:\\temp\\mount");
Assert.Equal("c:\\temp\\pdrive\\a\\b\\c", drive.GetFullPath("a\\b\\c"));
Assert.Equal("c:\\temp\\pdrive\\a", drive.GetFullPath("a"));
Assert.Equal("c:\\temp\\mount\\b\\c", drive.GetFullPath("m\\b\\c"));
Assert.Equal("c:\\temp\\mount\\b", drive.GetFullPath("m\\b"));
}
else
{
var drive = new ProjectDrive("/tmp/pdrive");
drive.AddMountPoint("m", "/tmp/mount");
Assert.Equal("/tmp/pdrive/a/b/c", drive.GetFullPath("a\\b\\c"));
Assert.Equal("/tmp/pdrive/a", drive.GetFullPath("a"));
Assert.Equal("/tmp/mount/b/c", drive.GetFullPath("m\\b\\c"));
Assert.Equal("/tmp/mount/b", drive.GetFullPath("m\\b"));
}
}
}
}
17 changes: 15 additions & 2 deletions GameRealisticMap.Arma3/IO/ProjectDrive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,28 @@ public string GetFullPath(string path)
{
if (path.StartsWith(item.Key, StringComparison.OrdinalIgnoreCase))
{
return Path.Combine(item.Value, path.Substring(item.Key.Length));
return Path.Combine(item.Value, ToRelativePhysicalPath(path.Substring(item.Key.Length)));
}
}
// Should call Arma3ToolsHelper.EnsureProjectDrive() if mountPath == "P:" on first call
return Path.Combine(mountPath, path);
return Path.Combine(mountPath, ToRelativePhysicalPath(path));
}

private string ToRelativePhysicalPath(string gamePath)
{
if (OperatingSystem.IsWindows())
{
return gamePath;
}
return gamePath.Replace("\\", "/");
}

public bool EnsureLocalFileCopy(string path)
{
if (!OperatingSystem.IsWindows())
{
return true; // Unsupported on Linux
}
var fullPath = GetFullPath(path);
if (File.Exists(fullPath))
{
Expand Down

0 comments on commit 7d5b65a

Please sign in to comment.