Ejemplo n.º 1
0
        /// <summary>
        /// Replaces BDS version in a data file (the version must be at the
        /// beginning of the file).
        /// </summary>
        public static void ReplaceInDataFile(string fileName, ReplaceDelegate replace)
        {
            string tempFile1 = fileName + ".repl";
            string tempFile2 = fileName + ".backup";

            using (BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
            {
                using (BinaryWriter w = new BinaryWriter(File.Open(tempFile1, FileMode.Create, FileAccess.Write)))
                {
                    BdsVersion currentVersion = new BdsVersion();
                    currentVersion.Read(r);
                    replace(ref currentVersion);
                    currentVersion.Write(w);
                    byte[] buffer = new byte[1024 * 100];
                    for (; ;)
                    {
                        int actRead = r.Read(buffer, 0, buffer.Length);
                        w.Write(buffer, 0, actRead);
                        if (actRead != buffer.Length)
                        {
                            break;
                        }
                    }
                }
            }
            // Now tempFile1 contains the copy of original file with replaced
            // version. Now rename the files and delete the old file.
            File.Move(fileName, tempFile2);
            File.Move(tempFile1, fileName);
            File.Delete(tempFile2);
        }
 /// <summary>
 /// Reads the standard BDS header.
 /// </summary>
 public static void ReadHeader(BinaryReader r, out BdsVersion bdsVersion, out int formatVersion)
 {
     bdsVersion = new BdsVersion();
     bdsVersion.Read(r);
     formatVersion = r.ReadInt32();
 }