-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImportDistributionInPlace.vb
71 lines (63 loc) · 2.99 KB
/
ImportDistributionInPlace.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
Imports WSLMan.My.Resources
Public Class ImportDistributionInPlace
Private inProgress As Boolean
Private Sub UpdateImportButtonEnabled()
Dim e = TextBoxFileName.Text.Length > 0 AndAlso
TextBoxDistributionName.Text.Length > 0
ButtonDoImport.Enabled = e AndAlso Not inProgress
End Sub
Private Sub ImportDistribution_Load(sender As Object, e As EventArgs) Handles Me.Load
inProgress = False
End Sub
Private Sub ImportDistribution_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If inProgress Then
Beep()
e.Cancel = True
End If
End Sub
Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBoxFileName.TextChanged,
TextBoxDistributionName.TextChanged
UpdateImportButtonEnabled()
End Sub
Private Sub ButtonOpenFileName_Click(sender As Object, e As EventArgs) Handles ButtonOpenFileName.Click
With CommonOpenFileDialog
.Filter = JoinFilter(Resources.FileDialogFilterHarddiskFiles, Resources.FileDialogFilterAllFiles)
.FileName = TextBoxFileName.Text
If .ShowDialog() <> DialogResult.OK Then Exit Sub
TextBoxFileName.Text = .FileName
End With
End Sub
Private Sub ButtonDoImport_Click(sender As Object, e As EventArgs) Handles ButtonDoImport.Click
Dim fileName = TextBoxFileName.Text
Dim distroName = TextBoxDistributionName.Text
If fileName Is Nothing OrElse fileName.Length = 0 OrElse
distroName Is Nothing OrElse distroName.Length = 0 Then
Exit Sub
End If
inProgress = True
ButtonDoImport.Enabled = False
ButtonCancel.Enabled = False
TextBoxProgress.Text = Resources.Installing
TextBoxProgress.Visible = True
ClientSize = New Size(ClientSize.Width, TextBoxProgress.Top + TextBoxProgress.Height + 16)
Dim arguments = $"--import-in-place {distroName} ""{fileName}"""
Dim commandLine = $"wsl.exe {arguments}"
ExecCommandSimple("wsl.exe", arguments, True).ContinueWith(
Sub(t)
Invoke(Sub()
inProgress = False
ButtonCancel.Enabled = True
If t.Result = 0 Then
MessageBox.Show(Resources.WSLImportDone, GetApplicationName(), MessageBoxButtons.OK, MessageBoxIcon.Information)
Close()
Else
TextBoxProgress.Text = String.Format(Resources.ProcessExitedWithCode, t.Result, commandLine)
ButtonDoImport.Enabled = True
End If
End Sub)
End Sub)
End Sub
Private Sub ButtonCancel_Click(sender As Object, e As EventArgs) Handles ButtonCancel.Click
Close()
End Sub
End Class