本文整理汇总了C#中SevenZip.SevenZipExtractor.ExtractFiles方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipExtractor.ExtractFiles方法的具体用法?C# SevenZipExtractor.ExtractFiles怎么用?C# SevenZipExtractor.ExtractFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipExtractor
的用法示例。
在下文中一共展示了SevenZipExtractor.ExtractFiles方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
private void Decompress(string[] args)
{
//If no file name is specified, write usage text.
if (args.Length == 0)
{
Console.WriteLine("error");
}
else
{
for (int i = 0; i < args.Length; i++)
{
if (File.Exists(args[i]))
{
SevenZipExtractor.SetLibraryPath(@"C:\Users\thlacroi\AppData\Local\Apps\COMOS\COMOS Walkinside 6.2 (64 bit)\7z.dll");
using (var tmp = new SevenZipExtractor(args[i]))
{
for (int n = 0; n < tmp.ArchiveFileData.Count; n++)
{
if (tmp.ArchiveFileData[n].FileName.Contains(".xml"))
{
tmp.ExtractFiles(Path.Combine(Resource.DirectoryTmp, i.ToString()), tmp.ArchiveFileData[n].Index);
}
}
}
}
}
}
}
示例2: UnpackArchive
static void UnpackArchive(IAbsoluteFilePath sourceFile, IAbsoluteDirectoryPath outputFolder, bool overwrite,
bool checkFileIntegrity,
SevenZipExtractor extracter) {
if (checkFileIntegrity && !extracter.Check())
throw new Exception(String.Format("Appears to be an invalid archive: {0}", sourceFile));
outputFolder.MakeSurePathExists();
extracter.ExtractFiles(outputFolder.ToString(), overwrite
? extracter.ArchiveFileNames.ToArray()
: extracter.ArchiveFileNames.Where(x => !outputFolder.GetChildFileWithName(x).Exists)
.ToArray());
}
示例3: Create
public ActionResult Create(Video video, HttpPostedFileBase previewZip)
{
if (!ModelState.IsValid || previewZip == null || !(previewZip.ContentLength > 0))
{
return View();
}
else
{
using (var tmp = new SevenZipExtractor(previewZip.InputStream))
{
for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
{
var fileData = tmp.ArchiveFileData[i];
if (fileData.FileName.EndsWith("png") || fileData.FileName.EndsWith("jpg"))
{
tmp.ExtractFiles(Server.MapPath("~/Content/Images/"), fileData.Index);
}
else if (fileData.FileName.EndsWith("mp4") || fileData.FileName.EndsWith("webm"))
{
tmp.ExtractFiles(Server.MapPath("~/Content/VideoPreviews/"), fileData.Index);
}
else
{
ModelState.AddModelError("", new Exception("Wrong file format"));
return View();
}
}
}
_videoRepository.Add(video);
//var fileName = video.Title;
//var path = Path.Combine(Server.MapPath("~/Content/Images/"), fileName + Path.GetExtension(previewZip.FileName));
//previewZip.SaveAs(path);
_cacheManager.Add(video);
return RedirectToAction("Index");
}
}
示例4: extractZip_DoWork
private void extractZip_DoWork(object sender, DoWorkEventArgs e)
{
using (SevenZipExtractor extractor = new SevenZipExtractor(e.Argument as String))
{
if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".xml")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith(".xml")) == 0)
throw new Exception("Not enough or too many XML Files");
if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".world_history.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_history.txt")) == 0)
throw new Exception("Not enough or too many World History Text Files");
if (extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) == 0)
throw new Exception("Not enough or too many Site & Pops Text Files");
if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 0)
throw new Exception("No map image found.");
string xml = extractor.ArchiveFileNames.Where(file => file.EndsWith(".xml")).Single();
if (File.Exists(xml)) throw new Exception(xml + " already exists.");
extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), xml);
extractedFiles.Add(xml);
string history = extractor.ArchiveFileNames.Where(file => file.EndsWith("-world_history.txt")).Single();
if (File.Exists(history)) throw new Exception(history + " already exists.");
extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), history);
extractedFiles.Add(history);
string sites = extractor.ArchiveFileNames.Where(file => file.EndsWith("-world_sites_and_pops.txt")).Single();
if (File.Exists(sites)) throw new Exception(sites + " already exists.");
extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), sites);
extractedFiles.Add(sites);
string map = "";
if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 1)
map = extractor.ArchiveFileNames.Single(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg"));
else
{
dlgFileSelect fileSelect = new dlgFileSelect(extractor.ArchiveFileNames.Where(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")).ToList());
fileSelect.Text = "Select Base Map";
fileSelect.ShowDialog();
if (fileSelect.SelectedFile == "") throw new Exception("No map file selected.");
if (File.Exists(fileSelect.SelectedFile)) { MessageBox.Show(fileSelect.SelectedFile + " already exists."); return; }
map = fileSelect.SelectedFile;
}
//extractor.ArchiveFileNames.Where(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")).Single();
if (File.Exists(map)) throw new Exception(map + " already exists.");
extractor.ExtractFiles(Directory.GetCurrentDirectory(), map);
extractedFiles.Add(map);
}
}
示例5: ExtractionTestExtractFiles
public void ExtractionTestExtractFiles(string format){
using (var tmp = new SevenZipExtractor(Path.Combine(archivePath, "Test."+format)))
for (int i = 0; i < tmp.ArchiveFileData.Count; i++) tmp.ExtractFiles(tempFolder, tmp.ArchiveFileData[i].Index);
}
示例6: DownloadUpdate
/// <summary>
/// Downloads update and installs the update
/// </summary>
/// <param name="update">The update xml info</param>
private void DownloadUpdate(SharpUpdateXml update)
{
SharpUpdateDownloadForm form = new SharpUpdateDownloadForm(update.Uri, update.MD5, this.applicationInfo.ApplicationIcon);
DialogResult result = form.ShowDialog(this.applicationInfo.Context);
// Download update
if (result == DialogResult.OK)
{
using (var tmp = new SevenZipExtractor(form.TempFilePath))
{
for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
{
tmp.ExtractFiles(@"d:\Temp\Result\", tmp.ArchiveFileData[i].Index);
}
}
string currentPath = this.applicationInfo.ApplicationAssembly.Location;
string newPath = Path.GetDirectoryName(currentPath) + "\\" + update.FileName;
// "Install" it
UpdateApplication(form.TempFilePath, currentPath, newPath, update.LaunchArgs);
Application.Exit();
}
else if (result == DialogResult.Abort)
{
MessageBox.Show("The update download was cancelled.\nThis program has not been modified.", "Update Download Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("There was a problem downloading the update.\nPlease try again later.", "Update Download Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
示例7: ExtractWrappedArchive
public static void ExtractWrappedArchive(string filePath, string targetPath)
{
Inits.EnsureBinaries();
FileInfo ufil = new FileInfo(filePath);
if (!ufil.Exists)
throw new FileNotFoundException();
using (FileStream fs = ufil.OpenRead()) {
using (MemoryStream ms = new MemoryStream()) {
using (LzmaDecodeStream dec = new LzmaDecodeStream(fs)) {
int byt = 0;
while ((byt = dec.ReadByte()) != -1) {
ms.WriteByte((byte)byt);
}
}
using (SevenZipExtractor ex = new SevenZipExtractor(ms)) {
ex.ExtractFiles(
f => {
string file = string.Format("{0}{1}{2}",
targetPath.TrimEnd(Path.DirectorySeparatorChar),
Path.DirectorySeparatorChar,
f.ArchiveFileInfo.FileName
);
string dir = Path.GetDirectoryName(file);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
f.ExtractToFile = file;
}
);
}
}
}
}
示例8: Main
static void Main(string[] args)
{
Console.WriteLine("SevenZipSharp test application.");
//Console.ReadKey();
/*
You may specify the custom path to 7-zip dll at SevenZipLibraryManager.LibraryFileName
or call SevenZipExtractor.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll");
or call SevenZipCompressor.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll");
You may check if your library fits your goals with
(SevenZipExtractor/Compressor.CurrentLibraryFeatures & LibraryFeature.<name>) != 0
Internal benchmark:
var features = SevenZip.SevenZipExtractor.CurrentLibraryFeatures;
Console.WriteLine(((uint)features).ToString("X6"));
*/
string SevenZipPath = @"C:\Program Files\7-Zip\7z.dll";
SevenZipExtractor.SetLibraryPath(SevenZipPath);
SevenZipCompressor.SetLibraryPath(SevenZipPath);
#region Temporary test
var features = SevenZipExtractor.CurrentLibraryFeatures;
Console.WriteLine(((uint)features).ToString("X6"));
#endregion
#region Extraction test - ExtractFiles
using (var tmp = new SevenZipExtractor(@"d:\Temp\tweetservice.7z"))
{
tmp.FileExtractionStarted += (s, e) =>
{
Console.WriteLine(String.Format("[{0}%] {1}",
e.PercentDone, e.FileInfo.FileName));
};
for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
{
tmp.ExtractFiles(@"d:\Temp\Result\", tmp.ArchiveFileData[i].Index);
}
// To extract more than 1 file at a time or when you definitely know which files to extract,
// use something like
//tmp.ExtractFiles(@"d:\Temp\Result", 1, 3, 5);
}
//
#endregion
#region Extraction test - multivolumes
//SevenZipExtractor.SetLibraryPath(@"d:\Work\Misc\7zip\9.04\CPP\7zip\Bundles\Format7zF\7z.dll");
/*using (var tmp = new SevenZipExtractor(@"d:\Temp\The_Name_of_the_Wind.part1.rar"))
{
tmp.ExtractArchive(@"d:\Temp\!Пусто");
}
//*/
#endregion
#region Compression tests - very simple
var tmpComp = new SevenZipCompressor();
tmpComp.VolumeSize = 10*1024*1024; // 10 MegaByte per Volume MultiPart Test
tmpComp.FileCompressionStarted += (s, e) =>
Console.WriteLine(String.Format("[{0}%] {1}", e.PercentDone, e.FileName));
//tmp.ScanOnlyWritable = true;
//tmp.CompressFiles(@"d:\Temp\arch.7z", @"d:\Temp\log.txt");
//tmp.CompressDirectory(@"c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\1033", @"D:\Temp\arch.7z");
tmpComp.CompressDirectory(@"D:\Temp\CompressTest", @"d:\Temp\test.7z");
//
#endregion
#region Compression test - features Append mode
/*var tmp = new SevenZipCompressor();
tmp.CompressionMode = CompressionMode.Append;
tmp.CompressDirectory(@"D:\Temp\!Пусто", @"D:\Temp\arch.7z");
tmp = null;
//*/
#endregion
#region Compression test - features Modify mode
/*var tmp = new SevenZipCompressor();
tmp.ModifyArchive(@"d:\Temp\7z465_extra.7z", new Dictionary<int, string>() { { 0, "xxx.bat" } });
//Delete
//tmp.ModifyArchive(@"d:\Temp\7z465_extra.7z", new Dictionary<int, string>() { { 19, null }, { 1, null } });
//*/
#endregion
#region Compression test - multivolumes
/*var tmp = new SevenZipCompressor();
tmp.VolumeSize = 10000;
tmp.CompressDirectory(@"D:\Temp\!Пусто", @"D:\Temp\arch.7z");
//*/
#endregion
#region Extraction test. Shows cancel feature.
/*using (var tmp = new SevenZipExtractor(@"D:\Temp\test.7z"))
{
tmp.FileExtractionStarted += (s, e) =>
{
/*if (e.FileInfo.Index == 10)
{
e.Cancel = true;
//.........这里部分代码省略.........
示例9: OpenRom
public void OpenRom(string romPath)
{
_romFileName = romPath;
if (File.Exists(romPath))
{
#region Check if archive
var extension = Path.GetExtension(romPath);
if (extension != null && extension.ToLower() != ".nes")
{
try
{
_extractor = new SevenZipExtractor(romPath);
}
catch
{
}
if (_extractor.ArchiveFileData.Count == 1)
{
if (
_extractor.ArchiveFileData[0].FileName.Substring(
_extractor.ArchiveFileData[0].FileName.Length - 4, 4).ToLower() == ".nes")
{
_extractor.ExtractArchive(Path.GetTempPath());
romPath = Path.GetTempPath() + _extractor.ArchiveFileData[0].FileName;
}
}
else
{
var ar = new ArchivesForm(_extractor.ArchiveFileData.Select(file => file.FileName).ToArray());
ar.ShowDialog(this);
if (ar.Ok)
{
string[] fil = { ar.SelectedRom };
_extractor.ExtractFiles(Path.GetTempPath(), fil);
romPath = Path.GetTempPath() + ar.SelectedRom;
}
else
{
return;
}
}
}
#endregion
#region Check the rom
var header = new NesHeaderReader(romPath);
if (header.ValidRom)
{
if (!header.SupportedMapper())
{
MessageBox.Show("Can't load rom:\n" + romPath +
"\n\nUNSUPPORTED MAPPER # " +
header.MemoryMapper);
return;
}
}
else
{
MessageBox.Show("Can't load rom:\n" + romPath +
"\n\nRom is damaged or not an INES format file");
return;
}
#endregion
//Exit current thread
if (_engine != null)
{
_engine.ShutDown();
_engine = null;
}
if (_gameThread != null)
{
_gameThread.Abort();
}
//Start new nes !!
if (Program.Settings.PaletteFormat == null)
Program.Settings.PaletteFormat = new PaletteFormat();
_engine = new NesEngine(Program.Settings.TV, Program.Settings.PaletteFormat);
_engine.PauseToggle += NesPauseToggle;
if (_engine.LoadRom(romPath))
{
#region Setup input
var manager = new InputManager(Handle);
var joy1 = new Joypad(manager);
joy1.A.Input = Program.Settings.CurrentControlProfile.Player1A;
joy1.B.Input = Program.Settings.CurrentControlProfile.Player1B;
joy1.Up.Input = Program.Settings.CurrentControlProfile.Player1Up;
joy1.Down.Input = Program.Settings.CurrentControlProfile.Player1Down;
joy1.Left.Input = Program.Settings.CurrentControlProfile.Player1Left;
joy1.Right.Input = Program.Settings.CurrentControlProfile.Player1Right;
joy1.Select.Input = Program.Settings.CurrentControlProfile.Player1Select;
joy1.Start.Input = Program.Settings.CurrentControlProfile.Player1Start;
var joy2 = new Joypad(manager);
joy2.A.Input = Program.Settings.CurrentControlProfile.Player2A;
joy2.B.Input = Program.Settings.CurrentControlProfile.Player2B;
//.........这里部分代码省略.........