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
51 changes: 51 additions & 0 deletions GameRealisticMap.Arma3.Test/Arma3ToolsHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.IO;
using GameRealisticMap.Arma3;
using GameRealisticMap.Arma3.IO;
using Xunit;

namespace GameRealisticMap.Arma3.Test
{
public class Arma3ToolsHelperTest
{
[Fact]
public void GetProjectDrivePath_Returns_Custom_If_Set_And_Exists()
{
// Arrange
var customPath = Path.Combine(Path.GetTempPath(), "Arma3CustomProjectDrive");
Directory.CreateDirectory(customPath);
var settings = new WorkspaceSettings { ProjectDriveBasePath = customPath };

// Act
var result = Arma3ToolsHelper.GetProjectDrivePath(settings);

// Assert
Assert.Equal(customPath, result);
}

[Fact]
public void GetProjectDrivePath_Returns_Default_If_Custom_Set_And_Not_Exists()
{
// Arrange
var settings = new WorkspaceSettings { ProjectDriveBasePath = "NoSuchFileOrDirectory" };

// Act
var result = Arma3ToolsHelper.GetProjectDrivePath(settings);

// Assert
Assert.Contains("Arma 3 Projects", result);
}

[Fact]
public void GetProjectDrivePath_Returns_Default_If_No_P_And_No_Custom()
{
// Arrange
var settings = new WorkspaceSettings { ProjectDriveBasePath = null };

// Act
var result = Arma3ToolsHelper.GetProjectDrivePath(settings);

// Assert
Assert.Contains("Arma 3 Projects", result);
}
}
}
59 changes: 56 additions & 3 deletions GameRealisticMap.Arma3/Arma3ToolsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Diagnostics;
using System.Runtime.Versioning;
using GameRealisticMap.Reporting;
using GameRealisticMap.Arma3.IO;
using Microsoft.Win32;
using Pmad.ProgressTracking;

namespace GameRealisticMap.Arma3
{
public static class Arma3ToolsHelper
{
public static WorkspaceSettings? WorkspaceSettings { get; set; }

public static void EnsureProjectDrive(bool auto = true)
{
if (OperatingSystem.IsWindows() && !Directory.Exists("P:\\"))
Expand All @@ -16,7 +18,21 @@ public static void EnsureProjectDrive(bool auto = true)
string path = GetArma3ToolsPath();
if (!string.IsNullOrEmpty(path))
{
var processs = Process.Start(Path.Combine(path, @"WorkDrive\WorkDrive.exe"), auto ? "/Mount /y" : "/Mount");
var args = new List<string>
{
"/Mount"
};
var customPath = GetCustomProjectDriveMappedPath();
if (!string.IsNullOrEmpty(customPath))
{
args.Add("P");
args.Add(customPath);
}
if (auto)
{
args.Add("/y");
}
var processs = Process.Start(Path.Combine(path, @"WorkDrive\WorkDrive.exe"), args);
processs.WaitForExit();
}
}
Expand Down Expand Up @@ -218,13 +234,50 @@ public static string GetPboProjectPath()
return @"C:\Program Files (x86)\Mikero\DePboTools\bin\pboProject.exe"; // Hard-coded because tool can only work from this location
}

public static string GetProjectDrivePath()
public static string GetProjectDrivePath(WorkspaceSettings? settings = null)
{
if (Directory.Exists("P:"))
{
return "P:";
}
return GetCustomProjectDriveMappedPath(settings) ?? GetDefaultProjectDriveMappedPath();
}

/// <summary>
/// Default value used by Arma 3 Tools
/// </summary>
/// <returns></returns>
public static string GetDefaultProjectDriveMappedPath()
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Arma 3 Projects");
}

/// <summary>
/// Get the custom project drive path from the settings
/// </summary>
/// <param name="settings"></param>
/// <returns></returns>
private static string? GetCustomProjectDriveMappedPath(WorkspaceSettings? settings = null)
{
var path = GetSettings(settings).ProjectDriveBasePath;
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
{
return path;
}
return null;
}

