2024-10-10 11:47:27 +03:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace GtaVUsersInfo.Sources
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class WindowParameters
|
|
|
|
|
{
|
|
|
|
|
public int width;
|
|
|
|
|
public int height;
|
|
|
|
|
public int leftPos;
|
|
|
|
|
public int rightPos;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
public bool isFullScreen;
|
2024-10-10 11:47:27 +03:00
|
|
|
|
public string? prevFile;
|
|
|
|
|
|
|
|
|
|
public WindowParameters() { }
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
public WindowParameters(Size window, Size pos, bool isfull)
|
2024-10-10 11:47:27 +03:00
|
|
|
|
{
|
|
|
|
|
width = window.Width;
|
|
|
|
|
height = window.Height;
|
|
|
|
|
leftPos = pos.Width;
|
|
|
|
|
rightPos = pos.Height;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
isFullScreen = isfull;
|
2024-10-10 11:47:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
public WindowParameters(Size window, Size pos, bool isfull, string file)
|
2024-10-10 11:47:27 +03:00
|
|
|
|
{
|
|
|
|
|
width = window.Width;
|
|
|
|
|
height = window.Height;
|
|
|
|
|
leftPos = pos.Width;
|
|
|
|
|
rightPos = pos.Height;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
isFullScreen = isfull;
|
2024-10-10 11:47:27 +03:00
|
|
|
|
prevFile = file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SaveWindowParameters(WindowParameters fontSettings)
|
|
|
|
|
{
|
|
|
|
|
string json = JsonConvert.SerializeObject(fontSettings, Formatting.Indented);
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(Resources.windowParametersJsonPath)))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(Resources.windowParametersJsonPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(Resources.windowParametersJsonPath, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static WindowParameters LoadWindowParameters()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string json = File.ReadAllText(Resources.windowParametersJsonPath);
|
|
|
|
|
return JsonConvert.DeserializeObject<WindowParameters>(json);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Файл с параметрами окна не найден: {Resources.windowParametersJsonPath}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (JsonException ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при десериализации JSON параметрами окна: {ex.Message}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Произошла неожиданная ошибка при открытии файла с параметрами окна: {ex.Message}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|