From 0973b67e567749b01b8cf3f5454734151f76fcb7 Mon Sep 17 00:00:00 2001
From: artehe <112902041+artehe@users.noreply.github.com>
Date: Sat, 27 Apr 2024 16:53:18 +0100
Subject: [PATCH 1/3] This should help thwart the other special inidivuals
---
SIT.Manager/Localization/en-US.axaml | 1 +
SIT.Manager/Localization/ru-RU.axaml | 1 +
SIT.Manager/Localization/uk-UA.axaml | 1 +
SIT.Manager/Localization/zh-CN.axaml | 1 +
SIT.Manager/Localization/zh-HK.axaml | 1 +
SIT.Manager/Localization/zh-TW.axaml | 1 +
.../Installation/ConfigureSitViewModel.cs | 40 ++++++++++++++++++-
7 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/SIT.Manager/Localization/en-US.axaml b/SIT.Manager/Localization/en-US.axaml
index 03a98011..3462f64d 100644
--- a/SIT.Manager/Localization/en-US.axaml
+++ b/SIT.Manager/Localization/en-US.axaml
@@ -371,6 +371,7 @@
Location Selection Error
You've selected the same folder as the BSG install of EFT, please choose a different location to install SIT to
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
Ok
diff --git a/SIT.Manager/Localization/ru-RU.axaml b/SIT.Manager/Localization/ru-RU.axaml
index 37ebe796..2de57362 100644
--- a/SIT.Manager/Localization/ru-RU.axaml
+++ b/SIT.Manager/Localization/ru-RU.axaml
@@ -376,6 +376,7 @@
Ошибка выбора местоположения
Вы выбрали ту же папку, что и установка BSG EFT, выберите другое местоположение для установки SIT
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
Ок
diff --git a/SIT.Manager/Localization/uk-UA.axaml b/SIT.Manager/Localization/uk-UA.axaml
index ed450ee4..c559fbb4 100644
--- a/SIT.Manager/Localization/uk-UA.axaml
+++ b/SIT.Manager/Localization/uk-UA.axaml
@@ -376,6 +376,7 @@
Помилка вибору місця розташування
Ви вибрали ту саму теку, що і встановлення BSG EFT, оберіть інше місце для встановлення SIT
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
Ok
diff --git a/SIT.Manager/Localization/zh-CN.axaml b/SIT.Manager/Localization/zh-CN.axaml
index 8ed20e74..7ed3735d 100644
--- a/SIT.Manager/Localization/zh-CN.axaml
+++ b/SIT.Manager/Localization/zh-CN.axaml
@@ -376,6 +376,7 @@
位置选择错误
您选择了与 BSG EFT 安装相同的目录,请选择另一个位置以安装 SIT
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
好的
diff --git a/SIT.Manager/Localization/zh-HK.axaml b/SIT.Manager/Localization/zh-HK.axaml
index 084443a6..59a69fc8 100644
--- a/SIT.Manager/Localization/zh-HK.axaml
+++ b/SIT.Manager/Localization/zh-HK.axaml
@@ -375,6 +375,7 @@
位置選擇錯誤
您選擇了與 BSG EFT 安裝相同的目錄,請選擇另一個位置以安裝 SIT
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
好的
diff --git a/SIT.Manager/Localization/zh-TW.axaml b/SIT.Manager/Localization/zh-TW.axaml
index c5abcbfc..74279ef6 100644
--- a/SIT.Manager/Localization/zh-TW.axaml
+++ b/SIT.Manager/Localization/zh-TW.axaml
@@ -376,6 +376,7 @@
位置選擇錯誤
您選擇了與 BSG EFT 安裝相同的目錄,請選擇另一個位置以安裝 SIT
+ You've selected the same folder as an existing SPT install, please choose a different location to install SIT to
好的
diff --git a/SIT.Manager/ViewModels/Installation/ConfigureSitViewModel.cs b/SIT.Manager/ViewModels/Installation/ConfigureSitViewModel.cs
index 22c18513..5598e9c5 100644
--- a/SIT.Manager/ViewModels/Installation/ConfigureSitViewModel.cs
+++ b/SIT.Manager/ViewModels/Installation/ConfigureSitViewModel.cs
@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -80,6 +81,7 @@ private async Task ChangeEftInstallLocation()
IStorageFolder? directorySelected = await _pickerDialogService.GetDirectoryFromPickerAsync();
if (directorySelected != null)
{
+ bool usingInvalidLocatiion = false;
if (directorySelected.Path.LocalPath == CurrentInstallProcessState.BsgInstallPath)
{
// Using the same location as the current BSG install and we don't want this the same as the SIT install.
@@ -89,8 +91,22 @@ private async Task ChangeEftInstallLocation()
Content = _localizationService.TranslateSource("ConfigureSitViewModelLocationSelectionErrorDescription"),
PrimaryButtonText = _localizationService.TranslateSource("ConfigureSitViewModelLocationSelectionErrorOk")
}.ShowAsync();
+ usingInvalidLocatiion = true;
}
- else
+
+ if (HasSelectedSPTInstallPath(directorySelected.Path.LocalPath))
+ {
+ // Using the same location as an existing SPT install and we don't want this the same as the SIT install.
+ await new ContentDialog()
+ {
+ Title = _localizationService.TranslateSource("ConfigureSitViewModelLocationSelectionErrorTitle"),
+ Content = _localizationService.TranslateSource("ConfigureSitViewModelLocationSelectionSPTErrorDescription"),
+ PrimaryButtonText = _localizationService.TranslateSource("ConfigureSitViewModelLocationSelectionErrorOk")
+ }.ShowAsync();
+ usingInvalidLocatiion = true;
+ }
+
+ if (!usingInvalidLocatiion)
{
CurrentInstallProcessState.EftInstallPath = directorySelected.Path.LocalPath;
OverridenBsgInstallPath = true;
@@ -163,6 +179,21 @@ private async Task FetchVersionAndMirrorMatrix()
ValidateConfiguration();
}
+ ///
+ /// Check if the currently selected EFT diretory has indicators of an SPT install and if so return true, otherwise return false
+ ///
+ /// True if this is an SPT install directory otherwise false
+ private bool HasSelectedSPTInstallPath(string requestedDirectory)
+ {
+ string sptLauncherPath = Path.Combine(requestedDirectory, "Aki.Launcher.exe");
+ string sptServerPath = Path.Combine(requestedDirectory, "Aki.Server.exe");
+ if (File.Exists(sptLauncherPath) || File.Exists(sptServerPath))
+ {
+ return true;
+ }
+ return false;
+ }
+
[RelayCommand]
private void Back()
{
@@ -175,6 +206,7 @@ private void Start()
ProgressInstall();
}
+ // TODO convert this view model into some kind of validator or something to make this part shorter and easier to handle
private void ValidateConfiguration()
{
IsConfigurationValid = true;
@@ -211,6 +243,12 @@ private void ValidateConfiguration()
IsConfigurationValid = false;
return;
}
+
+ if (HasSelectedSPTInstallPath(CurrentInstallProcessState.EftInstallPath))
+ {
+ IsConfigurationValid = false;
+ return;
+ }
}
private async Task LoadAvailableModsList()
From 268e2ba8210ac676d91e0ce7a69adcd50d35ac70 Mon Sep 17 00:00:00 2001
From: artehe <112902041+artehe@users.noreply.github.com>
Date: Sat, 27 Apr 2024 17:22:40 +0100
Subject: [PATCH 2/3] using usings helps
---
SIT.Manager/Interfaces/ICachingService.cs | 6 +-
.../Services/Caching/CachingService.cs | 7 +-
.../Services/Caching/OnDiskCachingProvider.cs | 100 +++++++++---------
3 files changed, 53 insertions(+), 60 deletions(-)
diff --git a/SIT.Manager/Interfaces/ICachingService.cs b/SIT.Manager/Interfaces/ICachingService.cs
index cdbcb0df..e00ed2cc 100644
--- a/SIT.Manager/Interfaces/ICachingService.cs
+++ b/SIT.Manager/Interfaces/ICachingService.cs
@@ -1,11 +1,7 @@
using SIT.Manager.Services.Caching;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace SIT.Manager.Interfaces;
+
public interface ICachingService
{
public ICachingProvider InMemory { get; }
diff --git a/SIT.Manager/Services/Caching/CachingService.cs b/SIT.Manager/Services/Caching/CachingService.cs
index 6827012e..8d457d7f 100644
--- a/SIT.Manager/Services/Caching/CachingService.cs
+++ b/SIT.Manager/Services/Caching/CachingService.cs
@@ -1,14 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using SIT.Manager.Interfaces;
using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
namespace SIT.Manager.Services.Caching;
+
public class CachingService(IServiceProvider provider) : ICachingService
{
private const string CACHE_PATH = "Cache";
diff --git a/SIT.Manager/Services/Caching/OnDiskCachingProvider.cs b/SIT.Manager/Services/Caching/OnDiskCachingProvider.cs
index e142d898..1078d404 100644
--- a/SIT.Manager/Services/Caching/OnDiskCachingProvider.cs
+++ b/SIT.Manager/Services/Caching/OnDiskCachingProvider.cs
@@ -1,9 +1,6 @@
-using Avalonia.Controls.ApplicationLifetimes;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using PeNet;
-using SIT.Manager.Interfaces;
using System;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -12,6 +9,7 @@
using System.Text.Json;
namespace SIT.Manager.Services.Caching;
+
internal class OnDiskCachingProvider(string cachePath, ILogger logger) : CachingProviderBase(cachePath)
{
private const string RESTORE_FILE_NAME = "fileCache.dat";
@@ -20,10 +18,10 @@ internal class OnDiskCachingProvider(string cachePath, ILogger() ?? string.Empty;
- if(File.Exists(cacheFilePath))
+ if (File.Exists(cacheFilePath))
File.Delete(cacheFilePath);
}
base.RemoveExpiredKey(key);
@@ -53,28 +51,30 @@ public override bool Add(string key, T value, TimeSpan? expiryTime = null)
string filename = MD5.HashData(Encoding.UTF8.GetBytes(key)).ToHexString();
string filePath = Path.Combine(_cachePath.FullName, filename);
- using FileStream fs = File.OpenWrite(filePath);
- if (value is Stream inputStream)
- {
- if (inputStream.CanSeek)
- inputStream.Seek(0, SeekOrigin.Begin);
-
- inputStream.CopyTo(fs);
- }
- else
+ using (FileStream fs = File.OpenWrite(filePath))
{
- byte[] buffer;
- if (typeof(T) == typeof(byte[]))
+ if (value is Stream inputStream)
{
- buffer = value as byte[] ?? [];
+ if (inputStream.CanSeek)
+ inputStream.Seek(0, SeekOrigin.Begin);
+
+ inputStream.CopyTo(fs);
}
else
{
- string serializedData = JsonSerializer.Serialize(value);
- buffer = Encoding.UTF8.GetBytes(serializedData);
- }
+ byte[] buffer;
+ if (typeof(T) == typeof(byte[]))
+ {
+ buffer = value as byte[] ?? [];
+ }
+ else
+ {
+ string serializedData = JsonSerializer.Serialize(value);
+ buffer = Encoding.UTF8.GetBytes(serializedData);
+ }
- fs.Write(buffer, 0, buffer.Length);
+ fs.Write(buffer, 0, buffer.Length);
+ }
}
DateTime expiryDate = DateTime.UtcNow + (expiryTime ?? TimeSpan.FromMinutes(15));
@@ -107,41 +107,43 @@ public override CacheValue Get(string key)
return CacheValue.Null;
Type tType = typeof(T);
- FileStream fs = File.OpenRead(filePath);
- if (tType == typeof(FileStream))
+ using (FileStream fs = File.OpenRead(filePath))
{
- return new CacheValue((T) (object) fs, true);
- }
-
- byte[] fileBytes;
- MemoryStream ms = new MemoryStream();
- try
- {
- byte[] buffer = new byte[1024 * 8];
- int bytesRead;
- while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
+ if (tType == typeof(FileStream))
{
- ms.Write(buffer, 0, bytesRead);
+ return new CacheValue((T) (object) fs, true);
}
- fileBytes = ms.ToArray();
- if (tType == typeof(byte[]))
+ byte[] fileBytes;
+ MemoryStream ms = new MemoryStream();
+ try
{
- return new CacheValue((T) (object) fileBytes, true);
+ byte[] buffer = new byte[1024 * 8];
+ int bytesRead;
+ while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ ms.Write(buffer, 0, bytesRead);
+ }
+
+ fileBytes = ms.ToArray();
+ if (tType == typeof(byte[]))
+ {
+ return new CacheValue((T) (object) fileBytes, true);
+ }
+ }
+ catch (Exception ex)
+ {
+ ms.Dispose();
+ _logger.LogError(ex, "Error occured during reading or casting file bytes.");
+ return CacheValue.Null;
}
- }
- catch (Exception ex)
- {
- ms.Dispose();
- _logger.LogError(ex, "Error occured during reading or casting file bytes.");
- return CacheValue.Null;
- }
- if (tType == typeof(string))
- {
- return new CacheValue((T) (object) Encoding.UTF8.GetString(fileBytes), true);
+ if (tType == typeof(string))
+ {
+ return new CacheValue((T) (object) Encoding.UTF8.GetString(fileBytes), true);
+ }
+ return new CacheValue(JsonSerializer.Deserialize(fileBytes), true);
}
- return new CacheValue(JsonSerializer.Deserialize(fileBytes), true);
}
catch (Exception ex)
{
From f59079c254aed38df78a277c594ef5fd7192dd0d Mon Sep 17 00:00:00 2001
From: artehe <112902041+artehe@users.noreply.github.com>
Date: Sat, 27 Apr 2024 17:25:51 +0100
Subject: [PATCH 3/3] Remember the last type of connection the user used
---
SIT.Manager/ViewModels/PlayPageViewModel.cs | 27 ++++++++++++++++++++-
SIT.Manager/Views/PlayPage.axaml | 2 +-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/SIT.Manager/ViewModels/PlayPageViewModel.cs b/SIT.Manager/ViewModels/PlayPageViewModel.cs
index c16d63f7..d56a3d9a 100644
--- a/SIT.Manager/ViewModels/PlayPageViewModel.cs
+++ b/SIT.Manager/ViewModels/PlayPageViewModel.cs
@@ -1,8 +1,10 @@
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
+using SIT.Manager.Interfaces;
using SIT.Manager.Models.Aki;
using SIT.Manager.Models.Play;
+using SIT.Manager.Services.Caching;
using SIT.Manager.Views.Play;
using System;
@@ -13,16 +15,39 @@ public partial class PlayPageViewModel : ObservableRecipient,
IRecipient,
IRecipient
{
+ private const string SELECTED_TAB_INDEX_CACHE_KEY = "LastSelectedPlayPageTabIndex";
+
+ private readonly ICachingService _cachingService;
+
private AkiServer? _connectedServer;
[ObservableProperty]
private UserControl _playControl;
- public PlayPageViewModel()
+ [ObservableProperty]
+ private int _selectedTabIndex = 0;
+
+ public PlayPageViewModel(ICachingService cachingService)
{
+ _cachingService = cachingService;
+
+ if (_cachingService.OnDisk.TryGet(SELECTED_TAB_INDEX_CACHE_KEY, out CacheValue indexValue))
+ {
+ SelectedTabIndex = indexValue.Value;
+ }
+
PlayControl = new ServerSelectionView();
}
+ partial void OnSelectedTabIndexChanged(int value)
+ {
+ if (_cachingService.OnDisk.Exists(SELECTED_TAB_INDEX_CACHE_KEY))
+ {
+ _cachingService.OnDisk.Remove(SELECTED_TAB_INDEX_CACHE_KEY);
+ }
+ _cachingService.OnDisk.Add(SELECTED_TAB_INDEX_CACHE_KEY, value);
+ }
+
public void Receive(ServerConnectMessage message)
{
_connectedServer = message.Value;
diff --git a/SIT.Manager/Views/PlayPage.axaml b/SIT.Manager/Views/PlayPage.axaml
index 5ded3e27..dd0849e2 100644
--- a/SIT.Manager/Views/PlayPage.axaml
+++ b/SIT.Manager/Views/PlayPage.axaml
@@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="vm:PlayPageViewModel"
x:Class="SIT.Manager.Views.PlayPage">
-
+