/// <summary> /// Final function to package and deliver to the enhancement software input directory /// If the item is tvod the package is delivered with a prefix of tvod. /// </summary> /// <returns></returns> private bool PackageAndDeliverAsset() { try { using (ZipHandler ziphandler = new ZipHandler()) { string fname = WorkDirname; string package = $"{WorkingDirectory}.zip"; string tmpPackage = Path.Combine(ITV2ADI_CONFIG.EnrichmentDirectory, $"{fname}.tmp"); string finalPackage = Path.Combine(ITV2ADI_CONFIG.EnrichmentDirectory, $"{fname}.zip"); if ((File.Exists(package)) || (File.Exists(tmpPackage))) { File.Delete(package); File.Delete(tmpPackage); } log.Info("Starting Packaging and Delivery operations."); log.Info($"Packaging Source directory: {WorkingDirectory} to Zip Archive: {package}"); ///Compress Package ziphandler.CompressPackage(WorkingDirectory, package); log.Info($"Zip Archive: {package} created Successfully."); log.Info($"Moving: {package} to {tmpPackage}"); ///Move package to to destination as a .tmp file extension to prevent enrichment picking it up FileDirectoryOperations.MoveFile(package, tmpPackage); log.Info($"Successfully Moved: {package} to {tmpPackage}"); log.Info($"Moving tmp Package: {tmpPackage} to {finalPackage}"); ///rename the package from .tmp to .zip FileDirectoryOperations.MoveFile(tmpPackage, finalPackage); log.Info($"Successfully Moved: {tmpPackage} to {finalPackage}"); log.Info("Updating Database with final data"); ///add remaining data to the database for later use UpdateItvData(); ///if the config value DeleteFromSource = true delete the source media if (DeleteFromSource) { FileDirectoryOperations.DeleteSourceMedia(MediaLocation); } log.Info("Starting Packaging and Delivery operations completed Successfully."); return(true); } } catch (Exception PADA_EX) { log.Error($"Failed to Package and Deliver Asset - {PADA_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {PADA_EX.StackTrace}"); } return(false); } }
public GitRepository(String url) { this.url = url; this.isBusy = false; this.taskDescription = ""; this.progress = 0; this.isIndetermerminate = false; this._gitHandler = new GitHandler(this); this._zipHandler = new ZipHandler(this); this._webDavHandler = new WebDavHandler(this); }
private List <string> Unzip(string unzipFolder, string filename) { //如果目录存在,那么删除指定目录 if (Directory.Exists(unzipFolder)) { Directory.Delete(unzipFolder, true); } //解压文件到该目录中 ZipHandler.UnZipFile(filename, unzipFolder); var files = CommonUnitity.GetAllFiles(unzipFolder); return(files); }
/// <summary> /// 解压 /// </summary> /// <param name="strPath">压缩文件路径</param> /// <param name="strZipPath">解压后文件路径</param> public void ExportZip(string strPath, string strZipPath) { ZipHandler handler = ZipHandler.GetInstance(); TaskFactory fasFactory = new TaskFactory(); Task[] tasks = new Task[] { fasFactory.StartNew(() => { handler.UnpackAll(strPath, strZipPath, (num) => { GetBarValue(num); }); }) }; fasFactory.ContinueWhenAll(tasks, ExportTasksEnded); }
public SeriesInfo GetSeriesInfo(long tvdbId) { HttpWebRequest request = (HttpWebRequest) WebRequest.Create(GetSeriesInfoUrl(tvdbId)); // execute the request HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); return(new SeriesInfo(ZipHandler.Unzip(resStream), ENGLISH_CODE, selectedBannerMirror)); }
private Exception CreateBaseMeta(string filePath, string fileKey, string signatureKey, string projectId, string baseMetaPath) { var md5Hash = ZipHandler.CalculateMD5(filePath); var metaInfo = new MetaInfo { baseBucket = deltaBucket, nameSpace = projectId, baseFileName = fileKey, baseFileSize = new FileInfo(filePath).Length, md5 = md5Hash, signatureKey = signatureKey }; File.WriteAllText(baseMetaPath, JsonConvert.SerializeObject(metaInfo)); return(new Exception()); }
/// <summary> /// 压缩文件夹并复制到制定目录 /// </summary> /// <param name="strPath">待压缩的文件夹路径</param> /// <param name="strZipPath">需要复制到的目录路径(该路径需要带压缩文件名)</param> public void ImportZip(string strPath, string strZipPath) { ZipHandler handler = ZipHandler.GetInstance(); TaskFactory fastory = new TaskFactory(); Task[] tasks = new Task[] { fastory.StartNew(() => { handler.PackDirectory(strPath, strZipPath, (num) => { //pbYSJD.Value = Convert.ToInt32(num); SetBarValue(num); }); }) }; fastory.ContinueWhenAll(tasks, ImportTasksEnded); }
// // Pack // void StartPackingProject() { OnZipProgressChange(0f); try { ZipHandler.CleanPreviousZip(PathHelper.ZipDirectory); PathHelper.ProjectZipFullPath = ZipHandler.CompressProject(PathHelper.ProjectDirectory, PathHelper.ZipDirectory + "project-pack.zip", new BasicProgress <double>(OnZipProgressChange)); Debug.Log(PathHelper.ProjectZipFullPath); } catch (IOException ex) { //file hash exists Debug.LogError(ex); ShowNotification(new GUIContent(ex.Message)); } finally { EditorUtility.ClearProgressBar(); } }
private void button1_Click(object sender, EventArgs e) { string fromDic = Path.GetDirectoryName(typeof(Form1).Assembly.Location) + "\\GitHub.app"; string toZip = Path.GetDirectoryName(typeof(Form1).Assembly.Location) + "\\a.zip"; if (File.Exists(toZip)) { File.Delete(toZip); } double percent = 0; ZipHandler handler = ZipHandler.GetInstance(); TaskFactory fastory = new TaskFactory(); fastory.StartNew(() => { handler.PackDirectory(fromDic, toZip, (num) => { textBox1.Text = num.ToString() + "%"; progressBar1.Value = Convert.ToInt32(num); }); }); File.Delete(toZip); }
public void TestCompression() { var files = new List <string> { HelloFile }; var filesPath = new List <string> { "" }; CompressionHandler.CompressFiles(files, filesPath, out var dataCompressed, out var dataInfo, CompressionType.Zip, CompressionLevel.Medium); Assert.IsNotNull(dataCompressed); Assert.IsNotNull(dataInfo); using (var zipStream = new ZipOutputStream(File.Open("hello.zip", FileMode.CreateNew))) using (var bw = new BinaryWriter(zipStream)) { zipStream.SetLevel(0); var ze = new ZipEntry("hello"); zipStream.PutNextEntry(ze); CompressionHandler.WriteStreamToZip(bw, dataCompressed); bw.Flush(); zipStream.SetLevel(ZipHandler.GetCompressionLevel(CompressionLevel.Medium)); ze = new ZipEntry("hello.crc"); zipStream.PutNextEntry(ze); CompressionHandler.WriteStreamToZip(bw, dataInfo); bw.Flush(); } Assert.IsTrue(File.Exists("hello.zip")); dataCompressed.Close(); dataInfo.Close(); }
public static void CreateOMOD(OMODCreationOptions ops, string omodFileName) { Utils.Info($"Creating OMOD to {omodFileName}"); if (File.Exists(omodFileName)) { throw new OMODFrameworkException($"The provided omodFileName {omodFileName} already exists!"); } using (var zipStream = new ZipOutputStream(File.Open(omodFileName, FileMode.CreateNew))) using (var omodStream = new BinaryWriter(zipStream)) { ZipEntry ze; zipStream.SetLevel(ZipHandler.GetCompressionLevel(ops.OMODCompressionLevel)); if (!string.IsNullOrWhiteSpace(ops.Readme)) { Utils.Debug("Writing readme to OMOD"); ze = new ZipEntry("readme"); zipStream.PutNextEntry(ze); omodStream.Write(ops.Readme); omodStream.Flush(); } if (!string.IsNullOrWhiteSpace(ops.Script)) { Utils.Debug("Writing script to OMOD"); ze = new ZipEntry("script"); zipStream.PutNextEntry(ze); omodStream.Write(ops.Script); omodStream.Flush(); } if (!string.IsNullOrWhiteSpace(ops.Image)) { Utils.Debug("Writing image to OMOD"); ze = new ZipEntry("image"); zipStream.PutNextEntry(ze); try { using (var fs = File.OpenRead(ops.Image)) { CompressionHandler.WriteStreamToZip(omodStream, fs); omodStream.Flush(); } } catch (Exception e) { throw new OMODFrameworkException($"There was an exception while trying to read the image at {ops.Image}!\n{e}"); } } Utils.Debug("Writing config to OMOD"); ze = new ZipEntry("config"); zipStream.PutNextEntry(ze); omodStream.Write(Framework.Settings.CurrentOMODVersion); omodStream.Write(ops.Name); omodStream.Write(ops.MajorVersion); omodStream.Write(ops.MinorVersion); omodStream.Write(ops.Author); omodStream.Write(ops.Email); omodStream.Write(ops.Website); omodStream.Write(ops.Description); omodStream.Write(DateTime.Now.ToBinary()); omodStream.Write((byte)ops.CompressionType); omodStream.Write(ops.BuildVersion); omodStream.Flush(); FileStream dataCompressed; Stream dataInfo; if (ops.ESPs.Count > 0) { Utils.Debug("Writing plugins.crc to OMOD"); //TODO: find out why OBMM calls GC.Collect here ze = new ZipEntry("plugins.crc"); zipStream.PutNextEntry(ze); CompressionHandler.CompressFiles(ops.ESPs, ops.ESPPaths, out dataCompressed, out dataInfo, ops.CompressionType, ops.DataFileCompressionLevel); CompressionHandler.WriteStreamToZip(omodStream, dataInfo); omodStream.Flush(); zipStream.SetLevel(0); Utils.Debug("Writing plugins to OMOD"); ze = new ZipEntry("plugins"); zipStream.PutNextEntry(ze); CompressionHandler.WriteStreamToZip(omodStream, dataCompressed); omodStream.Flush(); zipStream.SetLevel(ZipHandler.GetCompressionLevel(ops.OMODCompressionLevel)); dataCompressed.Close(); dataInfo.Close(); } if (ops.DataFiles.Count > 0) { Utils.Debug("Writing data.crc to OMOD"); //TODO: find out why OBMM calls GC.Collect here ze = new ZipEntry("data.crc"); zipStream.PutNextEntry(ze); CompressionHandler.CompressFiles(ops.DataFiles, ops.DataFilePaths, out dataCompressed, out dataInfo, ops.CompressionType, ops.DataFileCompressionLevel); CompressionHandler.WriteStreamToZip(omodStream, dataInfo); omodStream.Flush(); zipStream.SetLevel(0); Utils.Debug("Writing data to OMOD"); ze = new ZipEntry("data"); zipStream.PutNextEntry(ze); CompressionHandler.WriteStreamToZip(omodStream, dataCompressed); omodStream.Flush(); zipStream.SetLevel(ZipHandler.GetCompressionLevel(ops.OMODCompressionLevel)); dataCompressed.Close(); dataInfo.Close(); } zipStream.Finish(); } Utils.Info("Finished OMOD creation"); }
public ZipHandlerTest() { zipHandler = new ZipHandler(); }
private void Buttonstart_DoWork() { Logger.Writer("----------------------------------------"); this.Dispatcher.Invoke(() => { DealWithCheckboxes(); }); if (!Directory.Exists(InputFolder)) { Logger.Writer($"Folder {InputFolder} doesn't exist!"); } else { foreach (var currentWorkingFile in Directory.EnumerateFiles(InputFolder, "*.*", SearchOption.AllDirectories)) { try { var currentDir = Path.GetDirectoryName(currentWorkingFile); if (currentWorkingFile.Contains(".zip")) { ZipHandler.Extract(currentWorkingFile, TempFolder); } else if (currentWorkingFile.Contains(".png")) { var possibleCard = new FileInfo(currentWorkingFile); UserContentHandler.Identifier(possibleCard, currentWorkingFile, OutputFolder); continue; } if (ModIntegrity.Check(TempFolder)) { string ModType = ModIntegrity.ModType(TempFolder); bool CABOverride = ModIntegrity.CABOverride(TempFolder); Logger.Writer($"Modtype: {ModType}"); if (CABOverride) { Logger.Writer($"Cab override active, Cab will be unchanged."); } // guid, name, version, author, game List <string> ManifestData = ManifestHandler.CheckIntegrity(TempFolder, tagList); var guid = ManifestData[0]; var name = ManifestData[1]; var version = ManifestData[2]; var author = ManifestData[3]; var game = ManifestData[4]; var game2 = ManifestData[5]; //if (version == "Unknown") // version = "v1.0"; Console.Write(""); if (game == "Unknown") { game = "NoDeclaredGame"; } if (game2 == "Unknown") { game2 = "NoDeclaredGame"; } string realOutputFolder = $@"{OutputFolder}\{game}\{game2}\{ModType}\{author}\"; string outFile = Misc.FileExists(realOutputFolder, author, name, version); if (guid == "" | version == "Unknown") { Mover.MalformedManifest(currentWorkingFile, InputFolder, OutputFolder); continue; } else { if (!Directory.Exists(realOutputFolder)) { Directory.CreateDirectory(realOutputFolder); } outFile = Misc.IllegalFilenameCheck(outFile); Logger.Writer($"Old name: {currentWorkingFile.Remove(0, currentDir.Length + 1)}."); Logger.Writer($"New name: {outFile}."); if (skiprenaming) { outFile = currentWorkingFile.Remove(0, currentDir.Length + 1); } var oMD5 = MD5Calc.CalculateMD5(currentWorkingFile); Logger.Writer($"Original MD5: {oMD5}"); } // Time to do something useful string[] removeExt = new[] { ".png", ".jpg" }; if (!skipremovejunk) { Misc.RemoveFiles(TempFolder, OutputFolder, removeExt); } foreach (var tempFile in Directory.EnumerateFiles(TempFolder, "*.*", SearchOption.AllDirectories)) { this.Dispatcher.Invoke(() => { Debug.Assert(RandomizeCAB.IsChecked != null, "RandomizeCAB.IsChecked != null"); if (!skipcompression) { Misc.PerformCompression(tempFile, RandomizeCAB.IsChecked.Value, CABOverride); } }); } // midl for testing // outFile = currentWorkingFile.Remove(0, currentDir.Length + 1); // midl end ZipHandler.Seal(TempFolder, realOutputFolder, outFile); // Then finally, some cleanup Directory.Delete(TempFolder, true); } else if (currentWorkingFile.Contains(".zip")) { Mover.InproperMod(currentWorkingFile, InputFolder, OutputFolder); } } catch (Exception exception) { Logger.Writer(exception.ToString()); } } } tagList.Clear(); MessageBox.Show("Done"); }