private void CheckTranslatedList(PatchContainer patchResult) { foreach (var key in translatedList.Keys) { if (key.TrimStart('\\') == "AUTOEXEC.BAT" || key.TrimStart('\\') == "CONFIG.SYS") { continue; } if (!translatedList.ContainsKey(key)) { var ret = form.AskAction($"Original HDI doesn't contains file {key}"); var file = new PatchedFile(); file.Name = key; if (ret == AskActionResult.Copy) { file.Action = PatchAction.Copy; using (var fh = translatedFs.OpenFile(key, FileMode.Open)) { file.FileData = DumpStream(fh); patchResult.TotalSize += fh.Length; } patchResult.Add(file); } else if (ret == AskActionResult.Ask) { file.Action = PatchAction.Ask; patchResult.Add(file); patchResult.TotalSize += 65 * 1024; } } } }
private void CheckOriginalList(PatchContainer patchResult) { foreach (var key in originalList.Keys) { if (key.TrimStart('\\') == "AUTOEXEC.BAT" || key.TrimStart('\\') == "CONFIG.SYS") { continue; } if (key.ToLower().EndsWith(@"\\CONFIG.SYS")) { continue; } var file = new PatchedFile { Name = key, Action = PatchAction.Original, OriginalMd5Sum = originalList[key] }; if (!translatedList.ContainsKey(key)) { if (form.Ask($"Translated HDI doesn't contain file {key}", $"Delete {key} from source during patching?")) { file.Action = PatchAction.Delete; } } else if (originalList[key] != translatedList[key]) { file.Action = PatchAction.Patch; using (var ms = new MemoryStream()) { using (var src = originalFs.OpenFile(key, FileMode.Open)) { using (var patched = translatedFs.OpenFile(key, FileMode.Open)) { BsDiff.Create(src, patched, ms); patchResult.TotalSize += patched.Length; } } file.Patch = ms.ToArray(); } } else { var info = originalFs.GetFileInfo(key); patchResult.TotalSize += info.Length; } patchResult.Add(file); } }
private void CheckConfigFiles(PatchContainer patchResult) { var files = new string[] { @"\AUTOEXEC.BAT", @"\CONFIG.SYS" }; foreach (var file in files) { var fileInfo = new PatchedFile(); fileInfo.Name = file; fileInfo.Action = PatchAction.Copy; if (originalFs.FileExists(file) && translatedFs.FileExists(file)) { using (var origFh = originalFs.OpenFile(file, FileMode.Open)) { using (var translatedFh = translatedFs.OpenFile(file, FileMode.Open)) { var origMd5 = Md5sum(origFh); var translatedMd5 = Md5sum(translatedFh); if (origMd5 != translatedMd5) { var useOriginal = form.AskConfigFileSource(file); if (useOriginal) { origFh.Position = 0; fileInfo.FileData = DumpStream(origFh); patchResult.TotalSize += origFh.Length; } else { translatedFh.Position = 0; fileInfo.FileData = DumpStream(translatedFh); patchResult.TotalSize += translatedFh.Length; } } else { origFh.Position = 0; fileInfo.FileData = DumpStream(origFh); patchResult.TotalSize += origFh.Length; } } } } else if (originalFs.FileExists(file)) { using (var origFh = originalFs.OpenFile(file, FileMode.Open)) { fileInfo.FileData = DumpStream(origFh); patchResult.TotalSize += origFh.Length; } } else if (translatedFs.FileExists(file)) { using (var translatedFh = translatedFs.OpenFile(file, FileMode.Open)) { fileInfo.FileData = DumpStream(translatedFh); patchResult.TotalSize += translatedFh.Length; } } else { continue; } patchResult.Add(fileInfo); } }