コード例 #1
0
        private string CreateZipFile()
        {
            int    CompressionLevel = 9;
            string ZipFileShortName = _Name;
            string ZipFileName      = _ZipFile;

            if (ZipFileName == "")
            {
                ZipFileName = ZipFileShortName + ".zip";
            }
            ZipFileName = Globals.HostMapPath + ZipFileName;

            FileStream strmZipFile = null;

            try
            {
                ProgressLog.AddInfo(string.Format(Localization.GetString("LOG.PAWriter.CreateArchive"), ZipFileShortName));
                strmZipFile = File.Create(ZipFileName);
                ZipOutputStream strmZipStream = null;
                try
                {
                    strmZipStream = new ZipOutputStream(strmZipFile);
                    strmZipStream.SetLevel(CompressionLevel);
                    foreach (PaFileInfo PaFile in _Files)
                    {
                        if (File.Exists(PaFile.FullName))
                        {
                            FileSystemUtils.AddToZip(ref strmZipStream, PaFile.FullName, PaFile.Name, "");
                            ProgressLog.AddInfo(string.Format(Localization.GetString("LOG.PAWriter.SavedFile"), PaFile.Name));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Exceptions.LogException(ex);
                    ProgressLog.AddFailure(string.Format(Localization.GetString("LOG.PAWriter.ERROR.SavingFile"), ex));
                }
                finally
                {
                    if (strmZipStream != null)
                    {
                        strmZipStream.Finish();
                        strmZipStream.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                ProgressLog.AddFailure(string.Format(Localization.GetString("LOG.PAWriter.ERROR.SavingFile"), ex));
            }
            finally
            {
                if (strmZipFile != null)
                {
                    strmZipFile.Close();
                }
            }

            return(ZipFileName);
        }