本文整理汇总了C#中SevenZip.SevenZipExtractor.ExtractArchive方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipExtractor.ExtractArchive方法的具体用法?C# SevenZipExtractor.ExtractArchive怎么用?C# SevenZipExtractor.ExtractArchive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipExtractor
的用法示例。
在下文中一共展示了SevenZipExtractor.ExtractArchive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
/// <summary>
/// Decompresses an archive.
/// </summary>
/// <param name="archive">Path for the archive</param>
/// <param name="destination">Archive content destination folder.</param>
/// <returns>True if no errors</returns>
public static bool Decompress(string archive, string destination)
{
try {
string archive_name = Path.GetFileNameWithoutExtension(archive);
if(main.full_path_output)
console.Write("Extracting " + archive + " to " + destination + " -> 0%", console.msgType.standard, false);
else
console.Write("Extracting " + archive_name + " to " + destination + " -> 0%", console.msgType.standard, false);
SevenZipExtractor zip = new SevenZipExtractor(archive);
zip.Extracting += Zip_Extracting;
if (!main.overwrite)
zip.FileExists += Zip_FileExists;
if (main.create_dir)
{
zip.ExtractArchive(destination + @"\" + archive_name);
}
else
zip.ExtractArchive(destination);
Console.WriteLine("");
return true;
}
catch (Exception e)
{
Console.WriteLine("");
console.Write(e.Message +"("+archive+")", console.msgType.error);
Log(e.ToString());
return false;
}
}
示例2: Execute
public override void Execute()
{
var libraryPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), Environment.Is64BitProcess ? "7z64.dll" : "7z.dll");
SevenZipBase.SetLibraryPath(libraryPath);
var targetPath = new FileInfo(Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, _cmdlet.TargetPath)).FullName;
var archiveFileName = new FileInfo(Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, _cmdlet.ArchiveFileName)).FullName;
var activity = String.Format("Extracting {0} to {1}", System.IO.Path.GetFileName(archiveFileName), targetPath);
var statusDescription = "Extracting";
Write(String.Format("Extracting archive {0}", archiveFileName));
WriteProgress(new ProgressRecord(0, activity, statusDescription) { PercentComplete = 0 });
using (var extractor = new SevenZipExtractor(archiveFileName)) {
extractor.Extracting += (sender, args) =>
WriteProgress(new ProgressRecord(0, activity, statusDescription) { PercentComplete = args.PercentDone });
extractor.FileExtractionStarted += (sender, args) => {
statusDescription = String.Format("Extracting file {0}", args.FileInfo.FileName);
Write(statusDescription);
};
extractor.ExtractArchive(targetPath);
}
WriteProgress(new ProgressRecord(0, activity, "Finished") { RecordType = ProgressRecordType.Completed });
Write("Extraction finished");
}
示例3: Extract
public static void Extract(string file, string to)
{
using (var extractor = new SevenZipExtractor(file))
{
extractor.ExtractArchive(to);
}
}
示例4: Update
public void Update()
{
if (!IsUpdateAvailable())
{
throw new LauncherException("no update is available");
}
using (var mutex = new WurmAssistantMutex())
{
mutex.Enter(1000, "You must close Wurm Assistant before running update");
var newFileZipped = WebApiClientSpellbook.GetFileFromWebApi(
AppContext.WebApiBasePath,
string.Format("{0}/{1}", AppContext.ProjectName, buildType),
TimeSpan.FromSeconds(15),
BasePath);
using (var extractor = new SevenZipExtractor(newFileZipped.FullName))
{
extractor.ExtractArchive(BasePath);
}
Thread.Sleep(1000);
var cleaner = new DirCleaner(BasePath);
cleaner.Cleanup();
}
}
示例5: Execute
public override void Execute(DirectoryInfo targetDirectory, PortableEnvironment portableEnvironment)
{
// Decompress the file.
SevenZipBase.SetLibraryPath(SevenZipLibPath);
using (var extractor = new SevenZipExtractor(Path.Combine(targetDirectory.FullName, FileName)))
extractor.ExtractArchive(targetDirectory.FullName);
}
示例6: FileReader
public FileReader(IFileStreamWrap stream)
{
if (stream == null) throw new ArgumentNullException(nameof(stream));
//Asses file ext
var ext = Path.GetExtension(stream.Name);
if (ext == ".gz")
{
Compression = CompressionScheme.GZip;
}
//Assign stream
Stream = stream;
//If not testing assign actual stream
if (stream.FileStreamInstance != null)
{
if (Compression == CompressionScheme.None)
{
_reader = new StreamReaderWrap(stream.FileStreamInstance);
}
else if (Compression == CompressionScheme.GZip)
{
// Toggle between the x86 and x64 bit dll
// var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
SevenZipExtractor.SetLibraryPath("C:\\Program Files (x86)\\7-Zip\\7z.dll");
_gzipStream = new SevenZipExtractor(stream.FileStreamInstance);
//_memoryStream = new MemoryStream();
//_gzipStream.ExtractFile(0, _memoryStream);
_gzipStream.ExtractArchive("D:\\test.txt");
_reader = new StreamReaderWrap(_memoryStream);
}
}
}
示例7: CreateByUnzippingFile
internal DirectoryHandle CreateByUnzippingFile(string zipFilePath)
{
var dir = CreateTempDirectory();
zipFilePath = AbsolutizePath(zipFilePath);
var extractor =
new SevenZipExtractor(File.OpenRead(zipFilePath));
extractor.ExtractArchive(dir.FullName);
return new DirectoryHandle(this, dir);
}
示例8: extract
public static void extract(string fileName, string directory)
{
SevenZipExtractor.SetLibraryPath("7z.dll");
SevenZipExtractor extractor = new SevenZipExtractor(fileName);
extractor.Extracting += new EventHandler<ProgressEventArgs>(extr_Extracting);
extractor.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(extr_FileExtractionStarted);
extractor.ExtractionFinished += new EventHandler<EventArgs>(extr_ExtractionFinished);
extractor.ExtractArchive(directory);
}
示例9: Unpack
public void Unpack(string outputPath)
{
SevenZipExtractor tmp = new SevenZipExtractor(_targetPath);
tmp.FileExtractionStarted += new EventHandler<IndexEventArgs>((s, e) =>
{
Console.WriteLine(String.Format("[{0}%] {1}",
e.PercentDone, tmp.ArchiveFileData[e.FileIndex].FileName));
});
tmp.ExtractionFinished += new EventHandler((s, e) => {Console.WriteLine("Finished!");});
tmp.ExtractArchive(outputPath);
}
示例10: extract
static public void extract(string fileName, string directory) {
SevenZipExtractor.SetLibraryPath("7z.dll");
try {
SevenZipExtractor extractor = new SevenZipExtractor(fileName);
extractor.Extracting += new EventHandler<ProgressEventArgs>(extr_Extracting);
extractor.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(extr_FileExtractionStarted);
extractor.ExtractionFinished += new EventHandler<EventArgs>(extr_ExtractionFinished);
extractor.ExtractArchive(directory);
}
catch (System.IO.FileNotFoundException e) {
MessageBox.Show(e.Message);
}
}
示例11: Search
public List<GrepSearchResult> Search(string file, string searchPattern, SearchType searchType, GrepSearchOption searchOptions, Encoding encoding)
{
List<GrepSearchResult> searchResults = new List<GrepSearchResult>();
SevenZipExtractor extractor = new SevenZipExtractor(file);
GrepEnginePlainText plainTextEngine = new GrepEnginePlainText();
plainTextEngine.Initialize(new GrepEngineInitParams(showLinesInContext, linesBefore, linesAfter, fuzzyMatchThreshold));
string tempFolder = Utils.FixFolderName(Utils.GetTempFolder()) + "dnGREP-Archive\\" + Utils.GetHash(file) + "\\";
if (Directory.Exists(tempFolder))
Utils.DeleteFolder(tempFolder);
Directory.CreateDirectory(tempFolder);
try
{
extractor.ExtractArchive(tempFolder);
foreach (string archiveFileName in Directory.GetFiles(tempFolder, "*.*", SearchOption.AllDirectories))
{
IGrepEngine engine = GrepEngineFactory.GetSearchEngine(archiveFileName, new GrepEngineInitParams(showLinesInContext, linesBefore, linesAfter, fuzzyMatchThreshold));
var innerFileResults = engine.Search(archiveFileName, searchPattern, searchType, searchOptions, encoding);
using (FileStream reader = File.Open(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader streamReader = new StreamReader(reader))
{
foreach (var result in innerFileResults)
{
if (!result.HasSearchResults)
result.SearchResults = Utils.GetLinesEx(streamReader, result.Matches, linesBefore, linesAfter);
}
}
searchResults.AddRange(innerFileResults);
}
foreach (GrepSearchResult result in searchResults)
{
result.FileNameDisplayed = file + "\\" + result.FileNameDisplayed.Substring(tempFolder.Length);
result.FileNameReal = file;
result.ReadOnly = true;
}
}
catch (Exception ex)
{
logger.LogException(LogLevel.Error, "Failed to search inside archive.", ex);
}
return searchResults;
}
示例12: extractBundledResourcesFromFile
private string extractBundledResourcesFromFile(string filename)
{
string sourceFile = Path.Combine(resourcesDir, "bundled", filename);
string timestampFile = Path.Combine(extractedResourcesDir, Path.ChangeExtension(filename, "timestamp"));
string destinationDir = Path.Combine(extractedResourcesDir, Path.GetFileNameWithoutExtension(filename));
if (!File.Exists(timestampFile) || File.GetLastWriteTimeUtc(sourceFile) > File.GetLastWriteTimeUtc(timestampFile))
{
DeleteRecursivelyWithMagicDust(destinationDir);
var extractor = new SevenZipExtractor(sourceFile);
// we typically have a properly-named root dir inside .7z itself, so extracting into destinationDir doesn't work
extractor.ExtractArchive(extractedResourcesDir);
extractor.Dispose();
File.WriteAllBytes(timestampFile, new byte[0]);
}
return destinationDir;
}
示例13: BeginTask
protected override void BeginTask(object state)
{
ExtractionTask task = (ExtractionTask)state;
Exception exception = null;
try
{
if (!CancelRequested)
{
task.OnProgressStarted(this, new ProgressStartedEventArgs(task));
}
SevenZipExtractor extractor = new SevenZipExtractor(task.Archive);
extractor.Extracting += new EventHandler<SevenZip.ProgressEventArgs>(delegate(object sender, SevenZip.ProgressEventArgs e)
{
if (!CancelRequested)
{
task.OnProgressUpdate(this, new ProgressUpdateEventArgs(task, e.PercentDone, 100));
}
});
extractor.ExtractArchive(task.Destination);
}
catch (Exception e)
{
exception = e;
}
finally
{
if (!CancelRequested)
{
task.OnProgressCompleted(this, new ProgressCompletedEventArgs(exception, CancelRequested, task, 100, 100));
}
}
base.BeginTask(state);
}
示例14: Extract
public void Extract(string archivePath, string installPath, List<ManifestFile> files)
{
this.SetLibraryPath();
int progress = 0;
var thread = new Thread(() =>
{
var extractor = new SevenZipExtractor(archivePath);
extractor.ExtractionFinished += ExtractionFinished;
extractor.FileExtractionFinished += (sender, e) =>
{
progress++;
this.progressNotifier.UpdateProgress(ProgressStage.ExtractFilesFromPackage, files.Count, progress);
};
extractor.ExtractArchive(installPath);
});
thread.Start();
thread.Join();
}
示例15: pptxParser
public static String pptxParser(String filename)
{
//path to the systems temporary folder
String tempFolderPath = Path.GetTempPath();
tempFolderPath += "excelTemp\\";
//create a directory to dump everything into inside the temp folder
Directory.CreateDirectory(tempFolderPath);
//set the path of the 7z.dll (it needs to be in the debug folder)
SevenZipExtractor.SetLibraryPath("7z.dll");
SevenZipExtractor extractor = new SevenZipExtractor(filename);
//Extract the entrie excel file
extractor.ExtractArchive(tempFolderPath);
extractor.Dispose();
//Count how many slides there are in the presentation
int count = Directory.GetFiles(tempFolderPath + "ppt\\slides", "*.xml", SearchOption.TopDirectoryOnly).Length;
//Create an array of filenames based off how many slides we counted
String[] files = new String[count];
for (int i = 1; i <= count; i++)
{
files[i - 1] = "ppt\\slides\\slide" + i + ".xml";
}
//send the slides to the xml parser
String result = "";
foreach (String s in files)
result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + s);
//delete the temporary directory we created at the beginning
Directory.Delete(tempFolderPath, true);
return result;
}