private void About_Load(object sender, EventArgs e) { commonSet.InitCommonSet(); commonSet.LoadSetting(); // Choose Language if (commonSet.loadedLanguageIndex == 0) { // show English this.label1.Text = "Version: " + version; this.linkLabel1.Text = "Check for Updates"; } else if (commonSet.loadedLanguageIndex == 1) { // show Chinese this.label1.Text = "版本:" + version; this.linkLabel1.Text = "檢查更新"; } else if (commonSet.loadedLanguageIndex == 2) { // show Japanese this.label1.Text = "バージョン:" + version; this.linkLabel1.Text = "更新を確認する"; } }
private void LoadSetting() { // load the configuration file by using common loading function if (commonSet.LoadSetting()) { // if the read is success, assign the value to different variable loadedLanguageIndex = commonSet.loadedLanguageIndex; loadedInterfaceName = commonSet.loadedInterfaceName; if (commonSet.GetInterfaceIndexWithName(loadedInterfaceName) != -1) { loadedInterfaceIndex = commonSet.GetInterfaceIndexWithName(loadedInterfaceName); } else { // set default index if the interfaced cannot be found loadedInterfaceIndex = 0; } loadedUpdateFrequency = commonSet.loadedUpdateFrequency; loadedSpeedUnitIndex = commonSet.loadedSpeedUnitIndex; loadedSpeedUnit = commonSet.loadedSpeedUnit; loadedDisplayMethodIndex = commonSet.loadedDisplayMethodIndex; loadedDisplaySizeIndex = commonSet.loadedDisplaySizeIndex; loadedDarkThemeIndex = commonSet.loadedDarkThemeIndex; loadedAutoStartCheck = commonSet.loadedAutoStartCheck; loadedShowBubbleCheck = commonSet.loadedShowBubbleCheck; // set the readed status to true configurationReaded = true; // set the parameter in form into loaded information this.LanguageSelectionBox.SelectedIndex = loadedLanguageIndex; this.NetworkInterfaceSelectionBox.SelectedIndex = loadedInterfaceIndex; this.UpdateFrequencySlider.Value = loadedUpdateFrequency; this.SpeedUnitSelectionBox.SelectedIndex = loadedSpeedUnitIndex; this.DisplaySelectionBox.SelectedIndex = loadedDisplayMethodIndex; this.WindowSizeSelectionBox.SelectedIndex = loadedDisplaySizeIndex; this.DarkThemeSelectionBox.SelectedIndex = loadedDarkThemeIndex; this.AutoRunCheckBox.IsChecked = loadedAutoStartCheck; this.ShowBubbleCheckBox.IsChecked = loadedShowBubbleCheck; changeLanguages(); changeTheme(); } else { if (this.LanguageSelectionBox.SelectedIndex == 1) { // if the cannot read the configuration file successfully, show error message MessageBox.Show("找不到檔案 \"configuration\" 或檔案 \"configuration\" 已損壞。\n請嘗試套用預設設定來修改此問題。"); } else if (this.LanguageSelectionBox.SelectedIndex == 2) { MessageBox.Show("ファイル \"configuration\" が見つからないまたはファイル \"configuration\" が破損している。\n初期設定が適用してください。"); } else { MessageBox.Show("Cannot find the configuration file or the configuration file is corrupted.\nPlease try to apply default setting to correct it."); } } #region Old Loading code /* * try * { * using (System.IO.StreamReader file = new System.IO.StreamReader(System.AppDomain.CurrentDomain.BaseDirectory + configFileName)) * { * bool formatError = false; * // read interface index * if (!Int32.TryParse(file.ReadLine(), out loadedInterfaceIndex)) * { * formatError = true; * } * else * { * // check if the index is in range * if (loadedInterfaceIndex < 0 || loadedInterfaceIndex >= interfaces.Length) * { * formatError = true; * } * } * * // read update frequency * if (!Double.TryParse(file.ReadLine(), out loadedUpdateFrequency)) * { * formatError = true; * } * // check if the update frequency is in range * else if (loadedUpdateFrequency < minFrequency || loadedUpdateFrequency > maxFrequency) * { * formatError = true; * } * * // read speed unit index * if (!Int32.TryParse(file.ReadLine(), out loadedSpeedUnitIndex)) * { * formatError = true; * } * else if (loadedSpeedUnitIndex < 0 || loadedSpeedUnitIndex > numberOfSpeedUnit) * { * formatError = true; * } * * // read speed unit * loadedSpeedUnit = file.ReadLine(); * * // read show method index * if (!Int32.TryParse(file.ReadLine(), out loadedDisplayMethodIndex)) * { * formatError = true; * } * else if (loadedDisplayMethodIndex < 0 || loadedDisplayMethodIndex > 3) * { * formatError = true; * } * * // read floating window size index * if (!Int32.TryParse(file.ReadLine(), out loadedDisplaySizeIndex)) * { * formatError = true; * } * else if (loadedDisplaySizeIndex < 0 || loadedDisplaySizeIndex >= numberOfWindowSize) * { * formatError = true; * } * * // read auto start option * if (!Boolean.TryParse(file.ReadLine(), out loadedAutoStartCheck)) * { * formatError = true; * } * * // check if the format of file correct * if (formatError) * { * // format of the file is wrong, show error message * MessageBox.Show("Configuration file corrupted\nPlease try to apply default setting to correct it"); * } * else * { * configurationReaded = true; * } * * } * } * catch * { * // error occur, show error message * MessageBox.Show("Cannot find the configuration file or the configuration file corrupted\nPlease try to apply default setting to correct it"); * }*/ #endregion }
private void LoadSetting() { // load the configuration file by using common loading function if (commonSet.LoadSetting()) { // if the read is success, assign the value to different variable loadedLanguageIndex = commonSet.loadedLanguageIndex; loadedInterfaceName = commonSet.loadedInterfaceName; if (commonSet.GetInterfaceIndexWithName(loadedInterfaceName) != -1) { loadedInterfaceIndex = commonSet.GetInterfaceIndexWithName(loadedInterfaceName); } else { // set default index if the interfaced cannot be found loadedInterfaceIndex = 0; } loadedUpdateFrequency = commonSet.loadedUpdateFrequency; loadedSpeedUnitIndex = commonSet.loadedSpeedUnitIndex; loadedSpeedUnit = commonSet.loadedSpeedUnit; loadedDisplayMethodIndex = commonSet.loadedDisplayMethodIndex; loadedDisplaySizeIndex = commonSet.loadedDisplaySizeIndex; loadedDarkModeIndex = commonSet.loadedDarkThemeIndex; loadedAutoStartCheck = commonSet.loadedAutoStartCheck; // *** added if (loadedLanguageIndex == 1) { this.configurationToolStripMenuItem.Text = "設定"; this.aboutToolStripMenuItem.Text = "關於 ..."; this.floatingWindowToolStripMenuItem.Text = "懸浮窗"; this.showFloatingWindowToolStripMenuItem.Text = "顯示懸浮窗"; this.hideFloatingWindowToolStripMenuItem.Text = "隱藏懸浮窗"; this.resetFloatingWindowPositionToolStripMenuItem.Text = "重設位置於此"; this.exitToolStripMenuItem.Text = "離開"; } else if (loadedLanguageIndex == 2) { this.configurationToolStripMenuItem.Text = "設定"; this.aboutToolStripMenuItem.Text = "概要 ..."; this.floatingWindowToolStripMenuItem.Text = "フローティング・ウインドウ"; this.showFloatingWindowToolStripMenuItem.Text = "フローティング・ウインドウを表示する"; this.hideFloatingWindowToolStripMenuItem.Text = "フローティング・ウインドウを隠す"; this.resetFloatingWindowPositionToolStripMenuItem.Text = "ここに位置をリセット"; this.exitToolStripMenuItem.Text = "出口"; } else { this.configurationToolStripMenuItem.Text = "Configurations"; this.aboutToolStripMenuItem.Text = "About ..."; this.floatingWindowToolStripMenuItem.Text = "Floating Window"; this.showFloatingWindowToolStripMenuItem.Text = "Show floating window"; this.hideFloatingWindowToolStripMenuItem.Text = "Hide floating window"; this.resetFloatingWindowPositionToolStripMenuItem.Text = "Reset position here"; this.exitToolStripMenuItem.Text = "Exit"; } } else { // if the cannot read the configuration file successfully, show error message MessageBox.Show("Cannot find the configuration file or the configuration file corrupted.\nPlease try to apply default setting to correct it."); } }
private void LoadSetting() { // load the configuration file by using common loading function if (commonSet.LoadSetting()) { // if the read is success, assign the value to different variable loadedLanguageIndex = commonSet.loadedLanguageIndex; loadedInterfaceName = commonSet.loadedInterfaceName; if (commonSet.GetInterfaceIndexWithName(loadedInterfaceName) != -1) { loadedInterfaceIndex = commonSet.GetInterfaceIndexWithName(loadedInterfaceName); } else { // set default index if the interfaced cannot be found loadedInterfaceIndex = 0; } loadedUpdateFrequency = commonSet.loadedUpdateFrequency; loadedSpeedUnitIndex = commonSet.loadedSpeedUnitIndex; loadedSpeedUnit = commonSet.loadedSpeedUnit; loadedDisplayMethodIndex = commonSet.loadedDisplayMethodIndex; loadedDisplaySizeIndex = commonSet.loadedDisplaySizeIndex; loadedDarkThemeIndex = commonSet.loadedDarkThemeIndex; loadedAutoStartCheck = commonSet.loadedAutoStartCheck; // set "loading" for different languages if (commonSet.loadedLanguageIndex == 0) { this.UploadTrafficTextBlock.Text = "Loading..."; this.DownloadTrafficTextBlock.Text = "Loading..."; } else if (commonSet.loadedLanguageIndex == 1) { // for Chinese this.UploadTrafficTextBlock.Text = "加載中..."; this.DownloadTrafficTextBlock.Text = "加載中..."; } else if (commonSet.loadedLanguageIndex == 2) { // *** please add Japanese version this.UploadTrafficTextBlock.Text = "ローディング..."; this.DownloadTrafficTextBlock.Text = "ローディング..."; } } else { // if the cannot read the configuration file successfully, show error message MessageBox.Show("Cannot find the configuration file or the configuration file corrupted.\nPlease try to apply default setting to correct it."); } #region Old Loading code /* * try * { * using (System.IO.StreamReader file = new System.IO.StreamReader(System.AppDomain.CurrentDomain.BaseDirectory + configFileName)) * { * bool formatError = false; * // read interface index * if (!Int32.TryParse(file.ReadLine(), out loadedInterfaceIndex)) * { * formatError = true; * } * else * { * // check if the index is in range * if (loadedInterfaceIndex < 0 || loadedInterfaceIndex >= interfaces.Length) * { * formatError = true; * } * } * * // read update frequency * if (!Double.TryParse(file.ReadLine(), out loadedUpdateFrequency)) * { * formatError = true; * } * // check if the update frequency is in range * else if (loadedUpdateFrequency < minFrequency || loadedUpdateFrequency > maxFrequency) * { * formatError = true; * } * * // read speed unit index * if (!Int32.TryParse(file.ReadLine(), out loadedSpeedUnitIndex)) * { * formatError = true; * } * else if (loadedSpeedUnitIndex < 0 || loadedSpeedUnitIndex > numberOfSpeedUnit) * { * formatError = true; * } * * // read speed unit * loadedSpeedUnit = file.ReadLine(); * * // read show method index * if (!Int32.TryParse(file.ReadLine(), out loadedDisplayMethodIndex)) * { * formatError = true; * } * else if (loadedDisplayMethodIndex < 0 || loadedDisplayMethodIndex > 3) * { * formatError = true; * } * * // read floating window size index * if (!Int32.TryParse(file.ReadLine(), out loadedDisplaySizeIndex)) * { * formatError = true; * } * else if (loadedDisplaySizeIndex < 0 || loadedDisplaySizeIndex >= numberOfWindowSize) * { * formatError = true; * } * * // read auto start option * if (!Boolean.TryParse(file.ReadLine(), out loadedAutoStartCheck)) * { * formatError = true; * } * * // check if the format of file correct * if (formatError) * { * // format of the file is wrong, show error message * MessageBox.Show("Configuration file corrupted\nPlease try to apply default setting to correct it"); * } * else * { * configurationReaded = true; * } * * } * } * catch * { * // error occur, show error message * MessageBox.Show("Cannot find the configuration file or the configuration file corrupted\nPlease try to apply default setting to correct it"); * }*/ #endregion }