-
Notifications
You must be signed in to change notification settings - Fork 8k
[FZ Editor] Serialize/deserialize settings #8615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbae580
0d52e75
12b5dad
ea94c03
dc75b48
b4fd8cd
f6786bf
553b713
6bde7d3
429deb0
5e47255
45b90d0
f3d97ce
8af951c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using System.Windows; | ||
| using FancyZonesEditor.Utils; | ||
| using ManagedCommon; | ||
|
|
@@ -41,6 +43,9 @@ public partial class App : Application | |
| private const string CrashReportDynamicAssemblyTag = "dynamic assembly doesn't have location"; | ||
| private const string CrashReportLocationNullTag = "location is null or empty"; | ||
|
|
||
| private const string ParsingErrorReportTag = "Settings parsing error"; | ||
| private const string ParsingErrorDataTag = "Data: "; | ||
|
|
||
| public MainWindowSettingsModel MainWindowSettings { get; } | ||
|
|
||
| public static FancyZonesEditorIO FancyZonesEditorIO { get; private set; } | ||
|
|
@@ -87,7 +92,55 @@ private void OnStartup(object sender, StartupEventArgs e) | |
| _themeManager = new ThemeManager(this); | ||
|
|
||
| FancyZonesEditorIO.ParseCommandLineArguments(); | ||
| FancyZonesEditorIO.ParseDeviceInfoData(); | ||
|
|
||
| var parseResult = FancyZonesEditorIO.ParseZoneSettings(); | ||
|
|
||
| // 10ms retry loop with 1 second timeout | ||
| if (!parseResult.Result) | ||
| { | ||
| CancellationTokenSource ts = new CancellationTokenSource(); | ||
| Task t = Task.Run(() => | ||
| { | ||
| while (!parseResult.Result && !ts.IsCancellationRequested) | ||
| { | ||
| Task.Delay(10).Wait(); | ||
| parseResult = FancyZonesEditorIO.ParseZoneSettings(); | ||
| } | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| bool result = t.Wait(1000, ts.Token); | ||
| ts.Cancel(); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| ts.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| // Error message if parsing failed | ||
| if (!parseResult.Result) | ||
| { | ||
| var sb = new StringBuilder(); | ||
| sb.AppendLine(); | ||
| sb.AppendLine("## " + ParsingErrorReportTag); | ||
| sb.AppendLine(); | ||
| sb.AppendLine(parseResult.Message); | ||
| sb.AppendLine(); | ||
| sb.AppendLine(ParsingErrorDataTag); | ||
| sb.AppendLine(parseResult.MalformedData); | ||
|
|
||
| string message = parseResult.Message + Environment.NewLine + Environment.NewLine + FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_User_Choice; | ||
| if (MessageBox.Show(message, FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_Title, MessageBoxButton.YesNo) == MessageBoxResult.No) | ||
| { | ||
| // TODO: log error | ||
| ShowExceptionReportMessageBox(sb.ToString()); | ||
| Environment.Exit(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to log the error.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added data saving to the file with a notification message box, as it was done for other errors.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, let's a comment for future reference when we fully enable logging in the editor. |
||
| } | ||
|
|
||
| ShowExceptionReportMessageBox(sb.ToString()); | ||
| } | ||
|
|
||
| MainWindowSettingsModel settings = ((App)Current).MainWindowSettings; | ||
| settings.UpdateSelectedLayoutModel(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.