private void CompressByManaged7z(string[] srcfiles, string outFile) { string dll = string.Empty; using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")) { if (key != null) { Object o = key.GetValue("BuildLabEx"); if (o != null) { if ((o as String).ToLower().Contains("amd64")) { CreateFileFromResource("create_sfx.Resources.7zx64.dll", "7zx64.dll"); dll = "7zx64.dll"; } else { CreateFileFromResource("create_sfx.Resources.7zx86.dll", "7zx86.dll"); dll = "7zx86.dll"; } } } } SevenZip.SevenZipCompressor.SetLibraryPath(Path.Combine(Directory.GetCurrentDirectory(), dll)); SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor(); compressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip; compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra; compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2; compressor.CompressionMode = SevenZip.CompressionMode.Create; compressor.CompressFiles(outFile, srcfiles); File.Delete(Path.Combine(Directory.GetCurrentDirectory(), dll)); }
private static byte[] Compress(string filename) { SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(runningFolder, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll")); var arch = new MemoryStream(); var compressor = new SevenZip.SevenZipCompressor(); compressor.CompressionLevel = SevenZip.CompressionLevel.High; compressor.CompressFiles(arch, filename); arch.Seek(0, SeekOrigin.Begin); var result = new byte[arch.Length]; arch.Read(result, 0, result.Length); return(result); }
public string fileExport(string fileType, string fileName, char delimiter = ',') { DataSetFileExport exp = new DataSetFileExport(); bool expSuccess = false; string exportText = ""; //Excel(.xlsx) //CSV //Tab Delimited //Choose Delimiter //XML //Multiset switch (fileType) { case "Excel (.xlsx)": exportText = DataSetFileExport.SendDataTableToExcel(currentTable, fileName); break; case "CSV": expSuccess = exp.DataTable2CSV(currentTable, fileName); break; case "Tab Delimited": expSuccess = exp.DataTable2txt(currentTable, fileName, '\t'); break; case "Choose Delimiter": expSuccess = exp.DataTable2txt(currentTable, fileName, delimiter); break; case "XML": try { currentTable.WriteXml(fileName, XmlWriteMode.WriteSchema); } catch (Exception ex) { exportText = ex.Message.ToString(); } break; case "Multiset": exp.dataTable2Multiset(ref currentTable, fileName); SevenZip.SevenZipCompressor szip = new SevenZip.SevenZipCompressor(); szip.ScanOnlyWritable = true; szip.CompressFiles(fileName + ".7z", fileName); System.IO.File.Delete(fileName); expSuccess = true; break; default: return("No file type selected!"); } if (expSuccess) { return("File export success"); } else { return("File export failed"); } }
/// <summary> /// Compresses the chosen map. /// </summary> /// <param name="worker_thread">The worker hred this function is being run by</param> /// <param name="args">Generic variable for passing an arguments class</param> public static void CompressMap(BackgroundWorker worker_thread, object args) { if (args == null) { throw new Exception("No arguments or an invalid arguments class passed to CompressMap"); } MapCompressorArgs arguments = (MapCompressorArgs)args; // create the output folders string output_folder; if (!BuildOutputFolders(arguments.Map, arguments.PartsFolder, out output_folder)) { throw new Exception("failed to create the output directories for map compression"); } string map_filename = Path.GetFileNameWithoutExtension(arguments.Map); MapDownloadList.MapDownloadClass map_entry = null; List <FileSplitter.FileListEntry> file_list = null; uint UncompressedSize; uint CompressedSize; using (FileStream map_file = File.OpenRead(arguments.Map)) UncompressedSize = (uint)map_file.Length; using (MemoryStream compressed_file = new MemoryStream()) { try { SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor(); compressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip; compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra; compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma; compressor.CompressionMode = SevenZip.CompressionMode.Create; // compress the map compressor.CompressFiles(compressed_file, arguments.Map); } catch (Exception e) { Exception temp = e; do { MessageBox.Show(temp.Message); } while ((temp = temp.InnerException) != null); } string archive_filename = string.Format("{0}.7z", map_filename); CompressedSize = (uint)compressed_file.Length; // save the archive parts, encrypting if necessary file_list = FileSplitter.SaveStream(compressed_file, 1048576, output_folder, archive_filename, arguments.EncryptArchive, arguments.ServerPassword); } // create the map entry if (file_list != null) { map_entry = new MapDownloadList.MapDownloadClass(); map_entry.Algorithm = MapDownloadList.MapDownloadCompressionFormat.SevenZip; map_entry.Name = Path.GetFileName(arguments.Map); map_entry.MD5 = BlamLib.Cryptography.MD5.GenerateFileMD5String(arguments.Map); map_entry.UncompressedSize = UncompressedSize; map_entry.CompressedSize = CompressedSize; map_entry.HostDirectory = Path.GetFileNameWithoutExtension(arguments.Map); map_entry.Parts = new List <MapDownloadList.MapPartClass>(); // add all of the map parts to the map entry foreach (var file in file_list) { MapDownloadList.MapPartClass part = new MapDownloadList.MapPartClass(); part.Name = Path.GetFileName(file.Location); part.MD5 = file.MD5; part.Index = file.Index; part.Size = file.Size; if (file.Encrypted) { part.Encrypted = true; part.UnencryptedMD5 = file.UnencryptedMD5; } map_entry.Parts.Add(part); } } // save the map entry to a map entry include xml MapDownloadList.MapIncludeClass map_include = new MapDownloadList.MapIncludeClass(); map_include.MapDownload = map_entry; string xml_path = Path.Combine(arguments.DefinitionsFolder, String.Format("{0}.xml", map_filename)); Util.SerializeObjectXML(map_include, xml_path); }
/// <summary> /// Compresses the chosen map. /// </summary> /// <param name="worker_thread">The worker hred this function is being run by</param> /// <param name="args">Generic variable for passing an arguments class</param> public static void CompressMap(BackgroundWorker worker_thread, object args) { MapCompressorArguments arguments = args as MapCompressorArguments; if (arguments == null) throw new Exception("No arguments or an invalid arguments class passed to CompressMap"); // create the output folders string output_folder; if (!BuildOutputFolders(arguments.Map, arguments.PartsFolder, out output_folder)) throw new Exception("failed to create the output directories for map compression"); string map_filename = Path.GetFileNameWithoutExtension(arguments.Map); MapDownloadList.MapDownloadClass map_entry = null; List<FileSplitter.FileListEntry> file_list = null; uint UncompressedSize; uint CompressedSize; using(FileStream map_file = File.OpenRead(arguments.Map)) UncompressedSize = (uint)map_file.Length; using (MemoryStream compressed_file = new MemoryStream()) { try { SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor(); compressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip; compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra; compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma; compressor.CompressionMode = SevenZip.CompressionMode.Create; // compress the map compressor.CompressFiles(compressed_file, arguments.Map); } catch (Exception e) { Exception temp = e; do { MessageBox.Show(temp.Message); } while ((temp = temp.InnerException) != null); } string archive_filename = string.Format("{0}.7z", map_filename); CompressedSize = (uint)compressed_file.Length; // save the archive parts, encrypting if necessary file_list = FileSplitter.SaveStream(compressed_file, 1048576, output_folder, archive_filename, arguments.EncryptArchive, arguments.ServerPassword); } // create the map entry if (file_list != null) { map_entry = new MapDownloadList.MapDownloadClass(); map_entry.Algorithm = MapDownloadList.MapDownloadCompressionFormat.SevenZip; map_entry.Name = Path.GetFileName(arguments.Map); map_entry.MD5 = BlamLib.Cryptography.MD5.GenerateFileMD5String(arguments.Map); map_entry.UncompressedSize = UncompressedSize; map_entry.CompressedSize = CompressedSize; map_entry.HostDirectory = Path.GetFileNameWithoutExtension(arguments.Map); map_entry.Parts = new List<MapDownloadList.MapPartClass>(); // add all of the map parts to the map entry foreach (var file in file_list) { MapDownloadList.MapPartClass part = new MapDownloadList.MapPartClass(); part.Name = Path.GetFileName(file.Location); part.MD5 = file.MD5; part.Index = file.Index; part.Size = file.Size; if (file.Encrypted) { part.Encrypted = true; part.UnencryptedMD5 = file.UnencryptedMD5; } map_entry.Parts.Add(part); } } // save the map entry to a map entry include xml MapDownloadList.MapIncludeClass map_include = new MapDownloadList.MapIncludeClass(); map_include.MapDownload = map_entry; string xml_path = Path.Combine(arguments.DefinitionsFolder, String.Format("{0}.xml", map_filename)); Util.SerializeObjectXML(map_include, xml_path); }