-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
455 additions
and
11 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
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
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,73 @@ | ||
<ui:UiWindow | ||
x:Class="GestureWheel.Dialogs.UpdateDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
Title="자동 업데이트" | ||
Width="400" | ||
Height="200" | ||
MinHeight="200" | ||
ExtendsContentIntoTitleBar="True" | ||
WindowBackdropType="Mica" | ||
WindowCornerPreference="Round" | ||
WindowStartupLocation="CenterScreen" | ||
mc:Ignorable="d"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid x:Name="RootMainGrid" Grid.Row="1"> | ||
<Border Background="{ui:ThemeResource ControlFillColorDefaultBrush}" CornerRadius="8,0,0,0"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="50" /> | ||
</Grid.RowDefinitions> | ||
|
||
<StackPanel Grid.Row="0" Margin="20,15,20,0"> | ||
<TextBlock x:Name="TextVersion" /> | ||
<ProgressBar | ||
x:Name="ProgressUpdate" | ||
Margin="0,20,0,0" | ||
Maximum="100" /> | ||
</StackPanel> | ||
|
||
<StackPanel | ||
Grid.Row="1" | ||
Margin="0,0,20,20" | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Bottom" | ||
Orientation="Horizontal"> | ||
|
||
<ui:Button | ||
x:Name="BtnCancel" | ||
Margin="0,0,10,0" | ||
Appearance="Secondary" | ||
Click="BtnCancel_Click" | ||
Content="취소" | ||
DockPanel.Dock="Right" | ||
Icon="Dismiss24" /> | ||
|
||
<ui:Button | ||
x:Name="BtnUpdate" | ||
Appearance="Primary" | ||
Click="BtnUpdate_Click" | ||
Content="업데이트" | ||
DockPanel.Dock="Right" | ||
Icon="ArrowDownload24" /> | ||
</StackPanel> | ||
</Grid> | ||
</Border> | ||
</Grid> | ||
|
||
<ui:TitleBar | ||
Title="자동 업데이트" | ||
Grid.Row="0" | ||
ShowMaximize="False" | ||
ShowMinimize="False" /> | ||
</Grid> | ||
</ui:UiWindow> |
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,69 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Windows; | ||
using GestureWheel.Extensions; | ||
using GestureWheel.Windows.Models; | ||
|
||
namespace GestureWheel.Dialogs | ||
{ | ||
public partial class UpdateDialog | ||
{ | ||
#region Properties | ||
private UpdateInfo Info { get; } | ||
#endregion | ||
|
||
public UpdateDialog(UpdateInfo info) | ||
{ | ||
Info = info; | ||
InitializeComponent(); | ||
|
||
TextVersion.Text = $"새로운 버전이 출시되었습니다.\n{nameof(GestureWheel)}을 {info.Version} 버전으로 업데이트 하시겠습니까?"; | ||
} | ||
|
||
private async void BtnUpdate_Click(object sender, RoutedEventArgs e) | ||
{ | ||
BtnCancel.IsEnabled = false; | ||
BtnUpdate.IsEnabled = false; | ||
|
||
var fileName = Path.Combine(Path.GetTempPath(), Info.FileName); | ||
|
||
using (var client = new HttpClient()) | ||
await using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) | ||
{ | ||
var progress = new Progress<double>(); | ||
|
||
progress.ProgressChanged += (_, value) => | ||
{ | ||
Dispatcher.Invoke(() => ProgressUpdate.Value = value); | ||
}; | ||
|
||
await client.DownloadAsync(Info.Url, file, progress); | ||
} | ||
|
||
try | ||
{ | ||
Process.Start(new ProcessStartInfo(fileName) | ||
{ | ||
UseShellExecute = true | ||
}); | ||
|
||
Application.Current.Shutdown(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
finally | ||
{ | ||
Close(); | ||
} | ||
} | ||
|
||
private void BtnCancel_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Close(); | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace GestureWheel.Extensions | ||
{ | ||
internal static class HttpClientExtensions | ||
{ | ||
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<double> progress = null, CancellationToken cancellationToken = default) | ||
{ | ||
using var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken); | ||
|
||
var contentLength = response.Content.Headers.ContentLength; | ||
await using var download = await response.Content.ReadAsStreamAsync(cancellationToken); | ||
|
||
if (progress is null || !contentLength.HasValue) | ||
{ | ||
await download.CopyToAsync(destination, cancellationToken); | ||
return; | ||
} | ||
|
||
var relativeProgress = new Progress<long>(totalBytes => progress.Report((double)totalBytes / contentLength.Value * 100)); | ||
await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken); | ||
|
||
progress.Report(100); | ||
} | ||
} | ||
} |
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,39 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace GestureWheel.Extensions | ||
{ | ||
internal static class StreamExtensions | ||
{ | ||
public static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<long> progress = null, CancellationToken cancellationToken = default) | ||
{ | ||
if (source == null) | ||
throw new ArgumentNullException(nameof(source)); | ||
|
||
if (!source.CanRead) | ||
throw new ArgumentException("Has to be readable", nameof(source)); | ||
|
||
if (destination == null) | ||
throw new ArgumentNullException(nameof(destination)); | ||
|
||
if (!destination.CanWrite) | ||
throw new ArgumentException("Has to be writable", nameof(destination)); | ||
|
||
if (bufferSize < 0) | ||
throw new ArgumentOutOfRangeException(nameof(bufferSize)); | ||
|
||
var buffer = new byte[bufferSize]; | ||
long totalBytesRead = 0; | ||
int bytesRead; | ||
|
||
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0) | ||
{ | ||
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false); | ||
totalBytesRead += bytesRead; | ||
progress?.Report(totalBytesRead); | ||
} | ||
} | ||
} | ||
} |
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
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
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; | ||
|
||
namespace GestureWheel.Windows.Models | ||
{ | ||
public class UpdateInfo | ||
{ | ||
public string Version { get; set; } | ||
|
||
public DateTime Timestamp { get; set; } | ||
|
||
public string ReleaseNote { get; set; } | ||
|
||
public string FileName { get; set; } | ||
|
||
public string Url { 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
Oops, something went wrong.