예제 #1
0
        public void Unprepare()
        {
            if (PreparedStream == null)
            {
                return;
            }

            PreparedStream.Close();
            PreparedStream.Dispose();
            PreparedStream = null;
        }
예제 #2
0
        public override IPatchResult Parse(string inputDir, string outputDir)
        {
            if (!IsFile)
            {
                var path = Path.Combine(outputDir, Filename).TrimEnd('\\');
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                return(new PatchResultSuccessful(path));
            }

            using (var reader = new BinaryReader(PreparedStream))
            {
                var Length   = reader.ReadInt32();
                var Checksum = reader.ReadUInt32();



                var calculatedChecksum = CRC32.CalculateChecksumStream(PreparedStream);
                PreparedStream.Position = 8;

                var outputFile = Path.Combine(outputDir, Filename);

                Directory.CreateDirectory(Path.GetDirectoryName(outputFile));

                using (var os = File.OpenWrite(outputFile))
                {
                    PreparedStream.CopyTo(os);
                }

                if (calculatedChecksum != Checksum)
                {
                    return(new PatchResultPatchedFileCorrupt(outputFile));
                }

                return(new PatchResultSuccessful(outputFile));
            }
        }