Пример #1
0
        public void LoadLangFile(bool forceReload = false, bool verbose = false) //load language file
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (forceReload)
            {
                isLoaded = false;
            }
            if (isLoaded)
            {
                return;
            }

            if (!string.IsNullOrEmpty(projectPath))
            {
                string settingsPath = Path.Combine(projectPath, ".JSONExSettings");

                if (File.Exists(settingsPath))
                {
                    string json = File.ReadAllText(settingsPath);
                    try
                    {
                        SettingsJSON settingsJSON = JsonConvert.DeserializeObject <SettingsJSON>(json); //Using JsonConvert to deserialize and check jsonPath
                        languagePath = settingsJSON.languagePath;
                        languageCode = settingsJSON.languageCode;
                        string temp = File.ReadAllText(languagePath);

                        data = (JObject)JsonConvert.DeserializeObject(temp);
                        string lang = data[languageCode].Value <JObject>().ToString();
                        langFile = JsonConvert.DeserializeObject <Dictionary <string, string> >(lang);

                        isLoaded = true;
                    }
                    catch (Exception ex)
                    {
                        ShowMessageAndStopExecution($"Invalid .JSONExSettings file: {ex.Message}");
                    }
                }
                else if (verbose)
                {
                    ShowMessageAndStopExecution("Path not set!\nMake sure to set it using JSONEx settings in Tools menu.");
                }
            }
            else if (verbose)
            {
                ShowMessageAndStopExecution("Error getting project path!\nOpen the project first.");
            }
        }
Пример #2
0
        private void AcceptButton_Click(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string languageCode = languageCodeText.Text;
            string languagePath = languagePathText.Text;
            string projectPath  = JSONExtensionPackage.settings.projectPath; //get project path from settings

            if (!string.IsNullOrEmpty(projectPath) && !string.IsNullOrEmpty(languageCode) && !string.IsNullOrEmpty(languagePath))
            {
                SettingsJSON settingsJSON = new SettingsJSON
                {
                    languageCode = languageCode,
                    languagePath = languagePath
                };
                File.WriteAllText(Path.Combine(projectPath, ".JSONExSettings"), JsonConvert.SerializeObject(settingsJSON));
                JSONExtensionPackage.settings.LoadLangFile(true); //force reload lang file
                Dispose();
            }
            else
            {
                MessageBox.Show("Error selecting JSON file\n1. Open project for which you want to set JSON file.\n2. Select valid JSON.", "JSONEx");
            }
        }