Skip to content

Commit e0a037f

Browse files
committed
Added option to opt out of error reporting and auto updates + an option to change what is transfered
1 parent 665ece0 commit e0a037f

15 files changed

+533
-19
lines changed

Arma.Studio.Data/ArmA.Studio.Data.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<Compile Include="UI\AttachedProperties\LooseFocusOnKeyAttached.cs" />
124124
<Compile Include="UI\AttachedProperties\SelectAllOnFocusAttached.cs" />
125125
<Compile Include="UI\AttachedProperties\SelectFileNameOnFocusAttached.cs" />
126+
<Compile Include="UI\Converters\InvertConverter.cs" />
126127
<Compile Include="UI\Converters\AllFalseMultiConverter.cs" />
127128
<Compile Include="UI\Converters\AllTrueMultiConverter.cs" />
128129
<Compile Include="UI\Converters\BoolAndMultiConverter.cs" />
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
9+
namespace Arma.Studio.Data.UI.Converters
10+
{
11+
/// <summary>
12+
/// Inverts the incoming <see cref="Boolean"/> value.
13+
/// </summary>
14+
public class InvertConverter : IValueConverter
15+
{
16+
/// <summary>
17+
/// Converts a value
18+
/// </summary>
19+
/// <param name="value">The value produced by the binding source.</param>
20+
/// <param name="targetType">The type of the binding target property.</param>
21+
/// <param name="parameter">The converter parameter to use.</param>
22+
/// <param name="culture">The culture to use in the converter.</param>
23+
/// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
24+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
25+
{
26+
if (value is bool flag)
27+
{
28+
return !flag;
29+
}
30+
else if (value is short s)
31+
{
32+
return -s;
33+
}
34+
else if (value is int i)
35+
{
36+
return -i;
37+
}
38+
else if (value is long l)
39+
{
40+
return -l;
41+
}
42+
else if (value is float f)
43+
{
44+
return -f;
45+
}
46+
else if (value is double d)
47+
{
48+
return -d;
49+
}
50+
else if (value is decimal dec)
51+
{
52+
return -dec;
53+
}
54+
else
55+
{
56+
return value;
57+
}
58+
}
59+
60+
/// <summary>
61+
/// Converts a value.
62+
/// </summary>
63+
/// <param name="value">The value that is produced by the binding target.</param>
64+
/// <param name="targetType">The type to convert to.</param>
65+
/// <param name="parameter">The converter parameter to use.</param>
66+
/// <param name="culture">The culture to use in the converter.</param>
67+
/// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
68+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
69+
{
70+
value = System.Convert.ChangeType(value, targetType);
71+
if (value is bool flag)
72+
{
73+
return !flag;
74+
}
75+
else if (value is short s)
76+
{
77+
return -s;
78+
}
79+
else if (value is int i)
80+
{
81+
return -i;
82+
}
83+
else if (value is long l)
84+
{
85+
return -l;
86+
}
87+
else if (value is float f)
88+
{
89+
return -f;
90+
}
91+
else if (value is double d)
92+
{
93+
return -d;
94+
}
95+
else if (value is decimal dec)
96+
{
97+
return -dec;
98+
}
99+
else
100+
{
101+
return value;
102+
}
103+
}
104+
}
105+
}

Arma.Studio/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<asd:AllTrueMultiConverter x:Key="AllTrueMultiConverter"/>
1919
<asd:BoolOrMultiConverter x:Key="BoolOrMultiConverter"/>
2020
<asd:BoolAndMultiConverter x:Key="BoolAndMultiConverter"/>
21+
<asd:InvertConverter x:Key="InvertConverter"/>
2122
<asd:IsAssignableFromConverter x:Key="IsAssignableFromConverter"/>
2223
<asd:StringEndsWithConverter x:Key="StringEndsWithConverter"/>
2324
</ResourceDictionary>

