private void Validate(string chanLstBinPath) { var baseDir = Path.GetDirectoryName(chanLstBinPath); string errors = ""; foreach (var entry in crcOffsetByRelPath) { var crcOffset = entry.Value; var expectedCrc = BitConverter.ToUInt16(this.content, crcOffset); if (expectedCrc == 0) { continue; } var filePath = baseDir + entry.Key; if (!File.Exists(filePath)) { errors += $"\nchanLst.bin: file not found in directory structure: {entry.Key}"; continue; } var data = File.ReadAllBytes(filePath); var length = data.Length; if (VersionMajor < 12 && length > 0x6000) { length = 0x6000; // there might be another cap at 0x013FA000 + 0x6000 in some versions } //if (length > 0x0140000) // length = 0x0140000; var actualCrc = Crc16.Calc(data, 0, length); if (actualCrc != expectedCrc) { var msg = $"chanLst.bin: stored CRC for {entry.Key} is {expectedCrc:x4} but calculated {actualCrc:x4}"; errors += "\n" + msg; } } if (errors != "") { this.log?.Invoke(errors); } }
public void Save(string chanLstBinPath) { var baseDir = Path.GetDirectoryName(chanLstBinPath); foreach (var entry in crcOffsetByRelPath) { var path = baseDir + entry.Key; var data = File.ReadAllBytes(path); var length = data.Length; if (VersionMajor < 12 && length > 0x6000) { length = 0x6000; // there might be another cap at 0x013FA000 + 0x6000 in some versions } var crc = Crc16.Calc(data, 0, length); var off = entry.Value; content[off] = (byte)crc; content[off + 1] = (byte)(crc >> 8); } File.WriteAllBytes(chanLstBinPath, content); }
private void Validate(string chanLstBinPath) { var baseDir = Path.GetDirectoryName(chanLstBinPath); string errors = ""; foreach (var entry in crcOffsetByRelPath) { var crcOffset = entry.Value; var expectedCrc = BitConverter.ToUInt16(this.content, crcOffset); if (expectedCrc == 0) { continue; } var filePath = baseDir + entry.Key; if (!File.Exists(filePath)) { this.log?.Invoke($"\nchanLst.bin: file not found in directory structure: {entry.Key}"); continue; } var data = File.ReadAllBytes(filePath); var length = data.Length; if (VersionMajor < 12 && length > 0x6000) { length = 0x6000; // there might be another cap at 0x013FA000 + 0x6000 in some versions } //if (length > 0x0140000) // length = 0x0140000; var actualCrc = Crc16.Calc(data, 0, length); if (actualCrc != expectedCrc) { var msg = $"chanLst.bin: stored CRC for {entry.Key} is {expectedCrc:x4} but calculated {actualCrc:x4}"; errors += "\n" + msg; } } if (errors != "") { this.log?.Invoke(errors); if (View.Default != null) // can't show dialog while unit-testing { var dlg = View.Default.CreateActionBox(Resources.WarningChecksumErrorMsg); dlg.AddAction(Resources.WarningChechsumErrorIgnore, 1); dlg.AddAction(Resources.Cancel, 0); dlg.ShowDialog(); switch (dlg.SelectedAction) { case 0: throw new FileLoadException("Aborted due to checksum errors"); } } } var info = Resources.InfoRestartAfterImport; if (this.VersionMajor >= 25 && this.VersionMajor <= 45) { info += "\n" + Resources.InfoIgnoreImportError; } View.Default?.MessageBox(info, "Philips"); }