Reset Server Button

- added new button to reset your server.
This commit is contained in:
Brett Hewitson 2022-06-15 20:01:05 +10:00
parent e2f92bf7a9
commit 9c5b096429
19 changed files with 308 additions and 136 deletions

View file

@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.Tpl.Dataflow" Version="4.5.24" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog" Version="4.7.2" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="TaskScheduler" Version="2.8.19" />
<PackageReference Include="WindowsFirewallHelper" Version="1.6.3.40" />
</ItemGroup>

View file

@ -275,5 +275,44 @@ namespace ServerManagerTool.Common.Utils
zip.Save();
}
}
public static void ZipFiles(string zipFile, Dictionary<string, List<(string file, string entryName)>> filesToZip, string comment = "")
{
if (string.IsNullOrWhiteSpace(zipFile))
throw new ArgumentNullException(nameof(zipFile));
if (filesToZip is null || filesToZip.IsEmpty())
throw new ArgumentNullException(nameof(filesToZip));
using (var zip = new ZipFile(zipFile))
{
foreach (var zipFolder in filesToZip.Keys)
{
filesToZip[zipFolder]
.Where(f => !string.IsNullOrWhiteSpace(f.file) && File.Exists(f.file)).ToList()
.ForEach(f =>
{
var zipEntry = zip.AddFile(f.file, zipFolder);
var entryName = string.IsNullOrWhiteSpace(f.entryName) ? Path.GetFileName(f.file) : f.entryName;
if (string.IsNullOrWhiteSpace(zipFolder))
{
zipEntry.FileName = entryName;
}
else
{
zipEntry.FileName = $"{zipFolder}/{entryName}";
}
});
}
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
if (!string.IsNullOrWhiteSpace(comment))
{
zip.Comment = comment;
}
zip.Save();
}
}
}
}