本文整理汇总了C#中Nexus.Client.Util.FileUtil.CreateTempDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# FileUtil.CreateTempDirectory方法的具体用法?C# FileUtil.CreateTempDirectory怎么用?C# FileUtil.CreateTempDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nexus.Client.Util.FileUtil
的用法示例。
在下文中一共展示了FileUtil.CreateTempDirectory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginReadOnlyTransaction
/// <summary>
/// Starts a read-only transaction.
/// </summary>
/// <remarks>
/// This puts the OMod into read-only mode.
///
/// Read-only mode can greatly increase the speed at which multiple file are extracted.
/// </remarks>
public void BeginReadOnlyTransaction(FileUtil p_futFileUtil)
{
if (!IsPacked)
{
m_arcFile.ReadOnlyInitProgressUpdated += new CancelProgressEventHandler(ArchiveFile_ReadOnlyInitProgressUpdated);
m_arcFile.BeginReadOnlyTransaction(p_futFileUtil);
return;
}
m_strReadOnlyTempDirectory = p_futFileUtil.CreateTempDirectory();
string[] strFileStreamNames = { "plugins", "data" };
List<FileInfo> lstFiles = null;
byte[] bteUncompressedFileData = null;
m_intReadOnlyInitFileBlockExtractionCurrentStage = 0;
m_fltReadOnlyInitCurrentBaseProgress = 0;
foreach (string strFileStreamName in strFileStreamNames)
{
//extract the compressed file block...
using (Stream stmCompressedFiles = new MemoryStream())
{
using (SevenZipExtractor szeOmod = new SevenZipExtractor(m_strFilePath))
{
if (!szeOmod.ArchiveFileNames.Contains(strFileStreamName))
continue;
m_intReadOnlyInitFileBlockExtractionCurrentStage++;
szeOmod.ExtractFile(strFileStreamName, stmCompressedFiles);
switch (strFileStreamName)
{
case "plugins":
lstFiles = PluginList;
break;
case "data":
lstFiles = DataFileList;
break;
default:
throw new Exception("Unexpected value for file stream name: " + strFileStreamName);
}
}
stmCompressedFiles.Position = 0;
Int64 intTotalLength = lstFiles.Sum(x => x.Length);
bteUncompressedFileData = new byte[intTotalLength];
switch (CompressionType)
{
case InArchiveFormat.SevenZip:
byte[] bteProperties = new byte[5];
stmCompressedFiles.Read(bteProperties, 0, 5);
Decoder dcrDecoder = new Decoder();
dcrDecoder.SetDecoderProperties(bteProperties);
DecoderProgressWatcher dpwWatcher = new DecoderProgressWatcher(stmCompressedFiles.Length);
dpwWatcher.ProgressUpdated += new EventHandler<EventArgs<int>>(dpwWatcher_ProgressUpdated);
using (Stream stmUncompressedFiles = new MemoryStream(bteUncompressedFileData))
dcrDecoder.Code(stmCompressedFiles, stmUncompressedFiles, stmCompressedFiles.Length - stmCompressedFiles.Position, intTotalLength, dpwWatcher);
break;
case InArchiveFormat.Zip:
using (SevenZipExtractor szeZip = new SevenZipExtractor(stmCompressedFiles))
{
szeZip.Extracting += new EventHandler<ProgressEventArgs>(szeZip_Extracting);
using (Stream stmFile = new MemoryStream(bteUncompressedFileData))
{
szeZip.ExtractFile(0, stmFile);
}
}
break;
default:
throw new Exception("Cannot get files: unsupported compression type: " + CompressionType.ToString());
}
}
float fltFileStreamPercentBlockSize = FILE_BLOCK_EXTRACTION_PROGRESS_BLOCK_SIZE / m_intReadOnlyInitFileBlockExtractionStages;
float fltFileWritingPercentBlockSize = FILE_WRITE_PROGRESS_BLOCK_SIZE / m_intReadOnlyInitFileBlockExtractionStages;
m_fltReadOnlyInitCurrentBaseProgress += fltFileStreamPercentBlockSize;
//...then write each file to the temporary location
Int64 intFileStart = 0;
byte[] bteFile = null;
Crc32 crcChecksum = new Crc32();
for (Int32 i = 0; i < lstFiles.Count; i++)
{
FileInfo ofiFile = lstFiles[i];
bteFile = new byte[ofiFile.Length];
Array.Copy(bteUncompressedFileData, intFileStart, bteFile, 0, ofiFile.Length);
intFileStart += ofiFile.Length;
FileUtil.WriteAllBytes(Path.Combine(m_strReadOnlyTempDirectory, ofiFile.Name), bteFile);
crcChecksum.Initialize();
crcChecksum.ComputeHash(bteFile);
if (crcChecksum.CrcValue != ofiFile.CRC)
throw new Exception(String.Format("Unable to extract {0}: checksums did not match. OMod is corrupt.", ofiFile.Name));
UpdateReadOnlyInitProgress(m_fltReadOnlyInitCurrentBaseProgress, fltFileWritingPercentBlockSize, i / lstFiles.Count);
}
m_fltReadOnlyInitCurrentBaseProgress += fltFileWritingPercentBlockSize;
//.........这里部分代码省略.........
示例2: BeginReadOnlyTransaction
/// <summary>
/// Starts a read-only transaction.
/// </summary>
/// <remarks>
/// This puts the archive into read-only mode.
/// </remarks>
/// <param name="p_futFileUtil">An instance of a <see cref="FileUtil"/> class.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="p_futFileUtil"/> is <c>null</c>.</exception>
public void BeginReadOnlyTransaction(FileUtil p_futFileUtil)
{
if (m_szeReadOnlyExtractor == null)
{
if (p_futFileUtil == null)
throw new ArgumentNullException("p_futFileUtil");
m_szeReadOnlyExtractor = GetThreadSafeExtractor(m_strPath);
if (m_szeReadOnlyExtractor.IsSolid)
{
m_szeReadOnlyExtractor.Dispose();
m_szeReadOnlyExtractor = null;
m_strReadOnlyTempDirectory = p_futFileUtil.CreateTempDirectory();
using (SevenZipExtractor szeExtractor = Archive.GetExtractor(m_strPath))
{
szeExtractor.FileExtractionFinished += new EventHandler<FileInfoEventArgs>(FileExtractionFinished);
szeExtractor.ExtractArchive(m_strReadOnlyTempDirectory);
}
}
}
}