-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.vb
571 lines (502 loc) · 26.8 KB
/
MainForm.vb
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
Imports System.IO
Imports WSLMan.My.Resources
Public Class MainForm
Private IsLoading As Boolean = False
Private BaseWslconfigContent As String()
Public Sub ShutdownWSL()
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", "--shutdown")
For Each page As TabPage In TabMain.TabPages
If page.Controls.Count >= 1 Then
Dim c = page.Controls(0)
If TypeOf c Is DistributionPage Then
Dim d = CType(c, DistributionPage)
d.OnShutdownWSL()
End If
End If
Next
End Sub
Private Sub ParseWslconfig()
Dim content As String()
Dim fileName = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wslconfig")
If Not File.Exists(fileName) Then
content = Array.Empty(Of String)()
Else
content = File.ReadAllLines(fileName)
End If
Dim kernel = ConfReadValue(content, "wsl2", "kernel")
CheckBoxDefaultKernel.Checked = kernel Is Nothing
TextBoxKernel.Enabled = kernel IsNot Nothing
TextBoxKernel.Text = If(kernel, "")
ButtonKernelOpen.Enabled = kernel IsNot Nothing
Dim kernelCmdline = ConfReadValue(content, "wsl2", "kernelCommandLine")
CheckBoxDefaultKernelCommandLine.Checked = kernelCmdline Is Nothing
TextBoxKernelCommandLine.Enabled = kernelCmdline IsNot Nothing
TextBoxKernelCommandLine.Text = If(kernelCmdline, "")
Dim memory = ConfReadValue(content, "wsl2", "memory")
CheckBoxDefaultMemory.Checked = memory Is Nothing
TextBoxMemory.Enabled = memory IsNot Nothing
TextBoxMemory.Text = If(memory, "")
Dim processors = ConfReadValue(content, "wsl2", "processors")
CheckBoxDefaultProcessors.Checked = processors Is Nothing
NumericProcessors.Enabled = processors IsNot Nothing
NumericProcessors.Value = If(processors IsNot Nothing And IsNumeric(processors), CInt(processors), 0)
Dim swap = ConfReadValue(content, "wsl2", "swap")
CheckBoxDefaultSwap.Checked = swap Is Nothing
TextBoxSwap.Enabled = swap IsNot Nothing
TextBoxSwap.Text = swap
Dim swapFile = ConfReadValue(content, "wsl2", "swapFile")
CheckBoxDefaultSwapFile.Checked = swapFile Is Nothing
TextBoxSwapFile.Enabled = swapFile IsNot Nothing
ButtonSwapFileOpen.Enabled = swapFile IsNot Nothing
TextBoxSwapFile.Text = If(swapFile, "")
Dim localhostForwarding = ConfReadBooleanValue(content, "wsl2", "localhostForwarding")
CheckBoxLocalhostForwarding.CheckState = If(localhostForwarding Is Nothing, CheckState.Indeterminate, If(localhostForwarding, CheckState.Checked, CheckState.Unchecked))
Dim safeMode = ConfReadBooleanValue(content, "wsl2", "safeMode")
CheckBoxSafeMode.CheckState = If(safeMode Is Nothing, CheckState.Indeterminate, If(safeMode, CheckState.Checked, CheckState.Unchecked))
Dim pageReporting = ConfReadBooleanValue(content, "wsl2", "pageReporting")
CheckBoxPageReporting.CheckState = If(pageReporting Is Nothing, CheckState.Indeterminate, If(pageReporting, CheckState.Checked, CheckState.Unchecked))
Dim guiApplications = ConfReadBooleanValue(content, "wsl2", "guiApplications")
CheckBoxGUIApplications.CheckState = If(guiApplications Is Nothing, CheckState.Indeterminate, If(guiApplications, CheckState.Checked, CheckState.Unchecked))
Dim debugConsole = ConfReadBooleanValue(content, "wsl2", "debugConsole")
CheckBoxDebugConsole.CheckState = If(debugConsole Is Nothing, CheckState.Indeterminate, If(debugConsole, CheckState.Checked, CheckState.Unchecked))
Dim nestedVirtualization = ConfReadBooleanValue(content, "wsl2", "nestedVirtualization")
CheckBoxNestedVirtualization.CheckState = If(nestedVirtualization Is Nothing, CheckState.Indeterminate, If(nestedVirtualization, CheckState.Checked, CheckState.Unchecked))
Dim vmIdleTimeout = ConfReadValue(content, "wsl2", "vmIdleTimeout")
CheckBoxDefaultVmIdleTimeout.Checked = vmIdleTimeout Is Nothing
NumericVmIdleTimeout.Enabled = vmIdleTimeout IsNot Nothing
NumericVmIdleTimeout.Value = If(vmIdleTimeout IsNot Nothing And IsNumeric(vmIdleTimeout), CInt(vmIdleTimeout), 0)
BaseWslconfigContent = content
End Sub
Private Sub LoadDistributions()
Dim currentIndex = 1
Dim allDistributions = GetAllWSLDistributions()
For Each s In allDistributions
Dim found = False
For i = 1 To TabMain.TabPages.Count - 1
Dim p = TabMain.TabPages(i)
Dim dp = CType(p.Controls(0), DistributionPage)
If dp.Data.Key = s.Key Then
dp.Data = s
dp.InitForm()
If i <> currentIndex Then
TabMain.TabPages.RemoveAt(i)
TabMain.TabPages.Insert(currentIndex, p)
End If
found = True
Exit For
End If
Next
If Not found Then
Dim page As New TabPage() With {
.UseVisualStyleBackColor = True
}
Dim dp As New DistributionPage() With {
.Data = s,
.TabPage = page,
.Left = 0,
.Top = 0
}
page.Text = s.DistributionName
page.Controls.Add(dp)
AddHandler page.Resize, AddressOf PageDistribution_Resize
TabMain.TabPages.Add(page)
End If
currentIndex += 1
Next
For i = TabMain.TabPages.Count - 1 To 1 Step -1
Dim p = TabMain.TabPages(i)
Dim dp = CType(p.Controls(0), DistributionPage)
Dim found = False
For Each s In allDistributions
If dp.Data.Key = s.Key Then
found = True
Exit For
End If
Next
If Not found Then
TabMain.TabPages.RemoveAt(i)
End If
Next
End Sub
Private Sub SaveWslconfig()
Dim fileName = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wslconfig")
Dim content = New List(Of String)(BaseWslconfigContent)
ConfWriteOrRemoveValue(content, "wsl2", "kernel", TextBoxKernel.Text, CheckBoxDefaultKernel.Checked)
ConfWriteOrRemoveValue(content, "wsl2", "kernelCommandLine", TextBoxKernelCommandLine.Text, CheckBoxDefaultKernelCommandLine.Checked)
ConfWriteOrRemoveValue(content, "wsl2", "memory", TextBoxMemory.Text, CheckBoxDefaultMemory.Checked)
ConfWriteOrRemoveValue(content, "wsl2", "processors", CStr(NumericProcessors.Value), CheckBoxDefaultProcessors.Checked)
ConfWriteOrRemoveValue(content, "wsl2", "swap", TextBoxSwap.Text, CheckBoxDefaultSwap.Checked)
ConfWriteOrRemoveValue(content, "wsl2", "swapFile", TextBoxSwapFile.Text, CheckBoxDefaultSwapFile.Checked)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "localhostForwarding", CheckBoxLocalhostForwarding.CheckState)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "safeMode", CheckBoxSafeMode.CheckState)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "pageReporting", CheckBoxPageReporting.CheckState)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "guiApplications", CheckBoxGUIApplications.CheckState)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "debugConsole", CheckBoxDebugConsole.CheckState)
ConfWriteOrRemoveBooleanValue(content, "wsl2", "nestedVirtualization", CheckBoxNestedVirtualization.CheckState)
ConfWriteOrRemoveValue(content, "wsl2", "vmIdleTimeout", CStr(NumericVmIdleTimeout.Value), CheckBoxDefaultVmIdleTimeout.Checked)
' If data is equal, then do nothing
If content.SequenceEqual(BaseWslconfigContent) Then
Exit Sub
End If
File.WriteAllLines(fileName, content)
End Sub
Private Sub UpdateWslconfigBase(Writer As Action(Of IList(Of String)))
If IsLoading Then Exit Sub
Dim fileName = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wslconfig")
Dim content = New List(Of String)(BaseWslconfigContent)
Writer(content)
' If data is equal, then do nothing
If content.SequenceEqual(BaseWslconfigContent) Then
Exit Sub
End If
File.WriteAllLines(fileName, content)
End Sub
Private Sub UpdateWslconfig(Section As String, Name As String, Value As String, UseDefault As Boolean)
UpdateWslconfigBase(Sub(content) ConfWriteOrRemoveValue(content, Section, Name, Value, UseDefault))
End Sub
Private Sub UpdateWslconfigBoolean(Section As String, Name As String, Value As CheckState)
UpdateWslconfigBase(Sub(content) ConfWriteOrRemoveBooleanValue(content, Section, Name, Value))
End Sub
Private Sub LayoutForm()
PanelSettings.SuspendLayout()
GroupBoxGeneral.SuspendLayout()
GroupBoxConfiguration.SuspendLayout()
GroupBoxConfiguration.ClientSize = New Size(GroupBoxConfiguration.ClientSize.Width, NumericVmIdleTimeout.Bottom + 8)
PanelSettings.ClientSize = New Size(PanelSettings.ClientSize.Width, GroupBoxConfiguration.Bottom + PanelSettings.Padding.Bottom)
GroupBoxConfiguration.ResumeLayout()
GroupBoxGeneral.ResumeLayout()
PanelSettings.ResumeLayout()
TabMain.ClientSize = New Size(TabMain.ClientSize.Width, PageSettings.Height)
ClientSize = New Size(ClientSize.Width, TabMain.Height + 8)
End Sub
Private Sub InitForm()
IsLoading = True
Dim inboxInstalled = IsInboxWSLInstalled()
Dim defVersion = GetDefaultWSLVersion()
RadioWSL1.Enabled = inboxInstalled
LabelInboxWSLNotInstalled.Visible = Not inboxInstalled
LabelWSLUpdateIsRecommended.Visible = inboxInstalled AndAlso GetWSLInstallationStatus() <> WSLInstallation.StoreWSL
RadioWSL2.Checked = defVersion = 2
RadioWSL1.Checked = defVersion = 1
ParseWslconfig()
IsLoading = False
UpdateWSLCommandAvailability().ContinueWith(
Sub() Invoke(Sub()
MenuItemDistributionImportInPlace.Enabled = IsImportInPlaceAvailable()
For Each tabPage As TabPage In TabMain.TabPages
If tabPage.Controls.Count >= 1 Then
Dim c = tabPage.Controls(0)
If TypeOf c Is DistributionPage Then
Dim d = CType(c, DistributionPage)
d.OnUpdateWSLCommandAvailability()
End If
End If
Next
End Sub))
End Sub
Private Function GetCurrentTabDistribution() As WSLDistributionData?
Dim activePage = TabMain.SelectedTab
If activePage Is Nothing OrElse activePage.Controls.Count < 1 Then
Return Nothing
End If
Dim c = activePage.Controls(0)
If TypeOf c IsNot DistributionPage Then
Return Nothing
End If
Dim d = CType(c, DistributionPage)
Return d.Data
End Function
Private Sub UpdateDistributionMenu()
Dim isActiveDistribution = GetCurrentTabDistribution() IsNot Nothing
MenuItemDistributionOpenShell.Enabled = isActiveDistribution
MenuItemDistributionOpenInExplorer.Enabled = isActiveDistribution
MenuItemDistributionExport.Enabled = isActiveDistribution
MenuItemDistributionTerminate.Enabled = isActiveDistribution
MenuItemDistributionUnregister.Enabled = isActiveDistribution
End Sub
Private Sub UpdateWSLUpdateMenu()
Dim s = GetWSLInstallationStatus()
MenuItemUpdateWSLUsingPrerelease.Enabled = s = WSLInstallation.StoreWSL
End Sub
Private Sub OnAfterUpdateWSL()
InitForm()
End Sub
Private Sub MainForm_Closed(sender As Object, e As EventArgs) Handles Me.Closed
Application.Exit()
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
Text = GetApplicationName()
LayoutForm()
InitForm()
LoadDistributions()
OnResizePageSettings()
UpdateDistributionMenu()
UpdateWSLUpdateMenu()
End Sub
Private Sub OnResizePageSettings()
PageSettings.SuspendLayout()
GroupBoxGeneral.SuspendLayout()
GroupBoxConfiguration.SuspendLayout()
Dim isOverflow = PageSettings.Height < PanelSettings.Bottom
Dim innerWidth = PageSettings.ClientSize.Width - PanelSettings.Padding.Horizontal
Dim halfWidth = CInt((innerWidth - PanelSettings.Padding.Horizontal - 8) / 2)
Dim memProcSwapWidth = CInt((innerWidth - PanelSettings.Padding.Horizontal - 16) / 3)
PanelSettings.Width = PageSettings.ClientSize.Width
GroupBoxGeneral.Width = innerWidth
GroupBoxConfiguration.Width = innerWidth
TextBoxKernel.Width = innerWidth - CheckBoxDefaultKernel.Width - PanelSettings.Padding.Horizontal - 8 - ButtonKernelOpen.Width - 4
ButtonKernelOpen.Left = TextBoxKernel.Right + 4
CheckBoxDefaultKernel.Left = innerWidth - CheckBoxDefaultKernel.Width - PanelSettings.Padding.Right
TextBoxKernelCommandLine.Width = innerWidth - CheckBoxDefaultKernelCommandLine.Width - PanelSettings.Padding.Horizontal - 8
CheckBoxDefaultKernelCommandLine.Left = innerWidth - CheckBoxDefaultKernelCommandLine.Width - PanelSettings.Padding.Right
CheckBoxDefaultSwap.Left = innerWidth - CheckBoxDefaultSwap.Width - PanelSettings.Padding.Right
TextBoxMemory.Width = memProcSwapWidth - CheckBoxDefaultMemory.Width - 8
CheckBoxDefaultMemory.Left = TextBoxMemory.Right + 8
LabelProcessors.Left = CheckBoxDefaultMemory.Right + 8
NumericProcessors.Left = CheckBoxDefaultMemory.Right + 8
NumericProcessors.Width = memProcSwapWidth - CheckBoxDefaultProcessors.Width - 8
CheckBoxDefaultProcessors.Left = NumericProcessors.Right + 8
LabelSwap.Left = CheckBoxDefaultProcessors.Right + 8
TextBoxSwap.Left = CheckBoxDefaultProcessors.Right + 8
TextBoxSwap.Width = memProcSwapWidth - CheckBoxDefaultSwap.Width - 8
TextBoxSwapFile.Width = innerWidth - CheckBoxDefaultSwapFile.Width - PanelSettings.Padding.Horizontal - 8 - ButtonSwapFileOpen.Width - 4
ButtonSwapFileOpen.Left = TextBoxSwapFile.Right + 4
CheckBoxDefaultSwapFile.Left = innerWidth - CheckBoxDefaultSwapFile.Width - PanelSettings.Padding.Right
CheckBoxSafeMode.Left = CheckBoxLocalhostForwarding.Left + halfWidth + 8
CheckBoxGUIApplications.Left = CheckBoxPageReporting.Left + halfWidth + 8
CheckBoxNestedVirtualization.Left = CheckBoxDebugConsole.Left + halfWidth + 8
NumericVmIdleTimeout.Width = halfWidth - 8 - CheckBoxDefaultVmIdleTimeout.Width
CheckBoxDefaultVmIdleTimeout.Left = NumericVmIdleTimeout.Right + 8
PageSettings.VerticalScroll.Visible = isOverflow
PageSettings.HorizontalScroll.Visible = False
GroupBoxGeneral.ResumeLayout()
GroupBoxConfiguration.ResumeLayout()
PageSettings.ResumeLayout()
End Sub
Private Sub PageSettings_Resize(sender As Object, e As EventArgs) Handles PageSettings.Resize
OnResizePageSettings()
End Sub
Private Sub PageDistribution_Resize(sender As Object, e As EventArgs)
Dim p = CType(sender, TabPage)
Dim c = CType(p.Controls(0), DistributionPage)
Dim w = p.ClientSize.Width
Dim h = p.ClientSize.Height
Dim isOverflow = h < c.MinimumHeight
If isOverflow Then
h = c.MinimumHeight
End If
c.Size = New Size(w, h)
p.VerticalScroll.Visible = isOverflow
p.HorizontalScroll.Visible = False
End Sub
Private Sub MainForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
InitForm()
LoadDistributions()
UpdateWSLUpdateMenu()
End Sub
Private Sub RadioWSL_CheckedChanged(sender As Object, e As EventArgs)
If RadioWSL2.Checked OrElse RadioWSL1.Checked Then
SetDefaultWSLVersion(If(RadioWSL2.Checked, 2, 1))
End If
End Sub
Private Sub TextBoxKernel_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "kernel", TextBoxKernel.Text, CheckBoxDefaultKernel.Checked)
End Sub
Private Sub CheckBoxDefaultKernel_CheckedChanged(sender As Object, e As EventArgs)
TextBoxKernel.Enabled = Not CheckBoxDefaultKernel.Checked
ButtonKernelOpen.Enabled = Not CheckBoxDefaultKernel.Checked
If CheckBoxDefaultKernel.Checked Then
UpdateWslconfig("wsl2", "kernel", TextBoxKernel.Text, CheckBoxDefaultKernel.Checked)
Else
TextBoxKernel.Focus()
End If
End Sub
Private Sub ButtonKernelOpen_Click(sender As Object, e As EventArgs)
With CommonOpenFileDialog
.Filter = Resources.FileDialogFilterAllFiles
.FileName = TextBoxKernel.Text
.Multiselect = False
If .ShowDialog() = DialogResult.OK Then
TextBoxKernel.Text = .FileName
UpdateWslconfig("wsl2", "kernel", TextBoxKernel.Text, CheckBoxDefaultKernel.Checked)
End If
End With
End Sub
Private Sub TextBoxKernelCommandLine_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "kernelCommandLine", TextBoxKernelCommandLine.Text, CheckBoxDefaultKernelCommandLine.Checked)
End Sub
Private Sub CheckBoxDefaultKernelCommandLine_CheckedChanged(sender As Object, e As EventArgs)
TextBoxKernelCommandLine.Enabled = Not CheckBoxDefaultKernelCommandLine.Checked
If CheckBoxDefaultKernel.Checked Then
UpdateWslconfig("wsl2", "kernelCommandLine", TextBoxKernelCommandLine.Text, CheckBoxDefaultKernelCommandLine.Checked)
Else
TextBoxKernelCommandLine.Focus()
End If
End Sub
Private Sub TextBoxMemory_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "memory", TextBoxMemory.Text, CheckBoxDefaultMemory.Checked)
End Sub
Private Sub CheckBoxDefaultMemory_CheckedChanged(sender As Object, e As EventArgs)
TextBoxMemory.Enabled = Not CheckBoxDefaultMemory.Checked
If CheckBoxDefaultKernel.Checked Then
UpdateWslconfig("wsl2", "memory", TextBoxMemory.Text, CheckBoxDefaultMemory.Checked)
Else
TextBoxMemory.Focus()
End If
End Sub
Private Sub NumericProcessors_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "processors", NumericProcessors.Text, CheckBoxDefaultProcessors.Checked)
End Sub
Private Sub CheckBoxDefaultProcessors_CheckedChanged(sender As Object, e As EventArgs)
NumericProcessors.Enabled = Not CheckBoxDefaultProcessors.Checked
If CheckBoxDefaultProcessors.Checked Then
UpdateWslconfig("wsl2", "processors", NumericProcessors.Text, CheckBoxDefaultProcessors.Checked)
Else
NumericProcessors.Focus()
End If
End Sub
Private Sub TextBoxSwap_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "swap", TextBoxSwap.Text, CheckBoxDefaultSwap.Checked)
End Sub
Private Sub CheckBoxDefaultSwap_CheckedChanged(sender As Object, e As EventArgs)
TextBoxSwap.Enabled = Not CheckBoxDefaultSwap.Checked
If CheckBoxDefaultProcessors.Checked Then
UpdateWslconfig("wsl2", "swap", TextBoxSwap.Text, CheckBoxDefaultSwap.Checked)
Else
TextBoxSwap.Focus()
End If
End Sub
Private Sub TextBoxSwapFile_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "swapFile", TextBoxSwapFile.Text, CheckBoxDefaultSwapFile.Checked)
End Sub
Private Sub ButtonSwapFileOpen_Click(sender As Object, e As EventArgs)
With CommonSaveFileDialog
.Filter = JoinFilter(Resources.FileDialogFilterHarddiskFiles, Resources.FileDialogFilterAllFiles)
.FileName = TextBoxSwapFile.Text
.OverwritePrompt = True
If .ShowDialog() = DialogResult.OK Then
TextBoxSwapFile.Text = .FileName
UpdateWslconfig("wsl2", "swapFile", TextBoxSwapFile.Text, CheckBoxDefaultSwapFile.Checked)
End If
End With
End Sub
Private Sub CheckBoxDefaultSwapFile_CheckedChanged(sender As Object, e As EventArgs)
TextBoxSwapFile.Enabled = Not CheckBoxDefaultSwapFile.Checked
ButtonSwapFileOpen.Enabled = Not CheckBoxDefaultSwapFile.Checked
If CheckBoxDefaultSwapFile.Checked Then
UpdateWslconfig("wsl2", "swapFile", TextBoxSwapFile.Text, CheckBoxDefaultSwapFile.Checked)
Else
TextBoxSwapFile.Focus()
End If
End Sub
Private Sub NumericVmIdleTimeout_LostFocus(sender As Object, e As EventArgs)
UpdateWslconfig("wsl2", "vmIdleTimeout", NumericVmIdleTimeout.Text, CheckBoxDefaultVmIdleTimeout.Checked)
End Sub
Private Sub CheckBoxDefaultVmIdleTimeout_CheckedChanged(sender As Object, e As EventArgs)
NumericVmIdleTimeout.Enabled = Not CheckBoxDefaultVmIdleTimeout.Checked
If CheckBoxDefaultVmIdleTimeout.Checked Then
UpdateWslconfig("wsl2", "vmIdleTimeout", NumericVmIdleTimeout.Text, CheckBoxDefaultVmIdleTimeout.Checked)
Else
NumericVmIdleTimeout.Focus()
End If
End Sub
Private Sub CheckBoxBooleanData_CheckStateChanged(sender As Object, e As EventArgs) Handles _
CheckBoxGUIApplications.CheckStateChanged,
CheckBoxDebugConsole.CheckStateChanged
Dim c = CType(sender, CheckBox)
If c.Tag Is Nothing Then Exit Sub
UpdateWslconfigBoolean("wsl2", CStr(c.Tag), c.CheckState)
End Sub
Private Sub TabMain_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabMain.SelectedIndexChanged
UpdateDistributionMenu()
End Sub
Private Sub MenuItemShutdownWSL_Click(sender As Object, e As EventArgs) Handles MenuItemShutdownWSL.Click
ShutdownWSL()
End Sub
Private Sub MenuItemExit_Click(sender As Object, e As EventArgs) Handles MenuItemExit.Click
Close()
End Sub
Private Sub MenuItemDistributionInstall_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionInstall.Click
Dim dlg As New InstallDistribution()
dlg.ShowDialog()
End Sub
Private Sub MenuItemDistributionImport_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionImport.Click
Dim dlg As New ImportDistribution()
dlg.ShowDialog()
End Sub
Private Sub MenuItemDistributionImportInPlace_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionImportInPlace.Click
Dim dlg As New ImportDistributionInPlace()
dlg.ShowDialog()
End Sub
Private Sub MenuItemDistributionOpenShell_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionOpenShell.Click
Dim _d = GetCurrentTabDistribution()
If _d Is Nothing Then
Exit Sub
End If
Dim d = _d.Value
ExecCommandDetached("wsl.exe", $"-d {d.DistributionName} --cd ~")
End Sub
Private Sub MenuItemDistributionOpenInExplorer_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionOpenInExplorer.Click
Dim _d = GetCurrentTabDistribution()
If _d Is Nothing Then
Exit Sub
End If
Dim d = _d.Value
OpenDistributionInExplorer(d.DistributionName)
End Sub
Private Sub MenuItemDistributionExport_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionExport.Click
Dim _d = GetCurrentTabDistribution()
If _d Is Nothing Then
Exit Sub
End If
Dim d = _d.Value
Dim exportDialog As New ExportDistribution() With {
.DistributionName = d.DistributionName
}
If exportDialog.ShowDialog(Me) <> DialogResult.OK Then
Exit Sub
End If
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", $"--export {d.DistributionName} ""{exportDialog.ExportTo}""{If(exportDialog.ExportAsVhdx, " --vhd", "")}", True)
End Sub
Private Sub MenuItemDistributionTerminate_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionTerminate.Click
Dim _d = GetCurrentTabDistribution()
If _d Is Nothing Then
Exit Sub
End If
Dim d = _d.Value
If MessageBox.Show(String.Format(Resources.TerminateDistributionPrompt, d.DistributionName), GetApplicationName(), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) <> DialogResult.Yes Then
Exit Sub
End If
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", $"--terminate {d.DistributionName}")
End Sub
Private Sub MenuItemDistributionUnregister_Click(sender As Object, e As EventArgs) Handles MenuItemDistributionUnregister.Click
Dim _d = GetCurrentTabDistribution()
If _d Is Nothing Then
Exit Sub
End If
Dim d = _d.Value
If MessageBox.Show(String.Format(Resources.UnregisterConfirmPrompt, d.DistributionName), GetApplicationName(), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) <> DialogResult.Yes Then
Exit Sub
End If
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", $"--unregister {d.DistributionName}")
End Sub
Private Sub MenuItemUpdateWSLDefault_Click(sender As Object, e As EventArgs) Handles MenuItemUpdateWSLDefault.Click
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", "--update")
OnAfterUpdateWSL()
End Sub
Private Sub MenuItemUpdateWSLFromWeb_Click(sender As Object, e As EventArgs) Handles MenuItemUpdateWSLFromWeb.Click
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", "--update --web-download")
OnAfterUpdateWSL()
End Sub
Private Sub MenuItemUpdateWSLUsingPrerelease_Click(sender As Object, e As EventArgs) Handles MenuItemUpdateWSLUsingPrerelease.Click
Dim exec = New ExecProgress()
exec.ShowExecute("wsl.exe", "--update --pre-release")
OnAfterUpdateWSL()
End Sub
End Class