///// <summary> ///// Add additional files to the package ///// </summary> ///// <param name="filename">The filename (including path) of the file to add</param> //public void AddAdditionalFile(string filename) //{ // if (additionalFiles == null) // { // additionalFiles = new ArrayList(); // } // additionalFiles.Add(Path.GetFullPath(filename)); //} ///// <summary> ///// Gets the list of additional files in the package ///// </summary> ///// <returns>The list of full paths to the additional files</returns> //public string[] GetAdditionalFiles() //{ // if (additionalFiles != null) // { // return (string[])additionalFiles.ToArray(typeof(string)); // } // return null; //} /// <summary> /// Save the package on disk /// </summary> /// <param name="packageFilename"></param> /// <param name="arguments"></param> /// <returns></returns> public string Save(string packageFilename, Arguments arguments) { // Set the package to the given filename string package = arguments.Name; if (Path.GetExtension(package).Length == 0) { package += defaultExtension; } if (resultFile == null || !File.Exists(resultFile)) { //throw new Exception("The package MUST contain a result file before being saved"); GlobalLog.LogEvidence(new Exception("The package MUST contain a result file before being saved")); } // Fully expand the archiver name to ensure it is saved in the requested place // Create archiver archiver = Archiver.Create(Path.GetFullPath(package), true); // Add Master File if (masterFile != null) { AddFileFromPath(MasterFile, masterKey); } // Add the Result File AddResultFileFromPath(); // Add info xml File CreateInfoXmlFile(arguments); if (File.Exists(infoXmlFile)) { archiver.AddFile(infoXmlFile, infoKey, true); } //creates test info file for future use in master update app. CreateTestInfoXml(arguments); if (File.Exists(TestInfo)) { //AddFileFromPath(TestInfoFile, "TestInfoFile"); archiver.AddFile(TestInfo, testInfoKey, true); } // Generate package archiver.GenerateArchive(); // Return the full path to the archive return(Path.GetFullPath(package)); }
/// <summary> /// Save the package on disk /// </summary> public void Save() { CheckWellFormedPackage(); // lock (_staticLock) { // Create archiver _archiver = Archiver.Create(_packageName, true); // Add all entries IDictionaryEnumerator iter = _entries.GetEnumerator(); while (iter.MoveNext()) { string key = (string)iter.Key; Stream stream = iter.Value as Stream; Bitmap bitmap = iter.Value as Bitmap; XmlNode node = iter.Value as XmlNode; Enum enumerator = iter.Value as Enum; if (stream != null) { AddStreamFile(stream, key); } if (bitmap != null) { AddBitmapFile(bitmap, key); } if (node != null) { AddXmlNode(node, key); } if (enumerator != null) { // Add entry to Extra xml } } // Add extra info xml XmlTextWriter textWriter = null; try { textWriter = new XmlTextWriter(LOADERINFO, System.Text.UTF8Encoding.UTF8); textWriter.Formatting = Formatting.Indented; // textWriter.Settings.OmitXmlDeclaration = true; textWriter.WriteStartElement("LoaderInfo"); textWriter.WriteElementString("IsFailureAnalysis", IsFailureAnalysis.ToString()); textWriter.WriteElementString("PackageCompareTypes", ((int)PackageCompare).ToString()); textWriter.WriteElementString("ChannelCompareMode", ((int)ChannelCompare).ToString()); if (MasterSDLocation != null && MasterSDLocation != String.Empty) { textWriter.WriteElementString("MasterSDLocation", MasterSDLocation); } if (CommandLine != null && CommandLine != string.Empty) { textWriter.WriteElementString("CommandLine", CommandLine); } textWriter.WriteEndElement(); } catch { } finally { if (textWriter != null) { textWriter.Flush(); textWriter.Close(); } } _archiver.AddFile(LOADERINFO, LOADERINFO, true); // Generate package _archiver.GenerateArchive(); } // File has been saved to disk, we can now release the Lock }