Skip to content

Commit 3968b56

Browse files
committed
[Refactor] Remove redundant blocks with specific methods
1 parent 05876d9 commit 3968b56

File tree

19 files changed

+58
-609
lines changed

19 files changed

+58
-609
lines changed

MainForm.vb

Lines changed: 26 additions & 287 deletions
Large diffs are not rendered by default.

Panels/DoWork/ProgressPanel.vb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6951,8 +6951,7 @@ Public Class ProgressPanel
69516951
TaskList.Clear()
69526952
MainForm.StatusStrip.BackColor = CurrentTheme.AccentColors(1)
69536953
MainForm.ToolStripButton4.Visible = False
6954-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
6955-
MainForm.WatcherTimer.Enabled = True
6954+
MainForm.StartMountedImageDetector()
69566955
Close()
69576956
Else
69586957
DynaLog.LogMessage("Tasks have not been successful.")
@@ -7301,19 +7300,7 @@ Public Class ProgressPanel
73017300
End If
73027301
' Cancel detector background worker which can interfere with image operations and cause crashes due to access violations
73037302
DynaLog.LogMessage("Mounted image detector might be busy. Stopping it if it is...")
7304-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
7305-
If MainForm.MountedImageDetectorBW.IsBusy Then MainForm.MountedImageDetectorBW.CancelAsync()
7306-
While MainForm.MountedImageDetectorBW.IsBusy
7307-
Application.DoEvents()
7308-
Thread.Sleep(100)
7309-
End While
7310-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
7311-
MainForm.WatcherTimer.Enabled = False
7312-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
7313-
While MainForm.WatcherBW.IsBusy
7314-
Application.DoEvents()
7315-
Thread.Sleep(100)
7316-
End While
7303+
MainForm.StopMountedImageDetector()
73177304
DynaLog.LogMessage("Setting mount directory target for operations...")
73187305
DynaLog.LogMessage("Images mounted in this system: " & MainForm.MountedImageMountDirs.Count)
73197306
If MainForm.MountedImageMountDirs.Count > 0 Then
@@ -7510,8 +7497,7 @@ Public Class ProgressPanel
75107497
End Select
75117498
MainForm.StatusStrip.BackColor = CurrentTheme.AccentColors(1)
75127499
MainForm.ToolStripButton4.Visible = False
7513-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
7514-
MainForm.WatcherTimer.Enabled = True
7500+
MainForm.StartMountedImageDetector()
75157501
End Sub
75167502

75177503
Sub SwitchLogContext(Context As Integer)

Panels/Get_Ops/Capabilities/GetCapabilityInfo.vb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,7 @@ Public Class GetCapabilityInfoDlg
267267
Thread.Sleep(500)
268268
End While
269269
End If
270-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
271-
If MainForm.MountedImageDetectorBW.IsBusy Then
272-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
273-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
274-
MainForm.MountedImageDetectorBW.CancelAsync()
275-
While MainForm.MountedImageDetectorBW.IsBusy
276-
Application.DoEvents()
277-
Thread.Sleep(500)
278-
End While
279-
End If
280-
DynaLog.LogMessage("Checking if image status watchers are busy...")
281-
MainForm.WatcherTimer.Enabled = False
282-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
283-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
284-
While MainForm.WatcherBW.IsBusy
285-
Application.DoEvents()
286-
Thread.Sleep(100)
287-
End While
270+
MainForm.StopMountedImageDetector()
288271
Select Case MainForm.Language
289272
Case 0
290273
Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
@@ -464,9 +447,7 @@ Public Class GetCapabilityInfoDlg
464447
End Sub
465448

466449
Private Sub GetCapabilityInfoDlg_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
467-
DynaLog.LogMessage("Restarting mounted image detector...")
468-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
469-
MainForm.WatcherTimer.Enabled = True
450+
MainForm.StartMountedImageDetector()
470451
End Sub
471452

472453
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Panels/Get_Ops/Drivers/GetDriverInfo.vb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -629,24 +629,7 @@ Public Class GetDriverInfo
629629
Thread.Sleep(500)
630630
End While
631631
End If
632-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
633-
If MainForm.MountedImageDetectorBW.IsBusy Then
634-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
635-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
636-
MainForm.MountedImageDetectorBW.CancelAsync()
637-
While MainForm.MountedImageDetectorBW.IsBusy
638-
Application.DoEvents()
639-
Thread.Sleep(500)
640-
End While
641-
End If
642-
DynaLog.LogMessage("Checking if image status watchers are busy...")
643-
MainForm.WatcherTimer.Enabled = False
644-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
645-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
646-
While MainForm.WatcherBW.IsBusy
647-
Application.DoEvents()
648-
Thread.Sleep(100)
649-
End While
632+
MainForm.StopMountedImageDetector()
650633
Select Case MainForm.Language
651634
Case 0
652635
Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
@@ -865,9 +848,7 @@ Public Class GetDriverInfo
865848
End Sub
866849