private static WorkspaceSettings GetSettings(WorkspaceSettings? settings = null)
{
if (settings != null)
{
return settings;
}
if (WorkspaceSettings == null)
{
WorkspaceSettings = WorkspaceSettings.Load().GetAwaiter().GetResult();
}
return WorkspaceSettings;
}
}
}
4 changes: 2 additions & 2 deletions GameRealisticMap.Arma3/IO/WorkspaceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WorkspaceSettings
public ProjectDrive CreateProjectDrive()
{
var drive = new ProjectDrive(
ProjectDriveBasePath ?? Arma3ToolsHelper.GetProjectDrivePath(),
Arma3ToolsHelper.GetProjectDrivePath(this),
new PboFileSystem(PboFileSystem.GetArma3Paths(Arma3BasePath ?? Arma3ToolsHelper.GetArma3Path()), ModsPaths));
foreach(var pair in ProjectDriveMountPoints)
{
Expand All @@ -34,7 +34,7 @@ public ProjectDrive CreateProjectDrive()

public ProjectDrive CreateProjectDriveStandalone()
{
var drive = new ProjectDrive(ProjectDriveBasePath ?? Arma3ToolsHelper.GetProjectDrivePath());
var drive = new ProjectDrive(Arma3ToolsHelper.GetProjectDrivePath(this));
foreach (var pair in ProjectDriveMountPoints)
{
drive.AddMountPoint(pair.Key, pair.Value);
Expand Down
7 changes: 7 additions & 0 deletions GameRealisticMap.Studio.Test/Mocks/Arma3DataModuleMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class Arma3DataModuleMock : IArma3DataModule
public IEnumerable<string> ActiveMods { get; set; } = new string[0];

public bool UsePboProject { get; set; }
public string ProjectDriveBasePath { get; set; } = "DefaultProjectDriveBasePath";

public event EventHandler<EventArgs>? Reloaded;

Expand All @@ -40,5 +41,11 @@ public Task SaveLibraryCache()
{
return Task.CompletedTask;
}

public Task SetProjectDriveBasePath(string projectDriveBasePath)
{
ProjectDriveBasePath = projectDriveBasePath;
return Task.CompletedTask;
}
}
}
25 changes: 25 additions & 0 deletions GameRealisticMap.Studio/Modules/Arma3Data/Arma3DataModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using GameRealisticMap.Arma3;
using GameRealisticMap.Arma3.GameEngine;
using GameRealisticMap.Arma3.IO;
using GameRealisticMap.Arma3.TerrainBuilder;
Expand Down Expand Up @@ -50,12 +51,18 @@ public bool UsePboProject
}
}

public string ProjectDriveBasePath
{
get { return Settings?.ProjectDriveBasePath ?? Arma3ToolsHelper.GetDefaultProjectDriveMappedPath(); }
}

private void CommitSettings(WorkspaceSettings settings)
{
lock (this)
{
settings.Save();
Settings = settings;
Arma3ToolsHelper.WorkspaceSettings = settings;
}
}

Expand All @@ -68,6 +75,8 @@ private void Initialize(WorkspaceSettings settings)
{
Settings = settings;

Arma3ToolsHelper.WorkspaceSettings = settings;

ProjectDrive = settings.CreateProjectDrive();

Library = new ModelInfoLibrary(ProjectDrive);
Expand Down Expand Up @@ -121,5 +130,21 @@ public IPboCompilerFactory CreatePboCompilerFactory()
}
return new PboCompilerFactory(Library, ProjectDrive);
}

public async Task SetProjectDriveBasePath(string projectDriveBasePath)
{
string? actualValue = projectDriveBasePath;
if (string.IsNullOrEmpty(projectDriveBasePath) || string.Equals(projectDriveBasePath, Arma3ToolsHelper.GetDefaultProjectDriveMappedPath(), StringComparison.OrdinalIgnoreCase))
{
actualValue = null;
}
var settings = Settings ?? new WorkspaceSettings();
if (actualValue != settings.ProjectDriveBasePath)
{
settings.ProjectDriveBasePath = actualValue;
CommitSettings(settings);
await Reload();
}
}
}
}
3 changes: 3 additions & 0 deletions GameRealisticMap.Studio/Modules/Arma3Data/IArma3DataModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ internal interface IArma3DataModule

IPboCompilerFactory CreatePboCompilerFactory();

Task SetProjectDriveBasePath(string projectDriveBasePath);

event EventHandler<EventArgs> Reloaded;

bool UsePboProject { get; set; }

