コード例 #1
0
ファイル: ZipFile.cs プロジェクト: un-pogaz/ChromatikTool
        /// <summary>
        /// Remove the entrie with the given filename from the ZIP archive.
        /// </summary>
        /// <param name="entryName"></param>
        /// <returns></returns>
        public bool RemoveEntry(string entryName)
        {
            int index = Entries.IndexOf(entryName);

            if (index >= 0)
            {
                try
                {
                    zipFile.RemoveEntry(entryName);
                }
                catch (Ionic.Zip.ZipException ex)
                {
                    throw ZipException.FromIonic(ex);
                }
                catch (Ionic.Zlib.ZlibException ex)
                {
                    throw ZipException.FromIonic(ex);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        private void SaveContentXml(Ionic.Zip.ZipFile templateFile, System.Xml.XmlDocument contentXml)
        {
            templateFile.RemoveEntry("content.xml");

            System.IO.MemoryStream memStream = new System.IO.MemoryStream();
            contentXml.Save(memStream);
            memStream.Seek(0, System.IO.SeekOrigin.Begin);

            templateFile.AddEntry("content.xml", memStream);
        }
コード例 #3
0
ファイル: Zip.cs プロジェクト: mythocalos/webauto
        public void Save(string path, string fileName, string content, string password)
        {
            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(path))
            {
                zip.Password   = password;
                zip.Encryption = Ionic.Zip.EncryptionAlgorithm.WinZipAes256;

                if (zip["" + fileName + ""] != null)
                {
                    zip.RemoveEntry(fileName);
                }

                zip.AddEntry(fileName, content, System.Text.Encoding.UTF8);
                zip.Save(path);
            }
        }
コード例 #4
0
        public void delete(String filename)
        {
            //Use our zip archive to figure out what to delete. Ours can find directories even if they do not physically exist in the zip file.
            List <String> removeFiles = new List <string>();
            //Figure out what we are dealing with
            var fileInfo = zipFile.getFileInfo(filename);

            if (fileInfo.IsDirectory)
            {
                filename += '/';
                removeFiles.Add(filename);
                removeFiles.AddRange(zipFile.listDirectories(filename, "*", true).Select(e => e.FullName));
                removeFiles.AddRange(zipFile.listFiles(filename, "*", true).Select(e => e.FullName));
            }
            else
            {
                removeFiles.Add(filename);
            }
            if (removeFiles.Count > 0)
            {
                zipFile.Dispose();
                try
                {
                    using (Ionic.Zip.ZipFile ionicZip = new Ionic.Zip.ZipFile(resourceLocation))
                    {
                        foreach (String file in removeFiles)
                        {
                            //Have to check to make sure the file exists or the ionic library throws an exception
                            var entry = ionicZip[file];
                            if (entry != null)
                            {
                                ionicZip.RemoveEntry(entry);
                            }
                        }
                        ionicZip.Save();
                    }
                }
                finally
                {
                    zipFile = new ZipFile(resourceLocation);
                }
            }
        }
コード例 #5
0
        private void MergeModpackJar()
        {
            DeleteTempFolder();

            Directory.CreateDirectory(cd + "\\temp");
            File.Delete(cd + "\\plugins\\mergedjar\\modpack.jar");

            foreach (string file in Directory.GetFiles(cd + "\\plugins\\forgemodloader", "*forge*.jar"))
            {
                File.Copy(file, cd + "\\plugins\\mergedjar\\modpack.jar");
                break;
            }

            ZipFile.ExtractToDirectory(cd + "\\modpack\\bin\\modpack.jar", cd + "\\temp\\extract");

            using (Ionic.Zip.ZipFile jar = Ionic.Zip.ZipFile.Read(cd + "\\plugins\\mergedjar\\modpack.jar")) {
                if (Directory.GetFiles(cd + "\\temp\\extract", "*.*", SearchOption.AllDirectories).Length > 0)
                {
                    foreach (string file in Directory.GetFiles(cd + "\\temp\\extract", "*.*", SearchOption.AllDirectories))
                    {
                        if (jar.ContainsEntry(file))
                        {
                            jar.RemoveEntry(file);
                        }
                        jar.AddFile(file, file.Replace(Path.GetFileName(file), "").Replace(cd + "\\temp\\extract", ""));
                    }

                    bool succeed = false;

                    while (!succeed)
                    {
                        try {
                            jar.Save();
                            succeed = true;
                        }
                        catch { }
                    }
                }
            }

            DeleteTempFolder();
        }
コード例 #6
0
        //This creates a backup rollout xml document that is placed within the zip file being rolled out.
        //This backup can be used if the back end ever gets broken to restore the rollout file.
        internal static void createBackupRolloutDocument(XmlNode rolloutNode, int versionNumber, string connectionString)
        {
            XmlDocument    doc            = new XmlDocument();
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmlDeclaration, root);

            XmlElement baseDoc = doc.CreateElement("RolloutDocumentation");

            doc.AppendChild(baseDoc);

            XmlElement connInfoElement = doc.CreateElement("ConnectionInfo");

            connInfoElement.SetAttribute("ConnectionString", connectionString);
            connInfoElement.SetAttribute("ConnectionDateSet", DateTime.Now.ToString());
            baseDoc.AppendChild(connInfoElement);

            string   zipPath     = rolloutNode.Attributes.GetNamedItem("FullZipPath").Value;
            DateTime rolloutDate = DateTime.Parse(rolloutNode.Attributes.GetNamedItem("DateTimeStamp").Value);

            XmlElement version = doc.CreateElement("Version");

            version.InnerText = versionNumber.ToString();
            baseDoc.AppendChild(version);

            XmlElement userTypeEl = doc.CreateElement("UserType");

            userTypeEl.InnerText = rolloutNode.Name;
            baseDoc.AppendChild(userTypeEl);

            foreach (XmlAttribute att in rolloutNode.Attributes)
            {
                XmlElement newElement = doc.CreateElement(att.Name);
                newElement.InnerText = att.Value;
                baseDoc.AppendChild(newElement);
            }

            string backUpXML = Directory.GetCurrentDirectory() + "\\TempBackups\\" + rolloutDate.ToShortDateString().Replace("/", "-") + ".xml";

            doc.Save(backUpXML);
            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(zipPath))
            {
                try
                {
                    var file = zip.Entries.Single(p => p.FileName.Contains(".xml"));
                    if (file != null)
                    {
                        zip.RemoveEntry(file.FileName);
                    }
                    zip.Save();
                }
                catch (Exception)
                {
                }
                zip.AddFile(backUpXML, "");
                zip.Save();
                zip.Dispose();
            }
        }
