-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSettings.cs
121 lines (105 loc) · 3.88 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (c) 2016 SolarLiner - Part of the TLE Orbiter Sceneraio Generator (TLEOSG)
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TLEOrbiter
{
public partial class SettingsForm : Form
{
public SettingsForm()
{
InitializeComponent();
Log.Write("new SettingsForm()");
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = TB_OrbPath.Text;
if (fbd.ShowDialog() != DialogResult.OK) return;
TB_OrbPath.Text = fbd.SelectedPath;
}
private void BT_OK_Click(object sender, EventArgs e)
{
string CultureName = Settings.Languages.First(k => k.Value == CB_Lang.Text).Key;
Settings.Lang = new CultureInfo(CultureName);
Settings.OrbiterPath = TB_OrbPath.Text;
Settings.Save();
this.Close();
}
private void SettingsForm_Load(object sender, EventArgs e)
{
foreach(KeyValuePair<string,string> kvp in Settings.Languages)
{
CB_Lang.Items.Add(kvp.Value);
}
CB_Lang.SelectedItem = Settings.Languages[Settings.Lang.Name];
TB_OrbPath.Text = Settings.OrbiterPath;
}
private void BT_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
public static class Settings
{
public static CultureInfo Lang { get; set; }
public static string OrbiterPath { get; set; }
static readonly string _config = Path.Combine(Application.StartupPath, "Config.cfg");
// List of available languages,
public static Dictionary<string, string> Languages
{
get
{
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("en-UK", "English (Traditional)");
d.Add("en-US", "English (Simplified)");
d.Add("fr-FR", "Français");
//TODO: Add more languages to translate
return d;
}
}
public static void Load()
{
CultureInfo _lang = Application.CurrentCulture;
try
{
Log.Write("Settings.Load()");
foreach (string line in File.ReadAllLines(_config))
{
string[] content = line.Split('=');
if (content.Length != 2) continue;
switch (content[0].Trim())
{
case "OrbiterPath":
Log.Write("Settings: Found OrbiterPath: " + content[1]);
OrbiterPath = content[1].Trim();
break;
case "Language":
Log.Write("Settings: Found language: " + content[1]);
_lang = new CultureInfo(content[1].Trim());
break;
}
}
}
catch { }
Lang = _lang; // That way if no languages are found, use the system one
}
public static void Save()
{
StringBuilder sb = new StringBuilder();
Log.Write("Settings.Save()");
sb.AppendLine(string.Format("; TLE Scenario Generator - v {0}", Application.ProductVersion));
sb.AppendLine();
sb.AppendLine("; Path to Orbiter root");
sb.AppendLine("OrbiterPath = " + OrbiterPath);
sb.AppendLine("; Application language");
sb.AppendLine("Language = " + Lang.Name);
File.WriteAllText(_config, sb.ToString());
}
}
}