1515
1616namespace winUpdateMiniTool ;
1717
18- public partial class MainForm : Form {
19-
18+ internal partial class MainForm : Form {
19+
2020 private static Timer mTimer ;
2121 private readonly WuAgent agent ;
2222 private readonly int idleDelay ;
23- private readonly Gpo . Respect mGpoRespect = Gpo . Respect . Unknown ;
23+ private readonly Gpo . Respect mGpoRespect ;
2424 private readonly float mWinVersion ;
2525 private bool allowShowDisplay = true ;
2626 private AutoUpdateOptions autoUpdate = AutoUpdateOptions . No ;
@@ -52,7 +52,7 @@ public MainForm() {
5252 notifyIcon . Visible = true ;
5353 }
5454
55- if ( ! OperatingSystemHelper . IsRunningAsUwp ( ) )
55+ if ( ! OSHelper . IsRunningAsUwp ( ) )
5656 Text = Updater . ApplicationTitle ;
5757
5858 btnWinUpd . Text = string . Format ( "Windows Update ({0})" , 0 ) ;
@@ -151,19 +151,19 @@ public MainForm() {
151151
152152 if ( Program . IsAutoStart ( ) )
153153 chkAutoRun_CheckedChanged ( null , EventArgs . Empty ) ;
154- if ( OperatingSystemHelper . IsRunningAsUwp ( ) && chkAutoRun . CheckState == CheckState . Checked )
154+ if ( OSHelper . IsRunningAsUwp ( ) && chkAutoRun . CheckState == CheckState . Checked )
155155 chkAutoRun . Enabled = false ;
156156 idleDelay = MiscFunc . ParseInt ( GetConfig ( "IdleDelay" , "20" ) ) ;
157157 if ( Program . IsSkipUacRun ( ) )
158158 chkNoUAC_CheckedChanged ( null , EventArgs . Empty ) ;
159- chkNoUAC . Enabled = OperatingSystemHelper . IsAdministrator ( ) ;
160- chkNoUAC . Visible = chkNoUAC . Enabled || chkNoUAC . Checked || ! OperatingSystemHelper . IsRunningAsUwp ( ) ;
159+ chkNoUAC . Enabled = OSHelper . IsAdministrator ( ) ;
160+ chkNoUAC . Visible = chkNoUAC . Enabled || chkNoUAC . Checked || ! OSHelper . IsRunningAsUwp ( ) ;
161161
162162 chkOffline . Checked = MiscFunc . ParseInt ( GetConfig ( "Offline" , "0" ) ) != 0 ;
163163 chkDownload . Checked = MiscFunc . ParseInt ( GetConfig ( "Download" , "1" ) ) != 0 ;
164164 chkManual . Checked = MiscFunc . ParseInt ( GetConfig ( "Manual" , "0" ) ) != 0 ;
165- if ( ! OperatingSystemHelper . IsAdministrator ( ) ) {
166- if ( OperatingSystemHelper . IsRunningAsUwp ( ) ) {
165+ if ( ! OSHelper . IsAdministrator ( ) ) {
166+ if ( OSHelper . IsRunningAsUwp ( ) ) {
167167 chkOffline . Enabled = false ;
168168 chkOffline . Checked = false ;
169169
@@ -177,7 +177,7 @@ public MainForm() {
177177 chkMsUpd . Checked = agent . IsActive ( ) && agent . TestService ( WuAgent . MsUpdGuid ) ;
178178
179179 // Note: when running in the UWP sandbox we cant write the real registry even as admins
180- if ( ! OperatingSystemHelper . IsAdministrator ( ) || OperatingSystemHelper . IsRunningAsUwp ( ) )
180+ if ( ! OSHelper . IsAdministrator ( ) || OSHelper . IsRunningAsUwp ( ) )
181181 foreach ( Control ctl in gbxAutoUpdate . Controls )
182182 ctl . Enabled = false ;
183183
@@ -283,9 +283,9 @@ private void InitializeTheme() {
283283 var item = new ToolStripRadioButtonMenuItem ( title , null , onClick ) ;
284284 themeMenuItem . DropDownItems . Add ( item ) ;
285285 return item ;
286- } ,
287- OnThemeCurrentChanged ,
288- Program . IniReadValue ( "Root" , "Theme" , "" ) , "winUpdateMiniTool.themes" ) ;
286+ } ,
287+ OnThemeCurrentChanged ,
288+ Program . IniReadValue ( "Root" , "Theme" ) , "winUpdateMiniTool.themes" ) ;
289289 currentItem ? . PerformClick ( ) ;
290290 Theme . Current . Apply ( this ) ;
291291 }
@@ -299,13 +299,13 @@ protected override void WndProc(ref Message m) {
299299 WindowState = FormWindowState . Normal ;
300300 Activate ( ) ;
301301 BringToFront ( ) ;
302- WinApiHelper . SetForegroundWindow ( this . Handle ) ;
302+ WinApiHelper . SetForegroundWindow ( Handle ) ;
303303 }
304304 else {
305305 base . WndProc ( ref m ) ;
306306 }
307307 }
308-
308+
309309 private void siteToolStripMenuItem_Click ( object sender , EventArgs e ) {
310310 Updater . VisitAppSite ( ) ;
311311 }
@@ -339,7 +339,7 @@ private void OnTimedEvent(object source, EventArgs e) {
339339 var daysDue = GetAutoUpdateDue ( ) ;
340340 if ( daysDue != 0 && ! agent . IsBusy ( ) ) {
341341 // ensure we only start a check when user is not doing anything
342- var idleTime = OperatingSystemHelper . GetIdleTime ( ) ;
342+ var idleTime = OSHelper . GetIdleTime ( ) ;
343343 if ( idleDelay * 60 < idleTime ) {
344344 AppLog . Line ( "Starting automatic search for updates." ) ;
345345 updateNow = true ;
@@ -636,7 +636,7 @@ private void UpdateState() {
636636 var isValid = agent . IsValid ( ) ;
637637 var isValid2 = isValid || chkManual . Checked ;
638638
639- var admin = OperatingSystemHelper . IsAdministrator ( ) || ! OperatingSystemHelper . IsRunningAsUwp ( ) ;
639+ var admin = OSHelper . IsAdministrator ( ) || ! OSHelper . IsRunningAsUwp ( ) ;
640640
641641 var enable = agent . IsActive ( ) && ! busy ;
642642 btnSearch . Enabled = enable ;
@@ -778,14 +778,14 @@ private void restoreDefaults_Click(object sender, EventArgs e) {
778778 chkOld . Checked = false ;
779779 chkMsUpd . Checked = false ;
780780 chkBlockMS . Checked = false ;
781-
781+
782782 chkDisableAU . Checked = false ;
783783 radDefault . Checked = true ;
784-
784+
785785 chkHideWU . Checked = false ;
786786 chkStore . Checked = false ;
787787 chkDrivers . Checked = true ;
788-
788+
789789 dlAutoCheck . SelectedIndex = 0 ;
790790
791791 MessageBox . Show ( "Default settings restored." , Updater . ApplicationTitle , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
@@ -850,42 +850,42 @@ private void btnHistory_CheckedChanged(object sender, EventArgs e) {
850850 private void btnSearch_Click ( object sender , EventArgs e ) {
851851 if ( ! agent . IsActive ( ) || agent . IsBusy ( ) )
852852 return ;
853- var ret = chkOffline . Checked
854- ? agent . SearchForUpdates ( chkDownload . Checked , chkOld . Checked )
853+ var ret = chkOffline . Checked
854+ ? agent . SearchForUpdates ( chkDownload . Checked , chkOld . Checked )
855855 : agent . SearchForUpdates ( dlSource . Text , chkOld . Checked ) ;
856856 ShowResult ( WuAgent . AgentOperation . CheckingUpdates , ret ) ;
857857 }
858858
859859 private void btnDownload_Click ( object sender , EventArgs e ) {
860- if ( ! chkManual . Checked && ! OperatingSystemHelper . IsAdministrator ( ) ) {
860+ if ( ! chkManual . Checked && ! OSHelper . IsAdministrator ( ) ) {
861861 MessageBox . Show ( "Administrator privileges are required in order to download updates using windows update services. Use 'Manual' download instead." , Updater . ApplicationTitle , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
862862 return ;
863863 }
864864
865865 if ( ! agent . IsActive ( ) || agent . IsBusy ( ) )
866866 return ;
867- var ret = chkManual . Checked
868- ? agent . DownloadUpdatesManually ( GetUpdates ( ) )
867+ var ret = chkManual . Checked
868+ ? agent . DownloadUpdatesManually ( GetUpdates ( ) )
869869 : agent . DownloadUpdates ( GetUpdates ( ) ) ;
870870 ShowResult ( WuAgent . AgentOperation . DownloadingUpdates , ret ) ;
871871 }
872872
873873 private void btnInstall_Click ( object sender , EventArgs e ) {
874- if ( ! OperatingSystemHelper . IsAdministrator ( ) ) {
874+ if ( ! OSHelper . IsAdministrator ( ) ) {
875875 MessageBox . Show ( "Administrator privileges are required in order to install updates." , Updater . ApplicationTitle , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
876876 return ;
877877 }
878878
879879 if ( ! agent . IsActive ( ) || agent . IsBusy ( ) )
880880 return ;
881- var ret = chkManual . Checked
882- ? agent . DownloadUpdatesManually ( GetUpdates ( ) , true )
881+ var ret = chkManual . Checked
882+ ? agent . DownloadUpdatesManually ( GetUpdates ( ) , true )
883883 : agent . DownloadUpdates ( GetUpdates ( ) , true ) ;
884884 ShowResult ( WuAgent . AgentOperation . InstallingUpdates , ret ) ;
885885 }
886886
887887 private void btnUnInstall_Click ( object sender , EventArgs e ) {
888- if ( ! OperatingSystemHelper . IsAdministrator ( ) ) {
888+ if ( ! OSHelper . IsAdministrator ( ) ) {
889889 MessageBox . Show ( "Administrator privileges are required in order to remove updates." , Updater . ApplicationTitle , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
890890 return ;
891891 }
@@ -978,7 +978,7 @@ private void OnUpdates(object sender, WuAgent.UpdatesArgs args) {
978978 if ( args . Found ) // if (agent.CurOperation() == WuAgent.AgentOperation.CheckingUpdates)
979979 {
980980 lastCheck = DateTime . Now ;
981- SetConfig ( "LastCheck" , lastCheck . ToString ( ) ) ;
981+ SetConfig ( "LastCheck" , lastCheck . ToString ( CultureInfo . InvariantCulture ) ) ;
982982 SwitchList ( UpdateLists . PendingUpdates ) ;
983983 }
984984 else {
@@ -1207,7 +1207,7 @@ private void chkAutoRun_CheckedChanged(object sender, EventArgs e) {
12071207 return ;
12081208 if ( chkAutoRun . CheckState == CheckState . Indeterminate )
12091209 return ;
1210- if ( OperatingSystemHelper . IsRunningAsUwp ( ) ) {
1210+ if ( OSHelper . IsRunningAsUwp ( ) ) {
12111211 if ( chkAutoRun . CheckState == CheckState . Checked ) {
12121212 mSuspendUpdate = true ;
12131213 chkAutoRun . CheckState = CheckState . Indeterminate ;
@@ -1398,7 +1398,7 @@ private enum UpdateLists {
13981398
13991399 // Implements the manual sorting of items by columns.
14001400 private class ListViewItemComparer : IComparer {
1401- private int col = 0 ;
1401+ private int col ;
14021402 private int inv = 1 ;
14031403
14041404 public int Compare ( object x , object y ) {
@@ -1436,7 +1436,7 @@ private void selectUIFontToolStripMenuItem_Click(object sender, EventArgs e) {
14361436 fontDialog . Font = Font ;
14371437 if ( fontDialog . ShowDialog ( ) != DialogResult . OK )
14381438 return ;
1439- if ( fontDialog . Font == Font )
1439+ if ( Equals ( fontDialog . Font , Font ) )
14401440 return ;
14411441 Font = fontDialog . Font ;
14421442 SetConfig ( "UIFont" , $ "{ Font . Name } ;{ Font . Size } ;{ ( int ) Font . Style } ") ;
@@ -1480,10 +1480,10 @@ private void RestorePosition() {
14801480 bool hasW = int . TryParse ( GetConfig ( "Window_Width" ) , out var w ) ;
14811481 bool hasH = int . TryParse ( GetConfig ( "Window_Height" ) , out var h ) ;
14821482 bool hasAll = hasX && hasY && hasW && hasH ;
1483-
1483+
14841484 Rectangle bounds = new ( x , y , w , h ) ;
14851485 bool isVisible = Screen . AllScreens . Any ( s => s . WorkingArea . IntersectsWith ( bounds ) ) ;
1486-
1486+
14871487 if ( hasAll && isVisible ) {
14881488 StartPosition = FormStartPosition . Manual ;
14891489 Bounds = bounds ;
0 commit comments