init i18n, config. add Cut oper
This commit is contained in:
52
BallanceTASEditor/Core/ConfigManager.cs
Normal file
52
BallanceTASEditor/Core/ConfigManager.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BallanceTASEditor.Core {
|
||||
public class ConfigManager {
|
||||
|
||||
public ConfigManager(string fileName, Dictionary<string, string> defaultValue) {
|
||||
_fileName = fileName;
|
||||
_defaultValue = JsonConvert.SerializeObject(defaultValue);
|
||||
|
||||
Configuration = Read();
|
||||
}
|
||||
|
||||
string _fileName;
|
||||
string _defaultValue;
|
||||
public Dictionary<string, string> Configuration;
|
||||
|
||||
Dictionary<string, string> Read() {
|
||||
if (!File.Exists(Path.Combine(Environment.CurrentDirectory, _fileName)))
|
||||
Init();
|
||||
|
||||
Dictionary<string, string> data;
|
||||
using (StreamReader fs = new StreamReader(Path.Combine(Environment.CurrentDirectory, _fileName), Encoding.UTF8)) {
|
||||
data = JsonConvert.DeserializeObject<Dictionary<string, string>>(fs.ReadToEnd());
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Init() {
|
||||
using (StreamWriter fs = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _fileName), false, Encoding.UTF8)) {
|
||||
fs.Write(_defaultValue);
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void Save() {
|
||||
using (StreamWriter fs = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _fileName), false, Encoding.UTF8)) {
|
||||
fs.Write(JsonConvert.SerializeObject(this.Configuration));
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
40
BallanceTASEditor/Core/I18NProcessor.cs
Normal file
40
BallanceTASEditor/Core/I18NProcessor.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace BallanceTASEditor.Core {
|
||||
public static class I18NProcessor {
|
||||
|
||||
public static string GetI18N(string key, params string[] parameters) {
|
||||
try {
|
||||
var cache = (string)(App.Current.Resources[key]);
|
||||
return string.Format(cache, parameters);
|
||||
} catch (Exception) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void ChangeLanguage(string target) {
|
||||
ResourceDictionary langRd = null;
|
||||
try {
|
||||
langRd =
|
||||
Application.LoadComponent(
|
||||
new Uri(@"Language/" + target + ".xaml", UriKind.Relative))
|
||||
as ResourceDictionary;
|
||||
} catch {
|
||||
;
|
||||
}
|
||||
|
||||
if (langRd != null) {
|
||||
if (App.Current.Resources.MergedDictionaries.Count > 0) {
|
||||
App.Current.Resources.MergedDictionaries.Clear();
|
||||
}
|
||||
App.Current.Resources.MergedDictionaries.Add(langRd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user