Backup Bugfixes

- fixed the zip utils to read the file contents before backup.
- added new content backup metho for support zip creation.
This commit is contained in:
Brett Hewitson 2022-05-08 20:07:13 +10:00
parent 5374f8c7da
commit 1fc9bc87e4
13 changed files with 143 additions and 80 deletions

View file

@ -321,7 +321,7 @@
<Compile Include="Lib\Model\Level.cs" />
<Compile Include="Lib\Server.cs" />
<Compile Include="Lib\ServerProfile.cs" />
<Compile Include="Lib\ServerRCON.cs" />
<Compile Include="Lib\ServerRcon.cs" />
<Compile Include="Lib\ServerApp.cs" />
<Compile Include="Lib\ServerRuntime.cs" />
<Compile Include="Lib\ViewConverters\DifficultyOffsetValueConverter.cs" />

View file

@ -2040,14 +2040,14 @@ namespace ServerManagerTool.Lib
var saveFolderInfo = new DirectoryInfo(saveFolder);
// backup the world save file
ZipUtils.ZipAFile(backupFile, worldFileName, worldFile, comment.ToString());
ZipUtils.ZipFile(backupFile, worldFileName, worldFile, comment.ToString());
// backup the player files
var playerFileFilter = $"*{Config.Default.PlayerFileExtension}";
var playerFiles = saveFolderInfo.GetFiles(playerFileFilter, SearchOption.TopDirectoryOnly);
foreach (var file in playerFiles)
{
ZipUtils.ZipAFile(backupFile, file.Name, file.FullName);
ZipUtils.ZipFile(backupFile, file.Name, file.FullName);
}
// backup the tribe files
@ -2055,7 +2055,7 @@ namespace ServerManagerTool.Lib
var tribeFiles = saveFolderInfo.GetFiles(tribeFileFilter, SearchOption.TopDirectoryOnly);
foreach (var file in tribeFiles)
{
ZipUtils.ZipAFile(backupFile, file.Name, file.FullName);
ZipUtils.ZipFile(backupFile, file.Name, file.FullName);
}
// backup the tribute tribe files
@ -2063,7 +2063,7 @@ namespace ServerManagerTool.Lib
var tributeTribeFiles = saveFolderInfo.GetFiles(tributeTribeFileFilter, SearchOption.TopDirectoryOnly);
foreach (var file in tributeTribeFiles)
{
ZipUtils.ZipAFile(backupFile, file.Name, file.FullName);
ZipUtils.ZipFile(backupFile, file.Name, file.FullName);
}
if (Config.Default.AutoBackup_IncludeSaveGamesFolder)
@ -2078,7 +2078,7 @@ namespace ServerManagerTool.Lib
var saveGamesFiles = saveGamesFolderInfo.GetFiles(saveGamesFileFilter, SearchOption.AllDirectories);
foreach (var file in saveGamesFiles)
{
ZipUtils.ZipAFile(backupFile, file.FullName.Replace(saveGamesFolder, Config.Default.SaveGamesRelativePath), file.FullName);
ZipUtils.ZipFile(backupFile, file.FullName.Replace(saveGamesFolder, Config.Default.SaveGamesRelativePath), file.FullName);
}
}
}
@ -2365,10 +2365,10 @@ namespace ServerManagerTool.Lib
switch (commandValue.ToLower())
{
case "global":
return ServerRCON.RCON_COMMAND_SERVERCHAT;
return ServerRcon.RCON_COMMAND_SERVERCHAT;
default:
return ServerRCON.RCON_COMMAND_BROADCAST;
return ServerRcon.RCON_COMMAND_BROADCAST;
}
}

View file

