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:
parent
5e5343b7d6
commit
dbc2348ca5
59
Configuration/UserConfig.cs
Normal file
59
Configuration/UserConfig.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
12
Program.cs
12
Program.cs
@ -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();
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user