-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from Legi428/AsyncReleasesDL
Fix issues with fetching updates of Unity versions by using the new Api
- Loading branch information
Showing
15 changed files
with
531 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace UnityLauncherPro | ||
{ | ||
public readonly struct DownloadProgress | ||
{ | ||
public long TotalRead { get; } | ||
public long TotalBytes { get; } | ||
|
||
public DownloadProgress(long totalRead, long totalBytes) | ||
{ | ||
TotalRead = totalRead; | ||
TotalBytes = totalBytes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UnityLauncherPro | ||
{ | ||
public class UnityVersion | ||
{ | ||
[JsonPropertyName("version")] | ||
public string Version { get; set; } | ||
[JsonPropertyName("stream")] | ||
[JsonConverter(typeof(UnityVersionStreamConverter))] | ||
public UnityVersionStream Stream { get; set; } | ||
[JsonPropertyName("releaseDate")] | ||
public DateTime ReleaseDate { get; set; } | ||
} | ||
|
||
public class UnityVersionStreamConverter : JsonConverter<UnityVersionStream> | ||
{ | ||
public override UnityVersionStream Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
string streamString = reader.GetString(); | ||
if (Enum.TryParse<UnityVersionStream>(streamString, true, out var result)) | ||
{ | ||
return result; | ||
} | ||
throw new JsonException($"Unable to convert \"{streamString}\" to UnityVersionStream"); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, UnityVersionStream value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString().ToUpper()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UnityLauncherPro | ||
{ | ||
public class UnityVersionResponse | ||
{ | ||
[JsonPropertyName("offset")] | ||
public int Offset { get; set; } | ||
[JsonPropertyName("limit")] | ||
public int Limit { get; set; } | ||
[JsonPropertyName("total")] | ||
public int Total { get; set; } | ||
[JsonPropertyName("results")] | ||
public List<UnityVersion> Results { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace UnityLauncherPro | ||
{ | ||
public enum UnityVersionStream | ||
{ | ||
Alpha, | ||
Beta, | ||
LTS, | ||
Tech | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Window x:Class="UnityLauncherPro.DownloadProgressWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
Title="Download Progress" Height="70" Width="500" | ||
ResizeMode="NoResize" | ||
WindowStyle="None" | ||
PreviewLostKeyboardFocus="Window_PreviewLostKeyboardFocus" | ||
Background="{DynamicResource ThemeDarkestBackground}"> | ||
<Grid> | ||
<Grid> | ||
<Label Content="{Binding Title, RelativeSource={RelativeSource AncestorType=Window}, FallbackValue=Title}" IsHitTestVisible="False" Margin="5,0,0,-5" Foreground="{DynamicResource ThemeMainTitle}" FontSize="12" HorizontalAlignment="Left" /> | ||
<Button BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Click="CancelDownloadClick" Padding="0,2" IsTabStop="False"> | ||
<TextBlock Text="❌" FontSize="10" Foreground="{DynamicResource ThemeWindowMinClose}" Padding="5,3,4,4" HorizontalAlignment="Center" /> | ||
</Button> | ||
</Grid> | ||
<Grid VerticalAlignment="Bottom" Background="{DynamicResource ThemeMainBackgroundColor}"> | ||
<ProgressBar x:Name="ProgressBar" Height="23" VerticalAlignment="Center" Margin="10, 10, 70, 10"/> | ||
<TextBlock x:Name="ProgressText" Text="0%" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10, 10, 70, 10"/> | ||
<Button Style="{StaticResource CustomButton}" Content="Cancel" Width="50" Height="23" HorizontalAlignment="Right" Margin="10" Click="CancelDownloadClick"/> | ||
</Grid> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
|
||
namespace UnityLauncherPro | ||
{ | ||
public partial class DownloadProgressWindow | ||
{ | ||
private readonly Action _cancelAction; | ||
private readonly string _subjectName; | ||
private static MainWindow MainWindow => Tools.mainWindow; | ||
|
||
public DownloadProgressWindow(string subjectName, Action cancelAction = null) | ||
{ | ||
InitializeComponent(); | ||
_subjectName = subjectName; | ||
Title = subjectName; | ||
_cancelAction = cancelAction; | ||
Topmost = true; | ||
Owner = MainWindow; | ||
WindowStartupLocation = WindowStartupLocation.CenterOwner; | ||
MainWindow.IsEnabled = false; | ||
} | ||
|
||
public void UpdateProgress(DownloadProgress downloadProgress) | ||
{ | ||
Title = $"Downloading {_subjectName} ({downloadProgress.TotalRead / 1024d / 1024d:F1} MB / {downloadProgress.TotalBytes / 1024d / 1024d:F1} MB)"; | ||
var progress = downloadProgress.TotalBytes == 0 ? 0 : downloadProgress.TotalRead * 100d / downloadProgress.TotalBytes; | ||
ProgressBar.Value = progress; | ||
ProgressText.Text = $"{progress / 100:P1}"; | ||
} | ||
|
||
private void CancelDownloadClick(object sender, RoutedEventArgs e) | ||
{ | ||
CancelDownload(); | ||
} | ||
|
||
private void CancelDownload() | ||
{ | ||
_cancelAction?.Invoke(); | ||
} | ||
|
||
private void Window_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) | ||
{ | ||
var window = (Window)sender; | ||
window.Topmost = true; | ||
} | ||
|
||
protected override void OnClosed(EventArgs e) | ||
{ | ||
base.OnClosed(e); | ||
_cancelAction?.Invoke(); | ||
MainWindow.IsEnabled = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.