public override PackerResult PackFiles(string packedFile, string subPath, string srcPath, List <string> addList, PackFilesFlags flags) { if ((flags & PackFilesFlags.MoveFiles).Equals(PackFilesFlags.MoveFiles)) { return(PackerResult.NotSupported); } string arcFile = packedFile; string extension = Path.GetExtension(arcFile); if (extension != null) { string arcExt = extension.ToUpper(); if (!ExtensionsToUpdate.Contains(arcExt)) { MessageBox.Show( "Cannot add to archive - allowed extension(s): " + ExtensionsToUpdate, ".NET Packer Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(PackerResult.NotSupported); } } DriveInfo di = new DriveInfo(Path.GetPathRoot(srcPath)); if (di.DriveType == DriveType.CDRom) { return(PackerResult.ErrorCreate); } arcFile = Path.Combine(srcPath, Path.GetFileName(packedFile)); return(!File.Exists(arcFile) ? CreateArchive(arcFile, srcPath, addList) : UpdateArchive(arcFile, srcPath, addList)); }
public static int PackFilesInternal(string packedFile, string subPath, string srcPath, List <string> addList, PackFilesFlags flags) { PackerResult result = PackerResult.NotSupported; callSignature = String.Format("PackFiles ({0}, {1}, {2}, {3}) - {4} files)", packedFile, subPath, srcPath, flags.ToString(), addList.Count); try { result = Plugin.PackFiles(packedFile, subPath, srcPath, addList, flags); TraceCall(TraceLevel.Info, result.ToString()); } catch (Exception ex) { ProcessException(ex); } return((int)result); }
public virtual PackerResult PackFiles(string packedFile, string subPath, string srcPath, List <string> addList, PackFilesFlags flags) { return(PackerResult.NotSupported); }
public override PackerResult PackFiles(string packedFile, string subPath, string srcPath, List <string> addList, PackFilesFlags flags) { PackerResult result; bool stopProcess = false; string password = null; try { if ((flags & PackFilesFlags.Encrypt).Equals(PackFilesFlags.Encrypt)) { PackerPassword pswDialog = new PackerPassword(this, packedFile); if (pswDialog.ShowDialog() == DialogResult.OK) { password = pswDialog.Password; } if (String.IsNullOrEmpty(password)) { return(PackerResult.EAborted); } } using (FileStream archive = File.Create(packedFile)) using (ZipOutputStream zip = new ZipOutputStream(archive)) { if (!String.IsNullOrEmpty(password)) { zip.Password = password; } zip.SetLevel(6); byte[] buff = new byte[ArcBufferSize]; foreach (string fileName in addList) { if (stopProcess) { break; } bool skipFile = false; string zipFile = Path.Combine(srcPath, fileName); ZipEntry entry = new ZipEntry(fileName); zip.PutNextEntry(entry); if (Directory.Exists(zipFile)) { } else if (File.Exists(zipFile)) { using (FileStream source = File.OpenRead(zipFile)) { int count; while (!stopProcess && (count = source.Read(buff, 0, buff.Length)) > 0) { zip.Write(buff, 0, count); if (ProcessDataProc(zipFile, count) == 0) { stopProcess = true; break; } } } if (stopProcess) { break; } entry.DateTime = File.GetLastWriteTime(zipFile); } else { skipFile = true; } if (skipFile) { // delete entry ???; } else { // !!! delete directory if ((flags & PackFilesFlags.MoveFiles).Equals(PackFilesFlags.MoveFiles)) { File.Delete(zipFile); } } } zip.Finish(); result = PackerResult.OK; } if (stopProcess && File.Exists(packedFile)) { File.Delete(packedFile); } } catch (Exception) { if (File.Exists(packedFile)) { File.Delete(packedFile); } throw; } return(result); }
public static int PackFilesInternal(string packedFile, string subPath, string srcPath, List <string> addList, PackFilesFlags flags) { var result = PackerResult.NotSupported; _callSignature = $"PackFiles ({packedFile}, {subPath}, {srcPath}, {flags.ToString()}) - {addList.Count} files)"; try { result = Plugin.PackFiles(packedFile, subPath, srcPath, addList, flags); TraceCall(TraceLevel.Info, result.ToString()); } catch (Exception ex) { ProcessException(ex); } return((int)result); }