// Map Operations public void OpenMap(string path = null) { if (path == null) { // show a file dialog string[] paths = StandaloneFileBrowser.OpenFilePanel("Open Map", "", OpenMapExtensions, false); // make sure a file was selected if (paths.Length > 0) { path = paths[0]; mapStopwatch.Start(); Map mapToLoad = MapParser.Parse(paths[0]); // load the selected file mapStopwatch.Stop(); UnityEngine.Debug.Log($"Parsed {mapToLoad.Bricks.Count} bricks in " + mapStopwatch.ElapsedMilliseconds + " ms"); LoadMap(mapToLoad); } } else { mapStopwatch.Start(); Map mapToLoad = MapParser.Parse(path); // load the selected file mapStopwatch.Stop(); UnityEngine.Debug.Log($"Parsed {mapToLoad.Bricks.Count} bricks in " + mapStopwatch.ElapsedMilliseconds + " ms"); LoadMap(mapToLoad); } FileHistoryManager.AddToRecents(path); }
public void SaveMap(string path = null, bool bbData = true) { if (!MapIsLoaded) { return; } if (path == null) { // show a file dialog string savePath = StandaloneFileBrowser.SaveFilePanel("Save Map", "", LoadedMap.Name, SaveMapExtensions); // make sure a file was selected if (savePath != "") { path = savePath; mapStopwatch.Start(); string extension = Path.GetExtension(savePath); Map.MapVersion mv = Map.MapVersion.BrickBuilder; if (extension == ".brk") { mv = Map.MapVersion.v2; } MapExporter.Export(LoadedMap, savePath, mv, bbData); mapStopwatch.Stop(); UnityEngine.Debug.Log($"Saved {LoadedMap.Bricks.Count} bricks in " + mapStopwatch.ElapsedMilliseconds + " ms"); } } else { mapStopwatch.Start(); string extension = Path.GetExtension(path); Map.MapVersion mv = Map.MapVersion.BrickBuilder; if (extension == ".brk") { mv = Map.MapVersion.v2; } MapExporter.Export(LoadedMap, path, mv, bbData); mapStopwatch.Stop(); UnityEngine.Debug.Log($"Saved {LoadedMap.Bricks.Count} bricks in " + mapStopwatch.ElapsedMilliseconds + " ms"); } FileHistoryManager.AddToRecents(path); }
/// <summary> /// Start file processing /// </summary> /// <param name="filename">File name</param> /// <param name="appShutdown">Is mandatory application shutdown call required</param> public bool OpenFile(string filename, bool appShutdown = true) { try { if (Directory.Exists(filename)) { MessageBox.Show("Can't analyse directory!"); return(false); } isApplicationShutdownRequired = appShutdown; manager = new FileHistoryManager(filename); Title = APP_TITLE + ": " + manager.filePath; statusTbPausePlay.Source = new BitmapImage(new Uri("pack://application:,,,/GitArchaeology;component/Resources/Stop_16x.png")); View = new ViewData(); isFirstRendering = true; tiCodeCompare.Header = manager.filePath.Split('\\').Last(); var typeConverter = new HighlightingDefinitionTypeConverter(); var syntaxHighlighter = (IHighlightingDefinition)typeConverter.ConvertFrom(GetSyntax(filename)); tbCodeA.SyntaxHighlighting = syntaxHighlighter; tbCodeB.SyntaxHighlighting = syntaxHighlighter; manager.OnSnapshotsHistoryUpdated = (snapshots) => { this.Dispatcher.BeginInvoke(new Action(() => { if (!snapshots.Any()) { return; // TODO: < 2 } var addedSnaphots = View.Snapshots == null ? 0 : snapshots.Count - View.Snapshots.Count; View.Snapshots = snapshots; slHistoy.Maximum = View.Snapshots.Count; if (isFirstRendering) { isFirstRendering = false; slHistoy.Value = View.Snapshots.Count; tbCodeA.Text = View.Snapshot.File; SetupBackgroundRenderers(); lblCommitDetailsSection.Visibility = Visibility.Visible; } else { slHistoy.Value += addedSnaphots; } Canvas1.Children.Clear(); var crt = new CanvasTreeRenderer(View, Canvas1); crt.BuildTree(); crt.Draw(); treeRenderer = crt; })); }; if (scanningThread != null && scanningThread.IsAlive) { scanningThread.Abort(); } scanningThread = new Thread(() => { while (!View.SeekStatus.IsSeekCompleted) { manager.GetCommitsHistory(View.SeekStatus); View.SeekStatus.ItemsPerPage *= 2; this.Dispatcher.BeginInvoke(new Action(() => { statusProgressBar.Value = View.SeekStatus.ItemsProcessed * 100.0 / View.SeekStatus.ItemsTotal; statusTbProgressBar.Text = View.SeekStatus.ItemsProcessed + "/" + View.SeekStatus.ItemsTotal; })); } this.Dispatcher.BeginInvoke(new Action(() => { statusTbProgressBar.Text = "Done"; })); }); scanningThread.Start(); // TODO: Mediator patern???? // TODO: View should exist without snapshots View.OnViewIndexChanged = async(index, csnapshot, psnapshot) => { await this.Dispatcher.BeginInvoke(new Action(() => { tbCodeA.Text = csnapshot.File; tbCodeB.Text = psnapshot?.File; slHistoy.Value = slHistoy.Maximum - index; UpdateCommitDetails(csnapshot); // Initialize parents DropDown cbParentBranchesB.Items.Clear(); foreach (var p in csnapshot.Parents) { var item = new ComboBoxItem(); var text = new TextBlock(); var snapshot = View.ShaDictionary[p]; text.Text = "● " + snapshot.DescriptionShort; var textEffect = new TextEffect(); textEffect.PositionStart = 0; textEffect.PositionCount = 1; textEffect.Foreground = ColorPalette.GetBaseBrush(snapshot.TreeOffset); text.TextEffects.Add(textEffect); text.TextEffects.Add(textEffect); item.Content = text; item.Tag = TAG_PREFIX + snapshot.Sha; item.IsSelected = psnapshot.Sha == p; cbParentBranchesB.Items.Add(item); } })); await CompareCommitsTree(); }; View.OnSelectionChanged = () => { this.Dispatcher.BeginInvoke(new Action(() => { treeRenderer.ClearHighlighting(); treeRenderer.Draw(); tbCodeA.Text = View.Snapshot.File; tbCodeB.Text = View.SnapshotParent?.File; // TODO: BitmapImage cache BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.UriSource = new Uri(View.Snapshot.AvatarUrl + "&s=" + 40, UriKind.RelativeOrAbsolute); bmpImage.EndInit(); imgAuthor.Source = bmpImage; tbCodeA.TextArea.TextView.Redraw(); tbCodeB.TextArea.TextView.Redraw(); cbParentBranchesB.SelectedValue = TAG_PREFIX + View.SnapshotParent?.Sha; })); }; // TODO: Implement Search by commits // TODO: Highlight code on hover } catch (OutOfMemoryException ex) { // TODO: "Try to change end date." - add abilty to choose end dates or commits count. MessageBox.Show("File history too large."); } catch (Exception ex) { File.AppendAllText(string.Format("ERROR_{0}_.txt", DateTime.Now.ToString()), ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine); MessageBox.Show("Oops! Something went wrong."); } return(true); }