コード例 #7
0
ファイル: program.cs プロジェクト: AlkindiX/packager
        public static void Main(string[] args)
        {
            LogAttrbute.log.Info("Starting up packager program...");
            Console.WriteLine("Packager v" + typeof(Program).Assembly.GetName().Version.ToString());
            Console.WriteLine("Packager  Copyright (C) 2015 by Mohamed Alkindi\n\tThis program comes with ABSOLUTELY NO WARRANTY; for details type `-l'.\n\tThis is free software, and you are welcome to redistribute it\n\tunder certain conditions.");
            Console.WriteLine();
            if (Information.IsNothing(Settings.Default.ExcludeFileList))
            {
                LogAttrbute.log.Info("Exclude file list value is null, create it");
                Settings.Default.ExcludeFileList = new System.Collections.Specialized.StringCollection();
            }
            if (Information.IsNothing(Settings.Default.ReleaseLocation))
            {
                LogAttrbute.log.Info("Release directory list is null, create it");
                Settings.Default.ReleaseLocation = new System.Collections.Specialized.StringCollection();
            }
            LogAttrbute.log.Info("Save settings");
            Settings.Default.Save();
            if (args.Length > 0)
            {
                ArgumnentsAhead(args);
                Settings.Default.Save();

                return;
            }
            if (Settings.Default.ReleaseLocation == null)
            {
                Console.Error.WriteLine("Release location is not defined. Please locate the release location at least one by -h for instructions");

                return;
            }
            if (Settings.Default.ExcludeFileList.Count <= 0)
            {
                Console.WriteLine("Warning: Exclude list is empty, type -h for argument list");
            }
            if (Settings.Default.ReleaseLocation.Count <= 0)
            {
                Console.WriteLine("Welcome to the release maker program, if this is your first time to open this program, this program help you to packaging your file into zip. when you execute this program, the program is immediately packeging your binaries or your produced files into zip format easily, but first , you must add your release directory list from where you went , you can use gui by type -e --g to open it, or you can use the command line to configuring your custom configuration by type -h for more instructions");
                Console.Error.WriteLine("The release directory list is empty, please enter -h for instructions");

                return;
            }
            foreach (var itemdir in Settings.Default.ReleaseLocation)
            {
                Console.WriteLine("Processing release directory \"" + itemdir);
                DirectoryInfo info = new DirectoryInfo((string)itemdir);
                IList<string> files = new List<string>();
                foreach (var item in info.GetFiles())
                {
                    files.Add(item.FullName);
                }
                var f = Settings.Default.ExcludeFileList;
                f.Add("release.zip");
                Console.WriteLine("Starting release maker");
                foreach (string item in f)
                {
                    foreach (string item2 in files)
                    {
                        if (item2.Contains(item))
                        {
                            Console.WriteLine("INFO: Excluding \"" + item2 + "\" from the list");
                            files.Remove(item2);
                            break;
                        }
                    }
                }
                var releasezipname = "release.zip";
                var releasefile = Path.Combine(info.FullName, releasezipname);
                if (File.Exists(releasezipname))
                {
                    Console.WriteLine("Warning: Release file is exist");
                }
                Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(releasefile);
                foreach (var file in files)
                {
                    if (zip.ContainsEntry(Path.GetFileName(file)))
                    {
                        zip.RemoveEntry(Path.GetFileName(file));
                        Console.WriteLine("Removing \"" + Path.GetFileName(file) + "\" from zip entry");
                    }
                    FileIOPermission parm = new FileIOPermission(FileIOPermissionAccess.AllAccess, file);
                    parm.AllLocalFiles = FileIOPermissionAccess.AllAccess;
                    try
                    {
                        parm.Demand();
                    }
                    catch (Exception sx)
                    {
                        LogAttrbute.log.LogFast(Common.Logging.Logging.LogFastInfo.Exception, sx.ToString());
                        Console.Error.WriteLine("Cannot add file name {0}, because you do not have the permission to read it, so this file is skip and not added to the zip file", file);
                        LogAttrbute.log.LogFast(Common.Logging.Logging.LogFastInfo.Error, string.Format("Cannot add file name {0}, because you do not have the permission to read it, so this file is skip and not added to the zip file", file));
                        continue;
                    }
                    zip.AddFile(file, "/");
                    Console.WriteLine("Adding \"" + Path.GetFileName(file) + "\" in the zip");
                }
                Console.WriteLine("Creating zip file...");
                try
                {
                    zip.Save();
                }
                catch (Exception sx)
                {
                    LogAttrbute.log.LogFast(Common.Logging.Logging.LogFastInfo.Exception, sx.ToString());
                    LogAttrbute.log.LogFast(Common.Logging.Logging.LogFastInfo.Error, "Cannot add the zip file into the directory because you do not have the permission to write the file");
                    Console.Error.WriteLine("Cannot add the zip file into the directory because you do not have the permission to write the file");
                    return;
                }
                Console.WriteLine("Creating zip file successful, produced file is located in \"" + releasefile + "\"");
            }
            Console.WriteLine();
        }
コード例 #8
-1
ファイル: Zip.cs プロジェクト: EricBlack/web-automation
        public void Save(string path, string fileName, string content, string password)
        {
            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(path))
            {
                zip.Password = password;
                zip.Encryption = Ionic.Zip.EncryptionAlgorithm.WinZipAes256;

                if (zip["" + fileName + ""] != null)
                {
                    zip.RemoveEntry(fileName);
                }

                zip.AddEntry(fileName, content, System.Text.Encoding.UTF8);
                zip.Save(path);
            }
        }