本文整理汇总了C#中SevenZip.SevenZipExtractor.Check方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipExtractor.Check方法的具体用法?C# SevenZipExtractor.Check怎么用?C# SevenZipExtractor.Check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipExtractor
的用法示例。
在下文中一共展示了SevenZipExtractor.Check方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: Read
public Stream Read(CloudFile cloudFile, OnProgress onProgress)
{
if (cloudFile.Format == CloudFileFormat.Original)
{
return provider.Read(cloudFile, onProgress);
}
else
{
Stream stream = provider.Read(cloudFile, onProgress);
using (var decoder = new SevenZip.SevenZipExtractor(stream, password))
{
if (!decoder.Check())
{
return stream;
}
else
{
Stream result = new MemoryStream();
if (decoder.FilesCount != 1)
{
throw new SevenZipProviderException("Cannot extract 7z package which contains no file or more than 1 file.");
}
decoder.Extracting += new EventHandler<ProgressEventArgs>(
(o, p) =>
{
if (onProgress != null)
{
onProgress(cloudFile, ProcessTypes.Decompress, (p.PercentDone * stream.Length), stream.Length);
}
});
decoder.ExtractFile(0, result);
stream.Close();
result.Position = 0;
return result;
}
}
}
}
示例3: DoCheck
private void DoCheck()
{
string FileName = Explorer.SelectedItems[0].ParsingName;
SevenZipExtractor extractor = new SevenZipExtractor(FileName);
if (!extractor.Check())
MessageBox.Show("Not Pass");
else
MessageBox.Show("Pass");
extractor.Dispose();
}
示例4: Install
//where's my async?
public bool Install(out string err)
{
err = null;
using (var wc = new WebClient())
{
Log.File(Localization.RequestingNvsePage, Paths.NvseLink);
string dlLink;
using (var resStream = wc.OpenRead(Paths.NvseLink))
{
if (!Util.PatternSearch(resStream, Paths.NvseSearchPattern, out dlLink))
{
err = Localization.FailedDownloadNvse;
return false;
}
}
Log.File(Localization.ParsedNvseLink, dlLink.Truncate(100));
var archiveName = Path.GetFileName(dlLink);
var tmpPath = Path.Combine(Path.GetTempPath(), archiveName);
wc.DownloadFile(dlLink, tmpPath);
using (var lzExtract = new SevenZipExtractor(tmpPath))
{
if (!lzExtract.Check())
{
err = string.Format(Localization.Invalid7zArchive, archiveName);
return false;
}
var wantedFiles = (from file in lzExtract.ArchiveFileNames
let filename = Path.GetFileName(file)
let ext = Path.GetExtension(filename).ToUpperInvariant()
where ext == ".EXE" || ext == ".DLL"
select new { file, filename }).ToArray();
foreach (var a in wantedFiles)
{
var savePath = Path.Combine(_fnvPath, a.filename);
Log.File(Localization.Extracting, a.filename);
using (var fsStream = File.OpenWrite(savePath))
{
try
{
lzExtract.ExtractFile(a.file, fsStream);
}
catch
{
err = Localization.FailedExtractNvse;
throw;
}
}
}
}
}
Log.Dual(Localization.NvseInstallSuccessful);
return true;
}
示例5: Check
public bool Check(string iFileName, string iPassword)
{
FileInfo fif = new FileInfo(iFileName);
if (!fif.Exists)
throw new ArgumentException();
using (SevenZipExtractor sze = new SevenZipExtractor(iFileName, iPassword))
{
return sze.Check();
}
}
示例6: 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;
}
示例7: 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();
}
示例8: DoCheck
private void DoCheck()
{
SevenZipExtractor extractor = new SevenZipExtractor(archive.ParsingName);
if (!extractor.Check())
MessageBox.Show("Not Pass");
else
MessageBox.Show("Pass");
extractor.Dispose();
}
示例9: btn_checkarchive_Click
private void btn_checkarchive_Click(object sender, EventArgs e)
{
var sevenZipExtractor = new SevenZipExtractor(_pathArchive);
var check = sevenZipExtractor.Check();
var dialog = new TaskDialog();
dialog.Text = check ? CHECK_OKE : CHECK_ERROR;
dialog.StandardButtons = TaskDialogStandardButtons.Ok;
dialog.Show();
}
示例10: compressFolder
/// <summary>
/// Compress All Folders in a path each folder to a individual 7zip file
/// </summary>
/// <param name="blShuttingDown"></param>
private void compressFolder(ref bool blShuttingDown)
{
SevenZip.SevenZipCompressor compressor = null;
SevenZip.SevenZipExtractor extractor = null;
Stream exreader = null;
Stream creader = null;
Stream extestreader = null;
string[] strfilearr = new string[1];
try
{
SevenZip.SevenZipBase.SetLibraryPath(Get7ZipFolder());
string[] Directories = Directory.GetDirectories(SourceFolder);
//Loop through every local directory
foreach (string strDir in Directories)
{
bool blArchiveOk = false;
DirectoryInfo DirInfo1 = new DirectoryInfo(strDir);
string str7Dir = Common.WindowsPathClean(DirInfo1.FullName + ".7z");
string strDestination = Common.WindowsPathCombine(DestinationFolder, str7Dir, SourceFolder);
if (blShuttingDown)
{
_evt.WriteEntry("Compress: Shutting Down, about to Compress: " + strDir, System.Diagnostics.EventLogEntryType.Information, 5130, 50);
return;
}
if (!startCompressing(DirInfo1.LastWriteTime))
{
continue;
}
//Check for Original Folder
try
{
if (File.Exists(strDestination))
{
FileInfo file7 = new FileInfo(strDestination);
extestreader = new FileStream(strDestination, FileMode.Open);
extractor = new SevenZipExtractor(extestreader);
//If archive is not corrupted and KeepUncompressed is false then it is ok to delete the original
if (extractor.Check() && KeepOriginalFile == false)
{
//Same File compressed then ok to delete
if (DirInfo1.LastWriteTime == file7.LastWriteTime && Common.CalculateFolderSize(DirInfo1.FullName) == extractor.UnpackedSize && Common.GetFolderFileCount(DirInfo1.FullName) == extractor.FilesCount)
{
Directory.Delete(DirInfo1.FullName, true);
}
}
continue;
}
}
catch (Exception)
{
_evt.WriteEntry("Compress: Failed to Delete Original File: " + DirInfo1.FullName, System.Diagnostics.EventLogEntryType.Error, 5140, 50);
continue;
}
finally
{
if (extestreader != null)
{
extestreader.Close();
extestreader.Dispose();
extestreader = null;
}
if (extractor != null)
{
extractor.Dispose();
extractor = null;
}
}
//Compression of Entire Folder
strfilearr[0] = DirInfo1.FullName;
try
{
compressor = new SevenZip.SevenZipCompressor();
compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
compressor.CompressionLevel = CompressionLvl;
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
if (!string.IsNullOrEmpty(_encryptionPassword))
{
compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
}
long lFreeSpace = 0;
//.........这里部分代码省略.........
示例11: compressFile
/// <summary>
/// Compress files individually with .7z added on the end of the filename
/// </summary>
/// <param name="blShuttingDown"></param>
private void compressFile(ref bool blShuttingDown)
{
SevenZip.SevenZipCompressor compressor = null;
SevenZip.SevenZipExtractor extractor = null;
Stream exreader = null;
Stream creader = null;
Stream extestreader = null;
string[] strfilearr = new string[1];
try
{
AllFiles = Common.WalkDirectory(SourceFolder, ref blShuttingDown, FileNameFilter);
SevenZip.SevenZipBase.SetLibraryPath(Get7ZipFolder());
if (SourceFolder != DestinationFolder)
{
Common.CreateDestinationFolders(SourceFolder, DestinationFolder);
}
if (blShuttingDown)
{
throw new Exception("Shutting Down");
}
//Loop through every file
foreach (System.IO.FileInfo file1 in AllFiles)
{
string str7File = Common.WindowsPathClean(file1.FullName + ".7z");
string strDestination = Common.WindowsPathCombine(DestinationFolder, str7File, SourceFolder);
bool blArchiveOk = false;
if (blShuttingDown)
{
_evt.WriteEntry("Compress: Shutting Down, about to Compress: " + file1.FullName, System.Diagnostics.EventLogEntryType.Information, 5130, 50);
throw new Exception("Shutting Down");
}
//Skip over already compressed files
if (file1.Extension.ToLower() == ".7z" || file1.Extension.ToLower() == ".zip" || file1.Extension.ToLower() == ".rar")
{
continue;
}
if (Common.IsFileLocked(file1))
{
_evt.WriteEntry("Compress: File is locked: " + file1.FullName, System.Diagnostics.EventLogEntryType.Error, 5130, 50);
continue;
}
if (!startCompressing(file1.LastWriteTime))
{
continue;
}
try
{
if (File.Exists(strDestination))
{
extestreader = new FileStream(strDestination, FileMode.Open);
extractor = new SevenZipExtractor(extestreader);
//If archive is not corrupted and KeepUncompressed is false then it is ok to delete the original
if (extractor.Check() && KeepOriginalFile == false)
{
FileInfo file2 = new FileInfo(strDestination);
//Same File compressed then ok to delete
if (file1.LastWriteTime == file2.LastWriteTime && file1.Length == extractor.UnpackedSize && extractor.FilesCount == 1)
{
//File.SetAttributes(file1.FullName, FileAttributes.Normal);
file1.IsReadOnly = false;
File.Delete(file1.FullName);
}
file2 = null;
}
continue;
}
}
catch (Exception)
{
_evt.WriteEntry("Compress: Failed to Delete Original File: " + file1.FullName, System.Diagnostics.EventLogEntryType.Error, 5140, 50);
continue;
}
finally
{
if (extestreader != null)
{
extestreader.Close();
extestreader.Dispose();
extestreader = null;
}
if (extractor != null)
{
extractor.Dispose();
extractor = null;
//.........这里部分代码省略.........