本文整理汇总了C#中SevenZip.SevenZipExtractor.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipExtractor.Dispose方法的具体用法?C# SevenZipExtractor.Dispose怎么用?C# SevenZipExtractor.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipExtractor
的用法示例。
在下文中一共展示了SevenZipExtractor.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Determine_Parser
//.........这里部分代码省略.........
{
int retCode, count = 0;
retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
if (retCode > 0)
WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
//Console.WriteLine("\t" + text);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else if (ext.CompareTo(".odt") == 0 || ext.CompareTo(".ods") == 0 || ext.CompareTo(".odp") == 0)
{
try
{
String text = OfficeParser.Parser.openOfficeParser(fi.FullName);
if (text != null)
{
int retCode, count = 0;
retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
if (retCode > 0)
WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
//Console.WriteLine("\t" + text);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else if (ext.CompareTo(".xml") == 0)
{
try
{
String text = XMLParser.Parser.ParseXMLtoString(fi.FullName);
int retCode, count = 0;
retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
if (retCode > 0)
WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
//Console.WriteLine("\t" + text);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
else if (ext.CompareTo(".pst") == 0)
{
}
else if (ext.CompareTo(".zip") == 0 || ext.CompareTo(".7z") == 0 || ext.CompareTo(".xz") == 0 || ext.CompareTo(".bzip2") == 0 ||
ext.CompareTo(".gzip") == 0 || ext.CompareTo(".tar") == 0 || ext.CompareTo(".wim") == 0 || ext.CompareTo(".arj") == 0 ||
ext.CompareTo(".cab") == 0 || ext.CompareTo(".chm") == 0 || ext.CompareTo(".cpio") == 0 || ext.CompareTo(".cramfs") == 0 ||
ext.CompareTo(".deb") == 0 || ext.CompareTo(".fat") == 0 || ext.CompareTo(".hfs") == 0 || ext.CompareTo(".iso") == 0 ||
ext.CompareTo(".lzh") == 0 || ext.CompareTo(".lzma") == 0 || ext.CompareTo(".mbr") == 0 || ext.CompareTo(".msi") == 0 ||
ext.CompareTo(".nsis") == 0 || ext.CompareTo(".ntfs") == 0 || ext.CompareTo(".rar") == 0 || ext.CompareTo(".rpm") == 0 ||
ext.CompareTo(".squashfs") == 0 || ext.CompareTo(".udf") == 0 || ext.CompareTo(".vhd") == 0 || ext.CompareTo(".xar") == 0 ||
ext.CompareTo(".z") == 0)
{
//extract code
SevenZipExtractor extractor = null;
try
{
//path to the systems temporary folder
String tempFolderPath = Path.GetTempPath();
tempFolderPath += "temp_dir\\";
//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");
extractor = new SevenZipExtractor(fi.FullName);
//Extract the entire file
extractor.ExtractArchive(tempFolderPath);
extractor.Dispose();
//Count how many files in archive
int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length;
// traverse files
string[] fileEntries = Directory.GetFiles(tempFolderPath);
foreach (string fileName in fileEntries)
{
//Console.WriteLine("IN ARCHIVE: " + fileName);
}
//delete the temporary directory we created at the beginning
Directory.Delete(tempFolderPath, true);
}
catch (Exception e)
{
//get rid of the object because it is unmanaged
extractor.Dispose();
Console.WriteLine(e.Message);
}
}
}
示例2: docxParser
public static String docxParser(String filename)
{
//path to the systems temporary folder
String tempFolderPath = Path.GetTempPath();
//set the path of the 7z.dll (it needs to be in the debug folder)
SevenZipExtractor.SetLibraryPath("7z.dll");
SevenZipExtractor extractor = new SevenZipExtractor(filename);
//create a filestream for the file we are going to extract
FileStream f = new FileStream(tempFolderPath + "document.xml", FileMode.Create);
//extract the document.xml
extractor.ExtractFile("word\\document.xml", f);
//get rid of the object because it is unmanaged
extractor.Dispose();
//close the filestream
f.Close();
//send document.xml that we extracted from the .docx to the xml parser
String result = XMLParser.Parser.ParseXMLtoString(tempFolderPath + "document.xml");
//delete the extracted file from the temp folder
File.Delete(tempFolderPath + "document.xml");
return result;
}
示例3: extractArchive
public static int extractArchive(string inFileName, string extractPath)
{
// extract input archive
FileStream fileStream;
SevenZipExtractor extractor = null;
try
{
extractor = new SevenZipExtractor(File.OpenRead(inFileName));
foreach (var fileName in extractor.ArchiveFileNames)
{
// you of course can extract to a file stream instead of a memory stream if you want :)
//var memoryStream = new MemoryStream();
//extractor.ExtractFile(fileName, memoryStream);
// do what you want with your file here :)
fileStream = File.Create(Path.Combine(extractPath, fileName));
extractor.ExtractFile(fileName, fileStream);
int buffersize = 1024;
byte[] buffer = new byte[buffersize];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffersize)) != 0)
{
fileStream.Write(buffer, 0, bytesRead);
} // end while
fileStream.Close();
}
extractor.Dispose();
}
catch (Exception ex)
{
Logger.Logwrite(ex.Message);
Console.Error.WriteLine("Error: Could not open input archive: " + inFileName);
Console.Error.WriteLine("\t" + ex.Message);
}
finally
{
}
return 1;
}
示例4: 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;
}
示例5: 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;
}
示例6: RunThread
/// <summary>
/// The run method of the thread on which the <see cref="SevenZipExtractor"/> is created.
/// </summary>
/// <remarks>
/// This method creates a <see cref="SevenZipExtractor"/> and then watches for events to execute.
/// Other methods signal the thread that an action needs to be taken, and this thread executes said
/// actions.
/// </remarks>
protected void RunThread()
{
m_szeExtractor = String.IsNullOrEmpty(m_strPath) ? new SevenZipExtractor(m_stmArchive) : new SevenZipExtractor(m_strPath);
try
{
ActionPackage apkStartEvent = m_queEvents.Dequeue();
apkStartEvent.DoneEvent.Set();
while (true)
{
m_mreEvent.WaitOne();
ActionPackage apkEvent = m_queEvents.Dequeue();
if (apkEvent.Action == null)
break;
try
{
apkEvent.Action();
}
catch (Exception e)
{
apkEvent.Exception = e;
}
m_mreEvent.Reset();
apkEvent.DoneEvent.Set();
}
}
finally
{
m_szeExtractor.Dispose();
}
}
示例7: InstanciateZipExctractorWithPassword
private SevenZipExtractor InstanciateZipExctractorWithPassword(string FileName, IEventListener iel)
{
SevenZipExtractor Sex = new SevenZipExtractor(FileName);
bool valid = Sex.Check();
if (valid == false)
{
Sex.Dispose();
foreach (string psw in _IUnrarUserSettings.EnumerableRarPasswords)
{
Sex = new SevenZipExtractor(FileName, psw);
if (Sex.Check())
{
Trace.WriteLine(string.Format("Find Password in list: {0}", psw));
return Sex;
}
else
Sex.Dispose();
}
string same = Path.GetFileName(FileName);
CorruptedRarOrMissingPasswordArgs cr = new CorruptedRarOrMissingPasswordArgs(same, _AddRar);
OnErrorUserExit(iel, cr);
while ((!valid) && (cr.accept == true))
{
Sex = new SevenZipExtractor(FileName, cr.Password);
valid = Sex.Check();
if (valid == false)
{
Sex.Dispose();
cr = new CorruptedRarOrMissingPasswordArgs(same, cr.SavePassword);
OnErrorUserExit(iel, cr);
}
}
if (valid == false)
return null;
}
return Sex;
}
示例8: CompareFiles
void CompareFiles()
{
string rarfilename = "Update" + this.Version + ".rar";
string path = Path.GetDirectoryName(Path.GetFullPath(rarfilename));
SevenZipExtractor extr = new SevenZipExtractor(rarfilename);
for (int i = 0; i < extr.ArchiveFileNames.Count; i++) {
ArchiveFileInfo fileinfo = extr.ArchiveFileData[i];
string filename = extr.ArchiveFileNames[i];
bool updateFile = false;
if (!fileinfo.IsDirectory) {
if (!File.Exists(filename)) {
updateFile = true;
} else {
if (Resources.Blacklist.Split(',').Contains(Path.GetFileName(filename)))
continue;
uint currentHash = Crc32.Compute(File.ReadAllBytes(filename));
uint updateHash = extr.ArchiveFileData[i].Crc;
if (currentHash != updateHash)
updateFile = true;
}
} else {
if (!Directory.Exists(filename))
Directory.CreateDirectory(filename);
continue;
}
if (!updateFile)
continue;
string pth = Path.GetDirectoryName(filename);
if (pth != "") {
if (!Directory.Exists(pth))
Directory.CreateDirectory(pth);
if (File.Exists(filename))
File.Delete(filename);
}
AddLog("Updating " + filename + "...");
FileStream fs = File.Create(filename);
extr.ExtractFile(filename, fs);
fs.Close();
fs.Dispose();
AddLine(RepeatString(" ", 73 - filename.Length) + " DONE");
}
if (bool.Parse(Resources.SettingsKeySet)) {
appSettings.SetString("Version", this.Version);
appSettings.Save();
}
extr.Dispose();
if (File.Exists(rarfilename))
File.Delete(rarfilename);
buttonUpdate.Text = "Run " + Resources.Product;
AddLine("Updating finished!");
}
示例9: DoCheck
private void DoCheck() {
string FileName = _ShellListView.GetFirstSelectedItem().ParsingName;
var extractor = new SevenZipExtractor(FileName);
if (!extractor.Check())
MessageBox.Show("Not Pass");
else
MessageBox.Show("Pass");
extractor.Dispose();
}
示例10: DoCheck
private void DoCheck()
{
SevenZipExtractor extractor = new SevenZipExtractor(archive.ParsingName);
if (!extractor.Check())
MessageBox.Show("Not Pass");
else
MessageBox.Show("Pass");
extractor.Dispose();
}
示例11: update_ProgressCompleted
private void update_ProgressCompleted(object sender, ProgressCompletedEventArgs e)
{
if (e.Cancelled)
return;
Invoke((MethodInvoker)delegate
{
if (e.ExceptionObject != null)
{
Program.Status = UpdateStatus.Failure;
txtChangeLog.Text = string.Format("The following error occured while trying to get the lastest ConnectUO version information: \n {0}", ((Exception)e.ExceptionObject).Message);
Complete();
return;
}
pbProgress.Value = 100;
lblStatus.Text = string.Format("Status: Extracting...");
System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o)
{
_extractor = new SevenZipExtractor(_destinationFile);
_extractor.Extracting += new EventHandler<SevenZip.ProgressEventArgs>(extractor_Extracting);
_extractor.ExtractionFinished += new EventHandler(extractor_ExtractionFinished);
_extractor.ExtractArchive(_destinationDirectory);
_extractor.Dispose();
});
});
}
示例12: XlsxParser
public static String XlsxParser(String filename)
{
SevenZipExtractor extractor = null;
String result = null;
try
{
//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");
extractor = new SevenZipExtractor(filename);
//Extract the entrie excel file
extractor.ExtractArchive(tempFolderPath);
extractor.Dispose();
//Count how many sheets there are in the workbook
int count = Directory.GetFiles(tempFolderPath + "xl\\worksheets", "*.xml", SearchOption.TopDirectoryOnly).Length;
//Create an array of filenames based off how many sheets we counted
String[] files = new String[count];
for (int i = 1; i <= count; i++)
{
files[i - 1] = "xl\\worksheets\\sheet" + i + ".xml";
}
//send the worksheets to the xml parser
foreach (String s in files)
result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + s);
result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + "xl\\sharedStrings.xml");
//delete the temporary directory we created at the beginning
Directory.Delete(tempFolderPath, true);
}
catch (Exception)
{
//get rid of the object because it is unmanaged
extractor.Dispose();
}
return result;
}
示例13: ProcessFile
/*
* Determines if a file is an archive or not. If it's an archive it is extracted to the System temp forlder for processing.
* If it is not an archive it is passed to ProcessNonArchive.
*
* fInfo: Incoming FileInfo object to be processed
* returns: void
*/
public static void ProcessFile(Delimon.Win32.IO.FileInfo fInfo)
{
string extention = Path.GetExtension(fInfo.FullName);
if (extention == null)
extention = "";
if (IsArchive(extention))
{
//extract code
SevenZipExtractor extractor = null;
try
{
//path to the systems temporary folder
String tempFolderPath = Path.GetTempPath();
tempFolderPath += "temp_dir\\";
//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");
extractor = new SevenZipExtractor(fInfo.FullName);
//Extract the entire file
extractor.ExtractArchive(tempFolderPath);
extractor.Dispose();
bool arcs = true;
while (arcs)
{
arcs = false;
// traverse files
string[] fileEntries = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories);
foreach (string fileName in fileEntries)
{
//Console.WriteLine("IN ARCHIVE: " + fileName);
FileInfo archive = new FileInfo(fileName);
if (IsArchive(archive.Extension.ToString()))
{
arcs = true;
extractor = new SevenZipExtractor(fileName);
extractor.ExtractArchive(tempFolderPath);
File.Delete(fileName);
}
}
}
int[][] totals = {new int[5], new int[9]}; //totals[0] count; totals[1] results;
string[] fileEntries2 = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories);
foreach (string fileName in fileEntries2)
{
int[][] results = ProcessNonArchive(new Delimon.Win32.IO.FileInfo(fileName), true);
if (MainForm.socialSecurityMode)
{
totals[0][0] += results[0][0];
if (results[0][1] > totals[0][1])
totals[0][1] = results[0][1];
}
if (MainForm.creditCardMode)
{
totals[1][0] += results[1][0];
if (results[1][1] > totals[1][1])
totals[1][1] = results[1][1];
}
}
//Count how many files in archive
//int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length;
//delete the temporary directory we created at the beginning
Directory.Delete(tempFolderPath, true);
if (totals[0][1] > 0)
{
//WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + (ScanData.Code)totals[1]);
if (MainForm.socialSecurityMode)
{
ScanData returnedData = new ScanData(totals[0][0], totals[0][1], totals[0][3], totals[0][4]);
Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData);
try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); }
catch (InvalidOperationException) { }
}
if (MainForm.creditCardMode)
{
CreditData ccReturnedData = new CreditData(totals[1][0], totals[1][1], totals[1][3], totals[1][4], totals[1][5], totals[1][6], totals[1][7], totals[1][8]);
Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData);
try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); }
catch (InvalidOperationException) { }
}
}
}
catch (Exception e)
{
//get rid of the object because it is unmanaged
//.........这里部分代码省略.........
示例14: RunThread
/// <summary>
/// The run method of the thread on which the <see cref="SevenZipExtractor"/> is created.
/// </summary>
/// <remarks>
/// This method creates a <see cref="SevenZipExtractor"/> and then watches for events to execute.
/// Other methods signal the thread that an action needs to be taken, and this thread executes said
/// actions.
/// </remarks>
protected void RunThread()
{
m_szeExtractor = String.IsNullOrEmpty(m_strPath) ? new SevenZipExtractor(m_stmArchive) : new SevenZipExtractor(m_strPath);
try
{
KeyValuePair<Action<object>, ManualResetEvent> kvpStartEvent = m_queEvents.Dequeue();
kvpStartEvent.Value.Set();
while (true)
{
m_mreEvent.WaitOne();
KeyValuePair<Action<object>, ManualResetEvent> kvpEvent = m_queEvents.Dequeue();
if (kvpEvent.Key == null)
break;
kvpEvent.Key(null);
m_mreEvent.Reset();
kvpEvent.Value.Set();
}
}
finally
{
m_szeExtractor.Dispose();
}
}
示例15: LoadComicBook
/// <summary>
/// Loads the comic book.
/// </summary>
/// <param name="files">The files.</param>
/// <returns></returns>
public LoadedFilesData LoadComicBook(string[] files)
{
LoadedFiles = 0;
LoadedFilesData returnValue = new LoadedFilesData();
returnValue.ComicBook = new ComicBook();
Comic.ComicFile comicFile = new Comic.ComicFile();
Array.Sort(files);
string infoTxt = "";
MemoryStream ms = new MemoryStream();
SevenZipExtractor extractor;
Boolean nextFile = false;
foreach (String file in files)
{
if (!System.IO.File.Exists(file))
{
returnValue.Error = "One or more archives where not found";
return returnValue;
}
}
try
{
TotalFiles = files.Length;
foreach (string file in files)
{
//open archive
extractor = new SevenZipExtractor(file);
string[] fileNames = extractor.ArchiveFileNames.ToArray();
Array.Sort(fileNames);
//create ComicFiles for every single archive
for (int i = 0; i < extractor.FilesCount; i++)
{
for (int x = 0; x < Enum.GetNames(typeof(SupportedImages)).Length; x++)
{
//if it is an image add it to array list
if (Utils.ValidateImageFileExtension(fileNames[i]))
{
ms = new MemoryStream();
extractor.ExtractFile(fileNames[i], ms);
ms.Position = 0;
try
{
comicFile.Add(ms.ToArray());
}
catch (Exception)
{
ms.Close();
returnValue.Error = "One or more files are corrupted, and where skipped";
return returnValue;
}
ms.Close();
nextFile = true;
}
//if it is a txt file set it as InfoTxt
else if (Utils.ValidateTextFileExtension(fileNames[i]))
{
ms = new MemoryStream();
extractor.ExtractFile(fileNames[i], ms);
ms.Position = 0;
try
{
StreamReader sr = new StreamReader(ms);
infoTxt = sr.ReadToEnd();
}
catch (Exception)
{
ms.Close();
returnValue.Error = "One or more files are corrupted, and where skipped";
return returnValue;
}
ms.Close();
nextFile = true;
}
if (nextFile)
{
nextFile = false;
x = Enum.GetNames(typeof(SupportedImages)).Length;
}
}
}
//unlock files again
extractor.Dispose();
//Add a ComicFile
if (comicFile.Count > 0)
{
//.........这里部分代码省略.........