Skip to content

Commit

Permalink
- added error/suggestion reporting function, accessible from the bott…
Browse files Browse the repository at this point in the history
…om left corner of the main window

- improved exception handling
  • Loading branch information
AnthonyZJiang committed May 1, 2018
1 parent 4cdef8d commit 663238d
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 82 deletions.
2 changes: 2 additions & 0 deletions D-OS Save Editor/D-OS Save Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@
<Content Include="lslib\zlib.net.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Resource Include="Resources\ic_bug_black.png" />
<Resource Include="Resources\ic_bug_red.png" />
<Resource Include="Resources\ic_refresh3_blue.png" />
<Resource Include="Resources\ic_refresh2_blue.png" />
<Resource Include="Resources\ic_refresh2_black.png" />
Expand Down
28 changes: 21 additions & 7 deletions D-OS Save Editor/ErrorReporting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:D_OS_Save_Editor"
mc:Ignorable="d"
Title="Error" SizeToContent="WidthAndHeight" UseLayoutRounding="True">
WindowStyle="ToolWindow" UseLayoutRounding="True"
Title="Error" SizeToContent="WidthAndHeight" Height="367.639" Width="514.335" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Window.Resources>
<local:SystemIconConverter x:Key="iconConverter"/>
<Style TargetType="Button">
Expand All @@ -14,12 +15,25 @@
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions><RowDefinition/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
<Grid.ColumnDefinitions><ColumnDefinition Width="Auto"/><ColumnDefinition/></Grid.ColumnDefinitions>
<Image Margin="20" Stretch="Uniform" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Converter={StaticResource iconConverter}, ConverterParameter=Error}"/>
<TextBox Grid.Column="1" Focusable="False" Margin="0,20,20,0" MaxWidth="300" MaxHeight="500" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Text="{Binding ErrorMessage}" Background="#FFE2E2E2"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right">
<Button Content="Report"/>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Margin="20,20,20,0" Stretch="Uniform" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Converter={StaticResource iconConverter}, ConverterParameter=Error}" RenderTransformOrigin="0.549,4.213"/>
<StackPanel Grid.Column="1">
<TextBlock Text="An error has occurred. If you would like to help, please click the &quot;Report&quot; button." Margin="20,20,20,0" TextWrapping="Wrap" MaxWidth="401"></TextBlock>
<TextBlock Text="By clicking the &quot;Report&quot; button, a website will be open. The texts you will need to submit will be copied automatically. You only need to paste them in the Description box." Margin="20,5,20,10" TextWrapping="Wrap" MaxWidth="401" FontStyle="Italic"></TextBlock>
</StackPanel>

<TextBox Grid.Column="1" Grid.Row="1" Focusable="False" Margin="20,0,20,0" MaxWidth="400" MaxHeight="156" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Text="{Binding ErrorMessage}" Background="#FFE2E2E2"/>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right">
<Button Content="Report" Click="ReportButtonClicked"/>
<Button Content="Close" IsCancel="True"/>
</StackPanel>
</Grid>
Expand Down
16 changes: 14 additions & 2 deletions D-OS Save Editor/ErrorReporting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Reflection;
Expand All @@ -14,16 +15,27 @@ namespace D_OS_Save_Editor
/// </summary>
public partial class ErrorReporting
{
public ErrorModel ErrorModel;
public ErrorReporting()
{
InitializeComponent();
DataContext = new ErrorModel();
ErrorModel = new ErrorModel();
DataContext = ErrorModel;
}

public ErrorReporting(string message, object data)
{
InitializeComponent();
DataContext = new ErrorModel(message, data);
ErrorModel = new ErrorModel(message, data);
DataContext = ErrorModel;
}

private void ReportButtonClicked(object sender, RoutedEventArgs e)
{
Clipboard.SetText(ErrorModel.ErrorMessage);
Process.Start(
@"https://docs.google.com/forms/d/e/1FAIpQLSeUeKYdV8InQslbvCvA1rmffJ5t1ieond4W6hpUHkHTH7I7dg/viewform?usp=pp_url&entry.1687355392=Error+report");
this.Close();
}
}