@ -7,12 +7,10 @@ using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib.ViewModel;
using ServerManagerTool.Lib.ViewModel.RCON;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
@ -23,7 +21,7 @@ using WPFSharp.Globalizer;
namespace ServerManagerTool.Lib
{
public class ServerRCON : DependencyObject, IAsyncDisposable
public class ServerRcon : DependencyObject, IAsyncDisposable
{
private const int STEAM_UPDATE_INTERVAL = 60;
private const int PLAYER_LIST_INTERVAL = 5000;
@ -39,11 +37,11 @@ namespace ServerManagerTool.Lib
public event EventHandler PlayersCollectionUpdated;
public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(nameof(Status), typeof(ConsoleStatus), typeof(ServerRCON), new PropertyMetadata(ConsoleStatus.Disconnected));
public static readonly DependencyProperty PlayersProperty = DependencyProperty.Register(nameof(Players), typeof(SortableObservableCollection<PlayerInfo>), typeof(ServerRCON), new PropertyMetadata(null));
public static readonly DependencyProperty CountPlayersProperty = DependencyProperty.Register(nameof(CountPlayers), typeof(int), typeof(ServerRCON), new PropertyMetadata(0));
public static readonly DependencyProperty CountInvalidPlayersProperty = DependencyProperty.Register(nameof(CountInvalidPlayers), typeof(int), typeof(ServerRCON), new PropertyMetadata(0));
public static readonly DependencyProperty CountOnlinePlayersProperty = DependencyProperty.Register(nameof(CountOnlinePlayers), typeof(int), typeof(ServerRCON), new PropertyMetadata(0));
public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(nameof(Status), typeof(ConsoleStatus), typeof(ServerRcon), new PropertyMetadata(ConsoleStatus.Disconnected));
public static readonly DependencyProperty PlayersProperty = DependencyProperty.Register(nameof(Players), typeof(SortableObservableCollection<PlayerInfo>), typeof(ServerRcon), new PropertyMetadata(null));
public static readonly DependencyProperty CountPlayersProperty = DependencyProperty.Register(nameof(CountPlayers), typeof(int), typeof(ServerRcon), new PropertyMetadata(0));
public static readonly DependencyProperty CountInvalidPlayersProperty = DependencyProperty.Register(nameof(CountInvalidPlayers), typeof(int), typeof(ServerRcon), new PropertyMetadata(0));
public static readonly DependencyProperty CountOnlinePlayersProperty = DependencyProperty.Register(nameof(CountOnlinePlayers), typeof(int), typeof(ServerRcon), new PropertyMetadata(0));
private static readonly char[] lineSplitChars = new char[] { '\n' };
private static readonly char[] argsSplitChars = new char[] { ' ' };
@ -67,7 +65,7 @@ namespace ServerManagerTool.Lib
private readonly Logger _errorLogger;
private bool _disposed = false;
public ServerRCON(RCONParameters parameters)
public ServerRcon(RCONParameters parameters)
{
_rconParameters = parameters;
@ -363,20 +361,23 @@ namespace ServerManagerTool.Lib
onlinePlayers.Add(newPlayer);
var playerJoined = false;
_players.AddOrUpdate(newPlayer.PlayerId,
(k) =>
{
playerJoined = true;
return newPlayer;
},
(k, v) =>
{
playerJoined = !v.IsOnline;
v.PlayerName = newPlayer.PlayerName;
v.IsOnline = newPlayer.IsOnline;
return v;
}
);
if (!string.IsNullOrWhiteSpace(newPlayer.PlayerName))
{
_players.AddOrUpdate(newPlayer.PlayerId,
(k) =>
{
playerJoined = true;
return newPlayer;
},
(k, v) =>
{
playerJoined = !v.IsOnline;
v.PlayerName = newPlayer.PlayerName;
v.IsOnline = newPlayer.IsOnline;
return v;
}
);
}
if (playerJoined)
{

View file

@ -952,7 +952,7 @@ namespace ServerManagerTool
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
foreach (var kvp in obfuscateFiles)
{
ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value);
ZipUtils.ZipContent(zipFile, kvp.Key, kvp.Value);
}
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));

View file

@ -9,13 +9,18 @@
<entry>
<id>urn:uuid:2C48A585-72D2-43FB-8987-6B5F0B3E460F</id>
<title>1.1.425 (1.1.425.5)</title>
<summary>1.1.425.5</summary>
<title>1.1.425 (1.1.425.6)</title>
<summary>1.1.425.6</summary>
<link href="" />
<updated>2022-05-08T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>World Save Backup - fixed the backup of the files.</li>
</ul>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>

View file

@ -7,6 +7,29 @@
<link href="http://arkservermanager.freeforums.net/" />
<updated>2022-05-08T00:00:00Z</updated>
<entry>
<id>urn:uuid:973E001F-223C-4B57-89F7-8B8040900A7C</id>
<title>1.1.425 (1.1.425.6)</title>
<summary>1.1.425.6</summary>
<link href="" />
<updated>2022-05-08T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>World Save Backup - fixed the backup of the files.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:CEA21F86-5943-46F9-8807-604695E42A25</id>
<title>1.1.425 (1.1.425.5)</title>

View file

@ -176,7 +176,7 @@ namespace ServerManagerTool
public static readonly DependencyProperty PlayersViewProperty = DependencyProperty.Register(nameof(PlayersView), typeof(ICollectionView), typeof(RCONWindow), new PropertyMetadata(null));
public static readonly DependencyProperty RCONParametersProperty = DependencyProperty.Register(nameof(RCONParameters), typeof(RCONParameters), typeof(RCONWindow), new PropertyMetadata(null));
public static readonly DependencyProperty ScrollOnNewInputProperty = DependencyProperty.Register(nameof(ScrollOnNewInput), typeof(bool), typeof(RCONWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ServerRCONProperty = DependencyProperty.Register(nameof(ServerRCON), typeof(ServerRCON), typeof(RCONWindow), new PropertyMetadata(null));
public static readonly DependencyProperty ServerRCONProperty = DependencyProperty.Register(nameof(ServerRCON), typeof(ServerRcon), typeof(RCONWindow), new PropertyMetadata(null));
public RCONWindow(RCONParameters parameters)
{
@ -187,7 +187,7 @@ namespace ServerManagerTool
this.PlayerFiltering = (PlayerFilterType)Config.Default.RCON_PlayerListFilter;
this.PlayerSorting = (PlayerSortType)Config.Default.RCON_PlayerListSort;
this.RCONParameters = parameters;
this.ServerRCON = new ServerRCON(parameters);
this.ServerRCON = new ServerRcon(parameters);
this.ServerRCON.RegisterCommandListener(RenderRCONCommandOutput);
this.ServerRCON.Players.CollectionChanged += Players_CollectionChanged;
this.ServerRCON.PlayersCollectionUpdated += Players_CollectionUpdated;
@ -195,7 +195,7 @@ namespace ServerManagerTool
this.PlayersView = CollectionViewSource.GetDefaultView(this.ServerRCON.Players);
this.PlayersView.Filter = new Predicate<object>(PlayerFilter);
var notifier = new PropertyChangeNotifier(this.ServerRCON, ServerRCON.StatusProperty, (o, e) =>
var notifier = new PropertyChangeNotifier(this.ServerRCON, ServerRcon.StatusProperty, (o, e) =>
{
this.RenderConnectionStateChange(e);
});
@ -301,9 +301,9 @@ namespace ServerManagerTool
set { SetValue(ScrollOnNewInputProperty, value); }
}
public ServerRCON ServerRCON
public ServerRcon ServerRCON
{
get { return (ServerRCON)GetValue(ServerRCONProperty); }
get { return (ServerRcon)GetValue(ServerRCONProperty); }
set { SetValue(ServerRCONProperty, value); }
}
#endregion
@ -461,7 +461,7 @@ namespace ServerManagerTool
var message = _globalizer.GetResourceString("RCON_DestroyWildDinosLabel");
this.ServerRCON.IssueCommand($"{Config.Default.RCON_MessageCommand.ToLower()} {message}");
this.ServerRCON.IssueCommand(ServerRCON.RCON_COMMAND_WILDDINOWIPE);
this.ServerRCON.IssueCommand(ServerRcon.RCON_COMMAND_WILDDINOWIPE);
},
canExecute: (_) => true
);
@ -807,17 +807,17 @@ namespace ServerManagerTool
break;
case InputMode.Broadcast:
this.ServerRCON.IssueCommand($"{ServerRCON.RCON_COMMAND_BROADCAST} {commandText}");
this.ServerRCON.IssueCommand($"{ServerRcon.RCON_COMMAND_BROADCAST} {commandText}");
break;
case InputMode.Global:
if (!String.IsNullOrWhiteSpace(Config.Default.RCON_AdminName))
{
this.ServerRCON.IssueCommand($"{ServerRCON.RCON_COMMAND_SERVERCHAT} [{Config.Default.RCON_AdminName}] {commandText}");
this.ServerRCON.IssueCommand($"{ServerRcon.RCON_COMMAND_SERVERCHAT} [{Config.Default.RCON_AdminName}] {commandText}");
}
else
{
this.ServerRCON.IssueCommand($"{ServerRCON.RCON_COMMAND_SERVERCHAT} {commandText}");
this.ServerRCON.IssueCommand($"{ServerRcon.RCON_COMMAND_SERVERCHAT} {commandText}");
}
break;
}
@ -914,7 +914,7 @@ namespace ServerManagerTool
private IEnumerable<Inline> FormatCommandInput(ConsoleCommand command)
{
if (command.command.Equals(ServerRCON.RCON_COMMAND_BROADCAST, StringComparison.OrdinalIgnoreCase))
if (command.command.Equals(ServerRcon.RCON_COMMAND_BROADCAST, StringComparison.OrdinalIgnoreCase))
{
yield return new RCONOutput_Broadcast(command.args);
}
@ -933,7 +933,7 @@ namespace ServerManagerTool
{
bool firstLine = true;
if (command.command.Equals(ServerRCON.RCON_COMMAND_LISTPLAYERS, StringComparison.OrdinalIgnoreCase))
if (command.command.Equals(ServerRcon.RCON_COMMAND_LISTPLAYERS, StringComparison.OrdinalIgnoreCase))
{
foreach (var output in command.lines)
{
@ -945,7 +945,7 @@ namespace ServerManagerTool
}
firstLine = false;
if (trimmed == ServerRCON.NoResponseOutput)
if (trimmed == ServerRcon.NoResponseOutput)
{
yield return new RCONOutput_NoResponse();
}
@ -975,7 +975,7 @@ namespace ServerManagerTool
}
firstLine = false;
if (trimmed == ServerRCON.NoResponseOutput)
if (trimmed == ServerRcon.NoResponseOutput)
{
yield return new RCONOutput_NoResponse();
}

View file

@ -1962,7 +1962,7 @@ namespace ServerManagerTool.Lib
var saveFolderInfo = new DirectoryInfo(saveFolder);
// backup the world save file
ZipUtils.ZipAFile(backupFile, worldFileName, worldFile, comment.ToString());
ZipUtils.ZipFile(backupFile, worldFileName, worldFile, comment.ToString());
if (Config.Default.AutoBackup_IncludeSaveGamesFolder)
{
@ -1976,7 +1976,7 @@ namespace ServerManagerTool.Lib
var saveGamesFiles = saveGamesFolderInfo.GetFiles(saveGamesFileFilter, SearchOption.AllDirectories);
foreach (var file in saveGamesFiles)
{
ZipUtils.ZipAFile(backupFile, file.FullName.Replace(saveGamesFolder, Config.Default.SaveGamesRelativePath), file.FullName);
ZipUtils.ZipFile(backupFile, file.FullName.Replace(saveGamesFolder, Config.Default.SaveGamesRelativePath), file.FullName);
}
}
}

View file

@ -328,20 +328,23 @@ namespace ServerManagerTool.Lib
onlinePlayers.Add(newPlayer);
var playerJoined = false;
_players.AddOrUpdate(newPlayer.PlayerId,
(k) =>
{
playerJoined = true;
return newPlayer;
},
(k, v) =>
{
playerJoined = !v.IsOnline;
v.PlayerName = newPlayer.PlayerName;
v.IsOnline = newPlayer.IsOnline;
return v;
}
);
if (!string.IsNullOrWhiteSpace(newPlayer.PlayerName))
{
_players.AddOrUpdate(newPlayer.PlayerId,
(k) =>
{
playerJoined = true;
return newPlayer;
},
(k, v) =>
{
playerJoined = !v.IsOnline;
v.PlayerName = newPlayer.PlayerName;
v.IsOnline = newPlayer.IsOnline;
return v;
}
);
}
if (playerJoined)
{

View file

@ -721,7 +721,7 @@ namespace ServerManagerTool
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
foreach (var kvp in obfuscateFiles)
{
ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value);
ZipUtils.ZipContent(zipFile, kvp.Key, kvp.Value);
}
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));

