Skip to content

Commit

Permalink
Merge pull request #58 from Foxlider/feature/Update-1.8
Browse files Browse the repository at this point in the history
Update 1.8b
  • Loading branch information
Foxlider authored Dec 27, 2021
2 parents 9ec5b46 + 8f46a0f commit c39b415
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 60 deletions.
4 changes: 2 additions & 2 deletions FASTER/FASTER.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<UseWPF>true</UseWPF>
<Version>1.8.2.0</Version>
<Version>1.8.2.1</Version>
<Authors>Keelah Fox</Authors>
<Company>FoxliCorp.</Company>
<Description>Fox's Arma Server Tool Extended Rewrite</Description>
Expand All @@ -17,7 +17,7 @@
<ApplicationIcon>Resources\FASTER.ico</ApplicationIcon>
<StartupObject>FASTER.App</StartupObject>
<ApplicationManifest>Properties\FASTER.manifest</ApplicationManifest>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>FASTERKey.snk</AssemblyOriginatorKeyFile>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
Expand Down
10 changes: 5 additions & 5 deletions FASTER/Models/Encryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Encryption

private static byte[] TruncateHash(string key, int length)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
SHA1CryptoServiceProvider sha1 = new();

// Hash the key.
byte[] keyBytes = System.Text.Encoding.Unicode.GetBytes(key);
Expand Down Expand Up @@ -42,9 +42,9 @@ public string EncryptData(string plaintext)
byte[] plaintextBytes = System.Text.Encoding.Unicode.GetBytes(plaintext);

// Create the stream.
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.MemoryStream ms = new();
// Create the encoder to write to the stream.
CryptoStream encStream = new CryptoStream(ms, Crypt.CreateEncryptor(), CryptoStreamMode.Write);
CryptoStream encStream = new(ms, Crypt.CreateEncryptor(), CryptoStreamMode.Write);

// Use the crypto stream to write the byte array to the stream.
encStream.Write(plaintextBytes, 0, plaintextBytes.Length);
Expand All @@ -65,9 +65,9 @@ public string DecryptData(string encryptedtext)
byte[] encryptedBytes = Convert.FromBase64String(encryptedtext);

// Create the stream.
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.MemoryStream ms = new();
// Create the decoder to write to the stream.
CryptoStream decStream = new CryptoStream(ms, Crypt.CreateDecryptor(), CryptoStreamMode.Write);
CryptoStream decStream = new(ms, Crypt.CreateDecryptor(), CryptoStreamMode.Write);

// Use the crypto stream to write the byte array to the stream.
decStream.Write(encryptedBytes, 0, encryptedBytes.Length);
Expand Down
17 changes: 8 additions & 9 deletions FASTER/Models/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ public static string ParseFileSize(double fullSize)

public static string StringFromRichTextBox(System.Windows.Controls.RichTextBox rtb)
{
TextRange textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
TextRange textRange = new(rtb.Document.ContentStart, rtb.Document.ContentEnd);
return textRange.Text;
}

public static string SelectFile(string filter)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{ Filter = filter };
OpenFileDialog openFileDialog = new() { Filter = filter };
return openFileDialog.ShowDialog() == true ? openFileDialog.FileName : null;
}

Expand Down Expand Up @@ -108,15 +107,15 @@ internal static string GetVersion()
if (assembly.Build == 0) rev = "ALPHA";
if (assembly.Revision != 0)
{
string releaseType = assembly.Revision.ToString().Substring(0, 1) switch
string releaseType = (assembly.Revision / 100) switch
{
"1" => "H", // HOTFIX
"2" => "RC", // RELEASE CANDIDATE
"5" => "D", // DEV
1 => "H", // HOTFIX
2 => "RC", // RELEASE CANDIDATE
5 => "D", // DEV
_ => "" // EMPTY RELEASE TYPE
};

rev += $" {releaseType}{int.Parse(assembly.Revision.ToString()[1..])}";
if(releaseType != "")
rev += $" {releaseType}{int.Parse(assembly.Revision.ToString()[1..])}";
}
#if DEBUG
rev += "-DEV";
Expand Down
12 changes: 6 additions & 6 deletions FASTER/Models/ServerCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class ServerCfg : INotifyPropertyChanged
private string password;
private string hostname;
private int maxPlayers = 32;
private List<string> motd = new List<string>();
private List<string> motd = new();
private int motdInterval;
private List<string> admins = new List<string>();
private List<string> headlessClients = new List<string>();
private List<string> localClient = new List<string>();
private List<string> admins = new();
private List<string> headlessClients = new();
private List<string> localClient = new();
private bool headlessClientEnabled;
private bool votingEnabled;
private bool netlogEnabled;
Expand Down Expand Up @@ -74,7 +74,7 @@ public class ServerCfg : INotifyPropertyChanged

