private void LoadSettings() { this.m_moduleNames = new string[this.m_genericInputMethods.Count]; this.m_moduleXMLFilePaths = new string[this.m_genericInputMethods.Count]; this.m_moduleDictionaries = new Dictionary <string, string> [this.m_genericInputMethods.Count]; int i = 0; foreach (KeyValuePair <string, string> kvp in m_genericInputMethods) { string cin = kvp.Key; this.m_moduleNames[i] = cin; this.m_moduleXMLFilePaths[i] = TakaoHelper.GetXMLFullPath(m_venderIdentifer + "." + cin + ".plist"); this.m_moduleDictionaries[i] = TakaoHelper.DictionaryFromFile(m_moduleXMLFilePaths[i]); try { // The default values; this.m_moduleDictionaries[i].Add("MaximumRadicalLength", "20"); this.m_moduleDictionaries[i].Add("ShouldCommitAtMaximumRadicalLength", "false"); this.m_moduleDictionaries[i].Add("ClearReadingBufferAtCompositionError", "false"); this.m_moduleDictionaries[i].Add("MatchOneChar", "?"); this.m_moduleDictionaries[i].Add("MatchZeroOrMoreChar", "*"); this.m_moduleDictionaries[i].Add("UseDynamicFrequency", "false"); } catch { } this.u_modulesListBox.Items.Add(kvp.Value); PanelGenericSettings setting = new PanelGenericSettings(cin, kvp.Value, m_moduleDictionaries[i], u_applyButton); this.AddPanel(setting, cin); i++; } this.u_modulesListBox.SelectedIndex = 0; }
/// <summary> /// To dump the content of a dictionary. /// </summary> /// <param name="dictionary"></param> public static void PrintDictionary(Dictionary <string, string> dictionary) { foreach (KeyValuePair <string, string> kvp in dictionary) { string msg = "key: " + kvp.Key + "=> value: " + kvp.Value; TakaoHelper.msg(msg); } }
public void SaveSettings() { int i = 0; foreach (string cin in m_moduleNames) { TakaoHelper.DictionaryToFile(m_moduleDictionaries[i], m_moduleXMLFilePaths[i]); i++; } }
private static void LaunchDownloadUpdateAppMuteInThread() { string filename = Application.StartupPath + Path.DirectorySeparatorChar + "ServiceUI.exe"; string locale = CultureInfo.CurrentCulture.Name; try { string sourceURL = UpdateHelper.ActionURL(); string signatureURL = UpdateHelper.SignatureURL(); string sourceFile = TakaoHelper.GetTempFilePathFromURL(sourceURL); string sigantureFile = TakaoHelper.GetTempFilePathFromURL(signatureURL); string changeLogURL = UpdateHelper.LocaleTaggedChangeLogURL(); if (changeLogURL.Length == 0) { changeLogURL = "(null)"; } string args = "download " + sourceURL + " " + sourceFile + " " + signatureURL + " " + sigantureFile + " " + changeLogURL + " false"; Process serviceApp = Process.Start(filename, args); } catch (Exception) { } }
private void u_moduleCheckListBox_SelectedValueChanged(object sender, EventArgs e) { if (this.m_init) { return; } if (this.u_moduleCheckListBox.CheckedItems.Count == 0) { this.u_moduleCheckListBox.SetItemChecked(this.u_moduleCheckListBox.SelectedIndex, true); } try { this.m_generalDictionary.Remove("ModulesSuppressedFromUI"); } catch { } int i = 0; List <string> modules = new List <string>(); foreach (KeyValuePair <string, string> kvp in m_modulesDictionary) { bool itemChecked = u_moduleCheckListBox.GetItemChecked(i); if (itemChecked == false) { string moduleName = kvp.Key; modules.Add(moduleName); } i++; } string serializedString = TakaoHelper.SerializeListToString(modules); this.m_generalDictionary.Add("ModulesSuppressedFromUI", serializedString); this.u_applyButton.Enabled = true; }
private static void LaunchDownloadUpdateAppInThread() { string filename = Application.StartupPath + Path.DirectorySeparatorChar + "ServiceUI.exe"; string locale = CultureInfo.CurrentCulture.Name; try { string sourceURL = UpdateHelper.ActionURL(); string signatureURL = UpdateHelper.SignatureURL(); string sourceFile = TakaoHelper.GetTempFilePathFromURL(sourceURL); string sigantureFile = TakaoHelper.GetTempFilePathFromURL(signatureURL); string changeLogURL = UpdateHelper.LocaleTaggedChangeLogURL(); if (changeLogURL.Length == 0) { changeLogURL = "(null)"; } string args = "download " + sourceURL + " " + sourceFile + " " + signatureURL + " " + sigantureFile + " " + changeLogURL + " false"; Process serviceApp = Process.Start(filename, args); } catch (Exception) { if (locale == "zh-TW") { MessageBox.Show("\u7121\u6cd5\u4e0b\u8f09\u66f4\u65b0\u6a94\u6848\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684 Yahoo! \u5947\u6469\u8f38\u5165\u6cd5\u662f\u5426\u5b89\u88dd\u6b63\u78ba\u3002", "\u932f\u8aa4\uff01"); } else if (locale == "zh-CN") { MessageBox.Show("\u65e0\u6cd5\u4e0b\u8f7d\u66f4\u65b0\u6863\u6848\uff0c\u8bf7\u68c0\u67e5\u60a8\u7684 Yahoo! \u5947\u6469\u8f93\u5165\u6cd5\u662f\u5426\u5b89\u88c5\u6b63\u786e\u3002", "\u9519\u8bef\uff01"); } else { MessageBox.Show("Unable to download update! Please check your installation of Yahoo! Keykey. ", "Error!"); } } }
public static string GetTempFilePathFromURL(string URL) { string filename = URL.Remove(0, URL.LastIndexOf('/') + 1); return(TakaoHelper.GetEnvTempDir() + Path.DirectorySeparatorChar + filename); }
public static string GetTempFilePath(string filename) { return(TakaoHelper.GetEnvTempDir() + Path.DirectorySeparatorChar + filename); }
/// <summary> /// To dump the content of a dictionary. /// </summary> /// <param name="dictionary"></param> public static void DumpDictionary(Dictionary <string, string> dictionary) { TakaoHelper.PrintDictionary(dictionary); }
/// <summary> /// A helper to generate a dicitonary from a plist(xml) file. /// </summary> /// <param name="filename">The filename of the xml source.</param> /// <returns></returns> public static Dictionary <string, string> DictionaryFromFile(string filename) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (System.IO.File.Exists(filename)) { try { XmlTextReader myReader = new XmlTextReader(filename); myReader.XmlResolver = null; string myKey = ""; string myValue = ""; List <string> items = new List <string>(); while (myReader.Read()) { if (myReader.NodeType == XmlNodeType.Element) { if (myReader.Name == "key") { myReader.Read(); myKey = myReader.Value.Trim(); } if (myReader.Name == "array") { if (myReader.IsEmptyElement) { items.Clear(); } else { while (myReader.Read() && !(myReader.NodeType == XmlNodeType.EndElement && myReader.Name == "array")) { if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "string") { myReader.Read(); items.Add(myReader.Value.Trim()); } } } myValue = TakaoHelper.SerializeListToString(items); TakaoHelper.msg(myValue); if (myKey.Length > 0) { dictionary.Add(myKey, myValue); } items.Clear(); myKey = ""; myValue = ""; } if (myReader.Name == "string") { myReader.Read(); myValue = myReader.Value.Trim(); if (myKey.Length > 0) { dictionary.Add(myKey, myValue); } myKey = ""; myValue = ""; } } } myReader.Close(); } catch { } } return(dictionary); }
/// <summary> /// Write preference into XML files. /// </summary> private void SaveSettings() { #region Avoid keykey.plist changes by UI during setting preference. Dictionary <string, string> currenGeneralDictionary = TakaoHelper.DictionaryFromFile(m_generalXMLpath); if (currenGeneralDictionary.Count > 0) { string ActivatedAroundFiltersStirng; currenGeneralDictionary.TryGetValue("ActivatedAroundFilters", out ActivatedAroundFiltersStirng); try { if (ActivatedAroundFiltersStirng == null || ActivatedAroundFiltersStirng.Length == 0) { ActivatedAroundFiltersStirng = "ARRAY:"; } else { string stringToExplode = ActivatedAroundFiltersStirng.Remove(0, 6); string[] aroundFilters = stringToExplode.Split(", ".ToCharArray()); ActivatedAroundFiltersStirng = "ARRAY:"; int count = 0; foreach (string aroundFilter in aroundFilters) { if (aroundFilter.StartsWith("ReverseLookup-")) { continue; } ActivatedAroundFiltersStirng += aroundFilter; if (count < aroundFilters.Length - 1) { ActivatedAroundFiltersStirng += ", "; } count++; } } } catch { } try { // If lookup is enabled; if (this.u_panelGeneral.ReverseLookupMethod.Length > 0) { if (ActivatedAroundFiltersStirng == "ARRAY:") { ActivatedAroundFiltersStirng = "ARRAY:" + this.u_panelGeneral.ReverseLookupMethod; } else { ActivatedAroundFiltersStirng += ", " + this.u_panelGeneral.ReverseLookupMethod; } } } catch { } string ActivatedOutputFiltersString; currenGeneralDictionary.TryGetValue("ActivatedOutputFilters", out ActivatedOutputFiltersString); try { if (ActivatedOutputFiltersString == null || ActivatedOutputFiltersString.Length == 0) { ActivatedOutputFiltersString = "ARRAY:"; } } catch { } string PrimaryInputMethod; currenGeneralDictionary.TryGetValue("PrimaryInputMethod", out PrimaryInputMethod); try { m_generalDictionary.Remove("ActivatedAroundFilters"); m_generalDictionary.Remove("ActivatedOutputFilters"); m_generalDictionary.Remove("PrimaryInputMethod"); m_generalDictionary.Add("ActivatedAroundFilters", ActivatedAroundFiltersStirng); m_generalDictionary.Add("ActivatedOutputFilters", ActivatedOutputFiltersString); m_generalDictionary.Add("PrimaryInputMethod", PrimaryInputMethod); } catch { } } #endregion TakaoHelper.DictionaryToFile(m_generalDictionary, m_generalXMLpath); TakaoHelper.DictionaryToFile(m_traditionalPhoneticDictionary, m_traditionalPhoneticXMLpath); TakaoHelper.DictionaryToFile(m_smartPhoneticDictionary, m_smartPhoneticXMLpath); TakaoHelper.DictionaryToFile(m_cangjieDictionary, m_cangjieXMLpath); TakaoHelper.DictionaryToFile(m_simplexDictionary, m_simplexXMLpath); TakaoHelper.DictionaryToFile(m_searchDictionary, m_oneKeyXMLpath); if (this.m_hasGenericInputMethods) { this.u_panelGeneric.SaveSettings(); } }
/// <summary> /// Initializing configurations from saved XML files. /// </summary> private void LoadSettings() { #region Loading properties // Load the settings from the XML files into Dictionary objects. this.m_generalDictionary = TakaoHelper.DictionaryFromFile(m_generalXMLpath); this.m_traditionalPhoneticDictionary = TakaoHelper.DictionaryFromFile(m_traditionalPhoneticXMLpath); this.m_smartPhoneticDictionary = TakaoHelper.DictionaryFromFile(m_smartPhoneticXMLpath); this.m_cangjieDictionary = TakaoHelper.DictionaryFromFile(m_cangjieXMLpath); this.m_simplexDictionary = TakaoHelper.DictionaryFromFile(m_simplexXMLpath); this.m_searchDictionary = TakaoHelper.DictionaryFromFile(m_oneKeyXMLpath); // If some important settings do not exist in the XML files, we add them here with the default value. try { // The default general settings this.TryAddValueInDictionary(this.m_generalDictionary, "ShouldUseNotifyWindow", "true"); this.TryAddValueInDictionary(this.m_generalDictionary, "ShouldUseTransparentStatusBar", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "ShouldPlaySoundOnTypingError", "true"); this.TryAddValueInDictionary(this.m_generalDictionary, "SoundFilename", "Default"); this.TryAddValueInDictionary(this.m_generalDictionary, "ShouldCheckUpdateOnLaunch", "true"); this.TryAddValueInDictionary(this.m_generalDictionary, "IgnoreShiftAsAlphanumericModeToggleKey", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "EnablesCapsLockAsAlphanumericModeToggle", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "ToggleInputMethodWithControlBackslash", "true"); this.TryAddValueInDictionary(this.m_generalDictionary, "HighlightColor", "Purple"); this.TryAddValueInDictionary(this.m_generalDictionary, "BackgroundColor", "Black"); this.TryAddValueInDictionary(this.m_generalDictionary, "TextColor", "White"); this.TryAddValueInDictionary(this.m_generalDictionary, "BackgroundPattern", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "ShouldUseSystemTray", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "ChineseConverterToggleKey", "s"); this.TryAddValueInDictionary(this.m_generalDictionary, "RepeatLastCommitTextKey", "g"); this.TryAddValueInDictionary(this.m_generalDictionary, "KeyboardFormShouldFollowCursor", "false"); this.TryAddValueInDictionary(this.m_generalDictionary, "ModulesSuppressedFromUI", "ARRAY:"); // The default settings for the Traditional Phonetic Input Method this.TryAddValueInDictionary(this.m_traditionalPhoneticDictionary, "KeyboardLayout", "Standard"); this.TryAddValueInDictionary(this.m_traditionalPhoneticDictionary, "UseCharactersSupportedByEncoding", ""); // The default settings for the Smart Phonetic Input Method this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "KeyboardLayout", "Standard"); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "UseCharactersSupportedByEncoding", ""); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "ClearComposingTextWithEsc", "false"); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "ShowCandidateListWithSpace", "false"); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "UseCharactersSupportedByEncoding", ""); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "CandidateCursorAtEndOfTargetBlock", "false"); this.TryAddValueInDictionary(this.m_smartPhoneticDictionary, "ComposingTextBufferSize", "10"); // The default settings for CangJie Input Method this.TryAddValueInDictionary(this.m_cangjieDictionary, "ShouldCommitAtMaximumRadicalLength", "false"); this.TryAddValueInDictionary(this.m_cangjieDictionary, "UseDynamicFrequency", "false"); this.TryAddValueInDictionary(this.m_cangjieDictionary, "ClearReadingBufferAtCompositionError", "true"); this.TryAddValueInDictionary(this.m_cangjieDictionary, "ComposeWhileTyping", "false"); this.TryAddValueInDictionary(this.m_cangjieDictionary, "UseOverrideTable", "Punctuations-punctuations-cin"); this.TryAddValueInDictionary(this.m_cangjieDictionary, "UseCharactersSupportedByEncoding", ""); // The default settings for Simplex Input Method this.TryAddValueInDictionary(this.m_simplexDictionary, "ClearReadingBufferAtCompositionError", "true"); this.TryAddValueInDictionary(this.m_simplexDictionary, "ComposeWhileTyping", "false"); this.TryAddValueInDictionary(this.m_simplexDictionary, "UseCharactersSupportedByEncoding", ""); this.TryAddValueInDictionary(this.m_searchDictionary, "ShortcutKey", "`"); } catch (ArgumentException) { // @zonble // If some keys are already there, the Add() method will raise exceptions. // However, we ignore these exceptions. } #endregion }