public List<PrintItem> ImportFromProjectArchive(string loadedFileName = null) { if (loadedFileName == null) { loadedFileName = defaultProjectPathAndFileName; } if (System.IO.File.Exists(loadedFileName)) { FileStream fs = File.OpenRead(loadedFileName); ZipFile zip = new ZipFile(fs); int projectHashCode = zip.GetHashCode(); //If the temp folder doesn't exist - create it, otherwise clear it string stagingFolder = Path.Combine(applicationDataPath, "data", "temp", "project-extract", projectHashCode.ToString()); if (!Directory.Exists(stagingFolder)) { Directory.CreateDirectory(stagingFolder); } else { System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(@stagingFolder); EmptyFolder(directory); } List<PrintItem> printItemList = new List<PrintItem>(); Project projectManifest = null; foreach (ZipEntry zipEntry in zip) { if (!zipEntry.IsFile) { continue; // Ignore directories } if (zipEntry.Name == "manifest.json" || Path.GetExtension(zipEntry.Name).ToUpper() == ".STL" || Path.GetExtension(zipEntry.Name).ToUpper() == ".GCODE") { string extractedFileName = Path.Combine(stagingFolder, zipEntry.Name); string neededPathForZip = Path.GetDirectoryName(extractedFileName); if (!Directory.Exists(neededPathForZip)) { Directory.CreateDirectory(neededPathForZip); } Stream zipStream = zip.GetInputStream(zipEntry); using (FileStream streamWriter = File.Create(extractedFileName)) { CopyStream(zipStream, streamWriter); } if (zipEntry.Name == "manifest.json") { StreamReader sr = new System.IO.StreamReader(extractedFileName); projectManifest = (Project)Newtonsoft.Json.JsonConvert.DeserializeObject(sr.ReadToEnd(), typeof(Project)); sr.Close(); } } } if (projectManifest != null) { foreach (ManifestItem item in projectManifest.ProjectFiles) { for (int i = 1; i <= item.ItemQuantity; i++) { printItemList.Add(this.GetPrintItemFromFile(Path.Combine(stagingFolder, item.FileName), item.Name)); } } } else { string[] files = Directory.GetFiles(stagingFolder,"*.*", SearchOption.AllDirectories); foreach(string fileName in files) { printItemList.Add(this.GetPrintItemFromFile(fileName, Path.GetFileNameWithoutExtension(fileName))); } } return printItemList; } else { return null; } }