Expand Down
24 changes: 23 additions & 1 deletion D-OS Save Editor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
<Image x:Key="OpenBrowserImage" Source="Resources/ic_openbrowser_black.png"/>
<Image x:Key="RefreshImageMO" Source="Resources/ic_refresh3_blue.png"/>
<Image x:Key="OpenBrowserImageMO" Source="Resources/ic_openbrowser_blue.png"/>
<Image x:Key="BugIconImage" Source="Resources/ic_bug_black.png"/>
<Image x:Key="BugIconImageMO" Source="Resources/ic_bug_red.png"/>
<Style x:Key="BugReportButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Content" Value="{StaticResource BugIconImage}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Content" Value="{StaticResource BugIconImageMO}"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DismissButtonStyle" TargetType="Button">
<Setter Property="Background" Value="#FFFBFBB5" />
<Setter Property="BorderBrush" Value="Transparent"/>
Expand Down Expand Up @@ -136,7 +157,8 @@
</Grid.ColumnDefinitions>
<ListBox Grid.Row="0" x:Name="SavegameListBox" Margin="0,10,10,0" SelectionChanged="SavegameListBox_OnSelectionChanged" MaxHeight="400" MaxWidth="240" Width="240"/>
<Button x:Name="RefreshButton" Style="{StaticResource RefreshImageButtonStyle}" Grid.Row="1" Width="20" Height="20" HorizontalAlignment="Right" Margin="0, 5,10,0" Padding="0" VerticalAlignment="Top" Click="RefreshButton_OnClick"/>
<Button Content="About" Grid.Row="1" HorizontalAlignment="Left" Margin="0,30,0,0" Click="AboutButton_OnClick"/>
<Button Content="About" Grid.Row="1" HorizontalAlignment="Left" Margin="35,30,0,0" Click="AboutButton_OnClick"/>
<Button Style="{StaticResource BugReportButtonStyle}" Grid.Row="1" Width="20" Height="18" HorizontalAlignment="Left" Margin="0,30,20,0" Padding="0" VerticalAlignment="Top" Click="BugReportButton_OnClick" ToolTip="Bug report"/>
<Grid Grid.Column="1" Grid.RowSpan="3" Margin="20,20,0,0" >
<Grid.RowDefinitions>
<RowDefinition/>
Expand Down
11 changes: 9 additions & 2 deletions D-OS Save Editor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class MainWindow
private readonly string _defaultProfileDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}{DirectorySeparatorChar}Larian Studios{DirectorySeparatorChar}Divinity Original Sin Enhanced Edition{DirectorySeparatorChar}PlayerProfiles";
private enum BackupStatus { None, Current, Old, NoChecksum, NoImage }

public static string Version { get; } = "v1.4.2";
public static string Version { get; } = "v1.4.3";
private string _updateLink;

