Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nacrt committed Nov 7, 2020
1 parent ab77066 commit e11bf88
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 55 deletions.
13 changes: 1 addition & 12 deletions SkyblockClient/FrmAdvancedSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SkyblockClient
{
Expand Down
13 changes: 6 additions & 7 deletions SkyblockClient/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -17,8 +16,8 @@ namespace SkyblockClient
/// </summary>
public partial class MainWindow : Window
{
public string URL = "https://github.com/nacrt/SkyblockClient/blob/main/files/";
//public string URL = "http://localhost/files/";
//public string URL = "https://github.com/nacrt/SkyblockClient/blob/main/files/";
public string URL = "http://localhost/files/";

public string tempFolderLocation => Utils.exeLocation + @".temp\";
public string minecraftLocation = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\";
Expand Down Expand Up @@ -169,10 +168,10 @@ public async Task StartForgeAndModsInstaller()

private async Task ForgeInstaller()
{
Console.WriteLine("Downloading Forge");
Utils.Info("Downloading Forge");
const string FORGE = "forge.exe";
await DownloadFileByte(FORGE, tempFolderLocation + FORGE);
Console.WriteLine("Finished Downloading Forge");
Utils.Info("Finished Downloading Forge");

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
Expand Down Expand Up @@ -221,9 +220,9 @@ private async Task DownloadIndividualMods(List<IOption> modOptions)
{
try
{
Console.WriteLine("Downloading " + mod.display);
Utils.Info("Downloading " + mod.display);
await DownloadFileByte(mod.file, tempFolderLocation + mod.file);
Console.WriteLine("Finished Downloading " + mod.display);
Utils.Info("Finished Downloading " + mod.display);
}
catch (WebException webE)
{
Expand Down
26 changes: 14 additions & 12 deletions SkyblockClient/Option/ModOption.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;

namespace SkyblockClient.Option
namespace SkyblockClient.Option
{
public class ModOption : IOption
{
Expand All @@ -15,16 +12,15 @@ public class ModOption : IOption

public void Create(string line)
{
const int ID_INDEX = 0, ENABLED_INDEX = 1, FILE_INDEX = 2, DISPLAY_INDEX = 3, DESCRIPTION_INDEX = 4, CAUTION_INDEX = 5, WARNING_INDEX = 6;
var helper = new OptionHelper(line, 7);

id = helper.String(ID_INDEX);
enabled = helper.Boolean(ENABLED_INDEX, "Enabled");
file = helper.String(FILE_INDEX);
display = helper.String(DISPLAY_INDEX);
description = helper.String(DESCRIPTION_INDEX);
caution = helper.Boolean(CAUTION_INDEX, "Caution");
warning = helper.String(WARNING_INDEX);
id = helper.String(Index.ID);
enabled = helper.Boolean(Index.Enabled, "Enabled");
file = helper.String(Index.File);
display = helper.String(Index.Display);
description = helper.String(Index.Description);
caution = helper.Boolean(Index.Caution, "Caution");
warning = helper.String(Index.Warning);
}

public override string ToString()
Expand All @@ -33,8 +29,14 @@ public override string ToString()
result += $"\tfile: {file}\n";
result += $"\tenabled: {enabled}\n";
result += $"\tdescription: {description}\n";
result += $"\twarning: {warning}\n";

return result;
}

private enum Index
{
ID, Enabled, File, Display, Description, Caution, Warning
}
}
}
12 changes: 9 additions & 3 deletions SkyblockClient/Option/OptionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SkyblockClient.Option
{
Expand Down Expand Up @@ -50,10 +47,19 @@ public bool Boolean(int index, string name)
throw new ArgumentException($"Value of '{name}' is neither true or false");
}

public bool Boolean(Enum index, string name)
{
return Boolean(Convert.ToInt32(index), name);
}

public string String(int index)
{
return parts[index].Replace(@"\n", "\n").Trim();
}

public string String(Enum index)
{
return String(Convert.ToInt32(index));
}
}
}
26 changes: 12 additions & 14 deletions SkyblockClient/Option/ResourcepackOption.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SkyblockClient.Option
namespace SkyblockClient.Option
{
public class ResourcepackOption : IOption
{
Expand All @@ -17,15 +11,14 @@ public class ResourcepackOption : IOption

public void Create(string line)
{
const int ID_INDEX = 0, HIDDEN_INDEX = 1, ENABLED_INDEX = 2, FILE_INDEX = 3, DISPLAY_INDEX = 4, DESCRIPTION_INDEX = 5;
var helper = new OptionHelper(line, 6);

id = helper.String(ID_INDEX);
hidden = helper.Boolean(HIDDEN_INDEX, "Hidden");
enabled = helper.Boolean(ENABLED_INDEX, "Enabled");
file = helper.String(FILE_INDEX);
display = helper.String(DISPLAY_INDEX);
description = helper.String(DESCRIPTION_INDEX);
id = helper.String(Index.ID);
hidden = helper.Boolean(Index.Hidden, "Hidden");
enabled = helper.Boolean(Index.Enabled, "Enabled");
file = helper.String(Index.File);
display = helper.String(Index.Display);
description = helper.String(Index.Description);
}

public override string ToString()
Expand All @@ -38,5 +31,10 @@ public override string ToString()

return result;
}

private enum Index
{
ID, Hidden, Enabled, File, Display, Description
}
}
}
5 changes: 3 additions & 2 deletions SkyblockClient/SkyblockClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{2DEA9CD8-419E-4F59-82D9-D089DC282BB7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SkyblockClient</RootNamespace>
<AssemblyName>SkyblockClient-0.7</AssemblyName>
<AssemblyName>SkyblockClient-0.7.1</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand All @@ -28,13 +28,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
Expand Down
26 changes: 21 additions & 5 deletions SkyblockClient/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using System.Reflection;

namespace SkyblockClient
{
class Utils
{
private static TextWriter Out = Console.Out;
private static TextReader In = Console.In;

public static string exeLocation = Assembly.GetEntryAssembly().Location;

Expand All @@ -28,16 +28,32 @@ private static string logFileName

public static void Error(params string[] msgs)
{
Thread thread = new Thread(Error);
thread.Start(msgs);
}

private static void Error(object obj)
{
string[] msgs = (string[])obj;

Console.ForegroundColor = ConsoleColor.Red;
foreach (var msg in msgs)
Console.WriteLine(msg);
Out.WriteLine(msg);
Console.ResetColor();
}

public static void Info(params string[] msgs)
{
Thread thread = new Thread(Info);
thread.Start(msgs);
}

private static void Info(object obj)
{
string[] msgs = (string[])obj;

foreach (var msg in msgs)
Console.WriteLine(msg);
Out.WriteLine(msg);
}

public static Task InitLog()
Expand Down

0 comments on commit e11bf88

Please sign in to comment.