|
@@ -8,7 +8,9 @@ using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
+using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
+using VeloeMinecraftLauncher.Entity.Version;
|
|
|
using VeloeMinecraftLauncher.Entity.VersionManifest;
|
|
|
using VeloeMinecraftLauncher.MinecraftLauncher;
|
|
|
using VeloeMinecraftLauncher.Models.Entity;
|
|
@@ -18,7 +20,7 @@ namespace VeloeMinecraftLauncher.ViewModels;
|
|
|
|
|
|
public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
{
|
|
|
- private string _startButton = "Download";
|
|
|
+ private string _installModpackButtonText = "Download Modpack";
|
|
|
private bool _showOld = false;
|
|
|
private bool _showSnaps = false;
|
|
|
private bool _installFabric = false;
|
|
@@ -127,7 +129,29 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
public Modpack SelectedModpack
|
|
|
{
|
|
|
get => _selectedModpack;
|
|
|
- set => this.RaiseAndSetIfChanged(ref _selectedModpack, value);
|
|
|
+ set
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (System.IO.File.Exists(Settings.minecraftForlderPath + $"versions/{value.Name}/revision.json"))
|
|
|
+ {
|
|
|
+ if (value.Revision > JsonSerializer.Deserialize<int>(System.IO.File.ReadAllText(Settings.minecraftForlderPath + $"versions/{value.Name}/revision.json")))
|
|
|
+ InstallModpackButtonText = "Update Modpack";
|
|
|
+ else
|
|
|
+ InstallModpackButtonText = "Reinstall Modpack";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if (System.IO.Directory.Exists($"{Settings.minecraftForlderPath}versions/{value.Name}") && System.IO.File.Exists($"{Settings.minecraftForlderPath}versions/{value.Name}/{value.Name}.json"))
|
|
|
+ InstallModpackButtonText = "Update Modpack";
|
|
|
+ else
|
|
|
+ InstallModpackButtonText = "Download Modpack";
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ InstallModpackButtonText = "Update Modpack";
|
|
|
+ }
|
|
|
+ this.RaiseAndSetIfChanged(ref _selectedModpack, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public ObservableCollection<Entity.VersionManifest.Version> FilteredVersions
|
|
@@ -142,10 +166,10 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
set => this.RaiseAndSetIfChanged(ref _modpackVersions, value);
|
|
|
}
|
|
|
|
|
|
- public string StartButton
|
|
|
+ public string InstallModpackButtonText
|
|
|
{
|
|
|
- get => _startButton;
|
|
|
- set => this.RaiseAndSetIfChanged(ref _startButton, value);
|
|
|
+ get => _installModpackButtonText;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _installModpackButtonText, value);
|
|
|
}
|
|
|
|
|
|
public bool ShowOld
|
|
@@ -256,6 +280,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
|
|
|
public async Task OnStartBunttonClick()
|
|
|
{
|
|
|
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
Task.Run(() => {
|
|
|
|
|
|
if (FilteredVersion is null)
|
|
@@ -278,12 +303,20 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
InstallForgeOptifine,
|
|
|
InstallFabric);
|
|
|
return TaskStatus.RanToCompletion; });
|
|
|
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
}
|
|
|
|
|
|
public async void OnStartModpackBunttonClick()
|
|
|
{
|
|
|
+ if (SelectedModpack is null)
|
|
|
+ return;
|
|
|
+
|
|
|
FilteredVersion = FilteredVersions.Where(x => x.Id == SelectedModpack.Version).FirstOrDefault();
|
|
|
|
|
|
+ if (FilteredVersion is null)
|
|
|
+ return;
|
|
|
+
|
|
|
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
Task.Run(() => Downloader.StartDownloadModpack(
|
|
|
value => DownloadingFileName = value,
|
|
|
value => IsControlsEnabled = value,
|
|
@@ -296,6 +329,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
InstallForge = SelectedModpack.Forge,
|
|
|
InstallOptifine = SelectedModpack.Optifine,
|
|
|
InstallForgeOptifine = SelectedModpack.ForgeOptifine));
|
|
|
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
}
|
|
|
|
|
|
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
|
@@ -312,11 +346,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
if (_versionManifest.Versions is null)
|
|
|
return;
|
|
|
|
|
|
- foreach (var version in _versionManifest.Versions)
|
|
|
- {
|
|
|
- if (ShowSnaps && version.Type == "snapshot" || ShowOld && version.Type is ("old_alpha" or "old_beta") || version.Type == "release")
|
|
|
- FilteredVersions.Add(version);
|
|
|
- }
|
|
|
+ FilteredVersions.AddRange(_versionManifest.Versions.Where(version => ShowSnaps && version.Type == "snapshot" || ShowOld && version.Type is ("old_alpha" or "old_beta") || version.Type == "release"));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|