public AddItem ( String fileOrDirectoryName, String directoryPathInArchive ) : |
||
fileOrDirectoryName | String | the name of the file or directory to add. /// |
directoryPathInArchive | String |
/// The name of the directory path to use within the zip archive. This path
/// need not refer to an extant directory in the current filesystem. If the
/// files within the zip are later extracted, this is the path used for the
/// extracted file. Passing |
Résultat |
static string CreateFileToUpload(IList<string> files) { if (files == null || files.Count == 0) { Console.WriteLine("No files were supplied"); Environment.Exit(1); } string temporaryFile = Path.GetTempFileName() + ".zip"; using (var zip = new ZipFile()) { foreach (string file in files) { if (File.Exists(file) || Directory.Exists(file)) { zip.AddItem(file); } else if (file.Contains("*") || file.Contains("?")) { string parent = Path.GetDirectoryName(file); if (parent == null) { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } string wildCard = Path.GetFileName(file); if (wildCard == null) { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } foreach (FileInfo fileInPattern in new DirectoryInfo(parent).GetFiles(wildCard)) { zip.AddItem(fileInPattern.FullName); } } else { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } } zip.Save(temporaryFile); } return temporaryFile; }
private void button3_Click(object sender, RoutedEventArgs e) { Directory.SetCurrentDirectory("C:/tmp/soundpcker"); using (ZipFile zip = new ZipFile()) { // add this map file into the "images" directory in the zip archive zip.AddFile("pack.mcmeta"); // add the report into a different directory in the archive zip.AddItem("assets"); zip.AddFile("lcrm"); zip.Save("CustomSoundInjector_ResourcePack.zip"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.DefaultExt = ".zip"; saveFileDialog.Filter = "Minecraft ResourcePack (with Bytecode)|*.zip"; if (saveFileDialog.ShowDialog() == true) { exportpath = saveFileDialog.FileName; } else { MessageBox.Show("Operation Cancelled.", "Cancelled", MessageBoxButton.OK, MessageBoxImage.Error); } string originExport = "C:/tmp/soundpcker/CustomSoundInjector_ResourcePack.zip"; File.Copy(originExport, exportpath, true); MessageBox.Show("Saved.", "Saved", MessageBoxButton.OK, MessageBoxImage.Information); }
public void ZipAndDeleteDirectory(string directory, string zipFile) { var zip = new ZipFile(); zip.AddItem(directory); zip.Save(zipFile); Directory.Delete(directory, true); }
public static bool Zip(string filePath, string TargetDirectory) { if (!File.Exists(filePath)) throw new ApplicationException(""); //if (!Directory.Exists(TargetDirectory)) // throw new ApplicationException(""); bool rv = false; try { using (ZipFile zip = new ZipFile()) { zip.Password = ZipPassword; zip.Comment = ""; //zip.AddFile(filePath); zip.AddItem(filePath,""); zip.Save(TargetDirectory); } } catch (Exception) { rv = false; } return rv; }
private void FileForm_Load(object sender, EventArgs e) { this.Icon = Resources.icon; if (Clipboard.ContainsFileDropList()) { var fileDropList = Clipboard.GetFileDropList(); String now = DateTime.Now.ToString("yyyyMMdd_HHmmss"); if (fileDropList.Count == 1) { var path = fileDropList[0]; FileAttributes attr = File.GetAttributes(path); if ((attr & FileAttributes.Directory) != FileAttributes.Directory) { var filename = Path.GetFileNameWithoutExtension(path) + "-" + now + Path.GetExtension(path); File.Copy(path, Properties.Settings.Default.savefolder + @"\" + filename); String url = Properties.Settings.Default.urlprefix + filename + Properties.Settings.Default.urlsuffix; richTextBox1.Text += "Added file to Dropbox:\n" + filename; Clipboard.SetDataObject(url, true); return; } } //Multiple files/directory, zip it using (ZipFile zip = new ZipFile()) { var files = new List<string>(); richTextBox1.Text += "Zipped and added multiple files to Dropbox:\n"; foreach (var file in fileDropList) { files.Add(file); richTextBox1.Text += file + "\n"; } var commonDir = FindCommonDirectoryPath.FindCommonPath("/", files); foreach (var file in files) { zip.AddItem(file, commonDir); } var filename = now + ".zip"; zip.Save(Properties.Settings.Default.savefolder + @"\" + filename); String url = Properties.Settings.Default.urlprefix + filename + Properties.Settings.Default.urlsuffix; Clipboard.SetDataObject(url, true); return; } } }
public ActionResult Download_MyDebtonator() { Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("Content-Disposition", "filename=MyDebtonator.zip"); using (ZipFile zip = new ZipFile()) { var filePath = Server.MapPath("~/Content/downloads/my_debtonator/MydebtonatorInstaller.msi"); zip.AddItem(filePath, "MyDebtonator"); filePath = Server.MapPath("~/Content/downloads/my_debtonator/MydebtonatorInstaller.exe"); zip.AddItem(filePath, "MyDebtonator"); zip.Save(Response.OutputStream); Response.BufferOutput = false; } return View("Downloads"); }
public void CreateFolder(string directoryname) { int index = path.LastIndexOf('\\'); string name = path.Remove(index, path.Length - index); var dir = Directory.CreateDirectory(name + '\\' + directoryname); // zp.AddDirectory(dir.FullName); using (Ionic.Zip.ZipFile zp = Ionic.Zip.ZipFile.Read(path)) { zp.AddItem(dir.FullName, directoryname); zp.Save(); } dir.Delete(); }
/// <summary> /// 备份文件 /// </summary> /// <param name="dirs"></param> /// <param name="path"></param> static void BackUpFile(string baseDir, string[] dirs, string path) { string fileName = string.Format(@"{0}\source.zip", path); List<string> list = new List<string>(); //foreach (string dir in dirs) //{ // list.AddRange(GetFiles(dir)); //} using (ZipFile zf = new ZipFile()) { foreach (string dir in dirs) { zf.AddItem(baseDir + dir, dir); } zf.Save(fileName); } }
public void CreateZip_AddItem_WithDirectory() { // select the name of the zip file string zipFileToCreate = "CreateZip_AddItem.zip"; // create a bunch of files string subdir = "files"; string[] filesToZip = TestUtilities.GenerateFilesFlat(subdir); // Create the zip archive using (ZipFile zip1 = new ZipFile()) { //zip.StatusMessageTextWriter = System.Console.Out; for (int i = 0; i < filesToZip.Length; i++) zip1.AddItem(filesToZip[i], "files"); zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length); }
//public static bool ZipFiles(string outputFile, string password, List<string> inputFiles) public static bool ZipFiles(string outputFile, string password, string directoryToZip) { try { using (ZipFile zip = new ZipFile()) { if (!string.IsNullOrEmpty(password)) { zip.Password = password.Replace(@"\", "").Trim(); } //zip.AddFiles(inputFiles); zip.AddItem(directoryToZip); zip.Save(outputFile); } } catch (Exception ex) { string xxx = ex.ToString(); return false; } return true; }
[Timeout(3 * 60 * 1000)] // timeout in ms. public void VStudio_UnZip() { string zipFileToCreate = "VStudio_UnZip.zip"; string shortDir = "files"; string subdir = Path.Combine(TopLevelDir, shortDir); string extractDir = "extract"; string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); // Create the zip archive //Directory.SetCurrentDirectory(TopLevelDir); using (ZipFile zip1 = new ZipFile()) { for (int i = 0; i < filesToZip.Length; i++) zip1.AddItem(filesToZip[i], shortDir); zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // unzip var decompressor = new Microsoft.VisualStudio.Zip.ZipFileDecompressor(zipFileToCreate, false, true, false); decompressor.UncompressToFolder(extractDir, false); // check the files in the extract dir VerifyChecksums(Path.Combine(extractDir, shortDir), filesToZip, checksums); // visual Studio's ZIP library doesn't bother with times... //VerifyNtfsTimes(Path.Combine(extractDir, "files"), filesToZip); }
public void ShellApplication_Unzip_SFX() { // get a set of files to zip up string subdir = Path.Combine(TopLevelDir, "files"); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); var script = GetScript("VbsUnzip-ShellApp.vbs"); int i=0; foreach (var compLevel in compLevels) { // create and fill the directories string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("ShellApp_Unzip_SFX.{0}.exe", i)); string extractDir = Path.Combine(TopLevelDir, String.Format("extract.{0}",i)); // Create the zip archive using (ZipFile zip1 = new ZipFile()) { zip1.CompressionLevel = (Ionic.Zlib.CompressionLevel) compLevel; //zip.StatusMessageTextWriter = System.Console.Out; for (int j = 0; j < filesToZip.Length; j++) zip1.AddItem(filesToZip[j], "files"); zip1.SaveSelfExtractor(zipFileToCreate, SelfExtractorFlavor.ConsoleApplication); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // run the unzip script this.Exec(cscriptExe, String.Format("\"{0}\" {1} {2}", script, zipFileToCreate, extractDir)); // check the files in the extract dir VerifyChecksums(Path.Combine(extractDir, "files"), filesToZip, checksums); // verify the file times VerifyTimesDos(Path.Combine(extractDir, "files"), filesToZip); i++; } }
public void ShellApplication_Unzip_NonSeekableOutput() { // get a set of files to zip up string subdir = Path.Combine(TopLevelDir, "files"); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); var script = GetScript("VbsUnzip-ShellApp.vbs"); int i = 0; foreach (var compLevel in compLevels) { // create and fill the directories string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("ShellApplication_Unzip_NonSeekableOutput.{0}.zip", i)); string extractDir = Path.Combine(TopLevelDir, String.Format("extract.{0}", i)); // Create the zip archive //Directory.SetCurrentDirectory(TopLevelDir); // Want to test the library when saving to non-seekable output streams. Like // stdout or ASPNET's Response.OutputStream. This simulates it. using (var rawOut = System.IO.File.Create(zipFileToCreate)) { using (var nonSeekableOut = new Ionic.Zip.Tests.NonSeekableOutputStream(rawOut)) { using (ZipFile zip1 = new ZipFile()) { zip1.CompressionLevel = (Ionic.Zlib.CompressionLevel)compLevel; for (int j = 0; j < filesToZip.Length; j++) zip1.AddItem(filesToZip[j], "files"); zip1.Save(nonSeekableOut); } } } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // run the unzip script this.Exec(cscriptExe, String.Format("\"{0}\" {1} {2}", script, Path.GetFileName(zipFileToCreate), Path.GetFileName(extractDir))); // check the files in the extract dir VerifyChecksums(Path.Combine(extractDir, "files"), filesToZip, checksums); VerifyFileTimes(Path.Combine(extractDir, "files"), filesToZip, false, false, 20000 * 1000); // 2s threshold for DOS times i++; } }
public void SevenZip_Unzip_SFX() { if (!SevenZipIsPresent) throw new Exception("[7z_Unzip_SFX] : SevenZip is not present"); string zipFileToCreate = Path.Combine(TopLevelDir, "7z_Unzip_SFX.exe"); // create and fill the directories string subdir = Path.Combine(TopLevelDir, "files"); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); // Create the zip archive with DotNetZip //Directory.SetCurrentDirectory(TopLevelDir); using (ZipFile zip1 = new ZipFile()) { for (int i = 0; i < filesToZip.Length; i++) zip1.AddItem(filesToZip[i], "files"); zip1.SaveSelfExtractor(zipFileToCreate, SelfExtractorFlavor.ConsoleApplication); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // unpack the zip archive via 7z.exe Directory.CreateDirectory("extract"); Directory.SetCurrentDirectory("extract"); this.Exec(sevenZip, String.Format("x {0}", zipFileToCreate)); // check the files in the extract dir Directory.SetCurrentDirectory(TopLevelDir); VerifyChecksums(Path.Combine("extract", "files"), filesToZip, checksums); }
protected void test() { /* ��C:\TMP\TMP2\01.jpg �ļ�ѹ���� test01.zip �ļ��е� TMP\TMP2\01.jpg * 2: * �� D:\02.jpg�ļ�ѹ���� test01.zip �ļ��е� 02.jpg * 3: * �� C:\TMP\03.jpg�ļ�ѹ���� test01.zip �ļ��е� TMP\03.jpg * 4: */ using (ZipFile zip = new ZipFile(@"C:\test01.zip")) { zip.AddFile(@"C:\TMP\TMP2\01.jpg"); zip.AddFile(@"D:\02.jpg"); zip.AddFile(@"C:\TMP\03.jpg"); zip.Save(); } // �� TMP2 Ŀ¼ѹ���� test02.zip �ļ��е� TMP\TMP2 Ŀ¼ using (ZipFile zip = new ZipFile(@"C:\test02.zip")) { zip.AddDirectory(@"C:\TMP\TMP2"); zip.Save(); } /* �� TMP2 Ŀ¼ѹ���� test03.zip �ļ��е� TTT Ŀ¼ 21: * * �� C:\TMP\03.jpg�ļ�ѹ���� test03.zip �ļ��е� TTT\03.jpg 22: */ using (ZipFile zip = new ZipFile(@"C:\test03.zip")) { zip.AddFile(@"C:\TMP\03.jpg", "TTT"); zip.AddItem(@"C:\TMP\TMP2", "TTT"); zip.Save(); } // �� C:\test03.zip �ļ���ѹ���� C:\ using (ZipFile zip = new ZipFile(@"C:\test03.zip")) { zip.ExtractAll(@"C:\"); } }
private void worker_DoWork(object sender, DoWorkEventArgs e) { // create new zip file using (ZipFile zip = new ZipFile()) { // trim each csv file foreach (ThirdCouncelorMLSFilesMLSFile csvFile in this.thirdCouncelorXml.CSVFiles) { string newFilename = this.currentDirectory + "\\" + csvFile.Name; string origFilename = newFilename + ".orig"; File.Move(newFilename, origFilename); using (StreamReader origFile = new StreamReader(origFilename)) { using (StreamWriter newFile = new StreamWriter(newFilename)) { CSVTrimmer csvTrimmer = new CSVTrimmer(csvFile); csvTrimmer.ExtractData(origFile, newFile); } } // add new to zip file zip.AddItem(newFilename, ""); } zip.Save(this.currentDirectory + "\\" + "EQZipFile.zip"); } Thread.Sleep(1000); // delete csv files StringBuilder sb = new StringBuilder(); foreach (ThirdCouncelorMLSFilesMLSFile csvFile in this.thirdCouncelorXml.CSVFiles) { sb.Remove(0, sb.Length); sb.Append(this.currentDirectory); sb.Append("\\"); sb.Append(csvFile.Name); File.Delete(sb.ToString()); sb.Append(".orig"); File.Delete(sb.ToString()); } }
public void CreateZip_AddFile_AddItem() { string zipFileToCreate = "CreateZip_AddFile_AddItem.zip"; string subdir = "files"; string[] filesToZip = TestUtilities.GenerateFilesFlat(subdir); // use the parameterized ctor using (ZipFile zip1 = new ZipFile()) { for (int i = 0; i < filesToZip.Length; i++) { if (_rnd.Next(2) == 0) zip1.AddFile(filesToZip[i], "files"); else zip1.AddItem(filesToZip[i], "files"); } zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length); }
public void COM_Unzip() { string zipFileToCreate = Path.Combine(TopLevelDir, "COM_Unzip.zip"); // construct the directories //string ExtractDir = Path.Combine(TopLevelDir, "extract"); string extractDir = "extract"; string shortDir = "files"; string subdir = Path.Combine(TopLevelDir, shortDir); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); // Create the zip archive //Directory.SetCurrentDirectory(TopLevelDir); using (ZipFile zip1 = new ZipFile()) { for (int i = 0; i < filesToZip.Length; i++) zip1.AddItem(filesToZip[i], shortDir); zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // run the COM script to unzip the ZIP archive string script = GetScript("VbsUnzip-DotNetZip.vbs"); this.Exec(cscriptExe, String.Format("\"{0}\" {1} {2}", script, zipFileToCreate, extractDir)); // check the files in the extract dir VerifyChecksums(Path.Combine(extractDir, shortDir), filesToZip, checksums); VerifyTimesNtfs(Path.Combine(extractDir, shortDir), filesToZip); }
void Publish() { string webplayer = PlayerPrefs.GetString("Course_Export"); string tempdir = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName(); System.IO.Directory.CreateDirectory(tempdir); CopyFilesRecursively(new System.IO.DirectoryInfo(webplayer), new System.IO.DirectoryInfo(tempdir)); string zipfile = EditorUtility.SaveFilePanel("Choose Output File", webplayer, PlayerPrefs.GetString("Course_Title"), "zip"); if (zipfile != "") { if (File.Exists(zipfile)) { File.Delete(zipfile); } Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipfile); zip.AddDirectory(tempdir); if (PlayerPrefs.GetInt("SCORM_Version") < 3) { zip.AddItem(Application.dataPath + "/ADL SCORM/Plugins/2004"); string manifest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!-- exported by Unity-SCORM Integration Toolkit Version 1.4 Beta-->" + "<manifest xmlns=\"http://www.imsglobal.org/xsd/imscp_v1p1\" xmlns:imsmd=\"http://www.imsglobal.org/xsd/imsmd_v1p2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_v1p3\" xmlns:imsss=\"http://www.imsglobal.org/xsd/imsss\" xmlns:adlseq=\"http://www.adlnet.org/xsd/adlseq_v1p3\" xmlns:adlnav=\"http://www.adlnet.org/xsd/adlnav_v1p3\" identifier=\"MANIFEST-AECEF15E-06B8-1FAB-5289-73A0B058E2DD\" xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd\" version=\"1.3\">" + " <metadata>" + " <schema>ADL SCORM</schema>" + ((PlayerPrefs.GetInt("SCORM_Version") == 0)?" <schemaversion>2004 4th Edition</schemaversion>":"") + ((PlayerPrefs.GetInt("SCORM_Version") == 1)?" <schemaversion>2004 3rd Edition</schemaversion>":"") + ((PlayerPrefs.GetInt("SCORM_Version") == 2)?" <schemaversion>2004 CAM 1.3</schemaversion>":"") + " </metadata>" + " <organizations default=\"ORG-8770D9D9-AD66-06BB-9A3D-E87784C697FF\">" + " <organization identifier=\"ORG-8770D9D9-AD66-06BB-9A3D-E87784C697FF\">" + " <title>" + PlayerPrefs.GetString("Course_Title") + "</title>" + " <item identifier=\"ITEM-79701DB3-F0AD-9426-8C43-819F3CB0EE6E\" identifierref=\"RES-4F17946A-9286-D5F0-7B6A-04E980C04F46\" parameters=\"" + GetParameterString() + "\">" + " <title>"+ PlayerPrefs.GetString("SCO_Title") + "</title>" + " <adlcp:dataFromLMS>"+ PlayerPrefs.GetString("Data_From_Lms") + "</adlcp:dataFromLMS>" + " <adlcp:completionThreshold completedByMeasure = \""+ (System.Convert.ToBoolean(PlayerPrefs.GetInt("completedByMeasure"))).ToString().ToLower() + "\" minProgressMeasure= \"" + PlayerPrefs.GetFloat("minProgressMeasure") + "\" />"; if (PlayerPrefs.GetInt("satisfiedByMeasure") == 1) { manifest += " <imsss:sequencing>"+ " <imsss:objectives>"+ " <imsss:primaryObjective objectiveID = \"PRIMARYOBJ\""+ " satisfiedByMeasure = \""+ (System.Convert.ToBoolean(PlayerPrefs.GetInt("satisfiedByMeasure"))).ToString().ToLower() + "\">" + " <imsss:minNormalizedMeasure>"+ PlayerPrefs.GetFloat("minNormalizedMeasure") + "</imsss:minNormalizedMeasure>" + " </imsss:primaryObjective>"+ " </imsss:objectives>"+ " </imsss:sequencing>"; } manifest += " </item>" + " </organization>" + " </organizations>" + " <resources>" + " <resource identifier=\"RES-4F17946A-9286-D5F0-7B6A-04E980C04F46\" type=\"webcontent\" href=\"WebPlayer/WebPlayer.html\" adlcp:scormType=\"sco\">" + " <file href=\"WebPlayer/WebPlayer.html\" />" + " <file href=\"WebPlayer/scripts/scorm.js\" />" + " <file href=\"WebPlayer/scripts/ScormSimulator.js\" />"+ " <file href=\"WebPlayer/UnityObject.js\" />"+ " <file href=\"WebPlayer/Webplayer.unity3d\" />"+ " <file href=\"WebPlayer/images/scorm_progres_bar.png\" />"+ " <file href=\"WebPlayer/images/thumbnail.png\" />"+ " </resource>" + " </resources>" + "</manifest>"; zip.AddEntry("imsmanifest.xml", ".", System.Text.ASCIIEncoding.ASCII.GetBytes(manifest)); } else { zip.AddItem(Application.dataPath + "/ADL SCORM/Plugins/1.2"); string manifest = "<?xml version=\"1.0\"?>" + "<!-- exported by Unity-SCORM Integration Toolkit Version 1.4 Beta-->" + "<manifest identifier=\"SingleCourseManifest\" version=\"1.1\"" + " xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\"" + " xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_rootv1p2\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xsi:schemaLocation=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd" + " http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd" + " http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd\">" + " <organizations default=\"B0\">" + " <organization identifier=\"B0\">" + " <title>" + PlayerPrefs.GetString("Course_Title") + "</title>" + " <item identifier=\"IS12\" identifierref=\"RS12\" parameters=\""+ GetParameterString() + "\">" + " <title>"+ PlayerPrefs.GetString("SCO_Title") + "</title>" + " <adlcp:dataFromLMS>"+ PlayerPrefs.GetString("Data_From_Lms") + "</adlcp:dataFromLMS>" + " <adlcp:masteryscore>"+ PlayerPrefs.GetFloat("masteryscore") + "</adlcp:masteryscore>" + " </item>"+ " </organization>"+ " </organizations>"+ " <resources>"+ " <resource identifier=\"RS12\" type=\"webcontent\""+ " adlcp:scormtype=\"sco\" href=\"WebPlayer/WebPlayer.html\">"+ " </resource>"+ " </resources>"+ " </manifest>"; zip.AddEntry("imsmanifest.xml", ".", System.Text.ASCIIEncoding.ASCII.GetBytes(manifest)); } zip.Save(); } }
public void COM_CheckWithExtract() { string zipFileToCreate = Path.Combine(TopLevelDir, "COM_CheckWithExtract.zip"); // create and fill the directories string subdir = Path.Combine(TopLevelDir, "files"); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); // Create the zip archive //Directory.SetCurrentDirectory(TopLevelDir); using (ZipFile zip1 = new ZipFile()) { for (int i = 0; i < filesToZip.Length; i++) zip1.AddItem(filesToZip[i], "files"); zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file."); // run the COM script to check and test-extract the ZIP archive string script = GetScript("TestCheckZip.js"); string testOut = this.Exec(cscriptExe, String.Format("\"{0}\" -x {1}", script, zipFileToCreate)); Assert.IsTrue(testOut.StartsWith("That zip is OK"), "output: {0}", testOut); }
public ActionResult Download_SGVHS_VCDB() { Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("Content-Disposition", "filename=SGVHS-VCDB.zip"); using (var zip = new ZipFile()) { var filePath = Server.MapPath("~/Content/downloads/SGVHS_VCDB/SGVHS_VCDB_APP.zip"); zip.AddItem(filePath, "SGVHS-VCDB"); filePath = Server.MapPath("~/Content/downloads/SGVHS_VCDB/SGVHS_VCDB_Database.zip"); zip.AddItem(filePath, "SGVHS-VCDB"); zip.Save(Response.OutputStream); Response.BufferOutput = false; } return View("Downloads"); }
public static void magix_package_pack(object sender, ActiveEventArgs e) { Node ip = Ip(e.Params); if (ShouldInspect(ip)) { AppendInspectFromResource( ip["inspect"], "Magix.tiedown", "Magix.tiedown.hyperlisp.inspect.hl", "[magix.package.pack-dox].value"); AppendCodeFromResource( ip, "Magix.tiedown", "Magix.tiedown.hyperlisp.inspect.hl", "[magix.package.pack-sample]"); return; } Node dp = Dp(e.Params); if (!ip.Contains("files")) throw new ArgumentException("no [files] given to [magix.package.pack]"); string zipFile = Expressions.GetFormattedExpression("zip", e.Params, ""); string zipAbsolutePath = HttpContext.Current.Server.MapPath(zipFile); using (ZipFile zip = new ZipFile()) { foreach (Node idxZipFile in ip["files"]) { zip.AddItem(HttpContext.Current.Server.MapPath(idxZipFile.Get<string>()), idxZipFile.Name ?? ""); } zip.Save(zipAbsolutePath); } }
/// <summary> /// Publish this SCORM package to a conformant zip file. /// </summary> void Publish() { string timeLimitAction = ""; switch (PlayerPrefs.GetInt("Time_Limit_Action")) { case 0: timeLimitAction = ""; break; case 1: timeLimitAction = "exit,message"; break; case 2: timeLimitAction = "exit,no message"; break; case 3: timeLimitAction = "continue,message"; break; case 4: timeLimitAction = "continue,no message"; break; } string timeLimit = SecondsToTimeInterval(ParseFloat(PlayerPrefs.GetString("Time_Limit_Secs"))); string webplayer = PlayerPrefs.GetString("Course_Export"); string tempdir = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName(); System.IO.Directory.CreateDirectory(tempdir); CopyFilesRecursively(new System.IO.DirectoryInfo(webplayer), new System.IO.DirectoryInfo(tempdir)); string zipfile = EditorUtility.SaveFilePanel("Choose Output File", webplayer, PlayerPrefs.GetString("Course_Title"), "zip"); if (zipfile != "") { if (File.Exists(zipfile)) { File.Delete(zipfile); } Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipfile); zip.AddDirectory(tempdir); zip.AddItem(Application.dataPath + "/SCORM/Plugins/2004"); string manifest = "<?xml version=\"1.0\" standalone=\"no\" ?>\n" + "<manifest identifier=\"" + PlayerPrefs.GetString("Manifest_Identifier") + "\" version=\"1\"\n" + "\t\txmlns = \"http://www.imsglobal.org/xsd/imscp_v1p1\"\n" + "\t\txmlns:adlcp = \"http://www.adlnet.org/xsd/adlcp_v1p3\"\n" + "\t\txmlns:adlseq = \"http://www.adlnet.org/xsd/adlseq_v1p3\"\n" + "\t\txmlns:adlnav = \"http://www.adlnet.org/xsd/adlnav_v1p3\"\n" + "\t\txmlns:imsss = \"http://www.imsglobal.org/xsd/imsss\"\n" + "\t\txmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t\txmlns:lom=\"http://ltsc.ieee.org/xsd/LOM\"\n" + "\t\txsi:schemaLocation = \"http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd\n" + "\t\t\thttp://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd\n" + "\t\t\thttp://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd\n" + "\t\t\thttp://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd\n" + "\t\t\thttp://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd\n" + "\t\t\thttp://ltsc.ieee.org/xsd/LOM lom.xsd\" >\n" + "<metadata>\n" + "\t<schema>ADL SCORM</schema>\n" + "\t<schemaversion>2004 4th Edition</schemaversion>\n" + "<lom:lom>\n" + "\t<lom:general>\n" + "\t\t<lom:description>\n" + "\t\t\t<lom:string language=\"en-US\">" + PlayerPrefs.GetString("Course_Description") + "</lom:string>\n" + "\t\t</lom:description>\n" + "\t</lom:general>\n" + "\t</lom:lom>\n" + "</metadata>\n" + "<organizations default=\"B0\">\n" + "\t<organization identifier=\"B0\" adlseq:objectivesGlobalToSystem=\"false\">\n" + "\t\t<title>" + PlayerPrefs.GetString("Course_Title") + "</title>\n" + "\t\t<item identifier=\"i1\" identifierref=\"r1\" isvisible=\"true\">\n" + "\t\t\t<title>" + PlayerPrefs.GetString("SCO_Title") + "</title>\n" + "\t\t\t<adlcp:timeLimitAction>" + timeLimitAction + "</adlcp:timeLimitAction>\n" + "\t\t\t<adlcp:dataFromLMS>" + PlayerPrefs.GetString("Data_From_Lms") + "</adlcp:dataFromLMS> \n" + "\t\t\t<adlcp:completionThreshold completedByMeasure = \"" + (System.Convert.ToBoolean(PlayerPrefs.GetInt("completedByMeasure"))).ToString().ToLower() + "\" minProgressMeasure= \"" + PlayerPrefs.GetFloat("minProgressMeasure") + "\" />\n" + "\t\t\t<imsss:sequencing>\n" + "\t\t\t<imsss:limitConditions attemptAbsoluteDurationLimit=\"" + timeLimit + "\"/>\n" + "\t\t\t</imsss:sequencing>\n" + "\t\t</item>\n" + "\t</organization>\n" + "</organizations>\n" + "<resources>\n" + "\t<resource identifier=\"r1\" type=\"webcontent\" adlcp:scormType=\"sco\" href=\"" + PlayerPrefs.GetString("Course_Export_Name") + ".html\">\n" + "\t\t<file href=\"" + PlayerPrefs.GetString("Course_Export_Name") + ".html\" />\n" + "\t\t<file href=\"scripts/scorm.js\" />\n" + "\t\t<file href=\"scripts/ScormSimulator.js\" />\n" + "\t\t<file href=\"" + PlayerPrefs.GetString("Course_Export_Name") + ".unity3d\" />\n" + "\t</resource>\n" + "</resources>\n" + "</manifest>"; zip.AddEntry("imsmanifest.xml", ".", System.Text.ASCIIEncoding.ASCII.GetBytes(manifest)); zip.Save(); EditorUtility.DisplayDialog("SCORM Package Published", "The SCORM Package has been published to " + zipfile, "OK"); } }
public void CreateZip_Basic_ParameterizedSave() { string zipFileToCreate = "CreateZip_Basic_ParameterizedSave.zip"; string subdir = "files"; int numFilesToCreate = _rnd.Next(23) + 14; string[] filesToZip = TestUtilities.GenerateFilesFlat(subdir, numFilesToCreate); using (ZipFile zip1 = new ZipFile()) { //zip.StatusMessageTextWriter = System.Console.Out; for (int i = 0; i < filesToZip.Length; i++) { if (_rnd.Next(2) == 0) zip1.AddFile(filesToZip[i], "files"); else zip1.AddItem(filesToZip[i], "files"); } zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length); }
private static void savePreviousFiles() { try { if (File.Exists(PNStrings.OLD_EDITION_ARCHIVE)) File.Delete(PNStrings.OLD_EDITION_ARCHIVE); var zipFile = new ZipFile(PNStrings.OLD_EDITION_ARCHIVE); var di = new DirectoryInfo(PNPaths.Instance.DataDir); var files = di.GetFiles().Select(f => f.FullName); zipFile.AddFiles(files, false, Path.GetFileName(PNPaths.Instance.DataDir)); zipFile.AddItem(PNPaths.Instance.SettingsDBPath, ""); zipFile.Save(); } catch (Exception ex) { PNStatic.LogException(ex); } }
public void CreateZip_AddItem_NoDirectory() { string zipFileToCreate = "CreateZip_AddItem.zip"; string[] filesToZip = TestUtilities.GenerateFilesFlat("."); // Create the zip archive using (ZipFile zip1 = new ZipFile()) { foreach (var f in filesToZip) zip1.AddItem(f); zip1.Save(zipFileToCreate); } // Verify the number of files in the zip Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length); }
public void InfoZip_Unzip() { if (!InfoZipIsPresent) throw new Exception("[InfoZip_Unzip] : InfoZip is not present"); string shortDir = "filesToZip"; string subdir = Path.Combine(TopLevelDir, shortDir); string[] filesToZip; Dictionary<string, byte[]> checksums; CreateFilesAndChecksums(subdir, out filesToZip, out checksums); for (int j=0; j < 2; j++) // crypto.Length { // Cannot do WinZipAES encryption - not supported by InfoZip int i = 0; foreach (var compLevel in compLevels) { string zipFileToCreate = String.Format("InfoZip_Unzip.{0}.{1}.zip", i,j); string password = GeneratePassword(9); // Create the zip archive using (ZipFile zip1 = new ZipFile()) { zip1.CompressionLevel = (Ionic.Zlib.CompressionLevel)compLevel; if (j!=0) { zip1.Encryption = crypto[j]; zip1.Password = password; } for (int n = 0; n < filesToZip.Length; n++) zip1.AddItem(filesToZip[n], shortDir); zip1.Save(zipFileToCreate); } Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length, "Incorrect number of entries in the zip file"+ " (i,j)=({0},{1}).", i,j); string extractDir = String.Format("extract.{0}.{1}", i,j); if (j==0) { this.Exec(infoZipUnzip, String.Format("{0} -d {1}", Path.GetFileName(zipFileToCreate), Path.GetFileName(extractDir))); } else { this.Exec(infoZipUnzip, String.Format("-P {0} {1} -d {2}", password, Path.GetFileName(zipFileToCreate), Path.GetFileName(extractDir))); } var extractedFiles = Directory.GetFiles(Path.Combine(extractDir, shortDir)); Assert.AreEqual<int> (filesToZip.Length, extractedFiles.Length, "Incorrect number of extracted files. (i,j)={0},{1}", i,j); VerifyChecksums(Path.Combine(extractDir, shortDir), filesToZip, checksums); i++; } } }
void Publish() { string webplayer = PlayerPrefs.GetString("Course_Export"); string tempdir = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName(); System.IO.Directory.CreateDirectory(tempdir); CopyFilesRecursively(new System.IO.DirectoryInfo(webplayer),new System.IO.DirectoryInfo(tempdir)); string zipfile = EditorUtility.SaveFilePanel("Choose Output File",webplayer,PlayerPrefs.GetString("Course_Title"),"zip"); if(zipfile!= "") { if(File.Exists(zipfile)) File.Delete(zipfile); Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipfile); zip.AddDirectory(tempdir); if(PlayerPrefs.GetInt("SCORM_Version") < 3) { zip.AddItem(Application.dataPath + "/ADL SCORM/Plugins/2004"); string manifest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!-- exported by Unity-SCORM Integration Toolkit Version 1.3 Beta-->"+ "<manifest xmlns=\"http://www.imsglobal.org/xsd/imscp_v1p1\" xmlns:imsmd=\"http://www.imsglobal.org/xsd/imsmd_v1p2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_v1p3\" xmlns:imsss=\"http://www.imsglobal.org/xsd/imsss\" xmlns:adlseq=\"http://www.adlnet.org/xsd/adlseq_v1p3\" xmlns:adlnav=\"http://www.adlnet.org/xsd/adlnav_v1p3\" identifier=\"MANIFEST-AECEF15E-06B8-1FAB-5289-73A0B058E2DD\" xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd\" version=\"1.3\">"+ " <metadata>"+ " <schema>ADL SCORM</schema>" +((PlayerPrefs.GetInt("SCORM_Version") == 0)?" <schemaversion>2004 4th Edition</schemaversion>":"") +((PlayerPrefs.GetInt("SCORM_Version") == 1)?" <schemaversion>2004 3rd Edition</schemaversion>":"") +((PlayerPrefs.GetInt("SCORM_Version") == 2)?" <schemaversion>2004 CAM 1.3</schemaversion>":"") + " </metadata>"+ " <organizations default=\"ORG-8770D9D9-AD66-06BB-9A3D-E87784C697FF\">"+ " <organization identifier=\"ORG-8770D9D9-AD66-06BB-9A3D-E87784C697FF\">"+ " <title>"+PlayerPrefs.GetString("Course_Title")+"</title>"+ " <item identifier=\"ITEM-79701DB3-F0AD-9426-8C43-819F3CB0EE6E\" identifierref=\"RES-4F17946A-9286-D5F0-7B6A-04E980C04F46\" parameters=\"" + GetParameterString() +"\">"+ " <title>"+PlayerPrefs.GetString("SCO_Title")+"</title>"+ " <adlcp:dataFromLMS>"+ PlayerPrefs.GetString("Data_From_Lms") +"</adlcp:dataFromLMS>"+ " <adlcp:completionThreshold completedByMeasure = \""+ (System.Convert.ToBoolean(PlayerPrefs.GetInt("completedByMeasure"))).ToString().ToLower() +"\" minProgressMeasure= \""+PlayerPrefs.GetFloat("minProgressMeasure") +"\" />"; if(PlayerPrefs.GetInt("satisfiedByMeasure") == 1) { manifest += " <imsss:sequencing>"+ " <imsss:objectives>"+ " <imsss:primaryObjective objectiveID = \"PRIMARYOBJ\""+ " satisfiedByMeasure = \"" + (System.Convert.ToBoolean(PlayerPrefs.GetInt("satisfiedByMeasure"))).ToString().ToLower() + "\">"+ " <imsss:minNormalizedMeasure>"+ PlayerPrefs.GetFloat("minNormalizedMeasure") +"</imsss:minNormalizedMeasure>"+ " </imsss:primaryObjective>"+ " </imsss:objectives>"+ " </imsss:sequencing>"; } manifest += " </item>"+ " </organization>"+ " </organizations>"+ " <resources>"+ " <resource identifier=\"RES-4F17946A-9286-D5F0-7B6A-04E980C04F46\" type=\"webcontent\" href=\"WebPlayer/WebPlayer.html\" adlcp:scormType=\"sco\">"+ " <file href=\"WebPlayer/WebPlayer.html\" />"+ " <file href=\"WebPlayer/scripts/scorm.js\" />"+ " <file href=\"WebPlayer/scripts/ScormSimulator.js\" />"+ " <file href=\"WebPlayer/UnityObject.js\" />"+ " <file href=\"WebPlayer/Webplayer.unity3d\" />"+ " <file href=\"WebPlayer/images/scorm_progres_bar.png\" />"+ " <file href=\"WebPlayer/images/thumbnail.png\" />"+ " </resource>"+ " </resources>"+ "</manifest>"; zip.AddEntry("imsmanifest.xml",".",System.Text.ASCIIEncoding.ASCII.GetBytes(manifest)); }else { zip.AddItem(Application.dataPath + "/ADL SCORM/Plugins/1.2"); string manifest = "<?xml version=\"1.0\"?>"+ "<!-- exported by Unity-SCORM Integration Toolkit Version 1.3 Beta-->"+ "<manifest identifier=\"SingleCourseManifest\" version=\"1.1\""+ " xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\""+ " xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_rootv1p2\""+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+ " xsi:schemaLocation=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd"+ " http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd"+ " http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd\">"+ " <organizations default=\"B0\">"+ " <organization identifier=\"B0\">"+ " <title>"+PlayerPrefs.GetString("Course_Title")+"</title>"+ " <item identifier=\"IS12\" identifierref=\"RS12\" parameters=\""+ GetParameterString() +"\">"+ " <title>"+PlayerPrefs.GetString("SCO_Title")+"</title>"+ " <adlcp:dataFromLMS>"+ PlayerPrefs.GetString("Data_From_Lms") +"</adlcp:dataFromLMS>"+ " <adlcp:masteryscore>"+PlayerPrefs.GetFloat("masteryscore")+"</adlcp:masteryscore>"+ " </item>"+ " </organization>"+ " </organizations>"+ " <resources>"+ " <resource identifier=\"RS12\" type=\"webcontent\""+ " adlcp:scormtype=\"sco\" href=\"WebPlayer/WebPlayer.html\">"+ " </resource>"+ " </resources>"+ " </manifest>"; zip.AddEntry("imsmanifest.xml",".",System.Text.ASCIIEncoding.ASCII.GetBytes(manifest)); } zip.Save(); } }
public void CompressDirectory(DirectoryInfo directorySelected, DirectoryInfo directory) { foreach (DirectoryInfo directoryToCompress in directorySelected.GetDirectories()) { if (directoryToCompress.FullName == directory.FullName) { using (ZipFile zip = new ZipFile()) { SetAccessDirectory(directorySelected.FullName); zip.AddItem(directory.FullName); zip.TempFileFolder = directory.FullName; zip.Save(directory.FullName + ".zip"); } } } }