private void OnButtonAddClick(object sender, RoutedEventArgs e) { if (MessageBox.Show( "This will import all files to the smallest bundle of all loaded bundles (doesn't contain which were filtered)." + Environment.NewLine + "All files to be imported must be defined by the _.index.bin." + Environment.NewLine + "Are you sure you want to do this?", "Import Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK) { var fbd = new OpenFolderDialog(); if (fbd.ShowDialog() == true) { var fileNames = Directory.GetFiles(fbd.DirectoryPath, "*", SearchOption.AllDirectories); int l = loadedBundles[0].UncompressedSize; BundleRecord bundleToSave = loadedBundles[0]; RunBackground(() => { Dispatcher.Invoke(() => { CurrentBackground.Message.Text = "Checking files . . ."; }); foreach (var f in fileNames) { var path = f.Remove(0, fbd.DirectoryPath.Length + 1).Replace("\\", "/"); if (!paths.Contains(path)) { MessageBox.Show("The index didn't define the file:" + Environment.NewLine + path, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } foreach (var b in loadedBundles) { if (b.UncompressedSize < l) { l = b.UncompressedSize; bundleToSave = b; } } string str = "Imported {0}/" + fileNames.Length.ToString() + " Files"; int count = 0; foreach (var f in fileNames) { var path = f.Remove(0, fbd.DirectoryPath.Length + 1).Replace("\\", "/"); var fr = ic.FindFiles[IndexContainer.FNV1a64Hash(path)]; fr.Write(File.ReadAllBytes(f)); fr.Move(bundleToSave); ++count; Dispatcher.Invoke(() => { CurrentBackground.Message.Text = string.Format(str, count); }); } if (count > 0) { changed.Add(bundleToSave); } }); ButtonSave.IsEnabled = true; MessageBox.Show("Imported " + fileNames.Length.ToString() + " files into " + bundleToSave.Name, "Done"); } } }
/// <summary> /// Replace the file content with a new content, /// and return the bundle which have to be saved. /// </summary> /// <returns>Size of imported bytes</returns> public virtual int BatchReplaceContent(byte[] NewContent, BundleRecord BundleToSave) { BundleFileRecord.Write(NewContent); LastFileToUpdate = this; if (BundleFileRecord.bundleRecord != BundleToSave) { BundleFileRecord.Move(BundleToSave); } return(NewContent.Length); }
private void MoveD(BundleRecord br) { if (MessageBox.Show("Are you sure you want to move directory " + moveD.Name + " into " + br.Name + "?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { MessageBox.Show("Moved " + MoveDir(moveD.ChildItems, br).ToString() + " Files", "Done"); changed.Add(br); ButtonSave.IsEnabled = true; } moveD = null; MessageLabel.Text = ""; View1.Background = Brushes.White; }
private void MoveF(BundleRecord br) { if (MessageBox.Show("Are you sure you want to move " + ic.Hashes[moveF.Hash] + " into " + br.Name + "?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { changed.Add(moveF.bundleRecord); changed.Add(br); moveF.Move(br); MessageBox.Show("Done!", "Done"); ButtonSave.IsEnabled = true; } moveF = null; MessageLabel.Text = ""; View1.Background = Brushes.White; }
private int MoveDir(ICollection <ItemModel> fis, BundleRecord br) { int count = 0; foreach (var fi in fis) { var fr = fi.Record as FileRecord; if (fr == null) // is directory { count += MoveDir(fi.ChildItems, br); } else // is file { fr.Move(br); changed.Add(fr.bundleRecord); count++; } } return(count); }
public virtual void UpdateCache(BundleRecord br) { Hash = BundleFileRecord.NameHash; Offset = BundleFileRecord.Offset; Length = BundleFileRecord.Size; var node = CachedBundleData.First; while (node != null) { if (node.Value.Key == br) { CachedBundleData.Remove(node); break; } else { node = node.Next; } } }
private void OnDragDrop(object sender, DragEventArgs e) { if (!e.Effects.HasFlag(DragDropEffects.Copy)) { return; } if (MessageBox.Show("You are about to import the files." + Environment.NewLine + "This will import all files to the smallest bundle of all loaded bundles (doesn't contain which were filtered)." + Environment.NewLine + "The dropped paths must contain Bundles2." + Environment.NewLine + "All files to be imported must be defined by the _.index.bin." + Environment.NewLine + "Are you sure you want to do this?", "Import Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK) { var droppedFileNames = e.Data.GetData(DataFormats.FileDrop) as string[]; var checkedPaths = new Dictionary <string, string>(); int l = loadedBundles[0].UncompressedSize; BundleRecord bundleToSave = loadedBundles[0]; RunBackground(() => { Dispatcher.Invoke(() => { CurrentBackground.Message.Text = "Checking files . . ."; }); foreach (var f in droppedFileNames) { if (Directory.Exists(f)) { foreach (var p in Directory.GetFiles(f, "*", SearchOption.AllDirectories)) { var i = p.IndexOf("Bundles2"); if (i >= 0 && i + 9 < p.Length) { var path = p.Substring(i + 9).Replace("\\", "/"); if (!paths.Contains(path)) { MessageBox.Show("The index didn't define the file:" + Environment.NewLine + path, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } checkedPaths.Add(p, path); } } } else { var i = f.IndexOf("Bundles2"); if (i >= 0 && i + 9 < f.Length) { var path = f.Substring(i + 9).Replace("\\", "/"); if (!paths.Contains(path)) { MessageBox.Show("The index didn't define the file:" + Environment.NewLine + path, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } checkedPaths.Add(f, path); } } } foreach (var b in loadedBundles) { if (b.UncompressedSize < l) { l = b.UncompressedSize; bundleToSave = b; } } string str = "Imported {0}/" + checkedPaths.Count.ToString() + " Files"; int count = 0; foreach (var f in checkedPaths) { var fr = ic.FindFiles[IndexContainer.FNV1a64Hash(f.Value)]; fr.Write(File.ReadAllBytes(f.Key)); fr.Move(bundleToSave); ++count; Dispatcher.Invoke(() => { CurrentBackground.Message.Text = string.Format(str, count); }); } if (count > 0) { changed.Add(bundleToSave); } }); ButtonSave.IsEnabled = true; MessageBox.Show("Imported " + checkedPaths.Count.ToString() + " files into " + bundleToSave.Name, "Done"); } }
public IndexContainer(string path) : base(path) { var data = Read(); data.Seek(0, SeekOrigin.Begin); var br = new BinaryReader(data); int bundleCount = br.ReadInt32(); Bundles = new BundleRecord[bundleCount]; for (int i = 0; i < bundleCount; i++) { Bundles[i] = new BundleRecord(br) { bundleIndex = i } } ; int fileCount = br.ReadInt32(); Files = new FileRecord[fileCount]; for (int i = 0; i < fileCount; i++) { var f = new FileRecord(br); Files[i] = f; FindFiles[f.Hash] = f; f.bundleRecord = Bundles[f.BundleIndex]; Bundles[f.BundleIndex].Files.Add(f); } int directoryCount = br.ReadInt32(); Directorys = new DirectoryRecord[directoryCount]; for (int i = 0; i < directoryCount; i++) { var d = new DirectoryRecord(br); Directorys[i] = d; } var tmp = br.BaseStream.Position; directoryBundleData = br.ReadBytes((int)(br.BaseStream.Length - tmp)); br.BaseStream.Seek(tmp, SeekOrigin.Begin); var directoryBundle = new BundleContainer(br); var br2 = new BinaryReader(directoryBundle.Read(br)); br.Close(); Hashes = new Dictionary <ulong, string>(Files.Length); foreach (var d in Directorys) { var temp = new List <string>(); bool Base = false; br2.BaseStream.Seek(d.Offset, SeekOrigin.Begin); while (br2.BaseStream.Position - d.Offset <= d.Size - 4) { int index = br2.ReadInt32(); if (index == 0) { Base = !Base; if (Base) { temp = new List <string>(); } } else { index -= 1; var sb = new StringBuilder(); char c; while ((c = br2.ReadChar()) != 0) { sb.Append(c); } var str = sb.ToString(); if (index < temp.Count && index >= 0) { str = temp[index] + str; } if (Base) { temp.Add(str); } else { d.paths.Add(str); Hashes[FNV1a64Hash(str)] = str; } } } } br2.Close(); }
public IndexContainer(BinaryReader br) { BundleContainer = new BundleContainer(br); var data = BundleContainer.Read(br); data.Seek(0, SeekOrigin.Begin); var databr = new BinaryReader(data); var bundleCount = databr.ReadInt32(); Bundles = new BundleRecord[bundleCount]; for (int i = 0; i < bundleCount; i++) { Bundles[i] = new BundleRecord(databr) { bundleIndex = i } } ; var fileCount = databr.ReadInt32(); Files = new FileRecord[fileCount]; for (var i = 0; i < fileCount; i++) { var f = new FileRecord(databr); Files[i] = f; FindFiles[f.NameHash] = f; var b = Bundles[f.BundleIndex]; f.bundleRecord = b; b.Files.Add(f); if (f.Offset >= b.validSize) { b.validSize = f.Offset + f.Size; } } var directoryCount = databr.ReadInt32(); Directorys = new DirectoryRecord[directoryCount]; for (var i = 0; i < directoryCount; i++) { Directorys[i] = new DirectoryRecord(databr); } var tmp = databr.BaseStream.Position; directoryBundleData = databr.ReadBytes((int)(databr.BaseStream.Length - tmp)); databr.BaseStream.Seek(tmp, SeekOrigin.Begin); var directoryBundle = new BundleContainer(databr); var br2 = new BinaryReader(directoryBundle.Read(databr), Encoding.UTF8); // Array.Sort(Directorys, new Comparison<DirectoryRecord>((dr1, dr2) => { return dr1.Offset > dr2.Offset ? 1 : -1; })); foreach (var d in Directorys) { var temp = new List <string>(); var Base = false; br2.BaseStream.Seek(d.Offset, SeekOrigin.Begin); while (br2.BaseStream.Position - d.Offset <= d.Size - 4) { var index = br2.ReadInt32(); if (index == 0) { Base = !Base; if (Base) { temp.Clear(); } } else { index -= 1; var sb = new StringBuilder(); char c; while ((c = br2.ReadChar()) != 0) { sb.Append(c); } var str = sb.ToString(); if (index < temp.Count) { str = temp[index] + str; } if (Base) { temp.Add(str); } else { Paths.Add(str); var f = FindFiles[FNV1a64Hash(str)]; f.path = str; d.children.Add(f); f.parent = d; } } } } br2.Close(); }