コード例 #1
0
        /// <summary>
        /// Load settings from disk
        /// </summary>
        /// <param name="name">The name of the settings module to load, or null to load all</param>
        /// <returns>A task that completes when the load is complete</returns>
        private Task LoadSettings(string name)
        {
            if (name == null)
            {
                _values.Clear();
            }
            else if (_values.ContainsKey(name))
            {
                _values.Remove(name);
            }

            var path = _appInfo?.GetApplicationSettingsFolder("Shell");

            if (path == null)
            {
                return(Task.CompletedTask);
            }

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path, "*.json"))
                {
                    var containerName = Path.GetFileNameWithoutExtension(file);

                    if (containerName == null)
                    {
                        continue;
                    }
                    if (name != null && containerName != name)
                    {
                        continue;
                    }

                    JsonSettingsStore store;
                    try
                    {
                        store = new JsonSettingsStore(File.ReadAllText(file));
                    }
                    catch
                    {
                        store = new JsonSettingsStore();
                    }

                    _values[containerName] = store;
                }
            }

            foreach (var container in _containers)
            {
                if (name != null && container.Name != name)
                {
                    continue;
                }
                container.LoadValues(_values.ContainsKey(container.Name) ? _values[container.Name] : new JsonSettingsStore());
            }
            Log.Debug("Settings", "Settings loaded.");
            return(Task.CompletedTask);
        }
コード例 #2
0
        public void Load(Type type)
        {
            var loc = type.Assembly.Location ?? "";

            if (_loaded.Contains(loc))
            {
                return;
            }
            _loaded.Add(loc);

            // Load from the translations sub-directory of the assembly's directory first
            if (File.Exists(loc))
            {
                var dir = Path.Combine(Path.GetDirectoryName(loc) ?? "", "Translations");
                if (Directory.Exists(dir))
                {
                    foreach (var file in Directory.GetFiles(dir, "*.json", SearchOption.TopDirectoryOnly))
                    {
                        LoadFile(file);
                    }
                }
            }

            // Override these values with translations from the appdata directory
            var appdataTranslations = _appInfo?.GetApplicationSettingsFolder("Translations");

            if (appdataTranslations != null && Directory.Exists(appdataTranslations))
            {
                foreach (var file in Directory.GetFiles(appdataTranslations, "*.json", SearchOption.TopDirectoryOnly))
                {
                    LoadFile(file);
                }
            }
        }
コード例 #3
0
        public Task OnStartup()
        {
            // Load language setting early, as most settings are loaded on initialise
            var path = _appInfo?.GetApplicationSettingsFolder("Shell");

            if (path == null)
            {
                return(Task.CompletedTask);
            }

            var file = Path.Combine(path, Name + ".json");

            Dictionary <string, string> data = null;

            if (File.Exists(file))
            {
                try
                {
                    data = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(file));
                }
                catch
                {
                    data = null;
                }
            }
            if (data != null && data.ContainsKey("Language"))
            {
                Language = data["Language"] ?? "en";
            }

            foreach (var at in _autoTranslate)
            {
                try
                {
                    Translate(at.Value);
                }
                catch (Exception e)
                {
                    Oy.Publish("Shell:UnhandledException", e);
                }
            }

            return(Task.FromResult(0));
        }
コード例 #4
0
ファイル: TranslationForm.cs プロジェクト: vaulthunter/sledge
        /// <summary>
        /// Construct the translator form
        /// </summary>
        public TranslationForm()
        {
            InitializeComponent();

            _catalog = Common.Container.Get <TranslationStringsCatalog>();
            _appInfo = Common.Container.Get <IApplicationInfo>();

            _appTranslationsFolder  = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "Translations");
            _userTranslationsFolder = _appInfo.GetApplicationSettingsFolder("Translations");

            var source = new DataTable("Translations");

            source.Columns.Add("ID", typeof(string));
            source.Columns.Add("Type", typeof(string));
            source.Columns.Add("FriendlyID", typeof(string));
            source.Columns.Add("English", typeof(string));
            source.Columns.Add("Translation", typeof(string));
            dataGridView.DataSource = source;

            PopulateLanguageList();
            PopulateFileList();
        }