View file

@ -9,8 +9,8 @@
<entry>
<id>urn:uuid:AD8ABBB5-093A-4FDB-B473-FCED2DB46781</id>
<title>1.1.69 (1.1.69.5)</title>
<summary>1.1.69.5</summary>
<title>1.1.69 (1.1.69.6)</title>
<summary>1.1.69.6</summary>
<link href="" />
<updated>2022-05-08T00:00:00Z</updated>
<content type="xhtml">
@ -20,6 +20,7 @@
<br/>
<ul>
<li>Fixed an issue that would not send through the auto process messages via RCON using the correct mode selected in the global settings.</li>
<li>World Save Backup - fixed the backup of the files.</li>
</ul>
<u style="font-size: .9em;">CHANGE</u>
<br/>

View file

@ -7,6 +7,29 @@
<link href="http://servermanagers.freeforums.net/" />
<updated>2022-05-08T00:00:00Z</updated>
<entry>
<id>urn:uuid:72CA1005-0061-41A3-9883-F826B8F9F27F</id>
<title>1.1.69 (1.1.69.6)</title>
<summary>1.1.69.6</summary>
<link href="" />
<updated>2022-05-08T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>World Save Backup - fixed the backup of the files.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:68ECEA73-1C9C-4DCB-807B-0D812E986993</id>
<title>1.1.69 (1.1.69.5)</title>

