Example #1
0
        private void ExtractFiles(FileStream fs, string extractFolderPath)
        {
            if (!Directory.Exists(extractFolderPath))
            {
                Directory.CreateDirectory(extractFolderPath);
            }

            for (int i = 0; i < directoryNameList.Length; i++)
            {
                string path = Path.GetFullPath(Path.Combine(extractFolderPath, directoryNameList[i].Name));

                if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid folder path: " + path);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < fileNameList.Length; i++)
            {
                if (timer.ElapsedMilliseconds > 100)
                {
                    bw.ReportProgress(0, new ProgressInfo(i, fileNameList.Length, fileNameList[i].Name));
                    timer.Reset();
                    timer.Start();
                }

                string path = Path.GetFullPath(Path.Combine(extractFolderPath, fileNameList[i].Name));

                if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid file path: " + path);

                if (!File.Exists(path))
                {
                    using (FileStream fs2 = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        fs.CopyStream(fs2, fileNameList[i].File.Offset, fileNameList[i].File.Size);
                    }
                }

                if (AutoConvertPNG && Path.GetExtension(path) == ".tp")
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        fs.CopyStream(ms, fileNameList[i].File.Offset, fileNameList[i].File.Size);
                        DataHelpers.ConvertTPtoPNG(ms, path);
                    }
                }
            }

            bw.ReportProgress(0, new ProgressInfo(fileNameList.Length, fileNameList.Length, null));
        }
Example #2
0
        public override void Close()
        {
            long length = stream.Length;

            base.Close();
            stream.Close();

            if (length > 0)
            {
                //Write data to assembly
                using (FileStream tmpIn = new FileStream(assembly.Location, FileMode.Append))
                {
                    tmpIn.Write(signature, 0, signature.Length);

                    using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
                    {
                        tmpOut.CopyStream(tmpIn);
                        tmpOut.Close();
                    }

                    tmpIn.Close();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Close the file appender stream
        /// </summary>
        /// <param name="writeBack">
        /// TRUE if the stream must be write the content of himself to the appender file.
        /// <remarks>
        /// The file must be closed to this time
        /// </remarks>
        /// </param>
        public virtual void Close(bool writeBack)
        {
            long length = stream.Length;
            stream.Close();

            if (length > 0)
            {
                //Write data to appender file
                using (FileStream tmpIn = new FileStream(Filename, FileMode.Append))
                {
                    tmpIn.Write(signature, 0, signature.Length);

                    using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
                    {
                        tmpOut.CopyStream(tmpIn);
                        tmpOut.Close();
                    }

                    tmpIn.Close();
                }
            }
        }