private bool missionSelectorChecked;
private string missionContentOverride;
private List<ProfileMission> _missions = new List<ProfileMission>();
private List<ProfileMission> _missions = new();
private bool autoInit;
private string difficulty = "Custom";

Expand Down Expand Up @@ -717,7 +717,7 @@ public string ProcessFile()
{
if (!missionSelectorChecked)
{
List<string> lines = new List<string> { "class Missions {" };
List<string> lines = new() { "class Missions {" };
foreach (var mission in Missions.Where(m => m.MissionChecked).Select(m => m.Name))
{
lines.AddRange(new List<string>
Expand Down
4 changes: 2 additions & 2 deletions FASTER/Models/SteamMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SteamModCollection
public string CollectionName { get; set; } = "Main";

[XmlElement(Order = 2, ElementName = "SteamMod")]
public List<SteamMod> SteamMods = new List<SteamMod>();
public List<SteamMod> SteamMods = new();
}

[Serializable]
Expand Down Expand Up @@ -78,7 +78,7 @@ static long GetDirectorySize(string p)

public static List<SteamMod> GetSteamMods()
{
List<SteamMod> currentSteamMods = new List<SteamMod>();
List<SteamMod> currentSteamMods = new();

if (Properties.Settings.Default.steamMods == null) return currentSteamMods;

Expand Down
4 changes: 2 additions & 2 deletions FASTER/ViewModel/DeploymentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void OpenModFolder(DeploymentMod mod)
return;
}

ProcessStartInfo startInfo = new ProcessStartInfo
ProcessStartInfo startInfo = new()
{
Arguments = mod.Path,
FileName = "explorer.exe"
Expand Down Expand Up @@ -208,7 +208,7 @@ private void LinkMod(DeploymentMod mod, string linkPath)
{
var linkCommand = "/c mklink /D \"" + linkPath + "\" \"" + mod.Path + "\"";

ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe")
ProcessStartInfo startInfo = new("cmd.exe")
{
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas",
Expand Down
21 changes: 12 additions & 9 deletions FASTER/ViewModel/ModsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace FASTER.ViewModel
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task AddLocalModAsync()
if (string.IsNullOrEmpty(localPath))
return;

Random r = new Random();
Random r = new();
var modID = (uint) (uint.MaxValue - r.Next(ushort.MaxValue / 2));
var newPath = Path.Combine(Properties.Settings.Default.modStagingDirectory, modID.ToString());
var oldPath = localPath;
Expand Down Expand Up @@ -149,16 +150,18 @@ internal async Task OpenLauncherFile()
string modsFile = Functions.SelectFile("Arma 3 Launcher File|*.html");

if (string.IsNullOrEmpty(modsFile)) return;
using StreamReader dataReader = new StreamReader(modsFile);
using StreamReader dataReader = new(modsFile);

var lines = (await File.ReadAllLinesAsync(modsFile)).ToList();
var lines = (await File.ReadAllLinesAsync(modsFile))
.AsEnumerable()
.Where(l => l.Contains("steamcommunity.com/sharedfiles/filedetails"));

var extractedModlist = from line in lines
where line.Contains("steamcommunity.com/sharedfiles/filedetails")
select System.Web.HttpUtility.ParseQueryString(new Uri(line).Query).Get("id");

foreach (string modIdS in extractedModlist)
foreach (string line in lines)
{
var link = XElement.Parse(line).Attribute("href").Value;
if (link == null)
continue;
var modIdS = System.Web.HttpUtility.ParseQueryString(new Uri(link).Query).Get("id");
if (!uint.TryParse(modIdS, out uint modId)) continue;

if(ModsCollection.ArmaMods.FirstOrDefault(m => m.WorkshopId == modId) != null)
Expand Down Expand Up @@ -187,7 +190,7 @@ public void OpenModFolder(ArmaMod mod)
return;
}

ProcessStartInfo startInfo = new ProcessStartInfo
ProcessStartInfo startInfo = new()
{
Arguments = mod.Path,
FileName = "explorer.exe"
Expand Down
33 changes: 19 additions & 14 deletions FASTER/ViewModel/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows;
using System.Windows.Controls.Primitives;
using Microsoft.AppCenter.Analytics;
using System.Xml.Linq;

namespace FASTER.ViewModel
{
Expand Down Expand Up @@ -49,7 +50,7 @@ internal void OpenProfileLocation()
string folderPath = Path.Combine(Profile.ArmaPath, "Servers", Profile.Id);
if (Directory.Exists(folderPath))
{
ProcessStartInfo startInfo = new ProcessStartInfo
ProcessStartInfo startInfo = new()
{
Arguments = folderPath,
FileName = "explorer.exe"
Expand Down Expand Up @@ -85,7 +86,7 @@ internal void LaunchHCs()
private string SetHCCommandLine(int hc)
{
string headlessMods = string.Join(";", Profile.ProfileMods.Where(m => m.HeadlessChecked).Select(m =>$"@{Functions.SafeName(m.Name)}"));
List<string> arguments = new List<string>
List<string> arguments = new()
{
"-client",
" -connect=127.0.0.1",
Expand Down Expand Up @@ -226,11 +227,11 @@ internal void SaveProfile()

var armaPath = Path.GetDirectoryName(Profile.Executable);
var links = Directory.EnumerateDirectories(armaPath).Select(d => new DirectoryInfo(d)).Where(d => d.Attributes.HasFlag(FileAttributes.ReparsePoint));
bool displayMissingModMessage = false;
uint MissingMods = 0;
foreach (ProfileMod profileMod in Profile.ProfileMods.Where(m => m.ClientSideChecked || m.HeadlessChecked || m.ServerSideChecked))
{
if (!links.Any(l => l.Name == $"@{Functions.SafeName(profileMod.Name)}"))
displayMissingModMessage = true;
MissingMods++;
}


Expand All @@ -242,8 +243,8 @@ internal void SaveProfile()
Profile.RaisePropertyChanged("CommandLine");
DisplayMessage($"Saved Profile {Profile.Name}");

if (displayMissingModMessage)
DisplayMessage("Some mods were not found in the Arma directory.\nMake sure you have deployed the correct mods");
if (MissingMods > 0)
DisplayMessage($"{MissingMods} mods were not found in the Arma directory.\nMake sure you have deployed the correct mods");

}

Expand Down Expand Up @@ -274,21 +275,23 @@ internal void LoadModsFromFile()
return;
}

var lines = File.ReadAllLines(dialog.FileName).ToList();
var lines = File.ReadAllLines(dialog.FileName)
.AsEnumerable()
.Where(l => l.Contains("steamcommunity.com/sharedfiles/filedetails"));

//Clear mods
foreach (var mod in Profile.ProfileMods)
{ mod.ClientSideChecked = false; }

ushort? loadPriority = 1;

var extractedModlist = from line in lines
where line.Contains("steamcommunity.com/sharedfiles/filedetails")
select System.Web.HttpUtility.ParseQueryString(new Uri(line).Query).Get("id");

//Select new ones
foreach (var modIdS in extractedModlist )
foreach (string line in lines)
{
var link = XElement.Parse(line).Attribute("href").Value;
if (link == null)
continue;
var modIdS = System.Web.HttpUtility.ParseQueryString(new Uri(link).Query).Get("id");

if (!uint.TryParse(modIdS, out uint modId)) continue;
var mod = Profile.ProfileMods.FirstOrDefault(m => m.Id == modId);
if (mod != null)
Expand Down Expand Up @@ -403,6 +406,8 @@ public void LoadData()
modlist.Add(newProfile);
continue;
}
else //refresh mods names
{ existingMod.Name = mod.Name; }
modlist.Add(existingMod);
}

Expand All @@ -423,7 +428,7 @@ internal void LoadMissions()
if (!Directory.Exists(Path.Combine(Profile.ArmaPath, "mpmissions"))) return;

var missionList = new List<ProfileMission>();
List<string> newMissions = new List<string>();
List<string> newMissions = new();

//Load PBO files
newMissions.AddRange(Directory.EnumerateFiles(Path.Combine(Profile.ArmaPath, "mpmissions"), "*.pbo", searchOption: SearchOption.TopDirectoryOnly)
Expand Down
23 changes: 14 additions & 9 deletions FASTER/ViewModel/SteamUpdaterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public SteamUpdaterViewModel()

private static readonly Lazy<SteamUpdaterViewModel>
lazy =
new Lazy<SteamUpdaterViewModel>
(() => new SteamUpdaterViewModel(new SteamUpdaterModel()));
new(() => new SteamUpdaterViewModel(new SteamUpdaterModel()));

public static SteamUpdaterViewModel Instance => lazy.Value;

Expand All @@ -56,7 +55,7 @@ private SteamUpdaterViewModel(SteamUpdaterModel model)
public bool PFDLCChecked { get; set; }

public IDialogCoordinator DialogCoordinator { get; set; }
private CancellationTokenSource tokenSource = new CancellationTokenSource();
private CancellationTokenSource tokenSource = new();

public bool IsDownloading => DownloadTasks.Count > 0 || IsLoggingIn || IsDlOverride;

Expand Down Expand Up @@ -201,7 +200,7 @@ public async Task<int> RunServerUpdater(string path, uint appId, uint depotId, s

try
{
SteamOs steamOs = new SteamOs(_OS);
SteamOs steamOs = new(_OS);
ManifestId manifestId;

manifestId = await _steamContentClient.GetDepotDefaultManifestIdAsync(appId, depotId, branch, branchPass);
Expand Down Expand Up @@ -253,7 +252,7 @@ public async Task<int> RunModUpdater(ulong modId, string path)

try
{
SteamOs steamOs = new SteamOs(_OS);
SteamOs steamOs = new(_OS);
ManifestId manifestId = default;

Parameters.Output += $"\nFetching mod {modId} infos... ";
Expand Down Expand Up @@ -312,7 +311,7 @@ public async Task<int> RunModsUpdater(ObservableCollection<ArmaMod> mods)

Parameters.Output += "\nAdding mods to download list...";

SemaphoreSlim maxThread = new SemaphoreSlim(3);
SemaphoreSlim maxThread = new(3);
var ml = mods.Where(m => !m.IsLocal).ToList();
uint finished = 0;
IsDlOverride = true;
Expand All @@ -336,13 +335,20 @@ public async Task<int> RunModsUpdater(ObservableCollection<ArmaMod> mods)
Stopwatch sw = Stopwatch.StartNew();
try
{
SteamOs steamOs = new SteamOs(_OS);
SteamOs steamOs = new(_OS);
ManifestId manifestId = default;
var modDetails = _steamContentClient.GetPublishedFileDetailsAsync(mod.WorkshopId).Result;
if(mod.LocalLastUpdated > modDetails.time_updated)
{
mod.Status = ArmaModStatus.UpToDate;
Parameters.Output += $"\n Mod{mod.WorkshopId} already up to date. Ignoring...";
return;
}

if (!_steamClient.Credentials.IsAnonymous) //IS SYNC NEABLED
{
Parameters.Output += $"\n Getting manifest for {mod.WorkshopId}";
manifestId = _steamContentClient.GetPublishedFileDetailsAsync(mod.WorkshopId).Result.hcontent_file;
manifestId = modDetails.hcontent_file;
Manifest manifest = _steamContentClient.GetManifestAsync(107410, 107410, manifestId).Result;
Parameters.Output += $"\n Manifest retreived {mod.WorkshopId}";
SyncDeleteRemovedFiles(mod.Path, manifest);
Expand All @@ -355,7 +361,6 @@ public async Task<int> RunModsUpdater(ObservableCollection<ArmaMod> mods)
null,
null,
steamOs);

DownloadForMultiple(downloadHandler.Result, mod.Path).Wait();
}
catch (TaskCanceledException)
Expand Down
2 changes: 1 addition & 1 deletion FASTER/Views/Mods.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Info" CanUserSort="False" CanUserResize="False">
<DataGridTemplateColumn Header="Info" CanUserSort="False" Width="52" CanUserResize="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
Expand Down
Loading

0 comments on commit c39b415

Please sign in to comment.