mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
implemented async formats update.
This commit is contained in:
parent
d8eb3aed1a
commit
653ee4685d
@ -178,6 +178,9 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateDialog m_dialog;
|
||||||
|
Uri m_formats_url;
|
||||||
|
|
||||||
private void ShowUpdateResult (GarUpdateInfo result)
|
private void ShowUpdateResult (GarUpdateInfo result)
|
||||||
{
|
{
|
||||||
var app_version = Assembly.GetExecutingAssembly().GetName().Version;
|
var app_version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
@ -189,14 +192,16 @@ namespace GARbro.GUI
|
|||||||
m_main.SetStatusText (guiStrings.MsgUpToDate);
|
m_main.SetStatusText (guiStrings.MsgUpToDate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var dialog = new UpdateDialog (result, has_app_update, has_db_update);
|
m_formats_url = result.FormatsUrl;
|
||||||
dialog.Owner = m_main;
|
m_dialog = new UpdateDialog (result, has_app_update, has_db_update);
|
||||||
dialog.FormatsDownload.Click += (s, a) => StartFormatsDownload (dialog, result.FormatsUrl);
|
m_dialog.Owner = m_main;
|
||||||
dialog.ShowDialog();
|
m_dialog.FormatsDownload.Click += StartFormatsDownload;
|
||||||
|
m_dialog.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartFormatsDownload (UpdateDialog dialog, Uri formats_url)
|
private async void StartFormatsDownload (object control, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
var dialog = m_dialog;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dialog.FormatsDownload.IsEnabled = false;
|
dialog.FormatsDownload.IsEnabled = false;
|
||||||
@ -206,26 +211,35 @@ namespace GARbro.GUI
|
|||||||
using (var tmp_file = new GARbro.Shell.TemporaryFile (app_data_folder, Path.GetRandomFileName()))
|
using (var tmp_file = new GARbro.Shell.TemporaryFile (app_data_folder, Path.GetRandomFileName()))
|
||||||
{
|
{
|
||||||
client.Timeout = RequestTimeout;
|
client.Timeout = RequestTimeout;
|
||||||
// FIXME download blocks GUI thread.
|
await client.DownloadFileTaskAsync (m_formats_url, tmp_file.Name);
|
||||||
client.DownloadFile (formats_url, tmp_file.Name);
|
|
||||||
|
|
||||||
m_main.App.DeserializeScheme (tmp_file.Name);
|
m_main.App.DeserializeScheme (tmp_file.Name);
|
||||||
var local_formats_dat = Path.Combine (app_data_folder, App.FormatsDat);
|
var local_formats_dat = Path.Combine (app_data_folder, App.FormatsDat);
|
||||||
if (!GARbro.Shell.File.Rename (tmp_file.Name, local_formats_dat))
|
if (!GARbro.Shell.File.Rename (tmp_file.Name, local_formats_dat))
|
||||||
throw new Win32Exception (GARbro.Shell.File.GetLastError());
|
throw new Win32Exception (GARbro.Shell.File.GetLastError());
|
||||||
}
|
}
|
||||||
dialog.FormatsUpdateText.Text = guiStrings.MsgUpdateComplete;
|
SetFormatsUpdateStatus (dialog, guiStrings.MsgUpdateComplete);
|
||||||
}
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
dialog.FormatsUpdateText.Text = string.Format ("{0}\n{1}", guiStrings.MsgDownloadFailed, X.Message);
|
SetFormatsUpdateStatus (dialog, guiStrings.MsgDownloadFailed, X.Message);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
dialog.FormatsDownload.Visibility = Visibility.Collapsed;
|
dialog.FormatsDownload.Visibility = Visibility.Hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetFormatsUpdateStatus (UpdateDialog dialog, string text1, string text2 = null)
|
||||||
|
{
|
||||||
|
if (dialog.IsClosed)
|
||||||
|
m_main.SetStatusText (text1);
|
||||||
|
else if (null == text2)
|
||||||
|
dialog.FormatsUpdateText.Text = text1;
|
||||||
|
else
|
||||||
|
dialog.FormatsUpdateText.Text = string.Format ("{0}\n{1}", text1, text2);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if loaded assemblies match required versions.
|
/// Check if loaded assemblies match required versions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -15,8 +15,11 @@ namespace GARbro.GUI
|
|||||||
if (string.IsNullOrEmpty (info.ReleaseNotes))
|
if (string.IsNullOrEmpty (info.ReleaseNotes))
|
||||||
this.ReleaseNotes.Visibility = Visibility.Collapsed;
|
this.ReleaseNotes.Visibility = Visibility.Collapsed;
|
||||||
this.DataContext = info;
|
this.DataContext = info;
|
||||||
|
this.Closed += (s, e) => IsClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsClosed { get; private set; }
|
||||||
|
|
||||||
private void Hyperlink_RequestNavigate (object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
|
private void Hyperlink_RequestNavigate (object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
|
||||||
{
|
{
|
||||||
if (App.NavigateUri (e.Uri))
|
if (App.NavigateUri (e.Uri))
|
||||||
|
Loading…
Reference in New Issue
Block a user