Ejemplo n.º 1
0
 private void ApplyPatch(string srcName, PatchedFile file, PC98FatFileSystem srcFat, FatFileSystem dstFat)
 {
     if (srcName.EndsWith("CRUISER.COM"))
     {
         var dir  = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
         var name = Path.Combine(dir, srcName.TrimStart('\\'));
         using (var src = srcFat.OpenFile(srcName, FileMode.Open)) {
             using (var dst = File.Create(name)) {
                 src.CopyTo(dst);
             }
         }
         using (var dst = File.Create(name + ".patch")) {
             dst.Write(file.Patch, 0, file.Patch.Length);
         }
     }
     MakeDirectory(file.Name, dstFat);
     using (var ms = new MemoryStream(file.Patch)) {
         ms.Position = 0;
         using (var src = srcFat.OpenFile(srcName, FileMode.Open)) {
             using (var dst = dstFat.OpenFile(file.Name, FileMode.Create)) {
                 BsPatch.Apply(src, file.Patch, dst);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private static void CopySysFiles(PC98FatFileSystem fs, PC98FatFileSystem newfs, string[] sysFiles)
 {
     foreach (var file in sysFiles)
     {
         var compressedFile = file.Substring(0, file.Length - 1) + "_";
         if (fs.FileExists(file))
         {
             using (var dst = newfs.OpenFile(file, FileMode.CreateNew)) {
                 using (var src = fs.OpenFile(file, FileMode.Open)) {
                     src.CopyTo(dst);
                 }
             }
         }
         else if (fs.FileExists(compressedFile))
         {
             using (var dst = newfs.OpenFile(file, FileMode.CreateNew)) {
                 using (var src = fs.OpenFile(compressedFile, FileMode.Open)) {
                     UnpackMSLZ(src, dst);
                 }
             }
         }
         else
         {
             throw new FileNotFoundException($"Can't find file {file} in the system disk");
         }
     }
 }
Ejemplo n.º 3
0
        private void CopyFile(string srcName, string dstName, PC98FatFileSystem srcFat, FatFileSystem dstFat)
        {
            using (var src = srcFat.OpenFile(srcName, FileMode.Open)) {
                MakeDirectory(dstName, dstFat);
                if (dstFat.FileExists(dstName))
                {
                    Debug.WriteLine("exists");
                    //dstFat.DeleteFile(dstName);
                }
                var tmpfile = "~copy.tmp";
                if (dstFat.FileExists(tmpfile))
                {
                    dstFat.DeleteFile(tmpfile);
                }
                using (var dst = dstFat.OpenFile(tmpfile, FileMode.Create)) {
                    src.CopyTo(dst);
                }
                dstFat.MoveFile(tmpfile, dstName, true);
                var fi = dstFat.GetFileInfo(dstName);
                fi.LastWriteTime  = DateTime.Now;
                fi.LastAccessTime = DateTime.Now;

                /*try {
                 *  dstFat.MoveFile(tmpfile, dstName, true);
                 *  var fi = dstFat.GetFileInfo(dstName);
                 *  fi.LastWriteTime = DateTime.Now;
                 * } catch (Exception e) {
                 *  Debug.WriteLine(dstName);
                 * }*/
            }
        }
Ejemplo n.º 4
0
        private static void CopySysFiles(PC98FatFileSystem fs, PC98FatFileSystem newfs)
        {
            var files = new string[] { @"\IO.SYS", @"\MSDOS.SYS", @"\COMMAND.COM", @"\CONFIG.SYS" };

            foreach (var file in files)
            {
                using (var dst = newfs.OpenFile(file, FileMode.CreateNew)) {
                    using (var src = fs.OpenFile(file, FileMode.Open)) {
                        src.CopyTo(dst);
                    }
                }
            }
            using (var dst = newfs.OpenFile(@"\HIMEM.SYS", FileMode.CreateNew)) {
                using (var src = fs.OpenFile(@"\HIMEM.SY_", FileMode.Open)) {
                    UnpackMSLZ(src, dst);
                }
            }
        }
Ejemplo n.º 5
0
        private static void BuildChecksums(Dictionary <string, string> fileList, PC98FatFileSystem srcFat, string dir)
        {
            var files = srcFat.GetFiles(dir);

            foreach (var file in files)
            {
                using (var s = srcFat.OpenFile(file, FileMode.Open)) {
                    fileList.Add(file, Md5sum(s));
                }
            }
            var dirs = srcFat.GetDirectories(dir);

            foreach (var dirname in dirs)
            {
                BuildChecksums(fileList, srcFat, dirname);
            }
        }
Ejemplo n.º 6
0
 private static void WriteBootloader(Stream s, PC98FatFileSystem fs, FormatData format)
 {
     using (var fh = fs.OpenFile(@"\HDFORMAT.EXE", FileMode.Open)) {
         var sub = new byte[] {
             0xE9, 0xD1, 0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
             0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
         };
         var buf     = new byte[0x1000];
         var readPos = fh.Position;
         var len     = format.BootloaderEnd - format.BootloaderStart;
         var currPos = fh.Position;
         var found   = false;
         while (fh.Position < fh.Length)
         {
             currPos = fh.Position;
             fh.Read(buf, 0, buf.Length);
             var pos = FindSub(buf, sub);
             if (pos > (buf.Length - sub.Length))
             {
                 fh.Position = pos;
                 continue;
             }
             if (pos >= 0)
             {
                 currPos = currPos + pos;
                 found   = true;
                 break;
             }
         }
         if (!found)
         {
             throw new EntryPointNotFoundException("Can't find bootloader fingerprint in the HDFORMAT.EXE");
         }
         fh.Position = currPos;
         s.Position  = format.BootloaderStart;
         fh.Read(buf, 0, buf.Length);
         s.Write(buf, 0, buf.Length);
         fh.Read(buf, 0, buf.Length);
         s.Write(buf, 0, buf.Length);
     }
 }