86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using InfosysPublisher.Classes;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace InfosysPublisher
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for WinSettings.xaml
|
|
/// </summary>
|
|
public partial class WinSettings : Window
|
|
{
|
|
private static string _settingsPath;
|
|
private static string _applicationPath;
|
|
|
|
public WinSettings()
|
|
{
|
|
InitializeComponent();
|
|
|
|
BtnSave.Click += BtnSave_Click;
|
|
|
|
LoadSettings();
|
|
}
|
|
|
|
private void BtnSave_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SaveSettings();
|
|
}
|
|
|
|
private void SaveSettings()
|
|
{
|
|
var settings = new Settings.Application
|
|
{
|
|
BuildSeconds = Convert.ToInt32(TbBuildDuration.Text)
|
|
};
|
|
|
|
SaveSettings(settings);
|
|
|
|
this.DialogResult = true;
|
|
}
|
|
|
|
private void LoadSettings()
|
|
{
|
|
var settings = GetSettings() ?? new Settings.Application();
|
|
|
|
TbBuildDuration.Text = settings.BuildSeconds.ToString();
|
|
}
|
|
|
|
private static void SetPaths()
|
|
{
|
|
_applicationPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
_settingsPath = _applicationPath + @"\InfosysPublisher.json";
|
|
}
|
|
|
|
internal static Settings.Application? GetSettings()
|
|
{
|
|
SetPaths();
|
|
|
|
if (File.Exists(_settingsPath))
|
|
{
|
|
return JsonConvert.DeserializeObject<Settings.Application>(File.ReadAllText(_settingsPath)) ?? new Settings.Application();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
internal static void SaveSettings(Settings.Application iSettings)
|
|
{
|
|
SetPaths();
|
|
iSettings.Save(_settingsPath);
|
|
}
|
|
}
|
|
}
|