867850
Private Sub GetDriverInfo_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
868-
DynaLog.LogMessage("Restarting mounted image detector...")
869-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
870-
MainForm.WatcherTimer.Enabled = True
851+
MainForm.StartMountedImageDetector()
871852
End Sub
872853

873854
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged

Panels/Get_Ops/Features/GetFeatureInfo.vb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,7 @@ Public Class GetFeatureInfoDlg
271271
Thread.Sleep(500)
272272
End While
273273
End If
274-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
275-
If MainForm.MountedImageDetectorBW.IsBusy Then
276-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
277-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
278-
MainForm.MountedImageDetectorBW.CancelAsync()
279-
While MainForm.MountedImageDetectorBW.IsBusy
280-
Application.DoEvents()
281-
Thread.Sleep(500)
282-
End While
283-
End If
284-
DynaLog.LogMessage("Checking if image status watchers are busy...")
285-
MainForm.WatcherTimer.Enabled = False
286-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
287-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
288-
While MainForm.WatcherBW.IsBusy
289-
Application.DoEvents()
290-
Thread.Sleep(100)
291-
End While
274+
MainForm.StopMountedImageDetector()
292275
cPropPathView.Nodes.Clear()
293276
cPropName.Text = ""
294277
cPropValue.Text = ""
@@ -579,9 +562,7 @@ Public Class GetFeatureInfoDlg
579562
End Sub
580563

581564
Private Sub GetFeatureInfoDlg_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
582-
DynaLog.LogMessage("Restarting mounted image detector...")
583-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
584-
MainForm.WatcherTimer.Enabled = True
565+
MainForm.StartMountedImageDetector()
585566
End Sub
586567

587568
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Panels/Get_Ops/GetImgInfoDlg.vb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,7 @@ Public Class GetImgInfoDlg
376376

377377
Sub GetImageInfo(ImageFile As String)
378378
DynaLog.LogMessage("Image file to get information about: " & Quote & ImageFile & Quote)
379-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
380-
If MainForm.MountedImageDetectorBW.IsBusy Then
381-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
382-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
383-
MainForm.MountedImageDetectorBW.CancelAsync()
384-
While MainForm.MountedImageDetectorBW.IsBusy
385-
Application.DoEvents()
386-
Thread.Sleep(500)
387-
End While
388-
End If
389-
DynaLog.LogMessage("Checking if image status watchers are busy...")
390-
MainForm.WatcherTimer.Enabled = False
391-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
392-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
393-
While MainForm.WatcherBW.IsBusy
394-
Application.DoEvents()
395-
Thread.Sleep(100)
396-
End While
379+
MainForm.StopMountedImageDetector()
397380
ImageInfoList.Clear()
398381
ListView1.Items.Clear()
399382
Try

Panels/Get_Ops/InfoSave/ImgInfoSaveDlg.vb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,20 +2828,7 @@ Public Class ImgInfoSaveDlg
28282828
End If
28292829

28302830
' Stop the mounted image detector, as it makes the program crash when performing DISM API operations
2831-
If MainForm.MountedImageDetectorBW.IsBusy Then
2832-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
2833-
MainForm.MountedImageDetectorBW.CancelAsync()
2834-
While MainForm.MountedImageDetectorBW.IsBusy
2835-
Application.DoEvents()
2836-
Thread.Sleep(500)
2837-
End While
2838-
End If
2839-
MainForm.WatcherTimer.Enabled = False
2840-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
2841-
While MainForm.WatcherBW.IsBusy
2842-
Application.DoEvents()
2843-
Thread.Sleep(100)
2844-
End While
2831+
MainForm.StopMountedImageDetector()
28452832

28462833
' Close the image registry control panel before continuing. Operations with the DISM API open the image registry hives, something
28472834
' the control panel already loads. This causes the program to freeze for around a minute and then create a report with an
@@ -2993,8 +2980,7 @@ Public Class ImgInfoSaveDlg
29932980
If Contents <> "" And File.Exists(SaveTarget) Then File.WriteAllText(SaveTarget, Contents, UTF8)
29942981
If Debugger.IsAttached Then Process.Start(SaveTarget)
29952982
InfoSaveResults.FilePath = SaveTarget
2996-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
2997-
MainForm.WatcherTimer.Enabled = True
2983+
MainForm.StartMountedImageDetector()
29982984
Close()
29992985
End Sub
30002986
End Class

