Skip to content
This repository was archived by the owner on Dec 13, 2020. It is now read-only.

Commit 6e95eeb

Browse files
author
Firestack
committed
Error fixing
1 parent 76d8675 commit 6e95eeb

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

UnityMultiLauncher/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private void Current_DispatcherUnhandledException(object sender, System.Windows.
3535

3636
var eWin = new Views.ErrorWindow();
3737

38-
eWin.EVMP.Exception = e.Exception;
38+
eWin.EVMP.EVMException = e.Exception;
3939
eWin.EVMP.FileLocation = file;
4040

4141
eWin.metroWindow.ShowDialog();

UnityMultiLauncher/Models/Utility.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace UnityMultiLauncher
77
{
88
public static class Util
99
{
10-
private static Regex versionExp = new Regex(@"(\d+).(\d+).(\d+)f(\d+)", RegexOptions.Compiled);
10+
private static Regex versionExp = new Regex(@"(\d+)\.(\d+)\.(\d+)([A-z]+)(\d+)", RegexOptions.Compiled);
1111

1212
public static string UnityProjectSettings(Uri project, string key)
1313
{
@@ -33,13 +33,21 @@ public static string UnityProjectSettings(Uri project, string key)
3333

3434
public static Tuple<int, int, int, int> UnityProjectVersion(Uri project)
3535
{
36-
var filename = System.IO.Path.Combine(project.LocalPath, @"ProjectSettings /ProjectVersion.txt");
36+
var filename = System.IO.Path.Combine(project.LocalPath, @"ProjectSettings\ProjectVersion.txt");
3737
if (System.IO.File.Exists(filename))
3838
{
3939
var data = System.IO.File.ReadAllText(filename, Encoding.UTF8);
4040
var match = versionExp.Match(data);
41-
42-
return Tuple.Create(Convert.ToInt32(match.Groups[1].Value), Convert.ToInt32(match.Groups[2].Value), Convert.ToInt32(match.Groups[3].Value), Convert.ToInt32(match.Groups[4].Value));
41+
try
42+
{
43+
return Tuple.Create(Convert.ToInt32(match.Groups[1].Value), Convert.ToInt32(match.Groups[2].Value), Convert.ToInt32(match.Groups[3].Value), Convert.ToInt32(match.Groups[5].Value));
44+
}
45+
catch (Exception E)
46+
{
47+
E.Data["ProjectText"] = data.ToString();
48+
E.Data["Matches"] = match.ToString();
49+
throw;
50+
}
4351
}
4452
return null;
4553
}

UnityMultiLauncher/Util/ExtentionMethods.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,47 @@ public static string GetLocation(this System.Environment.SpecialFolder folder)
88
{
99
return Environment.GetFolderPath(folder);
1010
}
11+
12+
public static string Format(this string baseString, params object[] objs)
13+
{
14+
return string.Format(baseString, objs);
15+
}
16+
17+
public static string FormatExceptionData(this Exception exc)
18+
{
19+
// Extra Data
20+
if(exc.Data.Count == 0)
21+
{
22+
return "";
23+
}
24+
var ED = "Extra Data: \n";
25+
foreach (System.Collections.DictionaryEntry dp in exc.Data)
26+
{
27+
if(dp.Value != null)
28+
{
29+
var tmp = dp.Value.ToString();
30+
ED += "{0,-20}:\n{1}".Format(dp.Key, tmp);
31+
}
32+
else
33+
{
34+
ED += "\tKey: {0}".Format(dp.Key);
35+
}
36+
ED += Environment.NewLine;
37+
}
38+
39+
return ED;
40+
}
41+
42+
public static string FormatExceptionDataRecursive(this Exception exc)
43+
{
44+
var s = exc.FormatExceptionData();
45+
if(exc.InnerException != null)
46+
{
47+
s += "-- Inner Exception --";
48+
s += Environment.NewLine;
49+
s += exc.InnerException.FormatExceptionData();
50+
}
51+
return s;
52+
}
1153
}
1254
}

UnityMultiLauncher/ViewModels/ErrorViewModel.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UnityMultiLauncher.ViewModels
99
using Utils;
1010
public class ErrorViewModel : ViewModel
1111
{
12-
public System.Exception Exception
12+
public System.Exception EVMException
1313
{
1414
get
1515
{
@@ -26,7 +26,9 @@ public string ExceptionString
2626
{
2727
get
2828
{
29-
return Exception.ToString();
29+
30+
31+
return EVMException.FormatExceptionDataRecursive() + Environment.NewLine + EVMException.ToString() ;
3032
}
3133
}
3234

@@ -61,6 +63,20 @@ public ViewCommand OpenGithub
6163
}
6264
}
6365

66+
public void ExceptionToClipboardFunc(object obj)
67+
{
68+
System.Windows.Clipboard.SetText(ExceptionString);
69+
70+
}
71+
72+
public ViewCommand ExceptionToClipboard
73+
{
74+
get
75+
{
76+
return GetProperty() as ViewCommand ?? SetProperty(new ViewCommand(ExceptionToClipboardFunc));
77+
}
78+
}
79+
6480

6581
}
6682
}

UnityMultiLauncher/Views/ErrorWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Controls:MetroWindow.RightWindowCommands>
2222
<Controls:WindowCommands>
2323
<Button Content="Open Github" Command="{Binding OpenGithub, Mode=OneWay, Source={StaticResource EVM}}" />
24-
24+
<Button Content="Copy Error To Clipboard" Command=""/>
2525
</Controls:WindowCommands>
2626
</Controls:MetroWindow.RightWindowCommands>
2727
<Grid>

UnityMultiLauncher/Views/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public MainWindow()
1414
{
1515
cwin = this;
1616
InitializeComponent();
17-
throw new NotImplementedException();
17+
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)