// Renamer.rename() searches through DirectoryTree.Tree, renaming and rebuilding files // to reflect a change in the NameRegistry. public static void rename(UInt32[] hashes, string[] oldNames, PleaseWait progress) { // TODO: do something with progress bar var nameBytes = from n in oldNames select Encoding.UTF8.GetBytes(n.ToLowerInvariant()); DirectoryTree.Tree.Search( SearchSpec.all ); var renamer = new Renamer { oldNames = nameBytes.ToArray(), hashes = hashes, leftPath = MainWindow.Instance.LeftPath + "\\", rightPath = MainWindow.Instance.RightPath + "\\" }; renamer.renameTree( DirectoryTree.Tree ); DirectoryTree.Tree.Search(SearchSpec.all); if (renamer.errors.Count != 0) { string s = "There were errors updating the following files:\n"; foreach (var e in renamer.errors) s += " " + e + "\n"; MessageBox.Show(s, "Warning"); } }
public DirectoryTreeWatcher(DirectoryTree target, int side, string path, System.Windows.Threading.Dispatcher disp, ChangeHandler Change, HashSet<string> fullTextExtensions, PleaseWait initProgress) { this.target = target; this.side = side; this.path = path; this.Change += Change; this.disp = disp; this.fullTextExtensions = fullTextExtensions; init(initProgress); }
public PackagePack(Stream output, string sourceFolder, PleaseWait progress) { NameRegistry.Files.UsedHashes = new List<UInt32>(); var group_dirs = Directory.GetDirectories(sourceFolder); var file_query = from d in group_dirs where d != sourceFolder + "\\sporemaster\\" from f in Directory.GetFileSystemEntries(d) where !f.EndsWith(".search_index") // < these might appear in group directories if there are indexable files in subdirectories select f; var files = file_query.ToList(); files.Add(sourceFolder + "\\sporemaster\\names.txt"); if (progress != null) progress.beginTask(1.0, files.Count); DatabasePackedFile dbf = new DatabasePackedFile(); dbf.Version = new Version(2, 0); dbf.WriteHeader(output, 0, 0); var rw4_hash = NameRegistry.Types.toHash("rw4"); uint size, start = (uint)output.Position; foreach( var f in files ) { string relativePath = f.Substring(sourceFolder.Length + 1); bool additionalOutputFiles; byte[] autoLocale = null; do { additionalOutputFiles = false; var parts = relativePath.Split(new char[] { '\\' }); if (parts.Length != 2) continue; var group = parts[0]; parts = parts[1].Split(new char[] { '.' }, 2); var instance = parts[0]; var extension = parts[1]; var index = new DatabaseIndex(); index.GroupId = NameRegistry.Groups.toHash(group); index.InstanceId = NameRegistry.Files.toHash(instance); try { if (relativePath == "sporemaster\\names.txt") { writeNamesFile(output); } else if (autoLocale != null) { output.Write(autoLocale, 0, autoLocale.Length); } else if (extension == "prop.xml") { extension = "prop"; writePropFile(group, instance, f, output, out autoLocale); if (autoLocale.Length != 0) { additionalOutputFiles = true; relativePath = "locale~\\auto_" + group + "_" + instance + ".locale"; } } else if (NameRegistry.Types.toHash(extension)==rw4_hash && Directory.Exists(f)) { writeRW4File(f, output); } else writeBinaryFile(f, output); } catch (Exception e) { throw new Exception("Error packing file '" + relativePath + "'.", e); } size = (uint)output.Position - start; index.TypeId = NameRegistry.Types.toHash(extension); index.Compressed = false; index.Flags = 1; index.DecompressedSize = size; index.CompressedSize = size | 0x80000000; index.Offset = start; dbf.Indices.Add(index); start += size; } while (additionalOutputFiles); progress.addProgress(1.0); } dbf.WriteIndex(output); size = (uint)output.Position - start; output.Seek(0, SeekOrigin.Begin); dbf.WriteHeader(output, (int)start, (int)size); output.Close(); if (progress != null) progress.endTask(); }
private void init(PleaseWait progress) { fswatch = new FileSystemWatcher(path); fswatch.Changed += thr_onFileChanged; fswatch.Deleted += thr_onFileChanged; fswatch.Renamed += thr_onFileRenamed; fswatch.Created += thr_onFileChanged; fswatch.IncludeSubdirectories = true; if (progress != null) progress.beginTask(0.25, 1.0); // Process files in random order, to make the progress bar more useful // Getting file sizes is very slow in .NET :-( var r = new Random(); var files = (from f in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories) orderby r.Next() select f).ToArray(); if (progress != null) progress.endTask(); if (progress != null) progress.beginTask(0.75, files.Length); for(int i=0; i<files.Length; i++) { updateFile(files[i].Substring(path.Length + 1), +1); if (progress != null) progress.addProgress(1); } if (Change != null) thr_Change(); fswatch.EnableRaisingEvents = true; if (progress != null) progress.endTask(); }
public void SetPath(int side, string value, PleaseWait progress) { if (_Path[side] == value) return; _Path[side] = value; if (watcher[side] != null) watcher[side].Dispose(); if (_Path[side] != null && Directory.Exists(_Path[side])) watcher[side] = new DirectoryTreeWatcher(files, side, _Path[side], Dispatcher, update, fullTextExtensions, progress); }
public PackageUnpack(Stream[] packageFiles, string destinationFolder, PleaseWait progress) { double e = 0.0; FullTextIndex.ResetPath(destinationFolder); if (Directory.Exists(destinationFolder)) { if (progress != null) progress.beginTask(e = 0.25, 1.0); Directory.Delete(destinationFolder, true); if (progress != null) progress.endTask(); } Directory.CreateDirectory(destinationFolder); double totalSize = 0; for (int i = 0; i < packageFiles.Length; i++) { totalSize += packageFiles[i].Length; } if (progress != null) progress.beginTask(1.0 - e, totalSize); foreach (var filestream in packageFiles) { DatabasePackedFile db = new DatabasePackedFile(); db.Read(filestream); var DatabaseFiles = db.Indices.ToArray(); var group_sporemaster = "sporemaster".FNV(); var instance_names = "names".FNV(); foreach (var dbf in DatabaseFiles) { if (dbf.GroupId == group_sporemaster && dbf.InstanceId == instance_names) { byte[] data = unpack(filestream, dbf); readNamesFile(data); } } var locale_type = NameRegistry.Types.toHash("locale"); var prop_type = NameRegistry.Types.toHash("prop"); var rw4_type = NameRegistry.Types.toHash("rw4"); foreach (var dbf in DatabaseFiles) { // skip over automatically generated locale files if (!(dbf.TypeId == locale_type && ( NameRegistry.Groups.toName(dbf.InstanceId).StartsWith("auto_") || NameRegistry.Groups.toName(dbf.InstanceId).EndsWith("_auto")))) { var fn = Path.Combine(destinationFolder, NameRegistry.getFileName(dbf.GroupId, dbf.InstanceId, dbf.TypeId)); Directory.CreateDirectory(Path.GetDirectoryName(fn)); byte[] data = unpack(filestream, dbf); if (dbf.TypeId == prop_type) writePropFile(data, fn); else if (dbf.TypeId == rw4_type) writeRW4File(data, fn); else writeBinaryFile(data, fn); } if (progress != null) progress.addProgress(dbf.CompressedSize); } filestream.Close(); } if (progress != null) progress.endTask(); }
private void btnUpdatePassword_Click(object sender, RoutedEventArgs e) { checkPassword(); if (newPass1.Password != newPass2.Password) { newPass1.BorderBrush = red; newPass2.BorderBrush = red; MessageBox.Show("Passwords do not match.", "", MessageBoxButton.OK, MessageBoxImage.Error); } else { newPass1.BorderBrush = norm; newPass2.BorderBrush = norm; btnUpdatePassword.Content = "Update password"; // Update the password manifest.CredentialLocker = (bool)chkCredentialLocker.IsChecked; manifest.Save(); string newPassKey = newPass1.Password; if (newPassKey.Length == 0) { newPassKey = null; } string action = newPassKey == null ? "remove" : "change"; string action1 = newPassKey == null ? "Removing" : "Changing"; PleaseWait wait = new PleaseWait(action1 + " password, please wait . . ."); wait.Show(this); wait.Owner = this; new System.Threading.Thread(() => { System.Threading.Thread.CurrentThread.IsBackground = true; try { if (!manifest.ChangeEncryptionKey(pass.Password, newPassKey)) { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = "Unable to " + action + " passkey."; wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } else { Dispatcher.BeginInvoke((Action) delegate() { wait.Hide(); }); } } catch { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = "Unable to " + action + " passkey."; wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } }).Start(); pass.Password = newPassKey; newPass1.Password = newPass2.Password = ""; checkPassword(); } }