400 lines
12 KiB
VB.net
400 lines
12 KiB
VB.net
|
|
Imports System.Data.SqlClient
|
|
Imports System.Reflection
|
|
|
|
Public Class cProgrammeUpdate
|
|
Property pud_progId As Object = Nothing
|
|
Property pud_codename As String
|
|
Property pud_version As String
|
|
Property pud_fileName As String
|
|
Property pud_filePathFolder As Object = Nothing
|
|
Property pud_datum As Date = Now
|
|
|
|
Property pud_file_Verion As String
|
|
Property pud_file_Date As Date
|
|
Property pud_file_Size As Integer
|
|
|
|
|
|
Shared Function getParameterList(UD As cProgrammeUpdate) As List(Of SQLVariable)
|
|
Dim list As New List(Of SQLVariable)
|
|
list.Add(New SQLVariable("pud_progId", UD.pud_progId))
|
|
list.Add(New SQLVariable("pud_codename", UD.pud_codename))
|
|
list.Add(New SQLVariable("pud_version", UD.pud_version))
|
|
list.Add(New SQLVariable("pud_fileName", UD.pud_fileName))
|
|
list.Add(New SQLVariable("pud_filePathFolder", UD.pud_filePathFolder))
|
|
list.Add(New SQLVariable("pud_datum", UD.pud_datum))
|
|
list.Add(New SQLVariable("pud_file_Verion", UD.pud_file_Verion))
|
|
list.Add(New SQLVariable("pud_file_Date", UD.pud_file_Date))
|
|
list.Add(New SQLVariable("pud_file_Size", UD.pud_file_Size))
|
|
Return list
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Public Shared Function isNewFile(ByRef file As cProgrammeUpdate, LIST_DEST As List(Of cProgrammeUpdate)) As Boolean
|
|
For Each l In LIST_DEST
|
|
If l.pud_filePathFolder = file.pud_filePathFolder And l.pud_fileName = file.pud_fileName And l.pud_file_Size = file.pud_file_Size And l.pud_file_Date = file.pud_file_Date Then
|
|
Return False
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Public Shared Function isOldFile(ByRef file As cProgrammeUpdate, LIST_SOURCE As List(Of cProgrammeUpdate)) As Boolean
|
|
For Each l In LIST_SOURCE
|
|
If l.pud_filePathFolder = file.pud_filePathFolder And l.pud_fileName = file.pud_fileName And l.pud_file_Size = file.pud_file_Size And l.pud_file_Date = file.pud_file_Date Then
|
|
Return False
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
|
|
Public Shared Function copyProgramLIST(ByRef sourcePfad As String, ByVal destPfad As String, ignoreFilesBeginWith As String(), Optional progressCallback As Action(Of Integer, String) = Nothing) As Boolean
|
|
|
|
Try
|
|
|
|
If destPfad.Trim = "" Then Return False
|
|
If sourcePfad.Trim = "" Then Return False
|
|
|
|
If Not My.Computer.FileSystem.DirectoryExists(sourcePfad) Then
|
|
MsgBox("ERROR_COPY_01: Quell-Ordner existiert nicht.",
|
|
MsgBoxStyle.Critical, "ERROR")
|
|
Return False
|
|
End If
|
|
|
|
If Not My.Computer.FileSystem.DirectoryExists(destPfad) Then
|
|
MsgBox("ERROR_COPY_02: Ziel-Ordner existiert nicht.",
|
|
MsgBoxStyle.Critical, "ERROR")
|
|
Return False
|
|
End If
|
|
|
|
|
|
'--------------------------------------------------
|
|
' DATEILISTEN ERMITTELN
|
|
'--------------------------------------------------
|
|
|
|
progressCallback?.Invoke(0, "Dateien werden geprüft...")
|
|
|
|
Dim LIST_SOURCE As New List(Of cProgrammeUpdate)
|
|
Dim dirNameReplace_SOURCE = ""
|
|
|
|
Dim DI_SOURCE As New IO.DirectoryInfo(sourcePfad)
|
|
|
|
RekursivGetFiles(
|
|
DI_SOURCE,
|
|
dirNameReplace_SOURCE,
|
|
LIST_SOURCE,
|
|
{}
|
|
)
|
|
|
|
|
|
Dim LIST_DEST As New List(Of cProgrammeUpdate)
|
|
Dim dirNameReplace_DEST = ""
|
|
|
|
Dim DI_DEST As New IO.DirectoryInfo(destPfad)
|
|
|
|
RekursivGetFiles(
|
|
DI_DEST,
|
|
dirNameReplace_DEST,
|
|
LIST_DEST,
|
|
ignoreFilesBeginWith
|
|
)
|
|
|
|
|
|
If LIST_SOURCE.Count = 0 Then
|
|
MsgBox("ERROR_COPY_01: Quell-Daten existiert nicht.",
|
|
MsgBoxStyle.Critical, "ERROR")
|
|
Return False
|
|
End If
|
|
|
|
If LIST_DEST.Count = 0 Then
|
|
MsgBox("ERROR_COPY_02: Ziel-Daten existiert nicht.",
|
|
MsgBoxStyle.Critical, "ERROR")
|
|
Return False
|
|
End If
|
|
|
|
|
|
'--------------------------------------------------
|
|
' ORDNER ERSTELLEN
|
|
'--------------------------------------------------
|
|
|
|
For Each f In LIST_SOURCE
|
|
|
|
If If(f.pud_filePathFolder, "") <> "" Then
|
|
|
|
Dim folder =
|
|
dirNameReplace_DEST & "\" &
|
|
f.pud_filePathFolder.Replace("\\", "\")
|
|
|
|
If Not IO.Directory.Exists(folder) Then
|
|
IO.Directory.CreateDirectory(folder)
|
|
End If
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
|
|
'--------------------------------------------------
|
|
' NICHT MEHR BENÖTIGTE DATEIEN LÖSCHEN
|
|
'--------------------------------------------------
|
|
|
|
For Each f In LIST_DEST
|
|
|
|
If isOldFile(f, LIST_SOURCE) Then
|
|
|
|
Dim d_path =
|
|
dirNameReplace_DEST & "\" &
|
|
If(f.pud_filePathFolder, "") & "\" &
|
|
f.pud_fileName.Replace("\\", "\")
|
|
|
|
IO.File.Delete(d_path)
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
|
|
'--------------------------------------------------
|
|
' ERMITTELN, WELCHE DATEIEN TATSÄCHLICH
|
|
' KOPIERT WERDEN MÜSSEN
|
|
'--------------------------------------------------
|
|
|
|
Dim filesToCopy As New List(Of cProgrammeUpdate)
|
|
|
|
For Each f In LIST_SOURCE
|
|
|
|
'Bestehende Logik bleibt unverändert!
|
|
If isNewFile(f, LIST_DEST) Then
|
|
|
|
Dim d_path =
|
|
dirNameReplace_DEST & "\" &
|
|
If(f.pud_filePathFolder, "") & "\" &
|
|
f.pud_fileName.Replace("\\", "\")
|
|
|
|
'Bestehende Ignore-Logik bleibt ebenfalls erhalten
|
|
If fileStartsWith(f.pud_fileName, ignoreFilesBeginWith) AndAlso
|
|
IO.File.Exists(d_path) Then
|
|
|
|
'Nicht kopieren
|
|
|
|
Else
|
|
|
|
filesToCopy.Add(f)
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
|
|
'--------------------------------------------------
|
|
' NICHTS ZU KOPIEREN
|
|
'--------------------------------------------------
|
|
|
|
If filesToCopy.Count = 0 Then
|
|
|
|
progressCallback?.Invoke(
|
|
100,
|
|
"Alle Dateien sind aktuell."
|
|
)
|
|
|
|
Return True
|
|
|
|
End If
|
|
|
|
|
|
'--------------------------------------------------
|
|
' DATEIEN KOPIEREN
|
|
'--------------------------------------------------
|
|
|
|
Dim current As Integer = 0
|
|
Dim total As Integer = filesToCopy.Count
|
|
|
|
For Each f In filesToCopy
|
|
|
|
current += 1
|
|
|
|
Dim s_path =
|
|
dirNameReplace_SOURCE & "\" &
|
|
If(f.pud_filePathFolder, "") & "\" &
|
|
f.pud_fileName.Replace("\\", "\")
|
|
|
|
Dim d_path =
|
|
dirNameReplace_DEST & "\" &
|
|
If(f.pud_filePathFolder, "") & "\" &
|
|
f.pud_fileName.Replace("\\", "\")
|
|
|
|
|
|
'Relativen Dateinamen für Anzeige erstellen
|
|
Dim displayFile As String = ""
|
|
|
|
If If(f.pud_filePathFolder, "") <> "" Then
|
|
displayFile =
|
|
f.pud_filePathFolder.TrimStart("\"c) &
|
|
"\" &
|
|
f.pud_fileName
|
|
Else
|
|
displayFile = f.pud_fileName
|
|
End If
|
|
|
|
|
|
'Fortschritt berechnen
|
|
Dim percent As Integer =
|
|
CInt(((current - 1) / CDbl(total)) * 100)
|
|
|
|
|
|
'Vor dem Kopieren melden
|
|
progressCallback?.Invoke(
|
|
percent,
|
|
"Kopiere: " & displayFile
|
|
)
|
|
|
|
|
|
'==================================================
|
|
' EIGENTLICHER KOPIERVORGANG
|
|
'==================================================
|
|
|
|
IO.File.Copy(
|
|
s_path,
|
|
d_path,
|
|
True
|
|
)
|
|
|
|
|
|
'Fortschritt nach dem Kopieren
|
|
percent =
|
|
CInt((current / CDbl(total)) * 100)
|
|
|
|
progressCallback?.Invoke(
|
|
percent,
|
|
"Kopiert: " & displayFile
|
|
)
|
|
|
|
Next
|
|
|
|
|
|
progressCallback?.Invoke(
|
|
100,
|
|
"Update abgeschlossen. " &
|
|
filesToCopy.Count.ToString() &
|
|
" Datei(en) aktualisiert."
|
|
)
|
|
|
|
|
|
Catch ex As Exception
|
|
|
|
MsgBox(ex.Message & ex.StackTrace)
|
|
|
|
Return False
|
|
|
|
End Try
|
|
|
|
|
|
Return True
|
|
|
|
End Function
|
|
|
|
Public Shared Function fileStartsWith(fileName As String, ignoreFilesBeginWith As String())
|
|
For Each s In ignoreFilesBeginWith
|
|
If fileName.StartsWith(s) Then Return True
|
|
Next
|
|
Return False
|
|
End Function
|
|
Public Shared Sub RekursivGetFiles(ByVal oDir As IO.DirectoryInfo, ByRef dirNameReplace As String, ByRef LIST As List(Of cProgrammeUpdate), ignoreFilesBeginWith As String())
|
|
Dim oSubDir As IO.DirectoryInfo
|
|
Dim FI As IO.FileInfo
|
|
|
|
' zunächst alle Dateien des Ordners aufspüren
|
|
For Each FI In oDir.GetFiles()
|
|
If Not fileStartsWith(FI.Name, ignoreFilesBeginWith) Then 'DATEIEN beginnen mit betimmten Namen, z.B. UPDATER
|
|
|
|
|
|
' Dim FI As New IO.FileInfo(oFile)
|
|
If dirNameReplace = "" Then
|
|
dirNameReplace = FI.DirectoryName
|
|
End If
|
|
|
|
Dim UD As New cProgrammeUpdate
|
|
UD.pud_fileName = FI.Name
|
|
UD.pud_filePathFolder = FI.DirectoryName.Replace(dirNameReplace, "")
|
|
If UD.pud_filePathFolder = "" Then UD.pud_filePathFolder = Nothing
|
|
UD.pud_file_Size = FI.Length
|
|
UD.pud_file_Date = FI.LastWriteTime
|
|
UD.pud_file_Verion = "" 'FI.
|
|
LIST.Add(UD)
|
|
|
|
End If
|
|
'With oFile
|
|
' ListBox1.Items.Add(.DirectoryName & "\" & .Name & vbTab &
|
|
' .Length & vbTab & .LastWriteTime)
|
|
'End With
|
|
Next
|
|
|
|
' Jetzt alle Unterverzeichnis durchlaufen
|
|
' und die Prozedur rekursiv selbst aufrufen
|
|
For Each oSubDir In oDir.GetDirectories()
|
|
RekursivGetFiles(oSubDir, dirNameReplace, LIST, {})
|
|
Next
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class SQLVariable
|
|
Private TextSQLName As String
|
|
Private ValueSQLVALUE As Object
|
|
Private Scalarvariablename As String
|
|
Private primaryParam As Boolean
|
|
Private onlyForLoad As Boolean
|
|
|
|
Public Sub New(ByVal Text As String, ByVal Value As Object, Optional Scalarvariablename As String = "", Optional primaryParam As Boolean = False, Optional onlyForLoad As Boolean = False)
|
|
Me.TextSQLName = Text
|
|
Me.ValueSQLVALUE = Value
|
|
Me.primaryParam = primaryParam
|
|
Me.onlyForLoad = onlyForLoad
|
|
|
|
If Scalarvariablename <> "" Then Me.Scalarvariablename = Scalarvariablename Else Me.Scalarvariablename = Text
|
|
End Sub
|
|
|
|
Public ReadOnly Property Text() As String
|
|
Get
|
|
Return TextSQLName
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Value() As Object
|
|
Get
|
|
Return ValueSQLVALUE
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Scalarvariable() As Object
|
|
Get
|
|
Return Scalarvariablename
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property isPrimaryParam() As Boolean
|
|
Get
|
|
Return primaryParam
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property isonlyForLoad() As Boolean
|
|
Get
|
|
Return onlyForLoad
|
|
End Get
|
|
End Property
|
|
|
|
|
|
' Public Overrides Function ToString() As Object
|
|
' Return mText
|
|
' End Function
|
|
|
|
|
|
|
|
End Class
|