/// <summary> /// 1.获取到所有要打包文件的初始信息 /// </summary> private static void GetFilesInitInfo(string[] filePaths) { FileStream tempStream = null; BinaryReader tempReader = null; DirectoryInfo packFolderParent = (new DirectoryInfo(PackFromFolderPath)).Parent; int rootFolderPathLength = packFolderParent.FullName.Length + 1; //1.获取文件初始信息 for (int i = 0; i < filePaths.Length; i++) { FileInfo tempInfo = new FileInfo(filePaths [i]); if (!tempInfo.Extension.ToLower().Equals(MFilterFileExtention.ToLower())) { tempStream = new FileStream(filePaths [i], FileMode.Open); tempReader = new BinaryReader(tempStream); int tempFileLength = (int)tempStream.Length; //获取文件相对路径(包括其当前所属目录); string relativePath = filePaths [i].Substring(rootFolderPathLength); PackedFileInfo tempFileInfo = new PackedFileInfo(); tempFileInfo.fullPath = filePaths [i]; tempFileInfo.fileName = relativePath; tempFileInfo.size = tempFileLength; resInfoList.Add(tempFileInfo); //关闭BinaryReader文件阅读器 tempReader.Close(); //关闭FileStream文件流 tempStream.Close(); } } }
public string MakeMockFiles(int numberOfFiles, int fileSize = 350) { var packedFileInfo = new IPackedFileInfo[numberOfFiles]; var rng = new Random(); Directory.CreateDirectory("unpackedFiles"); var randomBuffer = new byte[fileSize]; for (var x = 0; x < numberOfFiles; x++) { packedFileInfo[x] = new PackedFileInfo(); rng.NextBytes(randomBuffer); packedFileInfo[x].Name = $"testfile{x}"; packedFileInfo[x].UnpackedFileLocation = $"unpackedFiles\\{packedFileInfo[x].Name}.bin"; File.WriteAllBytes(packedFileInfo[x].UnpackedFileLocation, randomBuffer); } var packedFile = "testFile.rpk"; ResourcePackFile.PackFiles(packedFileInfo, packedFile); Directory.Delete("unpackedFiles", true); return(packedFile); }
private void SelectedPackedFiledChanged(object sender, EventArgs e) { var selctedFileName = (string)packedFilesListView.SelectedItem; _selectedPackedFile = _packedFiles.Single(i => i.name == selctedFileName); packedFileNameLabel.Text = $"Packed File: {_selectedPackedFile.name}"; packedFileOffsetLabel.Text = $"Packed File Offset: {_selectedPackedFile.location}"; packedFileTypeLabel.Text = $"Packed File Type: {_selectedPackedFile.extension}"; packedFileSizeLabel.Text = $"Packed File Size: {_selectedPackedFile.size / 10} Kb"; selectedFileStatusLabel.Text = $"Selected File: {_selectedPackedFile.name}"; }