private void _menuItemOpenFrom_Click(object sender, RoutedEventArgs e) { try { string file = PathRequest.OpenFileMapcache("filter", "Dat Files (*.dat)|*.dat"); if (file != null) { if (File.Exists(file)) { _load(file); _recentFilesManager.AddRecentFile(file); } } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _menuItemMerge_Click(object sender, RoutedEventArgs e) { try { if (!_validateState()) { return; } string file = PathRequest.OpenFileMapcache("filter", "Grf and Dat Files (*.grf, *.dat)|*.grf;*.dat"); if (file != null) { if (file.IsExtension(".grf")) { _asyncOperation.SetAndRunOperation(new GrfThread(delegate { AProgress.Init(_cache); try { _cache.Commands.Begin(); List <FileEntry> files = new List <FileEntry>(); int count = 0; using (GrfHolder grf = new GrfHolder(file, GrfLoadOptions.Normal)) { files.AddRange(grf.FileTable.EntriesInDirectory("data\\", SearchOption.TopDirectoryOnly).Where(entry => entry.RelativePath.IsExtension(".gat"))); foreach (var entry in files) { count++; AProgress.IsCancelling(_cache); FileEntry rswEntry = grf.FileTable.TryGet(entry.RelativePath.ReplaceExtension(".rsw")); if (rswEntry == null) { continue; } _cache.Progress = (float)count / files.Count * 100f; _cache.Commands.AddMap(Path.GetFileNameWithoutExtension(entry.DisplayRelativePath), entry.GetDecompressedData(), rswEntry.GetDecompressedData()); } } } catch (OperationCanceledException) { _cache.IsCancelled = true; _cache.Commands.CancelEdit(); } catch (Exception err) { _cache.Commands.CancelEdit(); ErrorHandler.HandleException(err); } finally { _cache.Commands.End(); AProgress.Finalize(_cache); } }, _cache, 200)); } else if (file.IsExtension(".dat")) { Mapcache cache = new Mapcache(file); try { _cache.Commands.Begin(); foreach (var map in cache.Maps) { _cache.Commands.AddMapRaw(map.MapName, map); } } catch { _cache.Commands.CancelEdit(); throw; } finally { _cache.Commands.End(); } } else { throw new Exception("Unreognized file format."); } } } catch (Exception err) { ErrorHandler.HandleException(err); } }