mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
Support Zip Changes
- created new ZipContents method to handle multiple content objects to be zipped. - changed the CreateSupportZip to use the new ZipContents method and changed the type of obfuscateFiles.
This commit is contained in:
parent
10e6a08a3e
commit
ba78542184
3 changed files with 194 additions and 27 deletions
|
|
@ -703,7 +703,7 @@ namespace ServerManagerTool
|
||||||
Application.Current.Dispatcher.Invoke(() => this.Cursor = Cursors.Wait);
|
Application.Current.Dispatcher.Invoke(() => this.Cursor = Cursors.Wait);
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
var obfuscateFiles = new Dictionary<string, string>();
|
var obfuscateFiles = new Dictionary<string, List<(string entryName, string contents)>>();
|
||||||
var files = new List<string>();
|
var files = new List<string>();
|
||||||
|
|
||||||
// <server>
|
// <server>
|
||||||
|
|
@ -733,7 +733,16 @@ namespace ServerManagerTool
|
||||||
var iniFile = IniFileUtils.ReadFromFile(file);
|
var iniFile = IniFileUtils.ReadFromFile(file);
|
||||||
if (iniFile != null)
|
if (iniFile != null)
|
||||||
{
|
{
|
||||||
obfuscateFiles.Add(file, iniFile.ToOutputString());
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, iniFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, iniFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerGameUserSettingsConfigFile);
|
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerGameUserSettingsConfigFile);
|
||||||
|
|
@ -745,7 +754,17 @@ namespace ServerManagerTool
|
||||||
iniFile.WriteKey("ServerSettings", "ServerPassword", "obfuscated");
|
iniFile.WriteKey("ServerSettings", "ServerPassword", "obfuscated");
|
||||||
iniFile.WriteKey("ServerSettings", "ServerAdminPassword", "obfuscated");
|
iniFile.WriteKey("ServerSettings", "ServerAdminPassword", "obfuscated");
|
||||||
iniFile.WriteKey("ServerSettings", "SpectatorPassword", "obfuscated");
|
iniFile.WriteKey("ServerSettings", "SpectatorPassword", "obfuscated");
|
||||||
obfuscateFiles.Add(file, iniFile.ToOutputString());
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, iniFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, iniFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.LauncherFile);
|
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.LauncherFile);
|
||||||
|
|
@ -794,7 +813,17 @@ namespace ServerManagerTool
|
||||||
profileFile.WebAlarmKey = string.IsNullOrWhiteSpace(profileFile.WebAlarmKey) ? "empty" : "obfuscated";
|
profileFile.WebAlarmKey = string.IsNullOrWhiteSpace(profileFile.WebAlarmKey) ? "empty" : "obfuscated";
|
||||||
profileFile.WebAlarmUrl = string.IsNullOrWhiteSpace(profileFile.WebAlarmUrl) ? "empty" : "obfuscated";
|
profileFile.WebAlarmUrl = string.IsNullOrWhiteSpace(profileFile.WebAlarmUrl) ? "empty" : "obfuscated";
|
||||||
profileFile.BranchPassword = string.IsNullOrWhiteSpace(profileFile.BranchPassword) ? "empty" : "obfuscated";
|
profileFile.BranchPassword = string.IsNullOrWhiteSpace(profileFile.BranchPassword) ? "empty" : "obfuscated";
|
||||||
obfuscateFiles.Add(file, profileFile.ToOutputString());
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, profileFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, profileFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -824,29 +853,45 @@ namespace ServerManagerTool
|
||||||
|
|
||||||
// scheduled tasks (profile level)
|
// scheduled tasks (profile level)
|
||||||
var taskKey = this.Settings.GetProfileKey();
|
var taskKey = this.Settings.GetProfileKey();
|
||||||
|
var taskList = new List<(string entryName, string contents)>();
|
||||||
|
|
||||||
var taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoStart, taskKey, null);
|
var taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoStart, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoStart}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoStart}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#1");
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#1");
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#1.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#1.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#2");
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#2");
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#2.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#2.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
// scheduled tasks (manager level)
|
// scheduled tasks (manager level)
|
||||||
taskKey = TaskSchedulerUtils.ComputeKey(Config.Default.DataDir);
|
taskKey = TaskSchedulerUtils.ComputeKey(Config.Default.DataDir);
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoBackup, taskKey, null);
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoBackup, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoBackup}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoBackup}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoUpdate, taskKey, null);
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoUpdate, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoUpdate}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoUpdate}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(""))
|
||||||
|
obfuscateFiles[""].AddRange(taskList);
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add("", taskList);
|
||||||
|
|
||||||
// archive comment - mostly global config settings
|
// archive comment - mostly global config settings
|
||||||
var comment = new StringBuilder();
|
var comment = new StringBuilder();
|
||||||
|
|
@ -984,10 +1029,7 @@ namespace ServerManagerTool
|
||||||
if (File.Exists(zipFile)) File.Delete(zipFile);
|
if (File.Exists(zipFile)) File.Delete(zipFile);
|
||||||
|
|
||||||
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
|
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
|
||||||
foreach (var kvp in obfuscateFiles)
|
ZipUtils.ZipContents(zipFile, obfuscateFiles);
|
||||||
{
|
|
||||||
ZipUtils.ZipContent(zipFile, kvp.Key, kvp.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));
|
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));
|
||||||
MessageBox.Show(message, _globalizer.GetResourceString("ServerSettings_SupportZipTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
MessageBox.Show(message, _globalizer.GetResourceString("ServerSettings_SupportZipTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
|
|
||||||
|
|
@ -483,7 +483,7 @@ namespace ServerManagerTool
|
||||||
Application.Current.Dispatcher.Invoke(() => this.Cursor = Cursors.Wait);
|
Application.Current.Dispatcher.Invoke(() => this.Cursor = Cursors.Wait);
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
var obfuscateFiles = new Dictionary<string, string>();
|
var obfuscateFiles = new Dictionary<string, List<(string entryName, string contents)>>();
|
||||||
var files = new List<string>();
|
var files = new List<string>();
|
||||||
|
|
||||||
// <server>
|
// <server>
|
||||||
|
|
@ -511,7 +511,17 @@ namespace ServerManagerTool
|
||||||
{
|
{
|
||||||
iniFile.WriteKey("OnlineSubsystem", "ServerPassword", "obfuscated");
|
iniFile.WriteKey("OnlineSubsystem", "ServerPassword", "obfuscated");
|
||||||
iniFile.WriteKey("OnlineSubsystemSteam", "ServerPassword", "obfuscated");
|
iniFile.WriteKey("OnlineSubsystemSteam", "ServerPassword", "obfuscated");
|
||||||
obfuscateFiles.Add(file, iniFile.ToOutputString());
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, iniFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, iniFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerGameConfigFile);
|
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerGameConfigFile);
|
||||||
|
|
@ -520,7 +530,18 @@ namespace ServerManagerTool
|
||||||
var iniFile = IniFileUtils.ReadFromFile(file);
|
var iniFile = IniFileUtils.ReadFromFile(file);
|
||||||
if (iniFile != null)
|
if (iniFile != null)
|
||||||
{
|
{
|
||||||
obfuscateFiles.Add(file, iniFile.ToOutputString());
|
iniFile.WriteKey("RconPlugin", "RconPassword", "obfuscated");
|
||||||
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, iniFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, iniFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerSettingsConfigFile);
|
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.ServerSettingsConfigFile);
|
||||||
|
|
@ -530,7 +551,17 @@ namespace ServerManagerTool
|
||||||
if (iniFile != null)
|
if (iniFile != null)
|
||||||
{
|
{
|
||||||
iniFile.WriteKey("ServerSettings", "AdminPassword", "obfuscated");
|
iniFile.WriteKey("ServerSettings", "AdminPassword", "obfuscated");
|
||||||
obfuscateFiles.Add(file, iniFile.ToOutputString());
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, iniFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, iniFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.LauncherFile);
|
file = Path.Combine(this.Settings.GetProfileServerConfigDir(), Config.Default.LauncherFile);
|
||||||
|
|
@ -584,7 +615,17 @@ namespace ServerManagerTool
|
||||||
profileFile.ServerPassword = string.IsNullOrWhiteSpace(profileFile.ServerPassword) ? "empty" : "obfuscated";
|
profileFile.ServerPassword = string.IsNullOrWhiteSpace(profileFile.ServerPassword) ? "empty" : "obfuscated";
|
||||||
profileFile.RconPassword = string.IsNullOrWhiteSpace(profileFile.RconPassword) ? "empty" : "obfuscated";
|
profileFile.RconPassword = string.IsNullOrWhiteSpace(profileFile.RconPassword) ? "empty" : "obfuscated";
|
||||||
profileFile.BranchPassword = string.IsNullOrWhiteSpace(profileFile.BranchPassword) ? "empty" : "obfuscated";
|
profileFile.BranchPassword = string.IsNullOrWhiteSpace(profileFile.BranchPassword) ? "empty" : "obfuscated";
|
||||||
obfuscateFiles.Add(file, profileFile.ToOutputString());
|
|
||||||
|
var key = Path.GetDirectoryName(file);
|
||||||
|
var entryName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(key))
|
||||||
|
obfuscateFiles[key].Add((entryName, profileFile.ToOutputString()));
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add(key, new List<(string entryName, string contents)>
|
||||||
|
{
|
||||||
|
(entryName, profileFile.ToOutputString())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -611,29 +652,45 @@ namespace ServerManagerTool
|
||||||
|
|
||||||
// scheduled tasks (profile level)
|
// scheduled tasks (profile level)
|
||||||
var taskKey = this.Settings.GetProfileKey();
|
var taskKey = this.Settings.GetProfileKey();
|
||||||
|
var taskList = new List<(string entryName, string contents)>();
|
||||||
|
|
||||||
var taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoStart, taskKey, null);
|
var taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoStart, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoStart}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoStart}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#1");
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#1");
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#1.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#1.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#2");
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoShutdown, taskKey, "#2");
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#2.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoShutdown}-#2.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
// scheduled tasks (manager level)
|
// scheduled tasks (manager level)
|
||||||
taskKey = TaskSchedulerUtils.ComputeKey(Config.Default.DataPath);
|
taskKey = TaskSchedulerUtils.ComputeKey(Config.Default.DataPath);
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoBackup, taskKey, null);
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoBackup, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoBackup}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoBackup}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoUpdate, taskKey, null);
|
taskXML = TaskSchedulerUtils.GetScheduleTaskInformation(TaskSchedulerUtils.TaskType.AutoUpdate, taskKey, null);
|
||||||
if (!string.IsNullOrWhiteSpace(taskXML))
|
if (!string.IsNullOrWhiteSpace(taskXML))
|
||||||
obfuscateFiles.Add($"Task-{TaskSchedulerUtils.TaskType.AutoUpdate}.xml", taskXML);
|
{
|
||||||
|
taskList.Add(($"Task-{TaskSchedulerUtils.TaskType.AutoUpdate}.xml", taskXML));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obfuscateFiles.ContainsKey(""))
|
||||||
|
obfuscateFiles[""].AddRange(taskList);
|
||||||
|
else
|
||||||
|
obfuscateFiles.Add("", taskList);
|
||||||
|
|
||||||
// archive comment - mostly global config settings
|
// archive comment - mostly global config settings
|
||||||
var comment = new StringBuilder();
|
var comment = new StringBuilder();
|
||||||
|
|
@ -758,10 +815,7 @@ namespace ServerManagerTool
|
||||||
if (File.Exists(zipFile)) File.Delete(zipFile);
|
if (File.Exists(zipFile)) File.Delete(zipFile);
|
||||||
|
|
||||||
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
|
ZipUtils.ZipFiles(zipFile, files, comment.ToString());
|
||||||
foreach (var kvp in obfuscateFiles)
|
ZipUtils.ZipContents(zipFile, obfuscateFiles);
|
||||||
{
|
|
||||||
ZipUtils.ZipContent(zipFile, kvp.Key, kvp.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));
|
var message = _globalizer.GetResourceString("ServerSettings_SupportZipSuccessLabel").Replace("{filename}", Path.GetFileName(zipFile));
|
||||||
MessageBox.Show(message, _globalizer.GetResourceString("ServerSettings_SupportZipTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
MessageBox.Show(message, _globalizer.GetResourceString("ServerSettings_SupportZipTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,77 @@ namespace ServerManagerTool.Common.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ZipContents(string zipFile, Dictionary<string, List<(string entryName, string content)>> contentsToZip, string comment = "")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(zipFile))
|
||||||
|
throw new ArgumentNullException(nameof(zipFile));
|
||||||
|
|
||||||
|
if (contentsToZip is null || contentsToZip.IsEmpty())
|
||||||
|
throw new ArgumentNullException(nameof(contentsToZip));
|
||||||
|
|
||||||
|
if (!File.Exists(zipFile))
|
||||||
|
{
|
||||||
|
using (var zip = new ZipFile(zipFile))
|
||||||
|
{
|
||||||
|
foreach (var zipFolder in contentsToZip.Keys)
|
||||||
|
{
|
||||||
|
contentsToZip[zipFolder]
|
||||||
|
.Where(c => !string.IsNullOrWhiteSpace(c.entryName) && !string.IsNullOrWhiteSpace(c.content)).ToList()
|
||||||
|
.ForEach(c =>
|
||||||
|
{
|
||||||
|
var zipEntry = zip.AddEntry(c.entryName, c.content);
|
||||||
|
if (string.IsNullOrWhiteSpace(zipFolder))
|
||||||
|
{
|
||||||
|
zipEntry.FileName = c.entryName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zipEntry.FileName = $"{zipFolder}/{c.entryName}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
|
||||||
|
if (!string.IsNullOrWhiteSpace(comment))
|
||||||
|
{
|
||||||
|
zip.Comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using (var zip = Ionic.Zip.ZipFile.Read(zipFile))
|
||||||
|
{
|
||||||
|
foreach (var zipFolder in contentsToZip.Keys)
|
||||||
|
{
|
||||||
|
contentsToZip[zipFolder]
|
||||||
|
.Where(c => !string.IsNullOrWhiteSpace(c.entryName) && !string.IsNullOrWhiteSpace(c.content)).ToList()
|
||||||
|
.ForEach(c =>
|
||||||
|
{
|
||||||
|
var zipEntry = zip.AddEntry(c.entryName, c.content);
|
||||||
|
if (string.IsNullOrWhiteSpace(zipFolder))
|
||||||
|
{
|
||||||
|
zipEntry.FileName = c.entryName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zipEntry.FileName = $"{zipFolder}/{c.entryName}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(comment))
|
||||||
|
{
|
||||||
|
zip.Comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ZipFile(string zipFile, string directoryPath, string fileToZip)
|
public static void ZipFile(string zipFile, string directoryPath, string fileToZip)
|
||||||
{
|
{
|
||||||
ZipFile(zipFile, directoryPath, fileToZip, null);
|
ZipFile(zipFile, directoryPath, fileToZip, null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue