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
140
141
142
143
144
145
146
147
148
149
' Copyright 2014 European Union.
' Licensed under the EUPL (the 'Licence');
'
' * You may not use this work except in compliance with the Licence.
' * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
' * Unless required by applicable law or agreed to in writing,
' software distributed under the Licence is distributed on an "AS IS" basis,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'
' See the LICENSE.txt for the specific language governing permissions and limitations.
Imports System.Collections.Generic
Public Class cConfig
Public FilePath As String
Private Const FormatVersion As Short = 2
Private FileVersion As Short
Public GnUfromCycle As Boolean
Public BatchMode As Boolean
Public ModOut As Boolean
Public BATCHoutpath As String 'Output path for BATCH Mode
Public BATCHoutSubD As Boolean
Public DistCorr As Boolean
Public LogSize As Single
Public AirDensity As Single
Public OpenCmd As String
Public OpenCmdName As String
Public FuelDens As Single
Public CO2perFC As Single
Public FirstRun As Boolean
Public DeclMode As Boolean
Public Sub New()
SetDefault()
End Sub
Public Sub DeclInit()
AirDensity = cDeclaration.AirDensity
FuelDens = cDeclaration.FuelDens
CO2perFC = cDeclaration.CO2perFC
DistCorr = True
GnUfromCycle = False
End Sub
Public Sub SetDefault()
GnUfromCycle = True
BatchMode = False
ModOut = True
BATCHoutpath = sKey.JobPath
BATCHoutSubD = False
DistCorr = True
LogSize = 2
AirDensity = 1.2
OpenCmd = "notepad"
OpenCmdName = "Notepad"
FuelDens = 0.835
CO2perFC = 3.153
FirstRun = True
DeclMode = True
End Sub
Public Sub ConfigLOAD()
Dim JSON As New cJSON
SetDefault()
If Not IO.File.Exists(FilePath) Then Exit Sub
If Not JSON.ReadFile(FilePath) Then GUImsg(tMsgID.Err, "Failed to load settings! Using default settings.")
Try
FileVersion = JSON.Content("Header")("FileVersion")
If FileVersion < 2 Then
BatchMode = (JSON.Content("Body")("LastMode") = 1)
Else
BatchMode = JSON.Content("Body")("LastModeBatch")
End If
ModOut = JSON.Content("Body")("ModOut")
DistCorr = JSON.Content("Body")("DistCorrection")
GnUfromCycle = JSON.Content("Body")("UseGnUfromCycle")
LogSize = JSON.Content("Body")("LogSize")
BATCHoutpath = JSON.Content("Body")("BATCHoutpath")
BATCHoutSubD = JSON.Content("Body")("BATCHoutSubD")
AirDensity = JSON.Content("Body")("AirDensity")
FuelDens = JSON.Content("Body")("FuelDensity")
CO2perFC = JSON.Content("Body")("CO2perFC")
OpenCmd = JSON.Content("Body")("OpenCmd")
OpenCmdName = JSON.Content("Body")("OpenCmdName")
FirstRun = JSON.Content("Body")("FirstRun")
DeclMode = JSON.Content("Body")("DeclMode")
Catch ex As Exception
GUImsg(tMsgID.Err, "Error while loading settings!")
End Try
End Sub
Public Sub ConfigSAVE()
Dim JSON As New cJSON
Dim dic As Dictionary(Of String, Object)
'Header
dic = New Dictionary(Of String, Object)
dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
dic.Add("Date", Now.ToString)
dic.Add("AppVersion", VECTOvers)
dic.Add("FileVersion", FormatVersion)
JSON.Content.Add("Header", dic)
'Body
dic = New Dictionary(Of String, Object)
dic.Add("LastModeBatch", BatchMode)
dic.Add("ModOut", ModOut)
dic.Add("DistCorrection", DistCorr)
dic.Add("UseGnUfromCycle", GnUfromCycle)
dic.Add("LogSize", LogSize)
dic.Add("BATCHoutpath", BATCHoutpath)
dic.Add("BATCHoutSubD", BATCHoutSubD)
dic.Add("AirDensity", AirDensity)
dic.Add("FuelDensity", FuelDens)
dic.Add("CO2perFC", CO2perFC)
dic.Add("OpenCmd", OpenCmd)
dic.Add("OpenCmdName", OpenCmdName)
dic.Add("FirstRun", FirstRun)
dic.Add("DeclMode", DeclMode)
JSON.Content.Add("Body", dic)
JSON.WriteFile(FilePath)
End Sub
End Class