Newer
Older
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Imports System.Collections.Generic
Namespace My
' Fr MyApplication sind folgende Ereignisse verfgbar:
'
' Startup: Wird beim Starten der Anwendung noch vor dem Erstellen des Startformulars ausgelst.
' Shutdown: Wird nach dem Schlieen aller Anwendungsformulare ausgelst. Dieses Ereignis wird nicht ausgelst, wenn die Anwendung nicht normal beendet wird.
' UnhandledException: Wird ausgelst, wenn in der Anwendung eine unbehandelte Ausnahme auftritt.
' StartupNextInstance: Wird beim Starten einer Einzelinstanzanwendung ausgelst, wenn diese bereits aktiv ist.
' NetworkAvailabilityChanged: Wird beim Herstellen oder Trennen der Netzwerkverbindung ausgelst.
Partial Friend Class MyApplication
'Initialisierung
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
Dim logfDetail As IO.FileInfo
Dim BackUpError As Boolean
Dim s As String
Dim i As Int16
Dim file As cFile_V3
FirstTime = False
'Pfade
MyAppPath = My.Application.Info.DirectoryPath & "\"
MyConfPath = MyAppPath & "config\"
MyDeclPath = MyAppPath & "Declaration\"
FB_FilHisDir = MyAppPath & "FileHistory\"
StartLogfile()
'Falls Ordner nicht vorhanden: Erstellen!
If Not IO.Directory.Exists(MyConfPath) Then
FirstTime = True
Try
IO.Directory.CreateDirectory(MyConfPath)
Catch ex As Exception
MsgBox("Failed to create directory '" & MyConfPath & "'!", MsgBoxStyle.Critical)
LOGfile.WriteLine("Failed to create directory '" & MyConfPath & "'!")
e.Cancel = True
End Try
IO.File.Create(MyConfPath & "stdGENlist.txt")
IO.File.Create(MyConfPath & "batchGENlist.txt")
IO.File.Create(MyConfPath & "DRIlist.txt")
IO.File.Create(MyConfPath & "ADVlist.txt")
End If
If Not IO.Directory.Exists(FB_FilHisDir) Then
Try
IO.Directory.CreateDirectory(FB_FilHisDir)
'Directories.txt vorkonfigurieren
Try
s = IO.Directory.GetParent(My.Application.Info.DirectoryPath).ToString & "\"
Catch ex As Exception
s = MyAppPath
End Try
Try
file = New cFile_V3
file.OpenWrite(FB_FilHisDir & "Directories.txt")
file.WriteLine(s)
For i = 2 To 20
file.WriteLine(" ")
Next
file.Close()
Catch ex As Exception
End Try
Catch ex As Exception
MsgBox("Failed to create directory '" & FB_FilHisDir & "'!", MsgBoxStyle.Critical)
LOGfile.WriteLine("Failed to create directory '" & FB_FilHisDir & "'!")
e.Cancel = True
End Try
End If
'Trennzeichen!
SetCulture = False
If System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator <> "." Then
SetCulture = True
Try
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-US")
'MSGtoForm(8, "Set CurrentCulture to 'en-US'", True)
Catch ex As Exception
GUImsg(tMsgID.Err, "Failed to set Application Regional Settings to 'en-US'! Check system decimal- and group- separators!")
End Try
End If
'Klassen initialisieren
sKey = New csKey
JobFileList = New List(Of String)
JobCycleList = New List(Of String)
DEV = New cDEV
VEC = New cVECTO
Cfg = New cConfig 'ACHTUNG: cConfig.New lst cConfig.SetDefault aus welches sKey bentigt dehalb muss sKey schon vorher initialisiert werden!!
ProgBarCtrl = New cProgBarCtrl
'Config
Cfg.ConfigLOAD()
'Log starten
If IO.File.Exists(MyAppPath & "LOG.txt") Then
'Dateigre checken
logfDetail = My.Computer.FileSystem.GetFileInfo(MyAppPath & "LOG.txt")
'Falls Log zu gro: lschen
If logfDetail.Length / (2 ^ 20) > Cfg.LogSize Then
LOGfile.WriteLine("Starting new logfile")
LOGfile.Close()
BackUpError = False
Try
If IO.File.Exists(MyAppPath & "LOG_backup.txt") Then IO.File.Delete(MyAppPath & "LOG_backup.txt")
IO.File.Move(MyAppPath & "LOG.txt", MyAppPath & "LOG_backup.txt")
Catch ex As Exception
BackUpError = True
End Try
StartLogfile()
If BackUpError Then
MsgBox("Failed to backup logfile! (" & MyAppPath & "LOG_backup.txt)")
Else
LOGfile.WriteLine("Logfile restarted. Old log saved to LOG_backup.txt")
End If
End If
End If
'Lizenz initialisieren
Lic = New vectolic.cLicense
Lic.AppVersion = VECTOvers
Lic.FilePath = MyAppPath & "license.dat"
End Sub
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
e.ExitApplication = True
MsgBox("ERROR!" & ChrW(10) & ChrW(10) & e.Exception.Message.ToString, MsgBoxStyle.Critical, "Unexpected Error")
End Sub
End Class
End Namespace