Beispiel #1
0
		public string Import(out bool error)
		{
			error = false;
			int num = 0;
			int num2 = 0;
			string text = "";
			string reason = "Imported " + DateTime.get_Now();
			VehicleModule vehicleModule = new VehicleModule();
			this.ImportVBF();
			num2 = this.Params.get_Count();
			if (num2 <= 0)
			{
				throw new CarConfigException("No bytes loaded, invalid VBF file?");
			}
			VehiclePrototype vehiclePrototype = new VehiclePrototype(this.VehicleInstId);
			IEnumerator enumerator = vehiclePrototype.Modules.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VehicleModule vehicleModule2 = (VehicleModule)enumerator.get_Current();
					if (vehicleModule2.ID == this.ModuleID)
					{
						vehicleModule = vehicleModule2;
						break;
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			int noOfBytes = vehicleModule.NoOfBytes;
			if (noOfBytes > 0)
			{
				if (vehiclePrototype.VBFType == 1)
				{
					if (noOfBytes > num2)
					{
						text = "More bytes in database than imported, database records will remain unchanged for extra bytes [00].  File loaded.";
					}
					else if (num2 > noOfBytes)
					{
						text = "More bytes imported than available in the database, " + (num2 - noOfBytes).ToString() + " ignored!  Check you selected the correct module!";
						error = true;
					}
					enumerator = vehicleModule.Parameters.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							ConfigByte configByte = (ConfigByte)enumerator.get_Current();
							if (num >= num2)
							{
								break;
							}
							configByte.Update(this.VehicleInstId, ((ConfigByte)this.Params.get_Item(num)).ParamValue, this.UserName, reason);
							num++;
						}
						goto IL_7D3;
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
				int num3 = 1;
				int num4 = 0;
				int num5 = 8;
				int num6 = 0;
				int num7 = 0;
				int num8 = 1;
				DataSet dataSet = new DataSet();
				VDF vDF = new VDF();
				ArrayList arrayList = new ArrayList();
				VDFBlock vDFBlock = new VDFBlock();
				enumerator = this.Params.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ConfigByte configByte2 = (ConfigByte)enumerator.get_Current();
						if (num3 == 1)
						{
							vDF.CRC = (ushort)(configByte2.ParamValue << 8);
						}
						else if (num3 == 2)
						{
							vDF.CRC = (ushort)((int)vDF.CRC | configByte2.ParamValue);
						}
						else if (num3 == 3)
						{
							vDF.DataBlockSize = configByte2.ParamValue << 8;
						}
						else if (num3 == 4)
						{
							vDF.DataBlockSize |= configByte2.ParamValue;
						}
						else if (num3 == 5)
						{
							vDF.VDFVersion = configByte2.ParamValue << 8;
						}
						else if (num3 == 6)
						{
							vDF.VDFVersion |= configByte2.ParamValue;
						}
						else if (num3 == 7)
						{
							vDF.Blocksize = configByte2.ParamValue << 8;
						}
						else if (num3 == 8)
						{
							vDF.Blocksize |= configByte2.ParamValue;
						}
						else if (num3 == 9)
						{
							vDFBlock.Type = configByte2.ParamValue << 8;
						}
						else if (num3 == 10)
						{
							vDFBlock.Type |= configByte2.ParamValue;
						}
						else if (num3 == 11)
						{
							num6 = configByte2.ParamValue << 8;
							vDFBlock.Offset = num6;
						}
						else if (num3 == 12)
						{
							num6 |= configByte2.ParamValue;
							vDFBlock.Offset = num6;
							if (num6 == num3)
							{
								num7 = 1;
								vDFBlock.Size = vDF.DataBlockSize - num5;
							}
							else
							{
								num7 = (num6 - num5) / 4;
							}
							arrayList.Add(vDFBlock);
						}
						else
						{
							if (num3 > num6)
							{
								break;
							}
							int num9 = num3 - num5;
							switch (num9 % 4)
							{
							case 0:
							{
								vDFBlock.Offset |= configByte2.ParamValue;
								VDFBlock vDFBlock2 = (VDFBlock)arrayList.get_Item(num8 - 2);
								vDFBlock2.Size = vDFBlock.Offset - vDFBlock2.Offset;
								if (num8 == num7)
								{
									vDFBlock.Size = vDF.DataBlockSize - vDFBlock.Offset;
								}
								arrayList.Add(vDFBlock);
								break;
							}
							case 1:
								num8++;
								vDFBlock = new VDFBlock();
								vDFBlock.Type = configByte2.ParamValue << 8;
								break;
							case 2:
								vDFBlock.Type |= configByte2.ParamValue;
								break;
							case 3:
								vDFBlock.Offset = configByte2.ParamValue << 8;
								break;
							}
						}
						num3++;
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				if (vehicleModule.BuildTypes.get_Count() != arrayList.get_Count())
				{
					throw new CarConfigException("Incorrect no of blocks in import file compared to those in the database.");
				}
				int i = 1;
				for (int j = 0; j < vehicleModule.BuildTypes.get_Count(); j++)
				{
					int num10 = 1;
					BuildType buildType = (BuildType)vehicleModule.BuildTypes.get_Item(j);
					VDFBlock vDFBlock3 = (VDFBlock)arrayList.get_Item(j);
					int size = vDFBlock3.Size;
					if (buildType.FrameCount)
					{
						for (i = num3; i < size + num3; i++)
						{
							ConfigByte configByte3 = (ConfigByte)this.Params.get_Item(i - 1);
							if (num10 == 1)
							{
								dataSet = DataAccess.GetVehicleFrameParameterIDs(configByte3.ParamValue.ToString(), buildType.ID, this.VehicleInstId);
								if (dataSet.get_Tables().get_Item(0).get_Rows().get_Count() == 0)
								{
									text = text + "Frame 0x" + configByte3.ParamValueHex.ToString() + " does not exist in the database.  All bytes will not be imported.<br>";
									error = true;
								}
								else
								{
									num4 = configByte3.ParamValue;
								}
							}
							else if (dataSet.get_Tables().get_Item(0).get_Rows().get_Count() > 0)
							{
								try
								{
									DataRow dataRow = dataSet.get_Tables().get_Item(0).get_Rows().get_Item(num10 - 2);
									DataAccess.UpdateParamInst(this.VehicleInstId.ToString(), dataRow.get_Item(0).ToString(), configByte3.ParamValue.ToString(), 1, this.UserName, reason);
								}
								catch (SqlException)
								{
									throw;
								}
								catch
								{
									string text2 = text;
									text = string.Concat(new string[]
									{
										text2,
										"Frame 0x",
										num4.ToString("x2"),
										" byte ",
										(num10 - 1).ToString(),
										" missing from the database.<br>"
									});
									error = true;
								}
							}
							if (num10 == 8)
							{
								num10 = 1;
								dataSet.Dispose();
							}
							else
							{
								num10++;
							}
						}
					}
					else
					{
						if (buildType.DataBytes.get_Count() > vDFBlock3.Size)
						{
							text = "More bytes in database for [" + buildType.Name + "] than imported, database records will remain unchanged for extra bytes [00].  File loaded.";
						}
						else if (vDFBlock3.Size > buildType.DataBytes.get_Count())
						{
							text = string.Concat(new string[]
							{
								"More bytes imported than available in the database for [",
								buildType.Name,
								"], ",
								(vDFBlock3.Size - buildType.DataBytes.get_Count()).ToString(),
								" ignored!  Check you selected the correct module!"
							});
							error = true;
						}
						enumerator = buildType.DataBytes.GetEnumerator();
						try
						{
							while (enumerator.MoveNext())
							{
								ConfigByte configByte4 = (ConfigByte)enumerator.get_Current();
								if (i >= size + num3)
								{
									break;
								}
								configByte4.Update(this.VehicleInstId, ((ConfigByte)this.Params.get_Item(i - 1)).ParamValue, this.UserName, reason);
								i++;
							}
						}
						finally
						{
							IDisposable disposable = enumerator as IDisposable;
							if (disposable != null)
							{
								disposable.Dispose();
							}
						}
					}
					num3 = i;
					if (buildType.BlockType != vDFBlock3.Type)
					{
						DataAccess.UpdateBuildType(buildType.ID, vDFBlock3.Type);
					}
				}
				int vehicleBuildID = DataAccess.GetVehicleBuildID(this.VehicleInstId.ToString());
				DataAccess.UpdateVehicle(vehicleBuildID, vDF.VDFVersion, this.UserName);
				IL_7D3:
				DataAccess.UpdateVehicleInst(this.VehicleInstId.ToString(), "", string.Concat(new object[]
				{
					"Imported ",
					DateTime.get_Now(),
					" by ",
					this.UserName
				}), 1, this.UserName);
				return text;
			}
			throw new CarConfigException("No parameter records found for Vehicle ID " + this.VehicleInstId.ToString());
		}
Beispiel #2
0
		public VDF(int version, ArrayList vehicleParams, string eraseLength, ArrayList blocks)
		{
			int num = 0;
			int num2 = 8;
			int num3 = num2 + blocks.get_Count() * 4;
			ArrayList arrayList = new ArrayList();
			this.VDFVersion = version;
			this.DataBlockSize = vehicleParams.get_Count() + num3;
			if (eraseLength == "")
			{
				num = this.DataBlockSize;
			}
			else
			{
				try
				{
					num = int.Parse(eraseLength.Replace("0x", ""), 515);
					if (num < this.DataBlockSize)
					{
						num = this.DataBlockSize;
					}
				}
				catch
				{
					num = this.DataBlockSize;
				}
			}
			this.Blocksize = num / 64;
			arrayList.Add(new ConfigByte(0, this.DataBlockSize >> 8));
			arrayList.Add(new ConfigByte(0, this.DataBlockSize & 255));
			arrayList.Add(new ConfigByte(0, this.VDFVersion >> 8));
			arrayList.Add(new ConfigByte(0, this.VDFVersion & 255));
			arrayList.Add(new ConfigByte(0, this.Blocksize >> 8));
			arrayList.Add(new ConfigByte(0, this.Blocksize & 255));
			int num4 = num3;
			IEnumerator enumerator = blocks.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VDFBlock vDFBlock = (VDFBlock)enumerator.get_Current();
					arrayList.Add(new ConfigByte(0, vDFBlock.Type >> 8));
					arrayList.Add(new ConfigByte(0, vDFBlock.Type & 255));
					arrayList.Add(new ConfigByte(0, num4 >> 8));
					arrayList.Add(new ConfigByte(0, num4 & 255));
					num4 += vDFBlock.Size;
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			this.Data.AddRange(arrayList);
			this.Data.AddRange(vehicleParams);
			this.CRC = Checksum.CreateCRC16(this.Data);
			this.Data.Insert(0, new ConfigByte(0, (int)this.CRC >> 8));
			this.Data.Insert(1, new ConfigByte(0, (int)this.CRC & 255));
			for (int i = this.DataBlockSize; i < num; i++)
			{
				this.Data.Add(new ConfigByte(0, 255));
			}
		}
Beispiel #3
0
		private void GetHeaderVariables(ArrayList fileLines)
		{
			StringBuilder stringBuilder = new StringBuilder();
			char[] array = new char[]
			{
				Convert.ToChar(10),
				Convert.ToChar(13),
				Convert.ToChar(32)
			};
			for (int i = 0; i < fileLines.get_Count(); i++)
			{
				string text = fileLines.get_Item(i).ToString();
				stringBuilder.Append(text + Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());
				string text2 = text.Trim(array);
				text2 = text2.Replace(" ", "");
				if (!text2.StartsWith("//"))
				{
					if (text2.IndexOf(Constants.VBFVariableNames.ECUAddress) >= 0)
					{
						string text3 = this.TrimValue(text2.Substring(text2.IndexOf(Constants.VBFVariableNames.ECUAddress) + Constants.VBFVariableNames.ECUAddress.get_Length()));
						this.ECUAddress = text3;
					}
					else if (text2.IndexOf(Constants.VBFVariableNames.SWPartNo) >= 0)
					{
						string text3 = this.TrimValue(text2.Substring(text2.IndexOf(Constants.VBFVariableNames.SWPartNo) + Constants.VBFVariableNames.SWPartNo.get_Length()));
						this.PartNo = text3;
					}
					else if (text2.IndexOf(Constants.VBFVariableNames.SWPartType) >= 0)
					{
						string text3 = this.TrimValue(text2.Substring(text2.IndexOf(Constants.VBFVariableNames.SWPartType) + Constants.VBFVariableNames.SWPartType.get_Length()));
						this.PartType = text3;
					}
					else if (text2.IndexOf(Constants.VBFVariableNames.Network) >= 0)
					{
						string text3 = this.TrimValue(text2.Substring(text2.IndexOf(Constants.VBFVariableNames.Network) + Constants.VBFVariableNames.Network.get_Length()));
						this.Network = text3;
					}
					else if (text2.IndexOf(Constants.VBFVariableNames.FileChecksum) >= 0)
					{
						string text3 = this.TrimValue(text2.Substring(text2.IndexOf(Constants.VBFVariableNames.FileChecksum) + Constants.VBFVariableNames.FileChecksum.get_Length()));
						this._FileChecksum = text3;
					}
				}
			}
			this.Header = stringBuilder.ToString() + Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString() + "}";
		}