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