private AssocQueryString ( ASSOCF flags, ASSOCSTR str, string pszAssoc, string pszExtra, [ pszOut, uint &pcchOut ) : HRESULT | ||
flags | ASSOCF | |
str | ASSOCSTR | |
pszAssoc | string | |
pszExtra | string | |
pszOut | [ | |
pcchOut | uint | |
return | HRESULT |
/// <summary> /// Find the preferred application for .txt files and launch it to /// open .XCompose. If the file does not exist, try .XCompose.txt /// instead. If it doesn’t exist either, create .XCompose ourselves. /// </summary> public static void EditCustomRulesFile() { // Ensure the rules file exists. string user_file = Path.Combine(GetUserDir(), ".XCompose"); if (!File.Exists(user_file)) { string alt_file = Path.Combine(GetUserDir(), ".XCompose.txt"); if (File.Exists(alt_file)) { user_file = alt_file; } else { using (var s = File.OpenWrite(user_file)) using (var sw = new StreamWriter(s, new UTF8Encoding(true))) { sw.WriteLine("# Custom rule file for WinCompose"); sw.WriteLine(""); sw.WriteLine("# This causes Compose + h + w to print “Hello World!”."); sw.WriteLine("<Multi_key> <h> <w> : \"Hello world!\""); sw.WriteLine(""); sw.WriteLine("# More rule examples can be found in " + GetExeDir() + "\\res"); sw.WriteLine(""); } } } // Find the preferred application for .txt files HRESULT ret; uint length = 0; ret = NativeMethods.AssocQueryString(ASSOCF.NONE, ASSOCSTR.EXECUTABLE, ".txt", null, null, ref length); if (ret != HRESULT.S_FALSE) { return; } var sb = new StringBuilder((int)length); ret = NativeMethods.AssocQueryString(ASSOCF.NONE, ASSOCSTR.EXECUTABLE, ".txt", null, sb, ref length); if (ret != HRESULT.S_OK) { return; } // Open the rules file with that application var psinfo = new ProcessStartInfo { FileName = sb.ToString(), Arguments = user_file, UseShellExecute = true, }; Process.Start(psinfo); }
/// <summary> /// Find the preferred application for .txt files and launch it to /// open .XCompose. If the file does not exist, try .XCompose.txt /// instead. If it doesn’t exist either, create .XCompose ourselves. /// </summary> public static void EditCustomRulesFile() { // Ensure the rules file exists. string user_file = Path.Combine(GetUserDir(), ".XCompose"); if (!File.Exists(user_file)) { string alt_file = Path.Combine(GetUserDir(), ".XCompose.txt"); string default_file = Path.Combine(GetDataDir(), "DefaultUserSequences.txt"); if (File.Exists(alt_file)) { user_file = alt_file; } else if (File.Exists(default_file)) { var text = File.ReadAllText(default_file); var replacedText = text.Replace("%DataDir%", GetDataDir()); File.WriteAllText(user_file, replacedText, Encoding.UTF8); } } // Find the preferred application for .txt files HRESULT ret; uint length = 0; ret = NativeMethods.AssocQueryString(ASSOCF.NONE, ASSOCSTR.EXECUTABLE, ".txt", null, null, ref length); if (ret != HRESULT.S_FALSE) { return; } var sb = new StringBuilder((int)length); ret = NativeMethods.AssocQueryString(ASSOCF.NONE, ASSOCSTR.EXECUTABLE, ".txt", null, sb, ref length); if (ret != HRESULT.S_OK) { return; } // Open the rules file with that application var psinfo = new ProcessStartInfo { FileName = sb.ToString(), Arguments = user_file, UseShellExecute = true, }; Process.Start(psinfo); }