77using  System . Drawing ; 
88using  System . IO ; 
99using  System . Security . Cryptography ; 
10+ using  System . Security . Permissions ; 
1011using  System . Text ; 
1112using  System . Threading ; 
1213using  System . Windows . Forms ; 
@@ -27,39 +28,40 @@ private void Instance_CheckForUpdatesCompleted(object sender, CheckForUpdatesCom
2728        { 
2829            this . InvokeOnUI ( ( )  =>  checkForUpdatesToolStripMenuItem . Enabled  =  true ) ; 
2930
30-             if  ( e . Cancelled  ||  e . Error  !=  null ) 
31-             { 
32-                 this . InvokeOnUI ( ( )  =>  MessageDialog . Show ( 
33-                     this , 
34-                     "Updater" , 
35-                     e . Cancelled  ?  "Cancelled"  :  "Error" , 
36-                     e . Cancelled  ?  "Update got cancelled"  :  "Please check the logs for more information." , 
37-                     e . Cancelled  ?  SystemIcons . Warning  :  SystemIcons . Error , 
38-                     MessageBoxButtons . OK ) ) ; 
39- 
40-                 return ; 
41-             } 
42- 
43-             if  ( ! e . UpdateAvailable ) 
44-             { 
45-                 this . InvokeOnUI ( ( )  => 
46-                 MessageDialog . Show ( 
47-                     this , 
48-                     "Updater" , 
49-                     "No update available!" , 
50-                     $ "You already have the latest version ({ e . LatestVersion } ).", 
51-                     SystemIcons . Information , 
52-                     MessageBoxButtons . OK ) ) ; 
53- 
54-                 return ; 
55-             } 
31+             // if (e.Cancelled || e.Error != null)
32+             // {
33+             //     this.InvokeOnUI(() => MessageDialog.Show(
34+             //         this,
35+             //         "Updater",
36+             //         e.Cancelled ? "Cancelled" : "Error",
37+             //         e.Cancelled ? "Update got cancelled" : "Please check the logs for more information.",
38+             //         e.Cancelled ? SystemIcons.Warning : SystemIcons.Error,
39+             //         MessageBoxButtons.OK));
40+ 
41+             //     return;
42+             // }
43+ 
44+             // if (!e.UpdateAvailable)
45+             // {
46+             //     this.InvokeOnUI(() =>
47+             //     MessageDialog.Show(
48+             //         this,
49+             //         "Updater",
50+             //         "No update available!",
51+             //         $"You already have the latest version ({e.LatestVersion}).",
52+             //         SystemIcons.Information,
53+             //         MessageBoxButtons.OK));
54+ 
55+             //     return;
56+             // }
5657        } 
5758
5859        private  void  checkForUpdatesToolStripMenuItem_Click ( object  sender ,  EventArgs  e ) 
5960        { 
6061            checkForUpdatesToolStripMenuItem . Enabled  =  false ; 
6162
62-             Updater . Instance . CheckForUpdatesAsync ( ) ; 
63+             AsyncTask  task  =  Updater . Instance . CheckForUpdatesAsync ( ) ; 
64+             //task.Cancel(); 
6365        } 
6466
6567        private  void  Form1_Load ( object  sender ,  EventArgs  e ) 
@@ -79,6 +81,7 @@ private string ReadFile(string file)
7981            return  string . Join ( ", " ,  lines ) ; 
8082        } 
8183
84+         FileStream  fs ; 
8285        /// <summary> 
8386        /// Bad code that keeps the file open & locked 
8487        /// Purpose: to demonstrate the updater still works on locked files. 
@@ -90,18 +93,23 @@ private string ReadFileAndKeepStreamOpen(string file)
9093            if  ( ! File . Exists ( file ) ) 
9194                return  "ERROR: File doesn't exist.." ; 
9295
93-             FileStream   fs  =  new  FileStream ( file ,  FileMode . Open ,  FileAccess . ReadWrite ,  FileShare . None ) ; 
96+             fs  =  new  FileStream ( file ,  FileMode . Open ,  FileAccess . ReadWrite ,  FileShare . None ) ; 
9497            StreamReader  sr  =  new  StreamReader ( fs ) ; 
9598            string  text  =  sr . ReadToEnd ( ) ; 
9699
97100            return  text ; 
98101        } 
99- 
102+          
100103        private  void  button1_Click ( object  sender ,  EventArgs  e ) 
101104        { 
102105            DummyTask  task  =  new  DummyTask ( ) ; 
103-             task . TaskCompleted  +=  ( o ,  ex )  =>  Logger . Debug ( nameof ( DummyTask ) ,  "Callback task completed!" ) ; 
106+             task . TaskCompleted  +=  ( o ,  ex )  =>  Updater . Instance . Logger . Debug ( nameof ( DummyTask ) ,  "Callback task completed!" ) ; 
104107            task . Start ( ) ; 
105108        } 
109+ 
110+         private  void  button2_Click ( object  sender ,  EventArgs  e ) 
111+         { 
112+             //Updater.Instance.RestartApp(false, false, true, true); 
113+         } 
106114    } 
107115} 
0 commit comments