Panels/Get_Ops/Pkgs/GetPkgInfo.vb

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -762,24 +762,7 @@ Public Class GetPkgInfoDlg
762762
Thread.Sleep(500)
763763
End While
764764
End If
765-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
766-
If MainForm.MountedImageDetectorBW.IsBusy Then
767-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
768-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
769-
MainForm.MountedImageDetectorBW.CancelAsync()
770-
While MainForm.MountedImageDetectorBW.IsBusy
771-
Application.DoEvents()
772-
Thread.Sleep(500)
773-
End While
774-
End If
775-
DynaLog.LogMessage("Checking if image status watchers are busy...")
776-
MainForm.WatcherTimer.Enabled = False
777-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
778-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
779-
While MainForm.WatcherBW.IsBusy
780-
Application.DoEvents()
781-
Thread.Sleep(100)
782-
End While
765+
MainForm.StopMountedImageDetector()
783766
cPropPathView.Nodes.Clear()
784767
cPropName.Text = ""
785768
cPropValue.Text = ""
@@ -1163,24 +1146,7 @@ Public Class GetPkgInfoDlg
11631146
Thread.Sleep(500)
11641147
End While
11651148
End If
1166-
DynaLog.LogMessage("Checking if mounted image detector is busy...")
1167-
If MainForm.MountedImageDetectorBW.IsBusy Then
1168-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
1169-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
1170-
MainForm.MountedImageDetectorBW.CancelAsync()
1171-
While MainForm.MountedImageDetectorBW.IsBusy
1172-
Application.DoEvents()
1173-
Thread.Sleep(500)
1174-
End While
1175-
End If
1176-
DynaLog.LogMessage("Checking if image status watchers are busy...")
1177-
MainForm.WatcherTimer.Enabled = False
1178-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
1179-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
1180-
While MainForm.WatcherBW.IsBusy
1181-
Application.DoEvents()
1182-
Thread.Sleep(100)
1183-
End While
1149+
MainForm.StopMountedImageDetector()
11841150
Select Case MainForm.Language
11851151
Case 0
11861152
Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
@@ -1487,8 +1453,7 @@ Public Class GetPkgInfoDlg
14871453
End Sub
14881454

14891455
Private Sub GetPkgInfoDlg_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
1490-
If Not MainForm.MountedImageDetectorBW.IsBusy Then Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
1491-
MainForm.WatcherTimer.Enabled = True
1456+
MainForm.StartMountedImageDetector()
14921457
End Sub
14931458

14941459
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

Panels/ISOFiles/ISOCreator.vb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,7 @@ Public Class ISOCreator
505505
DynaLog.LogMessage("Image file to get information about: " & Quote & ImageFile & Quote)
506506
DynaLog.LogMessage("Checking if mounted image detector is busy...")
507507
ListView1.Items.Clear()
508-
If MainForm.MountedImageDetectorBW.IsBusy Then
509-
DynaLog.LogMessage("Mounted image detector is busy. Stopping it...")
510-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
511-
MainForm.MountedImageDetectorBW.CancelAsync()
512-
While MainForm.MountedImageDetectorBW.IsBusy
513-
Application.DoEvents()
514-
Thread.Sleep(500)
515-
End While
516-
End If
517-
DynaLog.LogMessage("Checking if image status watchers are busy...")
518-
MainForm.WatcherTimer.Enabled = False
519-
DynaLog.LogMessage("Image status watchers might be busy. Stopping them if they are...")
520-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
521-
While MainForm.WatcherBW.IsBusy
522-
Application.DoEvents()
523-
Thread.Sleep(100)
524-
End While
508+
MainForm.StopMountedImageDetector()
525509
Try
526510
DynaLog.LogMessage("Initializing API...")
527511
DismApi.Initialize(DismLogLevel.LogErrors)
@@ -577,7 +561,7 @@ Public Class ISOCreator
577561
End Try
578562
End Try
579563
DynaLog.LogMessage("This process has finished.")
580-
Call MainForm.MountedImageDetectorBW.RunWorkerAsync()
564+
MainForm.StartMountedImageDetector()
581565
End Sub
582566

583567
Private Sub SaveFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk

Panels/Img_Ops/Conversion/ImgWim2Esd.vb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,7 @@ Public Class ImgWim2Esd
296296
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
297297
If TextBox1.Text <> "" And File.Exists(TextBox1.Text) Then
298298
DynaLog.LogMessage("Getting image file information...")
299-
DynaLog.LogMessage("Detecting if the mounted image detector is busy...")
300-
If MainForm.MountedImageDetectorBW.IsBusy Then
301-
DynaLog.LogMessage("Stopping mounted image detector...")
302-
MainForm.MountedImageDetectorBWRestarterTimer.Enabled = False
303-
MainForm.MountedImageDetectorBW.CancelAsync()
304-
While MainForm.MountedImageDetectorBW.IsBusy
305-
Application.DoEvents()
306-
Thread.Sleep(500)
307-
End While
308-
End If
309-
DynaLog.LogMessage("Stopping image status watchers if they are active...")
310-
MainForm.WatcherTimer.Enabled = False
311-
If MainForm.WatcherBW.IsBusy Then MainForm.WatcherBW.CancelAsync()
312-
While MainForm.WatcherBW.IsBusy
313-
Application.DoEvents()
314-
Thread.Sleep(100)
315-
End While
299+
MainForm.StopMountedImageDetector()
316300
Try
317301
ListView1.Items.Clear()
318302
DynaLog.LogMessage("Initializing API...")

0 commit comments

Comments
 (0)