View file

@ -19,7 +19,7 @@ namespace ServerManagerTool.Common.Utils
if (!File.Exists(zipFile))
throw new FileNotFoundException();
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
return zip.Entries.Any(e => !e.IsDirectory && Path.GetFileName(e.FileName).Equals(entryName, StringComparison.OrdinalIgnoreCase));
}
@ -35,7 +35,7 @@ namespace ServerManagerTool.Common.Utils
if (!File.Exists(zipFile))
throw new FileNotFoundException();
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
return zip.Entries.Any(e => e.IsDirectory && e.FileName.EndsWith($"{folderName}/", StringComparison.OrdinalIgnoreCase))
? true
@ -57,7 +57,7 @@ namespace ServerManagerTool.Common.Utils
if (!Directory.Exists(destinationPath))
Directory.CreateDirectory(destinationPath);
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
var selection = zip.Entries.Where(e => Path.GetFileName(e.FileName).Equals(entryName, StringComparison.OrdinalIgnoreCase)).ToList();
@ -80,7 +80,7 @@ namespace ServerManagerTool.Common.Utils
if (!Directory.Exists(destinationPath))
Directory.CreateDirectory(destinationPath);
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.ExtractAll(destinationPath, ExtractExistingFileAction.OverwriteSilently);
@ -103,7 +103,7 @@ namespace ServerManagerTool.Common.Utils
if (sourceFolder.EndsWith("/"))
sourceFolder = sourceFolder.TrimEnd('/');
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
var selection = new List<ZipEntry>();
@ -135,7 +135,7 @@ namespace ServerManagerTool.Common.Utils
}
else
{
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.AddFiles(filesToZip.Where(f => !string.IsNullOrWhiteSpace(f) && File.Exists(f)), preserveDirHierarchy, directoryPathInArchive);
@ -147,7 +147,7 @@ namespace ServerManagerTool.Common.Utils
}
}
public static void ZipAFile(string zipFile, string entryName, string content)
public static void ZipContent(string zipFile, string entryName, string content)
{
if (string.IsNullOrWhiteSpace(zipFile))
throw new ArgumentNullException(nameof(zipFile));
@ -169,7 +169,7 @@ namespace ServerManagerTool.Common.Utils
}
else
{
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.AddEntry(entryName, content);
@ -178,20 +178,27 @@ namespace ServerManagerTool.Common.Utils
}
}
public static void ZipAFile(string zipFile, string entryName, string content, string comment)
public static void ZipFile(string zipFile, string entryName, string fileToZip)
{
ZipFile(zipFile, entryName, fileToZip, null);
}
public static void ZipFile(string zipFile, string entryName, string fileToZip, string comment)
{
if (string.IsNullOrWhiteSpace(zipFile))
throw new ArgumentNullException(nameof(zipFile));
if (string.IsNullOrWhiteSpace(entryName))
throw new ArgumentNullException(nameof(entryName));
if (string.IsNullOrWhiteSpace(content))
throw new ArgumentNullException(nameof(content));
if (string.IsNullOrWhiteSpace(fileToZip))
throw new ArgumentNullException(nameof(fileToZip));
if (!File.Exists(fileToZip))
throw new ArgumentException($"{fileToZip} does not exist or could not be found.");
if (!File.Exists(zipFile))
{
using (var zip = new ZipFile())
{
zip.AddEntry(entryName, File.ReadAllBytes(content));
zip.AddEntry(entryName, File.ReadAllBytes(fileToZip));
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
if (!string.IsNullOrWhiteSpace(comment))
@ -202,9 +209,9 @@ namespace ServerManagerTool.Common.Utils
}
else
{
using (var zip = ZipFile.Read(zipFile))
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.AddEntry(entryName, File.ReadAllBytes(content));
zip.AddEntry(entryName, File.ReadAllBytes(fileToZip));
if (!string.IsNullOrWhiteSpace(comment))
zip.Comment = comment;