static public void CreateZip(string filename) { int fileCount = 0; C1ZipFile ZipFile = null; try { ZipFile = new C1ZipFile(GetCompletePath() + filename); foreach (string file in Directory.GetFiles(GetCompletePath())) { if (!file.EndsWith(".zip")) { fileCount++; ZipFile.Entries.Add(file); } } ZipFile.Close(); } catch (System.Exception e) { ExitCode = JobStatus.JOB_FAILED; FatalError = "Failed to create zipped file archive. (" + e.Message + ")"; } finally { if (ZipFile != null) { ZipFile.Close(); ZipFile = null; } } }
static void Main(String[] args) { String DirectoryToRead = ""; String DirectoryToSave = ""; if (args.Length < 2) { Console.WriteLine("Usage: Zipper \\SourceFolder \\DestinationFile"); return; } if (args.Length > 0) { Console.WriteLine(args[0]); DirectoryToRead = args[0]; } if (args.Length > 1) { DirectoryToSave = args[1] + DateTime.Now.ToString("yyyyMMddHHmm") + ".zip"; Console.WriteLine(args[1] + DateTime.Now.ToString("yyyyMMddHHmm") + ".zip"); } Console.WriteLine(DirectoryToSave); Int32 Depth = 0; C1ZipFile zf = new C1ZipFile(DirectoryToSave, true); FolderLoop(DirectoryToRead, Depth, zf); zf.Close(); //Console.WriteLine("Press any key ..."); //Console.ReadKey(); }
private void InitializeCodeViewer() { // todo: correct below code to properly find samples inside zip string filename1 = _sample.TypeName.Replace('.', '/') + ".cs"; string filename2 = _sample.TypeName.Replace('.', '/') + ".Designer.cs"; // Code from WPF version: // var sourceArray = Source.Split('\\'); // string xaml = String.Format("{0}/{1}", sourceArray.First(), sourceArray.Last()); // string cs = String.Format("{0}/{1}.cs", sourceArray.First(), sourceArray.Last()); Stream s = _exAsm.GetManifestResourceStream(SOURCE_NAME); if (s != null) { C1ZipFile z = new C1ZipFile(); z.Open(s); if (z.Entries[filename1] != null) { _code.Add(filename1, string.Empty); } if (z.Entries[filename2] != null) { _code.Add(filename2, string.Empty); } z.Close(); } }
private void LoadZip() { // locate zip file string strFile = Application.ExecutablePath; int i = strFile.IndexOf("\\bin"); if (i > -1) { strFile = strFile.Substring(0, i); } strFile += "\\" + zipName; // open password-protected zip file C1ZipFile zip = new C1ZipFile(); zip.Open(strFile); zip.Password = zipPwd; // load report definition XML document from compressed stream Stream stream = zip.Entries[0].OpenReader(); _xmlDoc = new XmlDocument(); _xmlDoc.PreserveWhitespace = true; _xmlDoc.Load(stream); stream.Close(); // zip.Close(); // _lbReports.Items.AddRange(C1FlexReport.GetReportList(_xmlDoc)); }
void LoadProjectStructure() { Assembly asm = Assembly.GetExecutingAssembly(); Stream s = asm.GetManifestResourceStream("ControlExplorer.SourceCode.zip"); C1ZipFile z = new C1ZipFile(); z.Open(s); C1TreeNodeCollection targetNodeCollection = null; int previousLevel = -1; for (int i = 0; i < z.Entries.Count; i++) { string[] partsOfPath = z.Entries[i].FileName.Split('/'); int level = partsOfPath.Length - 2; int imageIndex = 0; if (!string.IsNullOrEmpty(partsOfPath[partsOfPath.Length - 1])) { level = partsOfPath.Length - 1; imageIndex = 2; } string nodeName = partsOfPath[level]; if (targetNodeCollection == null) { targetNodeCollection = c1TreeView1.Nodes; } else { if (previousLevel > level) { targetNodeCollection = targetNodeCollection.Parent.ParentCollection; } else if (previousLevel < level) { targetNodeCollection = targetNodeCollection.Last().Nodes; } } C1TreeNode node = targetNodeCollection.Add(nodeName); node.Images.Add(imageIndex); previousLevel = level; } z.Close(); }
private string GetCode(string filename) { Stream s = _exAsm.GetManifestResourceStream(SOURCE_NAME); string code = string.Empty; C1ZipFile z = new C1ZipFile(); z.Open(s); if (z.Entries[filename] != null) { StreamReader reader = new StreamReader(z.Entries[filename].OpenReader()); code = reader.ReadToEnd(); reader.Close(); } z.Close(); return(code); }
private void Clear() { _flex.ItemsSource = null; if (zipMemoryStream != null) { zipMemoryStream.Flush(); zipMemoryStream.Dispose(); } zipMemoryStream = null; _btnCompress.IsEnabled = false; _btnExtract.IsEnabled = false; if (_zip != null) { _zip.Close(); _zip = null; } }
/// <summary> /// Opens a package from a web instance. /// </summary> /// <param name="fileName"> The package file name.</param> public void OpenPackageWeb(string fileName) { C1ZipFile zipFile = new C1ZipFile(); // package = new ScriptingApplicationPackage(); try { zipFile.Open(fileName); // Application C1ZipEntry entry = zipFile.Entries[0]; // Get entry name and convert to guid // if invalid GUID, throw exception string name = entry.FileName; string applicationXml = string.Empty; string applicationArgumentsXml = string.Empty; // Get Scripting Application Xml. Guid g = new Guid(name); StreamReader reader = new StreamReader(entry.OpenReader(),System.Text.Encoding.UTF8); applicationXml= reader.ReadToEnd(); reader.Close(); if ( zipFile.Entries.Count > 1 ) { // Arguments entry = zipFile.Entries[1]; reader = new StreamReader(entry.OpenReader(),System.Text.Encoding.UTF8); applicationArgumentsXml = reader.ReadToEnd(); if ( applicationArgumentsXml.ToLower() != "none" ) { _arguments = ScriptingApplicationArgs.FromXml(applicationArgumentsXml); } else { _arguments = null; } reader.Close(); } // Get Custom Transforms int start = 2; for ( int i=2;i<zipFile.Entries.Count;i++ ) { entry = zipFile.Entries[i]; if ( entry.FileName == "CustomTransformsSeparator" ) { start = i+1; break; } // Add File References to Application Startup // string location = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + entry.FileName; // if ( !File.Exists(location) ) // { // zipFile.Entries.Extract(i, location); // } // Add WebTransform Entry in Configuration. // if exists don't add. // RegisterWebTransform(location); // ScriptingApplicationSerializer.UpdateSerializer(); } // Generate scripting application. XmlDocument document = new XmlDocument(); document.LoadXml(applicationXml); _application = ScriptingApplication.Decrypt(document); // _application = ScriptingApplication.FromXml(applicationXml); // // for ( int i=start;i<zipFile.Entries.Count;i++ ) // { // entry = zipFile.Entries[i]; // // // Add File References to Internet Cache // string location = Utils.AppLocation.InternetTemp + Path.DirectorySeparatorChar + _application.Header.ApplicationID + Path.DirectorySeparatorChar + entry.FileName; // if ( File.Exists(location) ) // { // File.Delete(location); // } // zipFile.Entries.Extract(i, location); // } } catch { throw; } finally { zipFile.Close(); } }
/// <summary> /// Reads the application id from the package. /// </summary> /// <param name="packageFile"> The package file.</param> /// <returns> An application id.</returns> public static string ReadApplicationID(string packageFile) { string result = string.Empty; C1ZipFile zipFile = new C1ZipFile(); try { zipFile.Open(packageFile); // Application C1ZipEntry entry = zipFile.Entries[0]; // Get entry name and convert to guid // if invalid GUID, throw exception string name = entry.FileName; Guid g = new Guid(name); result = name; } catch ( Exception ex ) { System.Diagnostics.Debug.Write(ex.ToString()); } finally { zipFile.Close(); } return result; }
// close current zip file void closeToolStripMenuItem_Click(object sender, EventArgs e) { _zipFile.Close(); UpdateUI(); }