示例#1
0
文件: VBFFile.cs 项目: demonzhq/JLR
		public void Output(bool withSDS)
		{
			if (File.Exists(this.InputFile))
			{
				if (File.Exists(this.OutputFile))
				{
					File.Delete(this.OutputFile);
				}
				StreamReader streamReader = File.OpenText(this.InputFile);
				string fileText = streamReader.ReadToEnd();
				streamReader.Close();
				if (withSDS && this.SDSTemplateFile != "" && this.SDSOutputFile != "")
				{
					SDSFile sDSFile = new SDSFile(this.VehicleName, this.ECUAddress, this.OutputFile, this.SDSOutputFile, this.SDSTemplateFile, this.Protocol, this.SBLFilename, this.SecurityInterface, this.ECUName);
					sDSFile.Output();
				}
				this.FileBytes.Clear();
				this.GenerateParameterArray();
				string text = this.ReplaceVariables(fileText);
				StreamWriter streamWriter = File.CreateText(this.OutputFile);
				streamWriter.Write(text);
				streamWriter.Close();
				Stream stream = File.Open(this.OutputFile, 3);
				stream.set_Position(stream.get_Length());
				byte[] array = new byte[checked((uint)this.FileBytes.get_Count())];
				int num = 0;
				IEnumerator enumerator = this.FileBytes.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ConfigByte configByte = (ConfigByte)enumerator.get_Current();
						array[num] = configByte.ParamValueByte;
						num++;
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				stream.Write(array, 0, array.Length);
				stream.Close();
				DataAccess.AddExtractData(this.VehicleInstId, this.UserName, 1);
				return;
			}
			throw new Exception("Cannot create VBF.  The Template file is missing!");
		}
示例#2
0
		public ArrayList OutputVBF(int vInstId, string outputFolder, string user, bool withSDS, bool withBackups, string fileName)
		{
			string text = "";
			string text2 = "";
			ArrayList arrayList = new ArrayList();
			string protocol = "";
			ArrayList arrayList2 = new ArrayList();
			VehiclePrototype vehiclePrototype = new VehiclePrototype(vInstId);
			bool withSDS2 = withSDS && !vehiclePrototype.XCLSDS;
			IEnumerator enumerator = vehiclePrototype.Modules.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VehicleModule vehicleModule = (VehicleModule)enumerator.get_Current();
					if (withBackups || vehicleModule.IsMaster)
					{
						text2 = fileName.Replace(".vbf", "_" + vehicleModule.Name + ".vbf");
						text = base.get_Server().MapPath(outputFolder + text2);
						string inputFile = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.VBFTemplate);
						VBFFile vBFFile = new VBFFile(vInstId, text, inputFile, user);
						vBFFile.VehicleName = vehiclePrototype.VehicleCode;
						vBFFile.PartNo = vehicleModule.PartNo;
						vBFFile.PartType = vehicleModule.PartType;
						vBFFile.Network = vehicleModule.Network;
						vBFFile.ECUName = vehicleModule.Name;
						vBFFile.ECUAddress = vehicleModule.ECUAddress;
						vBFFile.EraseStart = vehicleModule.EraseStart;
						vBFFile.NoOfBytes = vehicleModule.NoOfBytes;
						vBFFile.Protocol = vehicleModule.Protocol;
						vBFFile.SBLFilename = vehicleModule.SBLFilename;
						vBFFile.SecurityInterface = vehicleModule.SecurityInterface;
						vBFFile.Comment = string.Concat(new object[]
						{
							"\"",
							vehiclePrototype.Name,
							"\" - ",
							vBFFile.VehicleName,
							" ",
							vehicleModule.Name,
							" - Extracted ",
							DateTime.get_Now()
						});
						if (vehicleModule.IsMaster)
						{
							protocol = vehicleModule.Protocol;
						}
						if (vehiclePrototype.VBFType == 1)
						{
							vBFFile.EraseLength = vehicleModule.EraseLength;
							vBFFile.Params = vehicleModule.Parameters;
						}
						else
						{
							ArrayList arrayList3 = new ArrayList();
							IEnumerator enumerator2 = vehicleModule.BuildTypes.GetEnumerator();
							try
							{
								while (enumerator2.MoveNext())
								{
									BuildType buildType = (BuildType)enumerator2.get_Current();
									arrayList3.Add(new VDFBlock(buildType.BlockType, buildType.NoOfBytes));
								}
							}
							finally
							{
								IDisposable disposable = enumerator2 as IDisposable;
								if (disposable != null)
								{
									disposable.Dispose();
								}
							}
							VDF vDF = new VDF(vehiclePrototype.VDFVersion, vehicleModule.Parameters, vehicleModule.EraseLengthStored, arrayList3);
							vBFFile.Params = vDF.Data;
							vehicleModule.EraseLength = "0x" + vBFFile.Params.get_Count().ToString("x8");
							vBFFile.EraseLength = vehicleModule.EraseLength;
						}
						if (withSDS)
						{
							if (vehiclePrototype.XCLSDS)
							{
								string template = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.SDSTemplate);
								SDSNode sDSNode = new SDSNode(vehicleModule.Name, vehicleModule.ECUAddress, vehicleModule.SecurityInterface, vehicleModule.SBLFilename, text2, template);
								arrayList2.Add(sDSNode);
								arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF"));
							}
							else
							{
								vBFFile.SDSOutputFile = text.Replace(".vbf", ".sds");
								vBFFile.SDSTemplateFile = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehicleModule.SDSTemplate);
								arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF", text2.Replace(".vbf", ".sds"), outputFolder + text2.Replace(".vbf", ".sds"), "Save SDS"));
							}
						}
						else
						{
							arrayList.Add(new VBFLink(text2, outputFolder + text2, "Save VBF"));
						}
						vBFFile.Output(withSDS2);
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			if (withSDS && vehiclePrototype.XCLSDS)
			{
				string text3 = fileName.Replace(".vbf", ".sds");
				string outputFile = base.get_Server().MapPath(outputFolder + text3);
				string inputFile2 = base.get_Server().MapPath(Constants.Config.TemplateFolder + "/" + vehiclePrototype.SDSHeaderTemplate);
				SDSFile sDSFile = new SDSFile(vehiclePrototype.VehicleCode, protocol, outputFile, inputFile2, arrayList2);
				sDSFile.Output();
				arrayList.Add(new VBFLink(text3, outputFolder + text3, "Save SDS"));
			}
			return arrayList;
		}