Arma.Studio/App.xaml.cs

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,29 @@ public static void DisplayOperationFailed(Exception ex)
7474
{
7575
SentrySdk.WithScope((scope) =>
7676
{
77-
var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
78-
var userName = windowsIdentity.Name.LastIndexOf('\\') != -1 ?
79-
windowsIdentity.Name.Substring(windowsIdentity.Name.LastIndexOf('\\') + 1) :
80-
windowsIdentity.Name;
77+
// var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
78+
// var userName = windowsIdentity.Name.LastIndexOf('\\') != -1 ?
79+
// windowsIdentity.Name.Substring(windowsIdentity.Name.LastIndexOf('\\') + 1) :
80+
// windowsIdentity.Name;
81+
// scope.User = new Sentry.Protocol.User
82+
// {
83+
// Username = userName,
84+
// Other = new Dictionary<string, string>
85+
// {
86+
// { "OS-Language", System.Globalization.CultureInfo.InstalledUICulture.EnglishName },
87+
// { "App-Language", System.Globalization.CultureInfo.CurrentUICulture.EnglishName },
88+
// { "Full-username", windowsIdentity.Name },
89+
// }
90+
// };
8191
scope.User = new Sentry.Protocol.User
8292
{
83-
Username = userName,
93+
Username = Configuration.Instance.UserGuid.ToString(),
8494
Other = new Dictionary<string, string>
85-
{
86-
{ "OS-Language", System.Globalization.CultureInfo.InstalledUICulture.EnglishName },
87-
{ "App-Language", System.Globalization.CultureInfo.CurrentUICulture.EnglishName },
88-
{ "Full-username", windowsIdentity.Name },
89-
}
95+
{
96+
{ "OS-Language", System.Globalization.CultureInfo.InstalledUICulture.EnglishName },
97+
{ "App-Language", System.Globalization.CultureInfo.CurrentUICulture.EnglishName },
98+
{ "UserIdentifier", Configuration.Instance.UserIdentifier }
99+
}
90100
};
91101

92102
SentrySdk.CaptureException(ex);
@@ -206,23 +216,49 @@ public static string GetReleaseInfos()
206216
return builder.ToString();
207217
}
208218

219+
public static void Restart()
220+
{
221+
Configuration.Save(ConfigPath);
222+
(App.Current as App).Sentry?.Dispose();
223+
(App.Current as App).Sentry = null;
224+
var info = new System.Diagnostics.ProcessStartInfo();
225+
info.Arguments = "/C choice /C Y /N /D Y /T 1 & START \"\" \"" + System.Reflection.Assembly.GetEntryAssembly().Location + "\"";
226+
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
227+
info.CreateNoWindow = true;
228+
info.FileName = "cmd.exe";
229+
System.Diagnostics.Process.Start(info);
230+
System.Diagnostics.Process.GetCurrentProcess().Kill();
231+
}
232+
209233
private void Application_Startup(object sender, StartupEventArgs e)
210234
{
211-
this.Sentry = SentrySdk.Init((sentryOptions) => {
212-
sentryOptions.Dsn = new Dsn("https://76551f4da2934dc5b5553184ca3ebc03@sentry.io/2670888");
213-
sentryOptions.Release = GetReleaseInfos();
235+
Configuration.Load(ConfigPath);
236+
if (!Configuration.Instance.UserIdentificationDialogWasDisplayed)
237+
{
238+
var dlgdc = new UI.Windows.UserIdentificationDialogDataContext();
239+
var dlg = new UI.Windows.UserIdentificationDialog(dlgdc);
240+
dlg.ShowDialog();
241+
}
242+
243+
244+
if (!Configuration.Instance.OptOutOfReportingAndUpdates)
245+
{
246+
this.Sentry = SentrySdk.Init((sentryOptions) =>
247+
{
248+
sentryOptions.Dsn = new Dsn("https://76551f4da2934dc5b5553184ca3ebc03@sentry.io/2670888");
249+
sentryOptions.Release = GetReleaseInfos();
214250
#if DEBUG
215-
sentryOptions.Environment = $"Debug-{(System.Environment.Is64BitProcess ? "x64" : "x86")}";
251+
sentryOptions.Environment = $"Debug-{(System.Environment.Is64BitProcess ? "x64" : "x86")}";
216252
#else
217-
sentryOptions.Environment = $"Release-{(System.Environment.Is64BitProcess ? "x64" : "x86")}";
253+
sentryOptions.Environment = $"Release-{(System.Environment.Is64BitProcess ? "x64" : "x86")}";
218254
#endif
219-
sentryOptions.SendDefaultPii = true;
220-
});
255+
sentryOptions.SendDefaultPii = true;
256+
});
257+
}
221258
foreach (string dll in System.IO.Directory.GetFiles(App.ExecutablePath, "*.dll"))
222259
{
223260
PluginManager.Instance.LoadAssemblySafe(dll);
224261
}
225-
Configuration.Load(ConfigPath);
226262
var splashDataContext = new UI.Windows.SplashScreenDataContext();
227263
var splash = new UI.Windows.SplashScreen(splashDataContext);
228264
splash.Show();

Arma.Studio/ArmA.Studio.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
<DependentUpon>AboutDialog.xaml</DependentUpon>
126126
</Compile>
127127
<Compile Include="UI\Windows\AboutDialogDataContext.cs" />
128+
<Compile Include="UI\Windows\UserIdentificationDialogDataContext.cs" />
129+
<Compile Include="UI\Windows\UserIdentificationDialog.xaml.cs">
130+
<DependentUpon>UserIdentificationDialog.xaml</DependentUpon>
131+
</Compile>
128132
<Compile Include="UI\Windows\SplashScreen.xaml.cs">
129133
<DependentUpon>SplashScreen.xaml</DependentUpon>
130134
</Compile>
@@ -171,6 +175,10 @@
171175
<DependentUpon>MainWindow.xaml</DependentUpon>
172176
<SubType>Code</SubType>
173177
</Compile>
178+
<Page Include="UI\Windows\UserIdentificationDialog.xaml">
179+
<SubType>Designer</SubType>
180+
<Generator>MSBuild:Compile</Generator>
181+
</Page>
174182
<Page Include="UI\Windows\SplashScreen.xaml">
175183
<Generator>MSBuild:Compile</Generator>
176184
<SubType>Designer</SubType>
@@ -227,6 +235,9 @@
227235
<ItemGroup>
228236
<EmbeddedResource Include="git-version.txt" />
229237
</ItemGroup>
238+
<ItemGroup>
239+
<Resource Include="Resources\UserIdentificationDialog\UserIdentifier.png" />
240+
</ItemGroup>
230241
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
231242
<PropertyGroup>
232243
<PreBuildEvent>git rev-parse HEAD &gt; "$(ProjectDir)\git-version.txt"

Arma.Studio/Configuration.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace Arma.Studio
1111
[XmlRoot("config")]
1212
public class Configuration
1313
{
14+
public bool UserIdentificationDialogWasDisplayed { get; set; } = false;
15+
public bool OptOutOfReportingAndUpdates { get; set; } = false;
16+
public string UserIdentifier { get; set; } = String.Empty;
17+
public Guid UserGuid { get; set; } = default;
18+
19+
1420
[XmlIgnore]
1521
public static Configuration Instance { get; private set; }
1622
private Configuration()
@@ -41,6 +47,11 @@ public static void Load(string fpath)
4147
App.DisplayOperationFailed(ex, Properties.Language.Configuration_ExceptionDuringLoad);
4248
Instance = new Configuration();
4349
}
50+
if (Instance.UserGuid == default)
51+
{
52+
Instance.UserGuid = Guid.NewGuid();
53+
Save(fpath);
54+
}
4455
}
4556
public static void Save(string fpath)
4657
{

0 commit comments

Comments
 (0)