Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuOfficial committed May 30, 2021
1 parent 1923083 commit 1e826a8
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 103 deletions.
27 changes: 6 additions & 21 deletions BetacraftLauncher.Library/LanguageEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,26 @@ namespace BetacraftLauncher.Library
{
public class LanguageEndpoint : ILanguageEndpoint
{
//private string languagePath { get; } = Environment.GetEnvironmentVariable("APPDATA") + @"\.betacraftlegacy\launcher\lang\lang.txt";
private string languagePath { get; } = Environment.GetEnvironmentVariable("APPDATA") + @"\.betacraftlegacy\launcher\lang\";
public async Task<List<LanguageModel>> GetLanguages()
{
try
using (var webClient = new WebClient())
{
using (var webClient = new WebClient())
{
string versionList = await webClient.DownloadStringTaskAsync("https://betacraft.pl/lang/1.09_11/");
string versionList = await webClient.DownloadStringTaskAsync("https://betacraft.pl/lang/1.09_11/");

return await LanguageFileManager(versionList);
}
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
return await LanguageFileManager(versionList);
}
}

public async Task DownloadLanguage(string languageName)
{
try
if (!File.Exists($@"{languagePath}\{languageName}.txt"))
{
if (!File.Exists($@"{languagePath}\{languageName}.txt"))
using (var webClient = new WebClient())
{
using (var webClient = new WebClient())
{
await webClient.DownloadFileTaskAsync($@"https://betacraft.pl/lang/1.09_11/{languageName}.txt", $@"{languagePath}\{languageName}.txt");
}
await webClient.DownloadFileTaskAsync($@"https://betacraft.pl/lang/1.09_11/{languageName}.txt", $@"{languagePath}\{languageName}.txt");
}
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}

private async Task<List<LanguageModel>> LanguageFileManager(string languageList)
Expand Down
14 changes: 3 additions & 11 deletions BetacraftLauncher.Library/VersionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ public class VersionEndpoint : IVersionEndpoint

public async Task<List<VersionModel>> GetVersions()
{
try
using (var webClient = new WebClient())
{
using (var webClient = new WebClient())
{
string versionList = await webClient.DownloadStringTaskAsync("https://files.betacraft.pl/launcher/assets/version_list.txt");
string versionList = await webClient.DownloadStringTaskAsync("https://files.betacraft.pl/launcher/assets/version_list.txt");

return await VersionListFileManager(versionList);
}
}
catch (Exception ex)
{

throw new Exception(ex.ToString());
return await VersionListFileManager(versionList);
}
}

Expand Down
7 changes: 7 additions & 0 deletions BetacraftLauncher.Tests/BetacraftLauncher.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
39 changes: 0 additions & 39 deletions BetacraftLauncher.Tests/VersionEndpointTests.cs

This file was deleted.

3 changes: 3 additions & 0 deletions BetacraftLauncher.Tests/xunit.runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"methodDisplay": "method"
}
10 changes: 5 additions & 5 deletions BetacraftLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetacraftLauncher", "Betacr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetacraftLauncher.Library", "BetacraftLauncher.Library\BetacraftLauncher.Library.csproj", "{7C4E42C8-12EF-4514-9584-7CAE8FFEA02D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetacraftLauncher.Tests", "BetacraftLauncher.Tests\BetacraftLauncher.Tests.csproj", "{D0F124BD-73CA-4653-979D-4C756CF87FD7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetacraftLauncher.Tests", "BetacraftLauncher.Tests\BetacraftLauncher.Tests.csproj", "{25EC4C9E-876F-4454-8C46-DE6D27074C9A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -23,10 +23,10 @@ Global
{7C4E42C8-12EF-4514-9584-7CAE8FFEA02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C4E42C8-12EF-4514-9584-7CAE8FFEA02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C4E42C8-12EF-4514-9584-7CAE8FFEA02D}.Release|Any CPU.Build.0 = Release|Any CPU
{D0F124BD-73CA-4653-979D-4C756CF87FD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0F124BD-73CA-4653-979D-4C756CF87FD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0F124BD-73CA-4653-979D-4C756CF87FD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0F124BD-73CA-4653-979D-4C756CF87FD7}.Release|Any CPU.Build.0 = Release|Any CPU
{25EC4C9E-876F-4454-8C46-DE6D27074C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25EC4C9E-876F-4454-8C46-DE6D27074C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25EC4C9E-876F-4454-8C46-DE6D27074C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25EC4C9E-876F-4454-8C46-DE6D27074C9A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 0 additions & 22 deletions BetacraftLauncher/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ private IMapper ConfigureAutomapper()
return output;
}

// private IConfiguration AddConfiguration()
// {
// IConfigurationBuilder builder = new ConfigurationBuilder()
// .SetBasePath(Directory.GetCurrentDirectory())
// .AddJsonFile("appsettings.json");

//#if DEBUG
// builder.AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true);
//#else
// builder.AddJsonFile("appsettings.production.json", optional: true, reloadOnChange: true);
//#endif

// return builder.Build();
// }

private IConfiguration AddConfiguration()
{
IConfigurationBuilder builder = new ConfigurationBuilder()
Expand All @@ -75,17 +60,12 @@ protected override void Configure()
.PerRequest<IFileInit, FileInit>()
.PerRequest<ILaunchManager, LaunchManager>()
.PerRequest<ILanguageEndpoint, LanguageEndpoint>();
// .PerRequest<IProductEndpoint, ProductEndpoint>()
// .PerRequest<IUserEndpoint, UserEndpoint>()
// .PerRequest<ISaleEndpoint, SaleEndpoint>();

_container
.Singleton<IWindowManager, WindowManager>()
.Singleton<IEventAggregator, EventAggregator>()
.Singleton<ILog, LogHelper>()
.Singleton<IDiscordRPCManager, DiscordRPCManager>();
//.Singleton<ILoggedInUserModel, LoggedInUserModel>()
//.Singleton<IAPIHelper, APIHelper>();

_container.RegisterInstance(typeof(IConfiguration), "IConfiguration", AddConfiguration());

Expand All @@ -96,8 +76,6 @@ protected override void Configure()
.ForEach(viewModelType => _container.RegisterPerRequest(
viewModelType, viewModelType.ToString(), viewModelType));
}

//protected override void OnStartup(object sender, StartupEventArgs e) => DisplayRootViewFor<ShellViewModel>();
protected override void OnStartup(object sender, StartupEventArgs e)
{
var fileInit = IoC.Get<IFileInit>();
Expand Down
2 changes: 1 addition & 1 deletion BetacraftLauncher/ViewModels/InstanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task SubmitSettings()

if (RPC == false)
{
//discordRPC.Deinitialize();
discordRPC.Deinitialize();
}
else
{
Expand Down
1 change: 0 additions & 1 deletion BetacraftLauncher/ViewModels/LanguageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private async Task LoadLanguages()
public async Task SelectLanguage()
{
SaveLanguageSettings();
//await events.PublishOnUIThreadAsync(new SelectVersionEvent { CurrentVersionMessage = SelectedVersion.Version });

await languageEndpoint.DownloadLanguage(SelectedLanguage.Language);

Expand Down
2 changes: 1 addition & 1 deletion BetacraftLauncher/ViewModels/LauncherViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task Play()

SaveUsername();

await this.dwVersionEndpoint.DownloadVersion(CurrentVersion);
await dwVersionEndpoint.DownloadVersion(CurrentVersion);

await launchManager.LaunchGame(CurrentVersion, Nickname, InstanceName, GameWidth.ToString(), GameHeight.ToString(), Arguments);

Expand Down
8 changes: 6 additions & 2 deletions BetacraftLauncher/ViewModels/VersionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -89,9 +90,12 @@ public async Task SelectVersion()
{
SaveVersionSettings();

await events.PublishOnUIThreadAsync(new SelectVersionEvent { CurrentVersionMessage = SelectedVersion.Version });
if (SelectedVersion != null)
{
await events.PublishOnUIThreadAsync(new SelectVersionEvent { CurrentVersionMessage = SelectedVersion.Version });

logger.Info($"Version selected: {SelectedVersion.Version}");
logger.Info($"Version selected: {SelectedVersion.Version}");
}

await TryCloseAsync();
}
Expand Down

0 comments on commit 1e826a8

Please sign in to comment.