/// <summary>
        ///
        /// </summary>
        /// <param name="strBasePath">要压缩文件所在文件夹</param>
        /// <param name="strSourceFolderName">生成TAR包存放路径</param>
        /// <param name="sTarName">TAR包名</param>
        /// <returns></returns>
        //public bool CreatTar(string strBasePath, string strSourceFolderName, string sTarName)
        //{
        //    if (!Directory.Exists(strSourceFolderName))
        //    {
        //        Directory.CreateDirectory(strSourceFolderName);//不存在生成Tar文件目录就创建
        //    }
        //    if (string.IsNullOrEmpty(strBasePath)
        //        || string.IsNullOrEmpty(strSourceFolderName)
        //        || !Directory.Exists(strBasePath))
        //    {
        //        return false;
        //    }
        //    string strOupFileAllPath = strSourceFolderName + "\\EBDT_" + sTarName + ".tar";//压缩文件名及路径
        //    Stream outStream = new FileStream(strOupFileAllPath, FileMode.OpenOrCreate);
        //    SharpCompress.Archive.Tar.TarArchive archive = SharpCompress.Archive.Tar.TarArchive.Create();
        //    try
        //    {
        //        DirectoryInfo theFolder = new DirectoryInfo(strBasePath);
        //        FileInfo[] xmlfiles = theFolder.GetFiles("*.*");
        //        if (xmlfiles.Length > 0)
        //        {
        //            Console.WriteLine(strBasePath + "===>Count: " + xmlfiles.Length);
        //            for (int i = 0; i < xmlfiles.Length; i++)
        //            {
        //                archive.AddEntry(xmlfiles[i].Name, xmlfiles[i]);
        //            }
        //            SharpCompress.Common.CompressionInfo infs = new SharpCompress.Common.CompressionInfo();
        //            archive.SaveTo(outStream, infs);
        //            outStream.Close();
        //            archive.Dispose();
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //    catch
        //    {
        //        //outStream.Close();
        //        return false;
        //    }
        //    return true;
        //}   //注释于20180228

        /// <summary>
        /// 压缩新tar包
        /// </summary>
        /// <param name="strBasePath"></param>
        /// <param name="strSourceFolderName"></param>
        /// <param name="sTarName"></param>
        /// <param name="xmlname">需要压缩的xml文件名称</param>
        /// <returns></returns>
        public bool CreatTar(string strBasePath, string strSourceFolderName, string sTarName, string xmlname)
        {
            if (!Directory.Exists(strSourceFolderName))
            {
                Directory.CreateDirectory(strSourceFolderName);//不存在生成Tar文件目录就创建
            }
            if (string.IsNullOrEmpty(strBasePath) ||
                string.IsNullOrEmpty(strSourceFolderName) ||
                !Directory.Exists(strBasePath))
            {
                return(false);
            }
            string strOupFileAllPath = strSourceFolderName + "\\EBDT_" + sTarName + ".tar";//压缩文件名及路径
            Stream outStream         = new FileStream(strOupFileAllPath, FileMode.OpenOrCreate);

            SharpCompress.Archive.Tar.TarArchive archive = SharpCompress.Archive.Tar.TarArchive.Create();
            try
            {
                DirectoryInfo theFolder = new DirectoryInfo(strBasePath);
                FileInfo[]    xmlfiles  = theFolder.GetFiles("*.*");
                if (xmlfiles.Length > 0)
                {
                    Console.WriteLine(strBasePath + "===>Count: " + xmlfiles.Length);
                    for (int i = 0; i < xmlfiles.Length; i++)
                    {
                        if (xmlfiles[i].Name == xmlname)
                        {
                            archive.AddEntry(xmlfiles[i].Name, xmlfiles[i]);
                        }

                        //加入签名文件
                        if (xmlfiles[i].Name == ("EBDS_" + xmlname))
                        {
                            archive.AddEntry(xmlfiles[i].Name, xmlfiles[i]);
                        }
                    }
                    SharpCompress.Common.CompressionInfo infs = new SharpCompress.Common.CompressionInfo();
                    archive.SaveTo(outStream, infs);
                    outStream.Close();
                    archive.Dispose();
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Converts a folder into a new cbz file
        /// </summary>
        private void msZipSource_Click(object sender, EventArgs e)
        {
            string sBaseLoc = acTxBx_Loc.Text.Trim();

            if (!File.Exists(sBaseLoc + ".cbz")) {
                Cursor = Cursors.WaitCursor;
                Ext.PathType ptValid = Ext.Accessible(sBaseLoc);

                if (ptValid == Ext.PathType.ValidDirectory) {
                    SharpCompress.Common.CompressionInfo cmp = new SharpCompress.Common.CompressionInfo();

                    //zip the folder contents into a .cbz
                    Text = "Compressing...";
                    using (var archive = SCA.Zip.ZipArchive.Create()) {
                        string[] asFiles = Directory.GetFiles(sBaseLoc);
                        for (int x = 0; x < asFiles.Length; x++) {
                            Text = string.Format("Compressing...{0}/{1}", x + 1, asFiles.Length);
                            FileInfo fi = new FileInfo(asFiles[x]);
                            using (FileStream fs = new FileStream(asFiles[x], FileMode.Open)) {
                                archive.AddEntry(fi.Name, fs, closeStream: true);
                            }
                        }

                        Text = "Saving to disk...";
                        using (FileStream fs = new FileStream(sBaseLoc + ".cbz", FileMode.CreateNew)) {
                            archive.SaveTo(fs, cmp);
                        }
                        Text = "Compression complete";

                        //Update the manga location and delete the old folder
                        acTxBx_Loc.Text = sBaseLoc + ".cbz";
                        DeleteLocation(sBaseLoc);
                    }
                }
                else if (ptValid == Ext.PathType.ValidFile) {
                    string sfileType = null;
                    if (sBaseLoc.EndsWith(".zip")) {
                        sfileType = ".cbz";
                    }
                    else if (sBaseLoc.EndsWith(".rar")) {
                        sfileType = ".cbr";
                    }

                    if (sfileType != null) {
                        int indx = sBaseLoc.LastIndexOf('.');
                        string sNewPath = sBaseLoc.Remove(indx, sBaseLoc.Length - indx) + sfileType;

                        File.Move(sBaseLoc, sNewPath);
                        acTxBx_Loc.Text = sNewPath;

                        Text = string.Format("File changed from {0} to {1} format"
                            , Path.GetExtension(sBaseLoc)
                            , sfileType
                        );
                    }
                }

                Cursor = Cursors.Default;
                msZipSource.Enabled = false;
            }
            else {
                xMessage.ShowWarning(string.Format("The file \"{0}.cbz\" already exists.", sBaseLoc));
            }
        }
Пример #3
0
        /// <summary>
        /// Converts a folder into a new cbz file
        /// </summary>
        private void MnTS_ZipSource_Click(object sender, EventArgs e)
        {
            string sBaseLoc = TxBx_Loc.Text.Trim();

              if (!File.Exists(sBaseLoc + ".cbz")) {
            SharpCompress.Common.CompressionInfo cmp = new SharpCompress.Common.CompressionInfo();
            this.Cursor = Cursors.WaitCursor;

            //zip the folder contents into a .cbz
            this.Text = "Compressing...";
            using (var archive = SCA.Zip.ZipArchive.Create()) {
              string[] asFiles = Directory.GetFiles(sBaseLoc);
              for (int x = 0; x < asFiles.Length; x++) {
            this.Text = string.Format("Compressing...{0}/{1}", x + 1, asFiles.Length);
            FileInfo fi = new FileInfo(asFiles[x]);
            archive.AddEntry(fi.Name, fi);
              }

              this.Text = "Saving to disk...";
              using (FileStream fs = new FileStream(sBaseLoc + ".cbz", FileMode.CreateNew)) {
            archive.SaveTo(fs, cmp);
              }
            }
            this.Text = "Compression complete";

            //Update the manga location and delete the old folder
            TxBx_Loc.Text = sBaseLoc + ".cbz";
            if (Ext.Accessible(sBaseLoc)) {
              DeleteLocation(sBaseLoc);
            }
            MnTS_ZipSource.Enabled = false;
            this.Cursor = Cursors.Default;
              }
              else {
            MessageBox.Show("The file \"" + sBaseLoc + ".cbz\" already exists.",
              Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
              }
        }
        private void Deploy_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog diag = new SaveFileDialog();

            diag.Title      = AMLResources.Properties.Resources.Title;
            diag.Filter     = AMLResources.Properties.Resources.SupportedCompressedFiles + DataStrings.SupportedCompressedFilesFilter;
            diag.FileName   = Configuration.Title.Replace(":", string.Empty).Replace(";", string.Empty).Replace("\\", string.Empty).Replace(" ", string.Empty).Replace("-", string.Empty) + ".zip";
            diag.DefaultExt = ".zip";
            if (diag.ShowDialog() == true)
            {
                FileHelper.DeleteFile(diag.FileName);


                SharpCompress.Common.CompressionInfo ci = new SharpCompress.Common.CompressionInfo();
                ci.DeflateCompressionLevel = SharpCompress.Compressor.Deflate.CompressionLevel.BestCompression;
                using (FileStream sw = new FileStream(diag.FileName, FileMode.Create, FileAccess.Write))
                {
                    //using (

                    SharpCompress.Writer.Zip.ZipWriter zw = new SharpCompress.Writer.Zip.ZipWriter(sw,
                                                                                                   ci,
                                                                                                   string.Format("Artemis Spaceship Bridge Simulator Mod: {0}\r\n\r\nMod ID: {1}\r\n\r\nPackaged by Artemis Mod Loader\r\n{2}\r\n\r\nDownload the latest Artemis Mod Loader from {3}",
                                                                                                                 Configuration.Title, Configuration.ID,
                                                                                                                 DateTime.Now.ToString(CultureInfo.CurrentCulture),
                                                                                                                 DataStrings.AMLUpdateURL));

                    //)
                    //{
                    DirectoryInfo dir = new DirectoryInfo(Configuration.InstalledPath);
                    foreach (FileInfo f in dir.GetFiles("*.*", SearchOption.AllDirectories))
                    {
                        using (FileStream fs = f.OpenRead())
                        {
                            string relativePath = string.Empty;
                            if (f.FullName.Length > Configuration.InstalledPath.Length)
                            {
                                relativePath = f.FullName.Substring(Configuration.InstalledPath.Length + 1);
                                //relativePath = relativePath.Substring(0, relativePath.Length - f.Name.Length);
                            }
                            zw.Write(relativePath, fs, f.LastWriteTime);
                        }
                    }
                    string           tmpPath = Path.Combine(Path.GetTempPath(), Configuration.Title.Replace(":", string.Empty).Replace(";", string.Empty).Replace("\\", string.Empty) + ".aml");
                    ModConfiguration config  = new ModConfiguration();
                    config.CopyProperties(Configuration);
                    config.InstalledPath = null;
                    config.Sequence      = 0;
                    config.ActiveFiles   = null;
                    if (config.BaseFiles.Files.Count == 0)
                    {
                        config.BaseFiles = null;
                    }
                    if (config.SubMods.SubMods.Count == 0)
                    {
                        config.SubMods = null;
                    }
                    config.Save(tmpPath);
                    using (FileStream fs = new FileStream(tmpPath, FileMode.Open, FileAccess.Read))
                    {
                        FileInfo f = new FileInfo(tmpPath);
                        zw.Write(f.Name, fs, DateTime.Now);
                    }
                    //}
                }
                Locations.MessageBoxShow("Package saved.", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }