Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
crowbarmaster committed Oct 4, 2021
1 parent f239924 commit 5895886
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 59 deletions.
4 changes: 2 additions & 2 deletions BedrockService/Client/Forms/EditSrv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private void SaveBtn_Click(object sender, EventArgs e)
{
if (DelBackupBtn.Enabled)
{
if(dataGrid.SelectedRows.Count < 2)
RollbackFolderName = (string)dataGrid.CurrentRow.Cells[0].Value;
if (dataGrid.SelectedRows.Count < 2)
RollbackFolderName = (string)dataGrid.CurrentRow.Cells[0].Value;
DialogResult = DialogResult.OK;
Close();
}
Expand Down
2 changes: 1 addition & 1 deletion BedrockService/Client/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private void BackupManager_Click(object sender, EventArgs e)
private void ManPacks_Click(object sender, EventArgs e)
{
FormManager.GetTCPClient.SendData(NetworkMessageSource.Client, NetworkMessageDestination.Server, (byte)connectedHost.Servers.IndexOf(selectedServer), NetworkMessageTypes.PackList);
while(FormManager.GetTCPClient.RecievedPacks == null)
while (FormManager.GetTCPClient.RecievedPacks == null)
{
Thread.Sleep(150);
}
Expand Down
27 changes: 11 additions & 16 deletions BedrockService/Client/Forms/ManagePacksForms.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using BedrockService.Client.Management;
using BedrockService.Service.Networking;
using BedrockService.Utilities;
using BedrockService.Service.Server.PackParser;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.IO.Compression;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BedrockService.Service.Server.PackParser;
using System.IO.Compression;

namespace BedrockService.Client.Forms
{
Expand All @@ -28,7 +23,7 @@ public ManagePacksForms(byte serverIndex)
//FormManager.GetTCPClient.SendData(File.ReadAllBytes($@"E:\testRB.zip"), NetworkMessageSource.Client, NetworkMessageDestination.Server, ServerIndex, NetworkMessageTypes.PackFile);
}

public void PopulateServerPacks (List<MinecraftPackParser> packList)
public void PopulateServerPacks(List<MinecraftPackParser> packList)
{
foreach (MinecraftPackParser pack in packList)
foreach (MinecraftPackContainer container in pack.FoundPacks)
Expand All @@ -42,14 +37,14 @@ private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
parsedPacksListBox.SelectedIndex = -1;
if (thisBox == parsedPacksListBox)
serverListBox.SelectedIndex = -1;
if(thisBox.SelectedIndex != -1)
if (thisBox.SelectedIndex != -1)
{
MinecraftPackContainer selectedPack = (MinecraftPackContainer)thisBox.SelectedItem;
if(selectedPack.IconBytes != null)
using (MemoryStream ms = new MemoryStream(selectedPack.IconBytes))
{
selectedPackIcon.Image = Image.FromStream(ms);
}
if (selectedPack.IconBytes != null)
using (MemoryStream ms = new MemoryStream(selectedPack.IconBytes))
{
selectedPackIcon.Image = Image.FromStream(ms);
}
if (selectedPack.JsonManifest != null)
textBox1.Text = $"{selectedPack.JsonManifest.header.name}\r\n{selectedPack.JsonManifest.header.description}\r\n{selectedPack.JsonManifest.header.uuid}\r\n{selectedPack.JsonManifest.header.version[0]}";
else
Expand All @@ -72,7 +67,7 @@ private void removePackBtn_Click(object sender, EventArgs e)
private void removeAllPacksBtn_Click(object sender, EventArgs e)
{
List<MinecraftPackContainer> temp = new List<MinecraftPackContainer>();
foreach(object item in serverListBox.Items)
foreach (object item in serverListBox.Items)
temp.Add((MinecraftPackContainer)item);
FormManager.GetTCPClient.SendData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(temp)), NetworkMessageSource.Client, NetworkMessageDestination.Server, ServerIndex, NetworkMessageTypes.RemovePack);
serverListBox.Items.Clear();
Expand Down Expand Up @@ -116,7 +111,7 @@ private void openFileBtn_Click(object sender, EventArgs e)
openFileDialog.Filter = "MC pack file (.MCWORLD, .MCPACK, .MCADDON, .Zip)|*.mcworld;*.mcpack;*.mcaddon;*.zip";
openFileDialog.Title = "Select pack file(s)";
openFileDialog.Multiselect = true;
if(openFileDialog.ShowDialog() == DialogResult.OK)
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
MinecraftPackParser parser = new MinecraftPackParser(openFileDialog.FileNames);
PackExtractDir = parser.PackExtractDirectory;
Expand Down
2 changes: 0 additions & 2 deletions BedrockService/Client/Networking/TCPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using BedrockService.Service.Server.Logging;
using BedrockService.Service.Server.PackParser;
using BedrockService.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
Expand Down
3 changes: 3 additions & 0 deletions BedrockService/Service/BedrockService.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@
<ItemGroup>
<Reference Include="NCrontab.Signed, Version=3.3.2.0, Culture=neutral, PublicKeyToken=5247b4370afff365, processorArchitecture=MSIL">
<HintPath>..\packages\NCrontab.Signed.3.3.2\lib\net35\NCrontab.Signed.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down Expand Up @@ -102,6 +104,7 @@
<Reference Include="System.Xml" />
<Reference Include="Topshelf, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL">
<HintPath>..\packages\Topshelf.4.3.0\lib\net452\Topshelf.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions BedrockService/Service/BedrockService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BedrockService.Service.Networking;
using BedrockService.Service.Server;
using BedrockService.Service.Server.HostInfoClasses;
using BedrockService.Service.Server.PackParser;
using NCrontab;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -318,8 +317,8 @@ await Task.Run(() =>
else if (File.Exists($@"{Program.ServiceDirectory}\Server\MCSFiles\stock_filelist.ini"))
DeleteFilelist(File.ReadAllLines($@"{Program.ServiceDirectory}\Server\MCSFiles\stock_filelist.ini"), server.ServerPath.Value);
else
DeleteFilesRecursively(new DirectoryInfo(server.ServerPath.Value));
DeleteFilesRecursively(new DirectoryInfo(server.ServerPath.Value));

while (InstanceProvider.HostInfo.ServerVersion == null || InstanceProvider.HostInfo.ServerVersion == "None")
{
Thread.Sleep(150);
Expand Down
4 changes: 2 additions & 2 deletions BedrockService/Service/Management/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public bool RollbackToBackup(byte serverIndex, string folderName)
ServerInfo server = InstanceProvider.GetServerInfoByIndex(serverIndex);
BedrockServer brs = InstanceProvider.GetBedrockServerByIndex(serverIndex);
brs.CurrentServerStatus = BedrockServer.ServerStatus.Stopping;
while(brs.CurrentServerStatus != BedrockServer.ServerStatus.Stopped)
while (brs.CurrentServerStatus != BedrockServer.ServerStatus.Stopped)
{
Thread.Sleep(100);
}
Expand Down Expand Up @@ -462,7 +462,7 @@ private void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target)
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name), true);
}

private void DeleteFilesRecursively(DirectoryInfo source)
{
foreach (DirectoryInfo dir in source.GetDirectories())
Expand Down
5 changes: 2 additions & 3 deletions BedrockService/Service/Networking/TCPListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using BedrockService.Service.Server;
using BedrockService.Service.Server.HostInfoClasses;
using BedrockService.Service.Server.Logging;
using BedrockService.Service.Server.Management;
using BedrockService.Service.Server.PackParser;
using BedrockService.Utilities;
using Newtonsoft.Json;
Expand Down Expand Up @@ -202,7 +201,7 @@ private void IncomingListener()

MinecraftKnownPacksClass knownPacks = new MinecraftKnownPacksClass($@"{InstanceProvider.GetServerInfoByIndex(serverIndex).ServerPath.Value}\valid_known_packs.json", $@"{Program.ServiceDirectory}\Server\stock_packs.json");
List<MinecraftPackContainer> MCContainer = JsonConvert.DeserializeObject<List<MinecraftPackContainer>>(data);
foreach(MinecraftPackContainer cont in MCContainer)
foreach (MinecraftPackContainer cont in MCContainer)
knownPacks.RemovePackFromServer(InstanceProvider.GetServerInfoByIndex(serverIndex).ServerPath.Value, cont);

break;
Expand All @@ -214,7 +213,7 @@ private void IncomingListener()
List<MinecraftPackParser> list = new List<MinecraftPackParser>();
foreach (MinecraftKnownPacksClass.KnownPack pack in knownPacks.KnownPacks)
list.Add(new MinecraftPackParser($@"{InstanceProvider.GetServerInfoByIndex(serverIndex).ServerPath}\{pack.path.Replace(@"/", @"\")}"));

SendData(Encoding.UTF8.GetBytes(JArray.FromObject(list).ToString()), NetworkMessageSource.Server, NetworkMessageDestination.Client, NetworkMessageTypes.PackList);

break;
Expand Down
10 changes: 5 additions & 5 deletions BedrockService/Service/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Threading;
using BedrockService.Service.Server;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using Topshelf;
using Topshelf.Runtime;
using BedrockService.Service.Server;
using System.Diagnostics;

namespace BedrockService.Service
{
Expand Down Expand Up @@ -44,7 +44,7 @@ static void Main(string[] args)
x.Service(settings => InstanceProvider.BedrockService, s =>
{
s.BeforeStartingService(_ => InstanceProvider.ServiceLogger.AppendLine("Starting service..."));
s.BeforeStoppingService(_ =>
s.BeforeStoppingService(_ =>
{
InstanceProvider.ServiceLogger.AppendLine("Stopping service...");
IsExiting = true;
Expand Down
4 changes: 2 additions & 2 deletions BedrockService/Service/Server/BedrockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void ApplicationWatchdogMonitor()
{
return;
}

}
}

Expand Down Expand Up @@ -344,7 +344,7 @@ private void StdOutToLog(object sender, DataReceivedEventArgs e)
Console.WriteLine($"Player {username} disconnected with XUID: {xuid}");
InstanceProvider.PlayerManager.PlayerDisconnected(xuid, serverInfo);
}
if(dataMsg.Contains("Failed to load Vanilla"))
if (dataMsg.Contains("Failed to load Vanilla"))
{
CurrentServerStatus = ServerStatus.Stopping;
while (CurrentServerStatus != ServerStatus.Stopped)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace BedrockService.Service.Server.PackParser
{
Expand All @@ -29,7 +25,7 @@ public override string ToString()
}
}

public MinecraftKnownPacksClass (string serverFile, string stockFile)
public MinecraftKnownPacksClass(string serverFile, string stockFile)
{
KnownPacks = ParseJsonArray(serverFile);
stockPacks = ParseJsonArray(stockFile);
Expand All @@ -44,7 +40,7 @@ public MinecraftKnownPacksClass (string serverFile, string stockFile)
}
}

public void RemovePackFromServer (string serverPath, MinecraftPackContainer pack)
public void RemovePackFromServer(string serverPath, MinecraftPackContainer pack)
{
if (pack.ManifestType == "WorldPack")
Directory.Delete($@"{serverPath}\worlds\{pack.FolderName}", true);
Expand All @@ -54,7 +50,7 @@ public void RemovePackFromServer (string serverPath, MinecraftPackContainer pack
Directory.Delete($@"{serverPath}\resource_packs\{ pack.FolderName}", true);
KnownPacks.Remove(KnownPacks.First(p => p.uuid != null || p.uuid == pack.JsonManifest.header.uuid));
List<KnownPack> packsToWrite = new List<KnownPack>(stockPacks);
if(KnownPacks.Count > 0)
if (KnownPacks.Count > 0)
packsToWrite.AddRange(KnownPacks);
File.WriteAllText($@"{serverPath}\valid_known_packs.json", JArray.FromObject(packsToWrite).ToString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BedrockService.Service.Server.PackParser
{
Expand Down
12 changes: 4 additions & 8 deletions BedrockService/Service/Server/PackParser/MinecraftPackParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Newtonsoft.Json;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BedrockService.Service.Server.PackParser
{
Expand Down Expand Up @@ -69,9 +65,9 @@ public MinecraftPackParser(string[] files)
FileInfo fInfo = new FileInfo(file);
string zipFilePath = $@"{PackExtractDirectory.FullName}\{fInfo.Name.Replace(fInfo.Extension, "")}";
ZipFile.ExtractToDirectory(file, zipFilePath);
foreach(FileInfo extractedFile in new DirectoryInfo(zipFilePath).GetFiles())
foreach (FileInfo extractedFile in new DirectoryInfo(zipFilePath).GetFiles())
{
if(extractedFile.Extension == ".mcpack")
if (extractedFile.Extension == ".mcpack")
{
Directory.CreateDirectory($@"{zipFilePath}\{extractedFile.Name.Replace(extractedFile.Extension, "")}");
ZipFile.ExtractToDirectory(extractedFile.FullName, $@"{zipFilePath}\{fInfo.Name.Replace(fInfo.Extension, "")}_{extractedFile.Name.Replace(extractedFile.Extension, "")}");
Expand All @@ -82,7 +78,7 @@ public MinecraftPackParser(string[] files)
ParseDirectory(directory);
}

private void ParseDirectory(DirectoryInfo directoryToParse)
private void ParseDirectory(DirectoryInfo directoryToParse)
{
InstanceProvider.ServiceLogger.AppendLine($"Parsing directory {directoryToParse.Name}");
if (directoryToParse.Exists)
Expand Down

0 comments on commit 5895886

Please sign in to comment.