Imports System.ComponentModel Imports System.IO Public Class frmVersionCheck Private InitSteps As Integer = 6 Private bw As New BackgroundWorker() Private mainForm As Form Private Sub InitProgram() bw.WorkerReportsProgress = True AddHandler bw.DoWork, AddressOf bw_DoWork AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted ' mainForm = My.Forms.frmMain bw.RunWorkerAsync() End Sub Private Function CalcProgress(_step As Integer) Return _step * (100 / InitSteps) End Function Private Sub bw_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) 'Try Dim Init = New ClassInit() bw.ReportProgress(CalcProgress(1), "Initializing Logger") Init.InitLogger() System.Threading.Thread.Sleep(200) bw.ReportProgress(CalcProgress(3), "Initializing MySettings") MySettings_Load() System.Threading.Thread.Sleep(200) bw.ReportProgress(CalcProgress(2), "Initializing Database") If Init.InitDatabase() = True Then System.Threading.Thread.Sleep(200) bw.ReportProgress(CalcProgress(3), "Initializing Basic-Configuration") Init.InitBasics() System.Threading.Thread.Sleep(200) bw.ReportProgress(CalcProgress(4), "Initializing User-Configuration") If ClassInit.InitUserLogin = False Then Exit Sub Else If VERSION_USER = VERSION_SERVER Then Exit Sub End If If MyServer_UpdatePath <> String.Empty Then If Directory.Exists(MyServer_UpdatePath) Then GetTempFolderGuid() If FOLDER_TEMP <> String.Empty Then bw.ReportProgress(CalcProgress(5), "Copying files to tempfolder") ' Make a reference to a directory. Dim di As New DirectoryInfo(MyServer_UpdatePath) ' Get a reference to each file in that directory. Dim fiArr As FileInfo() = di.GetFiles() ' Display the names of the files. Dim fri As FileInfo Dim error_while_copying = False For Each fri In fiArr If error_while_copying = True Then Exit For End If Dim no_work = False For Each row As DataRow In DTEXCLUDE_FILES.Rows Dim content As String = row.Item(0).ToString.ToLower If fri.Name.Contains(content) Then no_work = True End If Next If no_work = False Then 'Copy the file to tempFolder Try System.IO.File.Copy(fri.FullName, Path.Combine(FOLDER_TEMP, fri.Name)) Catch ex As Exception ClassLogger.Add(String.Format("Error while copying file {0} to {1}: " & ex.Message, fri.FullName, Path.Combine(FOLDER_TEMP, fri.Name))) error_while_copying = True End Try If error_while_copying = False Then End If End If Console.WriteLine(fri.Name) Next fri Replace_Files() Try 'Delete the tempfolder and all data System.IO.Directory.Delete(FOLDER_TEMP, True) Catch ex As Exception End Try End If End If End If End If System.Threading.Thread.Sleep(200) bw.ReportProgress(CalcProgress(6), "Initializing Frontend") ' InitInterface wurde in frmMain integriert 'Init.InitInterface(mainForm) System.Threading.Thread.Sleep(200) Start_RO() Else End If 'Catch ex As Exception ' MsgBox("Unexpected Error in Init Classes: " & vbNewLine & ex.Message, MsgBoxStyle.Critical) 'End Try End Sub Sub Replace_Files() Try Dim ProductionPath As String = System.IO.Path.Combine(MY_ADDON_PATH, "Record Organizer") Dim DevelPath As String = System.IO.Path.Combine(MY_ADDON_PATH, "DD-Record-Organiser\bin\Debug") Dim COPY_FROM_PATH As String If Directory.Exists(ProductionPath) Then COPY_FROM_PATH = ProductionPath Else COPY_FROM_PATH = DevelPath End If Catch ex As Exception MsgBox("Unexpected Error in Replace_Files: " & vbNewLine & ex.Message, MsgBoxStyle.Critical) End Try End Sub Sub Start_RO() Try Dim ProductionPath As String = System.IO.Path.Combine(MY_ADDON_PATH, "Record Organizer", "DD-Record-Organiser.exe") Dim DevelPath As String = System.IO.Path.Combine(MY_ADDON_PATH, "DD-Record-Organiser\bin\Debug", "DD-Record-Organiser.exe") Dim startInfo As New ProcessStartInfo() startInfo.Arguments = """" & MyConnectionString & """" If System.IO.File.Exists(ProductionPath) Then startInfo.FileName = ProductionPath Else startInfo.FileName = DevelPath End If Process.Start(startInfo) Catch ex As Exception MsgBox("Could not find Right manager: " & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Function GetTempFolderGuid() As String Try Dim folder As String = Path.Combine(Path.GetTempPath, Guid.NewGuid.ToString) If Not Directory.Exists(folder) Then Directory.CreateDirectory(folder) End If FOLDER_TEMP = folder Catch ex As Exception ClassLogger.Add(String.Format("Error while Creating tempfolder: " & ex.Message)) End Try End Function Private Sub frmVersionCheck_Load(sender As Object, e As EventArgs) Handles Me.Load InitProgram() End Sub Private Sub bw_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) pbStatus.Value = e.ProgressPercentage lblStatus.Text = e.UserState.ToString() End Sub Private Sub bw_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) ' Bei Fehler MsgBox anzeigen und Programm beenden If e.Error IsNot Nothing Then MsgBox(e.Error.Message, MsgBoxStyle.Critical, "Unexpected Error in frmSplash") Application.Exit() End If ' Wenn kein Fehler, Splashscreen schließen Me.Close() End Sub End Class