63 lines
3.2 KiB
VB.net
63 lines
3.2 KiB
VB.net
Module Update
|
|
Sub Main()
|
|
If Not My.Computer.FileSystem.DirectoryExists("F:\Programme\VERAGMonitoring\") Then
|
|
MsgBox("ERROR_UPDATE_02: Update-Daten existieren nicht.", MsgBoxStyle.Critical, "ERROR")
|
|
Else
|
|
For i As Integer = 1 To 3 Step 1
|
|
If Not DoesProcessExists("VERAGMonitoring") Then
|
|
delFiles()
|
|
FileCopier()
|
|
If Not System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & "VERAGMonitoring.exe") Then
|
|
MsgBox("ERROR_UPDATE_03: VERAGMonitoring.exe konnte nicht gestartet werden.", MsgBoxStyle.Critical, "ERROR")
|
|
Environment.Exit(0)
|
|
End If
|
|
Process.Start("VERAGMonitoring.exe")
|
|
Environment.Exit(0)
|
|
End If
|
|
Threading.Thread.Sleep(1000)
|
|
Next
|
|
MsgBox("ERROR_UPDATE_01: Update konnte nicht durchgeführt werden. VERAGMonitoring.exe nicht beendet?", MsgBoxStyle.Critical, "ERROR")
|
|
End If
|
|
Environment.Exit(0)
|
|
End Sub
|
|
Private Sub FileCopier()
|
|
For Each file As String In IO.Directory.GetFiles("F:\Programme\VERAGMonitoring\") ' Ermittelt alle Dateien des Ordners
|
|
If cut_file(file).Contains("settings.txt") = False Then
|
|
IO.File.Copy(file, AppDomain.CurrentDomain.BaseDirectory & cut_file(file), True) ' Kopiert die Dateien Next
|
|
End If
|
|
For Each filed As String In IO.Directory.GetDirectories("F:\Programme\VERAGMonitoring\") ' Ermittelt alle Unterordner des Ordners
|
|
My.Computer.FileSystem.CopyDirectory(filed, AppDomain.CurrentDomain.BaseDirectory & cut_file(filed), True)
|
|
Next
|
|
Next
|
|
End Sub
|
|
Private Function cut_file(ByVal file As String) As String ' Funktion zum Entfernen der Backslashs / Ordner While file.Contains("\") file = file.Remove(0, 1) End While Return file End Function
|
|
While file.Contains("\")
|
|
file = file.Remove(0, 1)
|
|
End While
|
|
Return file
|
|
End Function
|
|
Private Sub delFiles()
|
|
Try
|
|
For Each file As String In IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory) ' Ermittelt alle Dateien des Ordners
|
|
If cut_file(file).Contains("VERAGMonitoringUPDATER") = False And cut_file(file).Contains("settings.txt") = False Then
|
|
My.Computer.FileSystem.DeleteFile(file) 'Löscht das ADMIN-Programm, außer den Updater
|
|
End If
|
|
Next
|
|
For Each file As String In IO.Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory) ' Ermittelt alle Dateien des Ordners
|
|
If cut_file(file).Contains("VERAGMonitoringUPDATER") = False Then
|
|
System.IO.Directory.Delete(file, True)
|
|
End If
|
|
Next
|
|
Catch ex As Exception
|
|
MsgBox("ERROR_UPDATE_04: Fehler beim Löschen", MsgBoxStyle.Critical, "ERROR")
|
|
Environment.Exit(0)
|
|
End Try
|
|
End Sub
|
|
Private Function DoesProcessExists(ByVal PName As String) As Boolean
|
|
If System.Diagnostics.Process.GetProcessesByName(PName).Length > 0 Then
|
|
Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
End Module |