private static async Task DownloadAndExtractAsync(string url, string dir) { await using Stream httpStream = await HttpClientInstance.GetStreamAsync(url); using IReader reader = ReaderFactory.Open(httpStream); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } while (reader.MoveToNextEntry()) { IEntry entry = reader.Entry; if (entry.IsDirectory) { continue; } string targetPath = Path.Combine(dir, entry.Key.Replace('/', '\\')); string targetDir = Path.GetDirectoryName(targetPath); if (targetDir == null) { throw new InvalidOperationException(); } if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } await using EntryStream stream = reader.OpenEntryStream(); await using FileStream fs = File.Create(targetPath); await stream.CopyToAsync(fs); } }
public void TestSharpCompressWithEmptyStream() { ResetScratch(); MemoryStream stream = new NonSeekableMemoryStream(); using (IWriter zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) { zipWriter.Write("foo.txt", new MemoryStream(new byte[0])); zipWriter.Write("foo2.txt", new MemoryStream(new byte[10])); } stream = new MemoryStream(stream.ToArray()); File.WriteAllBytes(Path.Combine(SCRATCH_FILES_PATH, "foo.zip"), stream.ToArray()); using (IReader zipReader = ZipReader.Open(stream)) { while (zipReader.MoveToNextEntry()) { using (EntryStream entry = zipReader.OpenEntryStream()) { MemoryStream tempStream = new MemoryStream(); const int bufSize = 0x1000; byte[] buf = new byte[bufSize]; int bytesRead = 0; while ((bytesRead = entry.Read(buf, 0, bufSize)) > 0) { tempStream.Write(buf, 0, bytesRead); } } } } }
public void TestWriteReadStreamSnapshot() { Journal journal = Journal.Open("test"); journal.Write("name123", 1, EntryBatch.Of("type1", "type1_instance1", "SNAPSHOT123-1")); journal.Write("name456", 1, EntryBatch.Of("type2", "type2_instance1", "SNAPSHOT456-1")); journal.Write("name123", 2, EntryBatch.Of("type1-1", "type1-1_instance1", "SNAPSHOT123-2")); journal.Write("name123", 3, EntryBatch.Of("type1-2", "type1-2_instance1")); journal.Write("name456", 2, EntryBatch.Of("type2-1", "type2-1_instance1", "SNAPSHOT456-2")); EntryStreamReader streamReader = journal.StreamReader(); EntryStream eventStream123 = streamReader.StreamFor("name123"); Assert.AreEqual("name123", eventStream123.StreamName); Assert.AreEqual(3, eventStream123.StreamVersion); Assert.AreEqual(1, eventStream123.Stream.Count); Assert.AreEqual("SNAPSHOT123-2", eventStream123.Snapshot); EntryStream eventStream456 = streamReader.StreamFor("name456"); Assert.AreEqual("name456", eventStream456.StreamName); Assert.AreEqual(2, eventStream456.StreamVersion); Assert.AreEqual(0, eventStream456.Stream.Count); Assert.AreEqual("SNAPSHOT456-2", eventStream456.Snapshot); journal.Close(); }
public void TestWriteReadStream() { Journal journal = Journal.Open("test"); journal.Write("name123", 1, EntryBatch.Of("type1", "type1_instance1")); journal.Write("name456", 1, EntryBatch.Of("type2", "type2_instance1")); journal.Write("name123", 2, EntryBatch.Of("type1-1", "type1-1_instance1")); journal.Write("name123", 3, EntryBatch.Of("type1-2", "type1-2_instance1")); journal.Write("name456", 2, EntryBatch.Of("type2-1", "type2-1_instance1")); EntryStreamReader streamReader = journal.StreamReader(); EntryStream eventStream123 = streamReader.StreamFor("name123"); Assert.AreEqual(3, eventStream123.StreamVersion); Assert.AreEqual(3, eventStream123.Stream.Count); Assert.AreEqual(new EntryValue("name123", 1, "type1", "type1_instance1", ""), eventStream123.Stream[0]); Assert.AreEqual(new EntryValue("name123", 2, "type1-1", "type1-1_instance1", ""), eventStream123.Stream[1]); Assert.AreEqual(new EntryValue("name123", 3, "type1-2", "type1-2_instance1", ""), eventStream123.Stream[2]); EntryStream eventStream456 = streamReader.StreamFor("name456"); Assert.AreEqual(2, eventStream456.StreamVersion); Assert.AreEqual(2, eventStream456.Stream.Count); Assert.AreEqual(new EntryValue("name456", 1, "type2", "type2_instance1", ""), eventStream456.Stream[0]); Assert.AreEqual(new EntryValue("name456", 2, "type2-1", "type2-1_instance1", ""), eventStream456.Stream[1]); journal.Close(); }
private void DoRar_Entry_Stream(string filename) { using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename))) using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); using (EntryStream entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); string folder = Path.GetDirectoryName(reader.Entry.Key); string destdir = Path.Combine(SCRATCH_FILES_PATH, folder); if (!Directory.Exists(destdir)) { Directory.CreateDirectory(destdir); } string destinationFileName = Path.Combine(destdir, file); using (FileStream fs = File.OpenWrite(destinationFileName)) { entryStream.CopyTo(fs); } } } } } VerifyFiles(); }
public EntryStream OpenEntryStream() { if (this.wroteCurrentEntry) { throw new ArgumentException("WriteEntryTo or OpenEntryStream can only be called once."); } EntryStream entryStream = this.GetEntryStream(); this.wroteCurrentEntry = true; return(entryStream); }
public void TestSharpCompressWithEmptyStream() { var expected = new Tuple <string, byte[]>[] { new Tuple <string, byte[]>("foo.txt", new byte[0]), new Tuple <string, byte[]>("foo2.txt", new byte[10]) }; using (var memory = new MemoryStream()) { Stream stream = new TestStream(memory, read: true, write: true, seek: false); using (IWriter zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) { zipWriter.Write(expected[0].Item1, new MemoryStream(expected[0].Item2)); zipWriter.Write(expected[1].Item1, new MemoryStream(expected[1].Item2)); } stream = new MemoryStream(memory.ToArray()); File.WriteAllBytes(Path.Combine(SCRATCH_FILES_PATH, "foo.zip"), memory.ToArray()); using (IReader zipReader = ZipReader.Open(new NonDisposingStream(stream, true))) { var i = 0; while (zipReader.MoveToNextEntry()) { using (EntryStream entry = zipReader.OpenEntryStream()) { MemoryStream tempStream = new MemoryStream(); const int bufSize = 0x1000; byte[] buf = new byte[bufSize]; int bytesRead = 0; while ((bytesRead = entry.Read(buf, 0, bufSize)) > 0) { tempStream.Write(buf, 0, bytesRead); } Assert.Equal(expected[i].Item1, zipReader.Entry.Key); Assert.Equal(expected[i].Item2, tempStream.ToArray()); } i++; } } } }
private YamlNodeImpl LoadYaml(IReader reader) { YamlNodeImpl impl; using (EntryStream stream = reader.OpenEntryStream()) { using (MemoryStream stream2 = new MemoryStream()) { this.TransferTo(stream, stream2); stream2.Seek(0L, SeekOrigin.Begin); using (StreamReader reader2 = new StreamReader(stream2)) { impl = YamlService.Load(reader2); } } } return(impl); }
private void Skip() { if (!this.Entry.IsSolid) { Stream rawStream = Enumerable.First <FilePart>(this.Entry.Parts).GetRawStream(); if (rawStream != null) { long compressedSize = this.Entry.CompressedSize; for (int i = 0; i < (compressedSize / ((long)this.skipBuffer.Length)); i++) { rawStream.Read(this.skipBuffer, 0, this.skipBuffer.Length); } rawStream.Read(this.skipBuffer, 0, (int)(compressedSize % ((long)this.skipBuffer.Length))); return; } } using (EntryStream stream2 = this.OpenEntryStream()) { while (stream2.Read(this.skipBuffer, 0, this.skipBuffer.Length) > 0) { } } }
public static async Task ExtractAllAsync(IEnumerable <string> SourceItemGroup, string BaseDestPath, bool CreateFolder, ProgressChangedEventHandler ProgressHandler) { ulong TotalSize = 0; ulong CurrentPosition = 0; List <FileSystemStorageFile> TransformList = new List <FileSystemStorageFile>(); foreach (string FileItem in SourceItemGroup) { if (await FileSystemStorageItemBase.OpenAsync(FileItem).ConfigureAwait(false) is FileSystemStorageFile File) { TransformList.Add(File); TotalSize += File.SizeRaw; } else { throw new FileNotFoundException("Could not found the file or path is a directory"); } } if (TotalSize == 0) { return; } foreach (FileSystemStorageFile File in TransformList) { string DestPath = BaseDestPath; //如果解压到独立文件夹,则要额外创建目录 if (CreateFolder) { string NewFolderName = File.Name.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase) ? File.Name.Substring(0, File.Name.Length - 7) : (File.Name.EndsWith(".tar.bz2", StringComparison.OrdinalIgnoreCase) ? File.Name.Substring(0, File.Name.Length - 8) : Path.GetFileNameWithoutExtension(File.Name)); if (string.IsNullOrEmpty(NewFolderName)) { NewFolderName = Globalization.GetString("Operate_Text_CreateFolder"); } DestPath = await MakeSureCreateFolderHelperAsync(Path.Combine(BaseDestPath, NewFolderName)); } if (File.Name.EndsWith(".gz", StringComparison.OrdinalIgnoreCase) && !File.Name.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase)) { await ExtractGZipAsync(File, DestPath, (s, e) => { ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * File.SizeRaw)) * 100d / TotalSize), null)); }); CurrentPosition += Convert.ToUInt64(File.SizeRaw); ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32(CurrentPosition * 100d / TotalSize), null)); } else if (File.Name.EndsWith(".bz2", StringComparison.OrdinalIgnoreCase) && !File.Name.EndsWith(".tar.bz2", StringComparison.OrdinalIgnoreCase)) { await ExtractBZip2Async(File, DestPath, (s, e) => { ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * File.SizeRaw)) * 100d / TotalSize), null)); }); CurrentPosition += Convert.ToUInt64(File.SizeRaw); ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32(CurrentPosition * 100d / TotalSize), null)); } else { ReaderOptions ReadOptions = new ReaderOptions(); ReadOptions.ArchiveEncoding.Default = EncodingSetting; using (FileStream InputStream = await File.GetFileStreamFromFileAsync(AccessMode.Read)) using (IReader Reader = ReaderFactory.Open(InputStream, ReadOptions)) { Dictionary <string, string> DirectoryMap = new Dictionary <string, string>(); while (Reader.MoveToNextEntry()) { if (Reader.Entry.IsDirectory) { string DirectoryPath = Path.Combine(DestPath, Reader.Entry.Key.Replace("/", @"\").TrimEnd('\\')); string NewDirectoryPath = await MakeSureCreateFolderHelperAsync(DirectoryPath); if (!DirectoryPath.Equals(NewDirectoryPath, StringComparison.OrdinalIgnoreCase)) { DirectoryMap.Add(DirectoryPath, NewDirectoryPath); } } else { string[] PathList = (Reader.Entry.Key?.Replace("/", @"\")?.Split(@"\")) ?? Array.Empty <string>(); string LastFolder = DestPath; for (int i = 0; i < PathList.Length - 1; i++) { LastFolder = Path.Combine(LastFolder, PathList[i]); if (DirectoryMap.ContainsKey(LastFolder)) { LastFolder = DirectoryMap[LastFolder]; } string NewDirectoryPath = await MakeSureCreateFolderHelperAsync(LastFolder); if (!LastFolder.Equals(NewDirectoryPath, StringComparison.OrdinalIgnoreCase)) { DirectoryMap.Add(LastFolder, NewDirectoryPath); LastFolder = NewDirectoryPath; } } string DestFileName = Path.Combine(LastFolder, PathList.LastOrDefault() ?? Path.GetFileNameWithoutExtension(File.Name)); if (await FileSystemStorageItemBase.CreateAsync(DestFileName, StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile) { using (FileStream OutputStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write)) using (EntryStream EntryStream = Reader.OpenEntryStream()) { await EntryStream.CopyToAsync(OutputStream, Reader.Entry.Size, (s, e) => { ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * Reader.Entry.CompressedSize)) * 100d / TotalSize), null)); }); CurrentPosition += Convert.ToUInt64(Reader.Entry.CompressedSize); ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32(CurrentPosition * 100d / TotalSize), null)); } } } } } } } }
public static IEnumerable <(EncodedTrainingPosition[], int)> EnumerateRawPos(string trainingTARFileName, Predicate <string> processFilePredicate = null, ReaderOptions options = ReaderOptions.None, int maxGames = int.MaxValue, int maxPositions = int.MaxValue) { if (!trainingTARFileName.ToUpper().EndsWith("TAR")) { throw new Exception("expected TAR"); } byte[] buffer = new byte[10 * 1000 * 1000]; const int MAX_POS_PER_GAME = 2000; EncodedTrainingPosition[] rawPosBuffer = new EncodedTrainingPosition[MAX_POS_PER_GAME]; int numGamesProcessed = 0; int numPositionsProcessed = 0; using (Stream stream = System.IO.File.OpenRead(trainingTARFileName)) { IReader reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (numPositionsProcessed >= maxPositions) { yield break; } if (!reader.Entry.IsDirectory) { // Skip if this file does not match our filter if (processFilePredicate != null && !processFilePredicate(reader.Entry.Key.ToUpper())) { continue; } using (EntryStream es = reader.OpenEntryStream()) { numGamesProcessed++; //if (numGamesProcessed % 1000 == 0) Console.WriteLine(" games read " + numGamesProcessed + " " + (bytesWritten / 1_000_000_000.0) + " GB"); // Process all GZIP files within using (GZipStream decompressionStream = new GZipStream(es, CompressionMode.Decompress)) { if (numGamesProcessed >= maxGames) { yield break; } // Uncompressed read const bool MIRROR_PLANES = true; // The board convention differs between this file storage format and what is sent to the neural network input int numRead = ReadFromStream(decompressionStream, buffer, ref rawPosBuffer, MIRROR_PLANES); if (options.HasFlag(ReaderOptions.FillInMoveNum)) { for (int moveNum = 0; moveNum < numRead; moveNum++) { // TO DO: Find a more elegant way of setting value; this reflection does not work due to copies being made // FieldInfo fieldMoveCount = typeof(LZPositionMiscInfo).GetField("MoveCount"); //fieldMoveCount.SetValue(rawPosBuffer[moveNum].MiscInfo, moveCountValue); // We start counting at 1, and truncate at 255 due to size being byte // WARNING: this potential truncation causes these values to be not always correct byte moveCountValue = moveNum >= 254 ? (byte)255 : (byte)(moveNum + 1); SetMoveNum(rawPosBuffer, moveNum, moveCountValue); } } numPositionsProcessed += numRead; yield return(rawPosBuffer, numRead); } } } } } }
private void Bworker_DoWork(object sender, DoWorkEventArgs e) { this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = "Preparing"; }), null); Operation operation = this.Operation; string tmpFolder, path_original, path_output, path_info; int counting = 0; if (operation == Operation.Patch) { tmpFolder = this.TemporaryFolder; path_original = Path.GetFullPath(this.OriginalXML); path_output = Path.GetFullPath(this.OutputXML); path_info = Path.GetFullPath(this.DirectoryOfPatchcingInfo); if (!Directory.Exists(path_info)) { throw new DirectoryNotFoundException(); } if (!File.Exists(path_original)) { throw new FileNotFoundException("The original xml file is not existed."); } if (path_original.IsEqual(path_output, true)) { throw new InvalidDataException("You can't specify output as same as original xml file."); } string tmpString; IniFile currentIni; Dictionary <string, string> nodes; Dictionary <string, Dictionary <string, string> > patchingList = new Dictionary <string, Dictionary <string, string> >(StringComparer.OrdinalIgnoreCase); foreach (string iniPath in Directory.EnumerateFiles(path_info, "*.xmlpatch", SearchOption.AllDirectories)) { tmpString = PathHelper.PathTrim(iniPath.Substring(path_info.Length + 1)); currentIni = new IniFile(iniPath); nodes = new Dictionary <string, string>(); foreach (string section in currentIni.Sections) { nodes.Add(section, currentIni.GetValue(section, "Replace", string.Empty)); } if (nodes.Count > 0) { patchingList.Add(Path.ChangeExtension(tmpString, ".xml"), nodes); } currentIni.Close(); } if (patchingList.Count > 0) { using (BnSDatArchive archive = BnSDatArchive.Read(path_original)) using (BnSDatWriter outputArchive = string.IsNullOrWhiteSpace(tmpFolder) ? BnSDatWriter.Create(path_output) : BnSDatWriter.Create(path_output, tmpFolder)) using (IReader reader = archive.ExtractAllEntries()) { this.sync.Post(new SendOrPostCallback(delegate { progressBar1.Maximum = archive.EntryCount; }), null); while (reader.MoveToNextEntry()) { if (this.bworker.CancellationPending) { this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = "Cancelling"; }), null); e.Cancel = true; break; } this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = $"Progressing: {reader.Entry.FilePath}"; }), null); if (patchingList.ContainsKey(reader.Entry.FilePath)) { using (EntryStream entryStream = reader.GetEntryStream()) using (StreamReader sr = new StreamReader(entryStream)) { tmpString = sr.ReadToEnd(); foreach (var keypair in patchingList[reader.Entry.FilePath]) { tmpString = tmpString.Replace(keypair.Key, keypair.Value); } outputArchive.CompressString(reader.Entry.FilePath, tmpString, sr.CurrentEncoding); } tmpString = null; } else { // Just copy the file reader.CopyEntryTo(outputArchive); } counting++; this.sync.Post(new SendOrPostCallback(delegate { progressBar1.Value = counting; }), null); } if (!this.bworker.CancellationPending) { outputArchive.WriteArchive(); } } } else { throw new Exception("There is nothing to patch."); } } else if (operation == Operation.Extract) { path_original = Path.GetFullPath(this.OriginalXML); path_output = Path.GetFullPath(this.OutputXML); using (BnSDatArchive archive = BnSDatArchive.Read(path_original)) using (IReader reader = archive.ExtractAllEntries()) { string filepath; this.sync.Post(new SendOrPostCallback(delegate { progressBar1.Maximum = archive.EntryCount; }), null); while (reader.MoveToNextEntry()) { this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = $"Extracting: {reader.Entry.FilePath}"; }), null); if (this.bworker.CancellationPending) { this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = "Cancelling"; }), null); e.Cancel = true; break; } filepath = Path.Combine(path_output, reader.Entry.FilePath); Microsoft.VisualBasic.FileIO.FileSystem.CreateDirectory(Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(filepath)); using (FileStream fs = File.Create(filepath)) reader.ExtractTo(fs); counting++; this.sync.Post(new SendOrPostCallback(delegate { progressBar1.Value = counting; }), null); } } } else if (operation == Operation.Compress) { tmpFolder = this.TemporaryFolder; path_original = Path.GetFullPath(this.OriginalXML); path_info = Path.GetFullPath(this.DirectoryOfPatchcingInfo); if (!Directory.Exists(path_info)) { throw new DirectoryNotFoundException(); } string[] filelist = Directory.GetFiles(path_info, "*", SearchOption.AllDirectories); if (filelist.Length == 0) { throw new Exception("There is nothing to compress."); } using (BnSDatWriter writer = string.IsNullOrWhiteSpace(tmpFolder) ? BnSDatWriter.Create(path_original) : BnSDatWriter.Create(path_original, tmpFolder)) { string filepath; this.sync.Post(new SendOrPostCallback(delegate { progressBar1.Maximum = filelist.Length; }), null); for (int i = 0; i < filelist.Length; i++) { filepath = filelist[i].Remove(0, path_info.Length + 1); this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = $"Compressing: {filepath}"; progressBar1.Value = i + 1; }), null); if (this.bworker.CancellationPending) { e.Cancel = true; break; } writer.CompressFile(filepath, filelist[i]); } this.sync.Post(new SendOrPostCallback(delegate { this.label1.Text = "Finalizing archive..."; }), null); writer.WriteArchive(); } } else { throw new InvalidEnumArgumentException(); } }
private void button3_Click(object sender, EventArgs e) { listBox1.Items.Clear(); if (!editMode) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Multiselect = true; openFileDialog.InitialDirectory = Form1.data.openDirectory; openFileDialog.Filter = "Mod files (*.zip,*.package;*.t4script;*.rar;)|*.zip;*.package;*.t4script;*.rar|Whatever (testing) (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file comboBox1.SelectedIndex = comboBox1.Items.Count - 1; mod = new Mod(Path.GetFileName(openFileDialog.FileNames[0])); mod.category = new Category(comboBox1.Items[comboBox1.SelectedIndex].ToString()); this.textBox1.Text = Path.GetFileName(openFileDialog.FileNames[0]).Replace(Path.GetExtension(openFileDialog.FileNames[0]), ""); this.Text = Path.GetFileName(openFileDialog.FileNames[0]) + " (" + Path.GetExtension(openFileDialog.FileNames[0]) + ")"; Busy = true; button2.Enabled = false; foreach (string filePath in openFileDialog.FileNames) { // string filePath = openFileDialog.FileName; string fileName = Path.GetFileName(filePath); string extention = Path.GetExtension(filePath); string folderpath = Path.GetDirectoryName(filePath); Form1.data.openDirectory = folderpath; if (extention == ".zip" || extention == ".7z") { progressBar1.Visible = true; //read files in zip an process them using (ZipArchive archive = ZipFile.Open(filePath, ZipArchiveMode.Read)) { progressBar1.Maximum = archive.Entries.Count; foreach (ZipArchiveEntry item in archive.Entries) { if (!String.IsNullOrEmpty(item.Name))//check if not folder { string itemName = item.FullName; if (itemName.Contains('/')) { itemName = itemName.Split('/')[1]; } string ext = Path.GetExtension(itemName); if (ForbinnenExtentions.Contains(ext)) { continue; } item.ExtractToFile(extractPath + itemName, true); listBox1.Items.Add(item); mod.files.Add(extractPath + itemName); progressBar1.Value = archive.Entries.IndexOf(item); } } } progressBar1.Visible = false; } else if (extention == ".rar") { int fileAmount = 0; // SharpCompress.Readers.Rar; using (RarReader reader = RarReader.Open(File.OpenRead(filePath))) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { fileAmount++; } } } progressBar1.Maximum = fileAmount; using (RarReader reader = RarReader.Open(File.OpenRead(filePath))) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { using (EntryStream entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); if (null != file) { string destinationFileName = extractPath + file; using (FileStream fs = File.OpenWrite(destinationFileName)) { string ext = Path.GetExtension(file); if (ForbinnenExtentions.Contains(ext)) { continue; } func.TransferTo(reader, entryStream, fs); listBox1.Items.Add(file); mod.files.Add(extractPath + file); // progressBar1.Value++; } } } } } } } else { mod.files.Add(filePath); listBox1.Items.Add(Path.GetFileName(filePath)); } } button2.Enabled = true; Busy = false; } } } }
public Mod HandleModFiles(string modpath) { comboBox1.SelectedIndex = comboBox1.Items.Count - 1; mod = new Mod(Path.GetFileName(modpath)); mod.category = new Category(comboBox1.Items[comboBox1.SelectedIndex].ToString()); this.textBox1.Text = Path.GetFileName(modpath).Replace(Path.GetExtension(modpath), ""); this.Text = Path.GetFileName(modpath) + " (" + Path.GetExtension(modpath) + ")"; Busy = true; button2.Enabled = false; // string filePath = openFileDialog.FileName; string fileName = Path.GetFileName(modpath); string extention = Path.GetExtension(modpath); string folderpath = Path.GetDirectoryName(modpath); Form1.data.openDirectory = folderpath; if (extention == ".zip" || extention == ".7z") { progressBar1.Visible = true; //read files in zip an process them using (ZipArchive archive = ZipFile.Open(modpath, ZipArchiveMode.Read)) { progressBar1.Maximum = archive.Entries.Count; foreach (ZipArchiveEntry item in archive.Entries) { if (!String.IsNullOrEmpty(item.Name))//check if not folder { string itemName = item.FullName; if (itemName.Contains('/')) { itemName = itemName.Split('/')[1]; } string ext = Path.GetExtension(itemName); if (ForbinnenExtentions.Contains(ext)) { continue; } item.ExtractToFile(extractPath + "\\" + itemName, true); listBox1.Items.Add(item); mod.files.Add(extractPath + "\\" + itemName); progressBar1.Value = archive.Entries.IndexOf(item); } } } progressBar1.Visible = false; } else if (extention == ".rar") { int fileAmount = 0; // SharpCompress.Readers.Rar; using (RarReader reader = RarReader.Open(File.OpenRead(modpath))) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { fileAmount++; } } } progressBar1.Maximum = fileAmount; using (RarReader reader = RarReader.Open(File.OpenRead(modpath))) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { using (EntryStream entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); if (null != file) { string destinationFileName = Path.Combine(extractPath + "\\", file); using (FileStream fs = File.OpenWrite(destinationFileName)) { string ext = Path.GetExtension(file); if (ForbinnenExtentions.Contains(ext)) { continue; } func.TransferTo(reader, entryStream, fs); listBox1.Items.Add(file); mod.files.Add(extractPath + "\\" + file); // progressBar1.Value++; } } } } } } } else { mod.files.Add(modpath); listBox1.Items.Add(Path.GetFileName(modpath)); } button2.Enabled = true; Busy = false; return(mod); }
public PersonES PersonOfId(string id) { EntryStream stream = reader.StreamFor(id); return(new PersonES(ToSourceStream <DomainEvent>(stream.Stream), stream.StreamVersion)); }