當前位置: 首頁>>代碼示例>>C#>>正文


C# FileUtil.CreateTempDirectory方法代碼示例

本文整理匯總了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;
//.........這裏部分代碼省略.........
開發者ID:etinquis,項目名稱:nexusmodmanager,代碼行數:101,代碼來源:OMod.cs

示例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);
					}
				}
			}
		}
開發者ID:NexusMods,項目名稱:NexusModManager-4.5,代碼行數:28,代碼來源:Archive.cs


注:本文中的Nexus.Client.Util.FileUtil.CreateTempDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。