source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,242 @@
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Utils;
using System;
using System.Windows;
using WPFSharp.Globalizer;
namespace ServerManagerTool.Lib
{
public class ModDetail : DependencyObject
{
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
public static readonly DependencyProperty AppIdProperty = DependencyProperty.Register(nameof(AppId), typeof(string), typeof(ModDetail), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IndexProperty = DependencyProperty.Register(nameof(Index), typeof(int), typeof(ModDetail), new PropertyMetadata(0));
public static readonly DependencyProperty IsFirstProperty = DependencyProperty.Register(nameof(IsFirst), typeof(bool), typeof(ModDetail), new PropertyMetadata(false));
public static readonly DependencyProperty IsLastProperty = DependencyProperty.Register(nameof(IsLast), typeof(bool), typeof(ModDetail), new PropertyMetadata(false));
public static readonly DependencyProperty LastWriteTimeProperty = DependencyProperty.Register(nameof(LastWriteTime), typeof(DateTime), typeof(ModDetail), new PropertyMetadata(DateTime.MinValue));
public static readonly DependencyProperty LastTimeUpdatedProperty = DependencyProperty.Register(nameof(LastTimeUpdated), typeof(int), typeof(ModDetail), new PropertyMetadata(0));
public static readonly DependencyProperty ModIdProperty = DependencyProperty.Register(nameof(ModId), typeof(string), typeof(ModDetail), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty ModTypeProperty = DependencyProperty.Register(nameof(ModType), typeof(string), typeof(ModDetail), new PropertyMetadata(ModUtils.MODTYPE_UNKNOWN));
public static readonly DependencyProperty ModTypeStringProperty = DependencyProperty.Register(nameof(ModTypeString), typeof(string), typeof(ModDetail), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty ModUrlProperty = DependencyProperty.Register(nameof(ModUrl), typeof(string), typeof(ModDetail), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty TimeUpdatedProperty = DependencyProperty.Register(nameof(TimeUpdated), typeof(int), typeof(ModDetail), new PropertyMetadata(0));
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(ModDetail), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IsValidProperty = DependencyProperty.Register(nameof(IsValid), typeof(bool), typeof(ModDetail), new PropertyMetadata(false));
public string AppId
{
get { return (string)GetValue(AppIdProperty); }
set { SetValue(AppIdProperty, value); }
}
public int Index
{
get { return (int)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value); }
}
public bool IsFirst
{
get { return (bool)GetValue(IsFirstProperty); }
set { SetValue(IsFirstProperty, value); }
}
public bool IsLast
{
get { return (bool)GetValue(IsLastProperty); }
set { SetValue(IsLastProperty, value); }
}
public DateTime LastWriteTime
{
get { return (DateTime)GetValue(LastWriteTimeProperty); }
set { SetValue(LastWriteTimeProperty, value); }
}
public int LastTimeUpdated
{
get { return (int)GetValue(LastTimeUpdatedProperty); }
set { SetValue(LastTimeUpdatedProperty, value); }
}
public string ModId
{
get { return (string)GetValue(ModIdProperty); }
set { SetValue(ModIdProperty, value); }
}
public string ModType
{
get { return (string)GetValue(ModTypeProperty); }
set
{
SetValue(ModTypeProperty, value);
SetModTypeString();
}
}
public string ModTypeString
{
get { return (string)GetValue(ModTypeStringProperty); }
set { SetValue(ModTypeStringProperty, value); }
}
public int TimeUpdated
{
get { return (int)GetValue(TimeUpdatedProperty); }
set { SetValue(TimeUpdatedProperty, value); }
}
public string Title
{
get { return (string)GetValue(TitleProperty); }
set
{
SetValue(TitleProperty, value);
TitleFilterString = value?.ToLower();
}
}
public bool IsValid
{
get { return (bool)GetValue(IsValidProperty); }
set { SetValue(IsValidProperty, value); }
}
public bool IsValidModType => !string.IsNullOrWhiteSpace(ModType) && (ModType.Equals(ModUtils.MODTYPE_MAP) || ModType.Equals(ModUtils.MODTYPE_MOD));
public string LastWriteTimeString => LastWriteTime == DateTime.MinValue ? string.Empty : LastWriteTime.ToString();
public string LastWriteTimeSortString => LastWriteTime == DateTime.MinValue ? string.Empty : LastWriteTime.ToString("yyyyMMdd_HHmmss");
public string MapName { get; set; }
public string ModUrl => $"http://steamcommunity.com/sharedfiles/filedetails/?id={ModId}";
public string TimeUpdatedString => TimeUpdated <= 0 ? string.Empty : DateTimeUtils.UnixTimeStampToDateTime(TimeUpdated).ToString();
public string TimeUpdatedSortString => TimeUpdated <= 0 ? string.Empty : DateTimeUtils.UnixTimeStampToDateTime(TimeUpdated).ToString("yyyyMMdd_HHmmss");
public string TitleFilterString
{
get;
private set;
}
public bool UpToDate => !IsValid && TimeUpdated == -1 || LastTimeUpdated > 0 && LastTimeUpdated == TimeUpdated;
public long FolderSize { get; set; }
public string FolderSizeString
{
get
{
// GB
var divisor = Math.Pow(1024, 3);
if (FolderSize > divisor)
return $"{FolderSize / divisor:N2} GB";
// MB
divisor = Math.Pow(1024, 2);
if (FolderSize > divisor)
return $"{FolderSize / divisor:N2} MB";
// KB
divisor = Math.Pow(1024, 1);
if (FolderSize > divisor)
return $"{FolderSize / divisor:N2} KB";
return $"{FolderSize} B";
}
}
public void PopulateExtended(string modsRootFolder)
{
var modExtended = new ModDetailExtended(ModId);
modExtended.PopulateExtended(modsRootFolder);
PopulateExtended(modExtended);
}
public void PopulateExtended(ModDetailExtended extended)
{
LastTimeUpdated = extended.LastTimeUpdated;
LastWriteTime = extended.LastWriteTime;
MapName = extended.MapName;
ModType = extended.ModType;
FolderSize = extended.FolderSize;
}
public void SetModTypeString()
{
if (string.IsNullOrWhiteSpace(ModType))
ModTypeString = _globalizer.GetResourceString("ModType_Unknown");
switch (ModType)
{
case ModUtils.MODTYPE_MAP:
ModTypeString = _globalizer.GetResourceString("ModType_Map");
break;
case ModUtils.MODTYPE_MOD:
ModTypeString = _globalizer.GetResourceString("ModType_Mod");
break;
default:
if (string.IsNullOrWhiteSpace(AppId))
ModTypeString = _globalizer.GetResourceString("ModType_Unknown");
else
ModTypeString = _globalizer.GetResourceString("ModType_NotDownloaded");
break;
}
}
public static ModDetail GetModDetail(PublishedFileDetail detail)
{
var result = new ModDetail()
{
AppId = detail.creator_app_id,
ModId = detail.publishedfileid,
TimeUpdated = detail.time_updated,
Title = detail.title,
IsValid = true,
};
return result;
}
public static ModDetail GetModDetail(WorkshopFileDetail detail)
{
var result = new ModDetail()
{
AppId = detail.creator_appid,
ModId = detail.publishedfileid,
TimeUpdated = detail.time_updated,
Title = detail.title,
IsValid = true,
};
return result;
}
public static ModDetail GetModDetail(WorkshopFileItem detail)
{
var result = new ModDetail()
{
AppId = detail.AppId,
ModId = detail.WorkshopId,
TimeUpdated = detail.TimeUpdated,
Title = detail.Title,
IsValid = true,
};
return result;
}
public override string ToString()
{
return $"{ModId} - {Title}";
}
}
}

View file

@ -0,0 +1,61 @@
using ServerManagerTool.Utils;
using System;
using System.IO;
namespace ServerManagerTool.Lib
{
public class ModDetailExtended
{
public ModDetailExtended(string modId)
{
ModId = modId;
}
public string MapName { get; set; }
private string ModId { get; set; }
public string ModType { get; set; }
public DateTime LastWriteTime { get; set; }
public int LastTimeUpdated { get; set; }
public long FolderSize { get; set; }
public void PopulateExtended(string modsRootFolder)
{
try
{
FolderSize = 0;
LastWriteTime = DateTime.MinValue;
ModType = ModUtils.MODTYPE_UNKNOWN;
MapName = string.Empty;
if (string.IsNullOrWhiteSpace(modsRootFolder) || !Directory.Exists(modsRootFolder))
return;
var modFileName = $"{ModId}.pak";
var modFile = Path.Combine(modsRootFolder, modFileName);
if (!string.IsNullOrWhiteSpace(modFile) && File.Exists(modFile))
{
var file = new FileInfo(modFile);
LastWriteTime = file.LastWriteTime;
FolderSize += file.Length;
ModType = ModUtils.MODTYPE_MOD;
}
var timeFileName = $"{ModId}.txt";
var modTimeFile = Path.Combine(modsRootFolder, timeFileName);
if (!string.IsNullOrWhiteSpace(modTimeFile) && File.Exists(modTimeFile))
{
LastTimeUpdated = ModUtils.GetModLatestTime(modTimeFile);
}
}
catch
{
// do nothing
}
}
}
}

View file

@ -0,0 +1,200 @@
using ServerManagerTool.Common.Model;
using ServerManagerTool.Utils;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
namespace ServerManagerTool.Lib
{
public class ModDetailList : ObservableCollection<ModDetail>
{
public bool AnyUnknownModTypes
{
get
{
return this.Any(m => !m.IsValidModType);
}
}
public new void Add(ModDetail mod)
{
if (mod == null || this.Any(m => m.ModId.Equals(mod.ModId)))
return;
base.Add(mod);
SetPublishedFileIndex();
}
public void AddRange(ModDetail[] mods)
{
foreach (var mod in mods)
{
if (mod == null || this.Any(m => m.ModId.Equals(mod.ModId)))
continue;
base.Add(mod);
}
SetPublishedFileIndex();
}
public new void Insert(int index, ModDetail mod)
{
if (mod == null || this.Any(m => m.ModId.Equals(mod.ModId)))
return;
base.Insert(index, mod);
SetPublishedFileIndex();
}
public void Move(ModDetail mod, int newIndex)
{
if (mod == null)
return;
var index = base.IndexOf(mod);
if (index <= 0)
return;
base.Move(index, newIndex);
SetPublishedFileIndex();
}
public void MoveDown(ModDetail mod)
{
if (mod == null)
return;
var index = base.IndexOf(mod);
if (index >= base.Count - 1)
return;
base.Move(index, index + 1);
SetPublishedFileIndex();
}
public void MoveUp(ModDetail mod)
{
if (mod == null)
return;
var index = base.IndexOf(mod);
if (index <= 0)
return;
base.Move(index, index - 1);
SetPublishedFileIndex();
}
public void PopulateExtended(string modsRootFolder)
{
var results = new Dictionary<ModDetail, ModDetailExtended>();
foreach (var mod in this)
{
results.Add(mod, new ModDetailExtended(mod.ModId));
}
Parallel.ForEach(results, kvp => kvp.Value.PopulateExtended(modsRootFolder));
foreach (var kvp in results)
{
kvp.Key.PopulateExtended(kvp.Value);
}
}
public new bool Remove(ModDetail mod)
{
if (mod == null)
return false;
var removed = base.Remove(mod);
SetPublishedFileIndex();
return removed;
}
public void SetPublishedFileIndex()
{
foreach (var mod in this)
{
mod.Index = base.IndexOf(mod) + 1;
mod.IsFirst = false;
mod.IsLast = false;
}
if (this.Count == 0)
return;
this[0].IsFirst = true;
this[base.Count - 1].IsLast = true;
}
public bool GetModStrings(out string mapString, out string modIdString)
{
mapString = null;
modIdString = string.Empty;
var delimiter = "";
foreach (var mod in this)
{
switch (mod.ModType)
{
case ModUtils.MODTYPE_MOD:
default:
modIdString += $"{delimiter}{mod.ModId}";
delimiter = ",";
break;
}
}
return true;
}
public static ModDetailList GetModDetails(List<string> modIdList, string modsRootFolder, WorkshopFileList workshopFiles, PublishedFileDetailsResponse response)
{
var result = new ModDetailList();
if (modIdList != null)
{
foreach (var modId in modIdList)
{
var temp = workshopFiles?.FirstOrDefault(w => w.WorkshopId.Equals(modId));
result.Add(new ModDetail()
{
AppId = temp?.AppId ?? string.Empty,
ModId = modId,
TimeUpdated = -1,
Title = temp?.Title ?? "Mod name not available",
IsValid = false,
});
}
}
if (response?.publishedfiledetails != null)
{
foreach (var item in result)
{
var temp = response.publishedfiledetails.FirstOrDefault(w => w.publishedfileid.Equals(item.ModId));
if (temp != null)
{
item.AppId = temp?.creator_app_id ?? string.Empty;
item.ModId = temp?.publishedfileid ?? item.ModId;
item.TimeUpdated = temp?.time_updated ?? item.TimeUpdated;
item.Title = temp?.title ?? item.Title;
item.IsValid = temp?.creator_app_id != null;
}
}
}
result.SetPublishedFileIndex();
result.PopulateExtended(modsRootFolder);
return result;
}
public override string ToString()
{
return $"{nameof(ModDetailList)} - {Count}";
}
}
}

View file

@ -0,0 +1,34 @@
using System.Windows;
namespace ServerManagerTool.Lib
{
public class PlayerListParameters : DependencyObject
{
public static readonly DependencyProperty ProfileNameProperty = DependencyProperty.Register(nameof(ProfileName), typeof(string), typeof(PlayerListParameters), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty MaxPlayersProperty = DependencyProperty.Register(nameof(MaxPlayers), typeof(int), typeof(PlayerListParameters), new PropertyMetadata(0));
public string ProfileName
{
get { return (string)GetValue(ProfileNameProperty); }
set { SetValue(ProfileNameProperty, value); }
}
public string ProfileId { get; set; }
public string InstallDirectory { get; set; }
public string GameFile { get; set; }
public Server Server { get; set; }
public Rect WindowExtents { get; set; }
public string WindowTitle { get; set; }
public int MaxPlayers
{
get { return (int)GetValue(MaxPlayersProperty); }
set { SetValue(MaxPlayersProperty, value); }
}
}
}

View file

@ -0,0 +1,32 @@
using System.Net;
using System.Windows;
namespace ServerManagerTool.Lib
{
public class RconParameters : PlayerListParameters
{
public string RconHost { get; set; }
public IPAddress RconHostIP
{
get
{
try
{
var ipAddresses = Dns.GetHostAddresses(RconHost);
if (ipAddresses.Length > 0)
return ipAddresses[0].MapToIPv4();
}
catch {}
return IPAddress.None;
}
}
public int RconPort { get; set; }
public string RconPassword { get; set; }
public double PlayerListWidth { get; set; }
}
}