1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 02:34:06 +02:00

Add a UserConfig class with currently unused config options

This commit is contained in:
chylex 2016-04-09 19:09:40 +02:00
parent 5e5343b7d6
commit dbc2348ca5
3 changed files with 67 additions and 5 deletions

View File

@ -0,0 +1,59 @@
using System;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace TweetDick.Configuration{
[Serializable]
sealed class UserConfig{
private static readonly IFormatter Formatter = new BinaryFormatter();
// START OF CONFIGURATION
public bool IgnoreMigration { get; set; }
public bool IsMaximized { get; set; }
public Point WindowLocation { get; set; }
public Size WindowSize { get; set; }
// END OF CONFIGURATION
[NonSerialized]
private readonly string file;
private UserConfig(string file){
this.file = file;
}
public bool Save(){
try{
Directory.CreateDirectory(file);
using(Stream stream = new FileStream(file,FileMode.Create,FileAccess.Write,FileShare.None)){
Formatter.Serialize(stream,this);
}
return true;
}catch(Exception){
// TODO
return false;
}
}
public static UserConfig Load(string file){
UserConfig config = null;
try{
using(Stream stream = new FileStream(file,FileMode.Open,FileAccess.Read,FileShare.Read)){
config = Formatter.Deserialize(stream) as UserConfig;
}
}catch(FileNotFoundException){
}catch(Exception){
// TODO
}
return config ?? new UserConfig(file);
}
}
}

View File

@ -3,15 +3,13 @@
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using TweetDick.Configuration;
using TweetDick.Core;
namespace TweetDick{
static class Program{
public static string StoragePath{
get{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"TweetDick");
}
}
public static readonly string StoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"TweetDick");
public static readonly UserConfig UserConfig;
private static string HeaderAcceptLanguage{
get{
@ -26,6 +24,10 @@ private static string HeaderAcceptLanguage{
}
}
static Program(){
UserConfig = UserConfig.Load(Path.Combine(StoragePath,"TD_UserConfig.cfg"));
}
[STAThread]
private static void Main(){
Application.EnableVisualStyles();

View File

@ -78,6 +78,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\UserConfig.cs" />
<Compile Include="Core\FormBrowser.cs">
<SubType>Form</SubType>
</Compile>