diff --git a/BetacraftLauncher.Library/LanguageEndpoint.cs b/BetacraftLauncher.Library/LanguageEndpoint.cs index 1dd0c5c..c3f5ae4 100644 --- a/BetacraftLauncher.Library/LanguageEndpoint.cs +++ b/BetacraftLauncher.Library/LanguageEndpoint.cs @@ -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> 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> LanguageFileManager(string languageList) diff --git a/BetacraftLauncher.Library/VersionEndpoint.cs b/BetacraftLauncher.Library/VersionEndpoint.cs index 92f2f07..e37188f 100644 --- a/BetacraftLauncher.Library/VersionEndpoint.cs +++ b/BetacraftLauncher.Library/VersionEndpoint.cs @@ -19,19 +19,11 @@ public class VersionEndpoint : IVersionEndpoint public async Task> 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); } } diff --git a/BetacraftLauncher.Tests/BetacraftLauncher.Tests.csproj b/BetacraftLauncher.Tests/BetacraftLauncher.Tests.csproj index c86ba77..f36e810 100644 --- a/BetacraftLauncher.Tests/BetacraftLauncher.Tests.csproj +++ b/BetacraftLauncher.Tests/BetacraftLauncher.Tests.csproj @@ -4,8 +4,15 @@ net5.0 + + x64 + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BetacraftLauncher.Tests/VersionEndpointTests.cs b/BetacraftLauncher.Tests/VersionEndpointTests.cs deleted file mode 100644 index 7a1dec3..0000000 --- a/BetacraftLauncher.Tests/VersionEndpointTests.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Xunit; - -namespace BetacraftLauncher.Tests -{ - public class VersionEndpointTests - { - [Fact] - public async void AddToList_ShouldAdd() - { - try - { - using (var webClient = new WebClient()) - { - string result = await webClient.DownloadStringTaskAsync(new Uri("https://files.betacraft.pl/launcher/assets/version_list.txt")); - - List s = new(); - - foreach (var line in result) - { - s.Add(result); - } - - Assert.Equal("x", result); - } - } - catch (Exception ex) - { - - throw new Exception(ex.ToString()); - } - } - } -} diff --git a/BetacraftLauncher.Tests/xunit.runner b/BetacraftLauncher.Tests/xunit.runner new file mode 100644 index 0000000..e64353f --- /dev/null +++ b/BetacraftLauncher.Tests/xunit.runner @@ -0,0 +1,3 @@ +{ + "methodDisplay": "method" +} diff --git a/BetacraftLauncher.sln b/BetacraftLauncher.sln index abb162b..77bd8c1 100644 --- a/BetacraftLauncher.sln +++ b/BetacraftLauncher.sln @@ -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 @@ -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 diff --git a/BetacraftLauncher/Bootstrapper.cs b/BetacraftLauncher/Bootstrapper.cs index 483c3a3..dd7a065 100644 --- a/BetacraftLauncher/Bootstrapper.cs +++ b/BetacraftLauncher/Bootstrapper.cs @@ -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() @@ -75,17 +60,12 @@ protected override void Configure() .PerRequest() .PerRequest() .PerRequest(); - // .PerRequest() - // .PerRequest() - // .PerRequest(); _container .Singleton() .Singleton() .Singleton() .Singleton(); - //.Singleton() - //.Singleton(); _container.RegisterInstance(typeof(IConfiguration), "IConfiguration", AddConfiguration()); @@ -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(); protected override void OnStartup(object sender, StartupEventArgs e) { var fileInit = IoC.Get(); diff --git a/BetacraftLauncher/ViewModels/InstanceViewModel.cs b/BetacraftLauncher/ViewModels/InstanceViewModel.cs index b54b7d3..c0c021b 100644 --- a/BetacraftLauncher/ViewModels/InstanceViewModel.cs +++ b/BetacraftLauncher/ViewModels/InstanceViewModel.cs @@ -118,7 +118,7 @@ public async Task SubmitSettings() if (RPC == false) { - //discordRPC.Deinitialize(); + discordRPC.Deinitialize(); } else { diff --git a/BetacraftLauncher/ViewModels/LanguageViewModel.cs b/BetacraftLauncher/ViewModels/LanguageViewModel.cs index a1dbe4b..b8ee1ae 100644 --- a/BetacraftLauncher/ViewModels/LanguageViewModel.cs +++ b/BetacraftLauncher/ViewModels/LanguageViewModel.cs @@ -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); diff --git a/BetacraftLauncher/ViewModels/LauncherViewModel.cs b/BetacraftLauncher/ViewModels/LauncherViewModel.cs index d4ca9f5..4aae28d 100644 --- a/BetacraftLauncher/ViewModels/LauncherViewModel.cs +++ b/BetacraftLauncher/ViewModels/LauncherViewModel.cs @@ -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); diff --git a/BetacraftLauncher/ViewModels/VersionViewModel.cs b/BetacraftLauncher/ViewModels/VersionViewModel.cs index ae6af65..adfcc31 100644 --- a/BetacraftLauncher/ViewModels/VersionViewModel.cs +++ b/BetacraftLauncher/ViewModels/VersionViewModel.cs @@ -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; @@ -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(); }