Repository navigation
Expand file tree
/
Copy pathAnimatedGifWindow.cs
More file actions
103 lines (88 loc) · 3.43 KB
/
Copy pathAnimatedGifWindow.cs
File metadata and controls
103 lines (88 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#if !MONO
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shell;
using WpfAnimatedGif;
namespace Squirrel.Update
{
public class AnimatedGifWindow : Window
{
public AnimatedGifWindow()
{
var img = new Image();
var src = default(BitmapImage);
var executionLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var source = Path.Combine(
executionLocation,
"background.gif");
if (File.Exists(source)) {
src = new BitmapImage();
src.BeginInit();
src.StreamSource = File.OpenRead(source);
src.EndInit();
ImageBehavior.SetAnimatedSource(img, src);
this.Content = img;
this.Width = src.Width;
this.Height = src.Height;
}
var setupIcon = Path.Combine(executionLocation, "setupIcon.ico");
if (File.Exists(setupIcon)) {
Icon = BitmapFrame.Create(new Uri(setupIcon, UriKind.Relative));
}
this.AllowsTransparency = true;
this.WindowStyle = WindowStyle.None;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.ShowInTaskbar = true;
this.Topmost = true;
this.TaskbarItemInfo = new TaskbarItemInfo {
ProgressState = TaskbarItemProgressState.Normal
};
this.Title = "Installing...";
this.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
}
public static void ShowWindow(TimeSpan initialDelay, CancellationToken token, ProgressSource progressSource)
{
var wnd = default(AnimatedGifWindow);
var thread = new Thread(() => {
if (token.IsCancellationRequested) return;
try {
Task.Delay(initialDelay, token).ContinueWith(t => { return true; }).Wait();
} catch (Exception) {
return;
}
wnd = new AnimatedGifWindow();
wnd.Show();
Task.Delay(TimeSpan.FromSeconds(5.0), token).ContinueWith(t => {
if (t.IsCanceled) return;
wnd.Dispatcher.BeginInvoke(new Action(() => wnd.Topmost = false));
});
token.Register(() => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close)));
EventHandler<int> progressSourceOnProgress = ((sender, p) =>
wnd.Dispatcher.BeginInvoke(
new Action(() => wnd.TaskbarItemInfo.ProgressValue = p/100.0)));
progressSource.Progress += progressSourceOnProgress;
try {
(new Application()).Run(wnd);
} finally {
progressSource.Progress -= progressSourceOnProgress;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
this.DragMove();
}
}
}
#endif