Improved change UI feature

Improved change UI feature
This commit is contained in:
2016-07-13 17:03:40 +08:00
parent 457fec8a9d
commit 0b70069416
25 changed files with 129 additions and 68 deletions
+89 -56
View File
@@ -1,17 +1,18 @@
Public Class frm_changeui
Dim skip As Boolean = False
Dim ongoing As Boolean = True
Dim status As Integer = 0
Public targetui As String
Private Sub frm_changeui_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If ongoing Then
If status = 1 Then
If vbNo = MsgBox("Change UI is still in progress." & vbNewLine & "Are you sure you want to cancel?" & vbNewLine & "(This may cause unexpected behavior)", vbYesNo + vbExclamation, "Confirm") Then
e.Cancel = True
Else
bw_changeui.CancelAsync()
status = 0
Form1.WindowState = FormWindowState.Normal
End If
Else
status = 0
Form1.WindowState = FormWindowState.Normal
End If
@@ -19,25 +20,14 @@
Private Sub frm_changeui_Load(sender As Object, e As EventArgs) Handles Me.Load
Form1.WindowState = FormWindowState.Minimized
bw_changeui.RunWorkerAsync()
End Sub
Private Sub frm_changeui_Shown(sender As Object, e As EventArgs) Handles Me.Shown
End Sub
Private Sub lbl_skip_MouseUp(sender As Object, e As MouseEventArgs)
skip = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Me.Close()
End Sub
Private Sub bw_changeui_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bw_changeui.DoWork
ongoing = True
Private Sub change_ui()
status = 1
lbl_caldata.Text = "Copying ""caldata_" & targetui.Replace(".", "") & """ to ""caldata"""
lbl_caldata_warning.Text = ""
lbl_testhead_warning.Text = ""
@@ -46,13 +36,16 @@
lbl_caldata.ForeColor = Color.Gray
Label3.ForeColor = Color.Gray
Label4.ForeColor = Color.Gray
Dim ping_result As Boolean = True
Dim mod_ctr As UInt64 = 0
While (skip = False And ping_result = True)
If My.Computer.Network.IsAvailable Then
If My.Computer.Network.IsAvailable And mod_ctr Mod 10 = 0 Then
ping_result = My.Computer.Network.Ping("10.1.1.1")
End If
System.Threading.Thread.Sleep(1000)
System.Threading.Thread.Sleep(100)
Application.DoEvents()
mod_ctr += 1
End While
If skip = True Then
@@ -62,65 +55,99 @@
pic_chk1.BackColor = Color.LimeGreen
End If
skip = False
Label1.ForeColor = Color.Gray
lbl_caldata.ForeColor = Color.Black
Label3.ForeColor = Color.Gray
Label4.ForeColor = Color.Gray
Dim tempctr As Integer = 50
Dim tempctr As Integer = 30
While (tempctr > 0)
System.Threading.Thread.Sleep(100)
Application.DoEvents()
tempctr -= 1
End While
'Copy caldata
'Copy caldata (Ugly code below, I know)
Dim new_caldata_path As String = "c:\nextest\" & "caldata_" & targetui.Replace(".", "")
Dim old_caldata_path As String = "c:\nextest\caldata"
Dim default_caldata_path As String = "c:\nextest\" & "caldata_" & targetui.Substring(0, 2) & "xxx"
If FileIO.FileSystem.DirectoryExists(new_caldata_path) And System.IO.Directory.GetFiles(new_caldata_path).Count > 0 Then
If FileIO.FileSystem.DirectoryExists(old_caldata_path) Then
FileIO.FileSystem.DeleteDirectory(old_caldata_path, FileIO.DeleteDirectoryOption.DeleteAllContents)
Dim def_caldata_path As String = "c:\nextest\" & "caldata_" & targetui.Substring(0, 2) & "xxx"
Try
If System.IO.Directory.GetFiles(new_caldata_path).Count > 0 Then
If FileIO.FileSystem.DirectoryExists(old_caldata_path) Then
FileIO.FileSystem.DeleteDirectory(old_caldata_path, FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
FileIO.FileSystem.CreateDirectory(old_caldata_path)
End If
FileIO.FileSystem.CopyDirectory(new_caldata_path, old_caldata_path, True)
pic_chk2.BackColor = Color.LimeGreen
Else
FileIO.FileSystem.CreateDirectory(old_caldata_path)
Try
If System.IO.Directory.GetFiles(def_caldata_path).Count > 0 Then
If FileIO.FileSystem.DirectoryExists(old_caldata_path) Then
FileIO.FileSystem.DeleteDirectory(old_caldata_path, FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
FileIO.FileSystem.CreateDirectory(old_caldata_path)
End If
FileIO.FileSystem.CopyDirectory(def_caldata_path, old_caldata_path, True)
pic_chk2.BackColor = Color.LimeGreen
lbl_caldata.Text = "Copying from ""caldata_" & targetui.Substring(0, 2) & "xxx"" to ""caldata"""
Else
pic_chk2.BackColor = Color.Red
lbl_caldata_warning.Text = "No available caldata for " & targetui
Button1.Text = "Close"
status = 2
Exit Sub
End If
Catch ex2 As Exception
pic_chk2.BackColor = Color.Red
lbl_caldata_warning.Text = "No available caldata for " & targetui
Button1.Text = "Close"
status = 2
Exit Sub
End Try
End If
Catch ex1 As Exception
Try
If System.IO.Directory.GetFiles(def_caldata_path).Count > 0 Then
If FileIO.FileSystem.DirectoryExists(old_caldata_path) Then
FileIO.FileSystem.DeleteDirectory(old_caldata_path, FileIO.DeleteDirectoryOption.DeleteAllContents)
FileIO.FileSystem.CopyDirectory(new_caldata_path, old_caldata_path, True)
pic_chk2.BackColor = Color.LimeGreen
Else
FileIO.FileSystem.CreateDirectory(old_caldata_path)
End If
ElseIf FileIO.FileSystem.DirectoryExists(default_caldata_path) And System.IO.Directory.GetFiles(default_caldata_path).Count > 0 Then
If FileIO.FileSystem.DirectoryExists(old_caldata_path) Then
FileIO.FileSystem.DeleteDirectory(old_caldata_path, FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
FileIO.FileSystem.CreateDirectory(old_caldata_path)
End If
FileIO.FileSystem.CopyDirectory(default_caldata_path, old_caldata_path, True)
pic_chk2.BackColor = Color.Black
lbl_caldata_warning.Text = "Copying from ""caldata_" & targetui.Substring(0, 2) & "xxx"" to ""caldata"""
Else
pic_chk2.BackColor = Color.Red
lbl_caldata_warning.Text = "No available caldata for " & targetui
MsgBox("No available caldata for " & targetui & vbNewLine & "Change UI will abort", vbOKOnly + vbCritical, "Abort")
ongoing = False
Me.Close()
Exit Sub
End If
FileIO.FileSystem.CopyDirectory(def_caldata_path, old_caldata_path, True)
pic_chk2.BackColor = Color.LimeGreen
lbl_caldata.Text = "Copying from ""caldata_" & targetui.Substring(0, 2) & "xxx"" to ""caldata"""
Else
pic_chk2.BackColor = Color.Red
lbl_caldata_warning.Text = "No available caldata for " & targetui
Button1.Text = "Close"
status = 2
Exit Sub
End If
Catch ex2 As Exception
pic_chk2.BackColor = Color.Red
lbl_caldata_warning.Text = "No available caldata for " & targetui
Button1.Text = "Close"
status = 2
Exit Sub
End Try
End Try
skip = False
Label1.ForeColor = Color.Gray
lbl_caldata.ForeColor = Color.Gray
Label3.ForeColor = Color.Black
Label4.ForeColor = Color.Gray
tempctr = 50
tempctr = 30
While (tempctr > 0)
System.Threading.Thread.Sleep(100)
Application.DoEvents()
@@ -142,21 +169,27 @@
Label3.ForeColor = Color.Gray
Label4.ForeColor = Color.Black
tempctr = 40
tempctr = 30
While (tempctr > 0)
System.Threading.Thread.Sleep(100)
Application.DoEvents()
tempctr -= 1
End While
ongoing = False
pic_chk4.BackColor = Color.LimeGreen
Button1.Text = "Close"
status = 2
End Sub
Private Sub lbl_skip_Click(sender As Object, e As EventArgs)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If status = 0 Then
Button1.Text = "Cancel"
Application.DoEvents()
change_ui()
Else
Me.Close()
End If
End Sub
End Class