コード例 #1
0
        /// <summary>
        /// Creates an instance of the class with the specified compression level.
        /// </summary>
        public ZipTagLibrary(string archivePath, string name, CompressionLevel compressionLevel)
        {
            try
            {
                this.name = name;
                DiskFile zipFile = new DiskFile(archivePath);

                if (zipFile.Exists)
                {
                    archive = new ZipArchive(zipFile);
                    archive.DefaultCompressionLevel = compressionLevel;
                    Trace.WriteLine("Opened archive: " + archivePath, "info");
                }
                else
                {
                    // Make sure directory exists - if not, create it.
                    string path = Path.GetPathRoot(archivePath);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    zipFile.Create();
                    archive = new ZipArchive(zipFile);
                    archive.DefaultCompressionLevel = compressionLevel;
                    Trace.WriteLine("Created archive: " + archivePath, "info");
                }
            }
            catch (Exception ex)
            {
                throw new PrometheusException("Could not open ZipTagLibrary: " + archivePath, ex, true);
            }
        }
コード例 #2
0
        void writeTempData(string filename)
        {
            //if we've already got the source file written, delete it
            if (File.Exists(Path.ChangeExtension(filename, ".ZIP")))
            {
                File.Delete(Path.ChangeExtension(filename, ".ZIP"));
            }


            DiskFile zipFile = new DiskFile(Path.ChangeExtension(filename, ".ZIP"));

            if (!zipFile.Exists)
            {
                zipFile.Create();
            }

            ZipArchive zip = new ZipArchive(zipFile);

            zip.DefaultCompressionMethod = CompressionMethod.Deflated;
            zip.AllowSpanning            = true;

            writeTempTerrainToZip(zip);
            writeTempModelsToZip(zip);
        }
コード例 #3
0
        public bool SaveData(string fileName, bool overwrite, bool checkReadOnly)
        {
            try
            {
                using (PerfSection p = new PerfSection("SaveData() " + Path.GetFileName(fileName)))
                {
                    if (File.Exists(fileName))
                    {
                        if (!overwrite)
                        {
                            return(false);
                        }
                        if (checkReadOnly && File.GetAttributes(fileName) == FileAttributes.ReadOnly)
                        {
                            return(false);
                        }
                        File.SetAttributes(fileName, FileAttributes.Normal);
                        File.Delete(fileName);
                    }

                    DiskFile zipFile = new DiskFile(fileName);
                    zipFile.Create();

                    if (!zipFile.Exists)
                    {
                        return(false);
                    }
                    ZipArchive zip = new ZipArchive(zipFile);

                    Dictionary <string, IDataStream> .Enumerator it = mStreams.GetEnumerator();
                    while (it.MoveNext() != false)
                    {
                        AbstractFile   md = zip.CreateFile(it.Current.Key, true);
                        Stream         s  = md.OpenWrite(true);
                        BufferedStream bs = null;
                        if (CoreGlobals.OutOfMemory == false)
                        {
                            bs = new BufferedStream(s, 10000000); //~10mb buffer
                            it.Current.Value.Save(bs);
                        }
                        else
                        {
                            it.Current.Value.Save(s);
                        }


                        if (bs != null)
                        {
                            bs.Flush();
                            bs.Close();
                        }
                        else
                        {
                            s.Close();
                        }
                    }
                }
                return(true);
            }
            catch (System.Exception ex)
            {
                CoreGlobals.FatalEdDataSaveError = true;
                throw ex;
            }
            return(false);
        }