string ProjectDriveBasePath { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks;
using Caliburn.Micro;
using GameRealisticMap.Arma3;
using Gemini.Modules.Settings;

namespace GameRealisticMap.Studio.Modules.Arma3Data.ViewModels
{
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(typeof(ISettingsEditor))]
internal class Arma3DataSettingsViewModel : PropertyChangedBase, ISettingsEditor
[Export(typeof(ISettingsEditorAsync))]
internal class Arma3DataSettingsViewModel : PropertyChangedBase, ISettingsEditorAsync
{
private readonly IArma3DataModule _arma3;

Expand All @@ -17,13 +18,16 @@ public Arma3DataSettingsViewModel(IArma3DataModule arma3)
{
_arma3 = arma3;
UsePboProject = _arma3.UsePboProject;
ProjectDriveBasePath = _arma3.ProjectDriveBasePath;
}

public string SettingsPageName => GameRealisticMap.Studio.Labels.GeneralSettings;

public string SettingsPagePath => "Arma 3";

public string ProjectDriveBasePath => _arma3.ProjectDrive.MountPath;
public string ProjectDriveBasePath { get; set; }

public string ProjectDriveMountPath => _arma3.ProjectDrive.MountPath;

public string Arma3Path => Arma3ToolsHelper.GetArma3Path();

Expand All @@ -32,13 +36,16 @@ public Arma3DataSettingsViewModel(IArma3DataModule arma3)
public string Arma3WorkshopPath => Arma3ToolsHelper.GetArma3WorkshopPath();

public bool UsePboProject { get; set; }

public bool UseBuiltinTool { get { return !UsePboProject; } set { UsePboProject = !value; } }

public bool IsPboProjectInstalled => File.Exists(Arma3ToolsHelper.GetPboProjectPath());

public void ApplyChanges()
public async Task ApplyChangesAsync()
{
_arma3.UsePboProject = UsePboProject;
await _arma3.SetProjectDriveBasePath(ProjectDriveBasePath);
NotifyOfPropertyChange(nameof(ProjectDriveMountPath));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,58 @@
<StackPanel>

<StackPanel Orientation="Horizontal">
<Label>Project drive location</Label>
<Label Width="150">Project drive location</Label>
<TextBox Text="{Binding ProjectDriveBasePath}" Width="300" />
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
<Label Width="150">
<Run Text="{x:Static r:Labels.PBOGenerationTool}" />
</Label>
<TextBlock VerticalAlignment="Center">
<Hyperlink NavigateUri="{Binding ProjectDriveBasePath}" b:HyperLinkBehaviors.ShellExecute="True">
<TextBlock Text="{Binding ProjectDriveBasePath}" />
</Hyperlink>
<RadioButton GroupName="PboCompiler" IsChecked="{Binding UseBuiltinTool}"><Run Text="{x:Static r:Labels.UseBuitinGenerator}" /></RadioButton>
<RadioButton GroupName="PboCompiler" IsChecked="{Binding UsePboProject}" IsEnabled="{Binding IsPboProjectInstalled}"><Run Text="{x:Static r:Labels.UsePBOProject}" /></RadioButton>
</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Margin="50 5 0 0">
<Run Text="{x:Static r:Labels.PboProjectText}" />
</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="50 5 0 0">
<Hyperlink b:HyperLinkBehaviors.ShellExecute="True" NavigateUri="https://mikero.bytex.digital/"><Run Text="{x:Static r:Labels.PboProjectDownload}"/></Hyperlink>
</TextBlock>

<Border Height="1" Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" Margin="0 15 0 10" HorizontalAlignment="Stretch" />

<StackPanel Orientation="Vertical" >
<Label>Current project drive location</Label>
<TextBlock Margin="50 0 0 0">
<Hyperlink NavigateUri="{Binding ProjectDriveMountPath}" b:HyperLinkBehaviors.ShellExecute="True">
<TextBlock Text="{Binding ProjectDriveMountPath}" />
</Hyperlink>
</TextBlock>

<Label>Game location</Label>
<TextBlock VerticalAlignment="Center">
<TextBlock Margin="50 0 0 0">
<Hyperlink NavigateUri="{Binding Arma3Path}" b:HyperLinkBehaviors.ShellExecute="True">
<TextBlock Text="{Binding Arma3Path}" />
</Hyperlink>
</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal">
<Label>Tools location</Label>
<TextBlock VerticalAlignment="Center">
<TextBlock Margin="50 0 0 0">
<Hyperlink NavigateUri="{Binding Arma3ToolsPath}" b:HyperLinkBehaviors.ShellExecute="True">
<TextBlock Text="{Binding Arma3ToolsPath}" />
</Hyperlink>
</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal">
<Label>Workshop location</Label>
<TextBlock VerticalAlignment="Center">
<TextBlock Margin="50 0 0 0">
<Hyperlink NavigateUri="{Binding Arma3WorkshopPath}" b:HyperLinkBehaviors.ShellExecute="True">
<TextBlock Text="{Binding Arma3WorkshopPath}" />
</Hyperlink>
</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
<Label>
<Run Text="{x:Static r:Labels.PBOGenerationTool}" />
</Label>
<TextBlock VerticalAlignment="Center">
<RadioButton GroupName="PboCompiler" IsChecked="{Binding UseBuiltinTool}"><Run Text="{x:Static r:Labels.UseBuitinGenerator}" /></RadioButton>
<RadioButton GroupName="PboCompiler" IsChecked="{Binding UsePboProject}" IsEnabled="{Binding IsPboProjectInstalled}"><Run Text="{x:Static r:Labels.UsePBOProject}" /></RadioButton>
</TextBlock>
</StackPanel>


<TextBlock TextWrapping="Wrap" Margin="50 5 0 0">
<Run Text="{x:Static r:Labels.PboProjectText}" />
</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="50 5 0 0">
<Hyperlink b:HyperLinkBehaviors.ShellExecute="True" NavigateUri="https://mikero.bytex.digital/"><Run Text="{x:Static r:Labels.PboProjectDownload}"/></Hyperlink>
</TextBlock>


</StackPanel>
</UserControl>
Loading