private void RefreshAllChanges() { bool changes = false; EditorStack.Children.Clear(); GameStack.Children.Clear(); if (editorDefinition == null) { editorDefinition = AppResources.XamlToString(SampleEditor); gameDefinition = AppResources.XamlToString(SampleGame); } DockPanel getRow(DockPanel dockPanel, string fileName, string dateModified, long byteChange, RoutedEventHandler onPush) { Brush brush = Brushes.Orange; if (byteChange > 0) { brush = Brushes.Green; } else if (byteChange < 0) { brush = Brushes.Red; } (dockPanel.Children[2] as TextBlock).Text = fileName; (dockPanel.Children[3] as TextBlock).Foreground = brush; (dockPanel.Children[3] as TextBlock).Text = (byteChange > 0 ? "+" : "") + byteChange.ToString() + " bytes"; (dockPanel.Children[4] as TextBlock).Text = dateModified; (dockPanel.Children[5] as Button).Click += onPush; return(dockPanel); } DockPanel getEditorRow(string fileName, string dateModified, long byteChange, RoutedEventHandler onPush) => getRow(AppResources.CloneXaml <DockPanel>(editorDefinition), fileName, dateModified, byteChange, onPush); DockPanel getGameRow(string fileName, string dateModified, long byteChange, RoutedEventHandler onPush) => getRow(AppResources.CloneXaml <DockPanel>(gameDefinition), fileName, dateModified, byteChange, onPush); void Push(FileInfo fInfo, string destination) { fInfo.CopyTo(destination, true); Properties.Settings.Default.GameResourcesPath = GamePathBox.Text; Properties.Settings.Default.Save(); } void Revert(FileInfo fInfo, string destination) { if (MessageBox.Show("This will delete any changes currently unsaved and restore the selected file to the Game's current version. " + "This cannot be undone.", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { fInfo.CopyTo(destination, true); Properties.Settings.Default.GameResourcesPath = GamePathBox.Text; Properties.Settings.Default.Save(); } } string animDBpath1 = AnimationDatabase.RelativeAnimationDatabasePath, animDBpath2 = System.IO.Path.Combine(GamePathBox.Text, "animDB.json"); string blockDBpath1 = LevelDataBlock.BlockDatabasePath, blockDBpath2 = System.IO.Path.Combine(GamePathBox.Text, "blockdb.xml"); string assetDBpath1 = AssetDBEntry.AssetDatabasePath, assetDBpath2 = System.IO.Path.Combine(GamePathBox.Text, "texturedb.xml"); //Block DB FileInfo info1 = new FileInfo(blockDBpath1), info2 = new FileInfo(blockDBpath2); if (info1.Exists && info2.Exists) { if (info1.LastWriteTime.ToFileTime() != info2.LastWriteTime.ToFileTime()) // one is modified { changes = true; string time = info1.LastWriteTime.ToShortDateString() + " " + info1.LastWriteTime.ToShortTimeString(); EditorStack.Children.Add( getEditorRow("Block Database", time, info1.Length - info2.Length, delegate { Push(info1, blockDBpath2); RefreshAllChanges(); })); time = info2.LastWriteTime.ToShortDateString() + " " + info2.LastWriteTime.ToShortTimeString(); GameStack.Children.Add( getGameRow("Block Database", time, info2.Length - info1.Length, delegate { Revert(info2, blockDBpath1); RefreshAllChanges(); })); } } //asset DB FileInfo ainfo1 = new FileInfo(assetDBpath1), ainfo2 = new FileInfo(assetDBpath2); if (ainfo1.Exists && ainfo2.Exists) { if (ainfo1.LastWriteTime.ToFileTime() != ainfo2.LastWriteTime.ToFileTime()) // one is modified { changes = true; string time = ainfo1.LastWriteTime.ToShortDateString() + " " + ainfo1.LastWriteTime.ToShortTimeString(); EditorStack.Children.Add( getEditorRow("Asset Database", time, ainfo1.Length - ainfo2.Length, delegate { Push(ainfo1, assetDBpath2); RefreshAllChanges(); })); time = ainfo2.LastWriteTime.ToShortDateString() + " " + ainfo2.LastWriteTime.ToShortTimeString(); GameStack.Children.Add( getGameRow("Asset Database", time, ainfo2.Length - ainfo1.Length, delegate { Revert(ainfo2, assetDBpath1); RefreshAllChanges(); })); } } //animation DB info1 = new FileInfo(animDBpath1); info2 = new FileInfo(animDBpath2); if (info1.Exists && info2.Exists) { if (info1.LastWriteTime.ToFileTime() != info2.LastWriteTime.ToFileTime()) // one is modified { changes = true; string time = info1.LastWriteTime.ToShortDateString() + " " + info1.LastWriteTime.ToShortTimeString(); EditorStack.Children.Add( getEditorRow("Animation Database", time, info1.Length - info2.Length, delegate { Push(info1, animDBpath2); RefreshAllChanges(); })); time = info2.LastWriteTime.ToShortDateString() + " " + info2.LastWriteTime.ToShortTimeString(); GameStack.Children.Add( getGameRow("Animation Database", time, info2.Length - info1.Length, delegate { Revert(info2, animDBpath1); RefreshAllChanges(); })); } } PushAllChanges.IsEnabled = changes; }