public MainWindow()
Expand Down Expand Up @@ -236,7 +236,8 @@ private bool UnpackSave(Savegame savegame)
}
catch (Exception ex)
{
MessageBox.Show(this, $"Internal error!\n\n{ex}", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
var er = new ErrorReporting($"Internal error!\n\n{ex}", null);
er.ShowDialog();
return false;
}
finally
Expand Down Expand Up @@ -531,5 +532,11 @@ private void DismissButton_OnClick(object sender, RoutedEventArgs e)
{
UpdatePanel.Visibility = Visibility.Collapsed;
}

private void BugReportButton_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(
"https://docs.google.com/forms/d/e/1FAIpQLSeUeKYdV8InQslbvCvA1rmffJ5t1ieond4W6hpUHkHTH7I7dg/viewform");
}
}
}
4 changes: 2 additions & 2 deletions D-OS Save Editor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
[assembly: AssemblyVersion("1.4.3.0")]
[assembly: AssemblyFileVersion("1.4.3.0")]
20 changes: 20 additions & 0 deletions D-OS Save Editor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions D-OS Save Editor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,10 @@
<data name="NoImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NoImage.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_bug_black" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_bug_black.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_bug_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_bug_red.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added D-OS Save Editor/Resources/ic_bug_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added D-OS Save Editor/Resources/ic_bug_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion D-OS Save Editor/SE/SaveEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
</Setter.Value>
</Setter>
</Style>
<Image x:Key="BugIconImage" Source="pack://siteoforigin:,,,/Resources/ic_bug_black.png"/>
<Image x:Key="BugIconImageMO" Source="pack://siteoforigin:,,,/Resources/ic_bug_red.png"/>
<Style x:Key="BugReportButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Content" Value="{StaticResource BugIconImage}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Content" Value="{StaticResource BugIconImageMO}"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -69,10 +90,11 @@
<ComboBox x:Name="PlayerSelectionComboBox" HorizontalAlignment="Left" Margin="20,20,0,0" VerticalAlignment="Top" Width="120" Height="21.24" SelectionChanged="PlayerSelectionComboBox_OnSelectionChanged"/>
<Button x:Name="SavePlayer" Content="Apply" Width="60" Margin="20,20,0,0" Click="SavePlayer_OnClick"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1">
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
<Button x:Name="ResetButton" Content="Reset" VerticalAlignment="Center" Padding="10,2" Margin ="10,20,40,0" Width="60" Click="ResetButton_OnClick"/>
<Button x:Name="SaveButton" Content="Save" VerticalAlignment="Center" Padding="10,2" Margin="0,20,0,0" Width="60" Click="SaveButton_OnClick"/>
<Button x:Name="CancelButton" Content="Cancel" VerticalAlignment="Center" Padding="10,2" Margin ="10,20,20,0" Width="60" IsCancel="True"/>
<Button Style="{StaticResource BugReportButtonStyle}" Width="20" Visibility="Collapsed" HorizontalAlignment="Right" Margin="0,20,20,0" Padding="0" VerticalAlignment="Top" Click="BugReportButton_OnClick" ToolTip="Bug report"/>
</StackPanel>
<TabControl Grid.Row="2" Margin="20" Grid.ColumnSpan="2">
<TabItem Header="Stats">
Expand Down
14 changes: 10 additions & 4 deletions D-OS Save Editor/SE/SaveEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ private void SaveButton_OnClick(object sender, RoutedEventArgs e)
catch (Exception ex)
{
SaveButton.IsEnabled = true;
MessageBox.Show(this, $"Failed to save changes.\n\n{ex}", "Failed", MessageBoxButton.OK,
MessageBoxImage.Error);
var er = new ErrorReporting($"Failed to save changes.\n\n{ex}", null);
er.ShowDialog();
}
finally
{
Expand Down Expand Up @@ -167,8 +167,8 @@ private void SavePlayer_OnClick(object sender, RoutedEventArgs e)
catch (Exception ex)
{
SavePlayer.IsEnabled = true;
MessageBox.Show(this, $"Failed to save changes.\n\n{ex}", "Failed", MessageBoxButton.OK,
MessageBoxImage.Error);
var er = new ErrorReporting($"Failed to save changes.\n\n{ex}", null);
er.ShowDialog();
}
finally
{
Expand Down Expand Up @@ -211,5 +211,11 @@ private void SaveEditor_OnClosing(object sender, CancelEventArgs e)
// "Unsaved changes", MessageBoxButton.YesNo, MessageBoxImage.Warning);
//}
}

private void BugReportButton_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(
"https://docs.google.com/forms/d/e/1FAIpQLSeUeKYdV8InQslbvCvA1rmffJ5t1ieond4W6hpUHkHTH7I7dg/viewform");
}
}
}
9 changes: 9 additions & 0 deletions D-OS Save Editor/savegame/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,13 @@ public ItemChange(Item item, ChangeType changeType, int itemIndex)
ItemIndex = itemIndex;
}
}

public class ItemParserException : Exception
{
public ItemParserException() { }

public ItemParserException(Exception inner, XmlNode node) :
base($"Item XML:\n\n{XmlUtilities.BeautifyXml(node)}\n\n", inner)
{ }
}
}
Loading

0 comments on commit 663238d

Please sign in to comment.