Fixed: session file writing bad format

This commit is contained in:
Ray 2021-07-23 14:38:07 +01:00
parent 515b81920f
commit dd32aee9d9
3 changed files with 34 additions and 4 deletions

View File

@ -277,7 +277,16 @@ namespace FizzyLauncher
options.Converters.Add(new JsonPointConverter());
options.Converters.Add(new JsonSizeConverter());
try
{
this.CurrentSession = JsonSerializer.Deserialize<LauncherSession>(sourceCode, options);
}
catch (Exception exc)
{
MessageBox.Show("Unable to read session", "Load session");
return;
}
if (this.CurrentSession == null)
{
this.CurrentSession = new LauncherSession();
@ -361,9 +370,13 @@ namespace FizzyLauncher
this.CurrentSession.Groups.Add(container.Model);
}
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonPointConverter());
options.Converters.Add(new JsonSizeConverter());
try
{
File.WriteAllText(filename, JsonSerializer.Serialize(this.CurrentSession));
File.WriteAllText(filename, JsonSerializer.Serialize(this.CurrentSession, options));
if (showNotices)
{

View File

@ -1,14 +1,21 @@
using System.Collections.Generic;
using FizzyLauncher.Text.Json;
using System.Collections.Generic;
using System.Drawing;
using System.Text.Json.Serialization;
namespace FizzyLauncher.Models
{
public class TileGroupModel
{
public string Title { get; set; }
public bool IsExpanded { get; set; } = false;
public bool IsExclusive { get; set; } = false;
public List<TileModel> Items { get; set; } = new List<TileModel>();
[JsonConverter(typeof(JsonSizeConverter))]
public Size GridSize { get; set; } = new Size(0, 0);
}
}

View File

@ -1,21 +1,31 @@
using System;
using FizzyLauncher.Text.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text.Json.Serialization;
namespace FizzyLauncher.Models
{
public class TileModel
{
public string Title { get; set; }
public string ProcessFilename { get; set; }
public string ProcessArgument { get; set; }
public string ProcessWorkingDirectory { get; set; }
public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal;
public bool ProcessAsAdmin { get; set; } = false;
[JsonConverter(typeof(JsonPointConverter))]
public Point Position { get; set; }
public bool IsGroup { get; set; } = false;
public List<TileModel> Items { get; set; } = new List<TileModel>();
public override string ToString() => this.Title ?? string.Empty;