public void LoadFile(string path) { string qualifier = null; string qualifier2 = null; int colon = path.IndexOf(':', Path.IsPathRooted(path) ? 2 : 0); if (colon >= 0) { qualifier = path.Substring(colon + 1); path = path.Substring(0, colon); } if (qualifier != null) { colon = qualifier.IndexOf(':'); if (colon >= 0) { qualifier2 = qualifier.Substring(colon + 1); qualifier = qualifier.Substring(0, colon); } } ITextStorageFactory factory = null; if (!String.IsNullOrEmpty(qualifier2)) { try { effectiveBackingStore = (BackingStore)Enum.Parse(typeof(BackingStore), qualifier2); } catch (ArgumentException) { throw new Exception(String.Format("Buffer qualifier '{0}' is not recognized - should be one of '{1}' or '{2}'", qualifier, BackingStore.String, BackingStore.Utf8SplayGapBuffer)); } factory = GetBackingStore(effectiveBackingStore); } else if (this.textEditControl.TextStorageFactory == null) { factory = GetBackingStore(MainClass.Config.BackingStore); } if (factory != null) { this.textEditControl.Reload(factory, factory.New()); } if (String.IsNullOrEmpty(qualifier)) { EncodingInfo encodingInfo = GuessEncoding(path); Type[] permittedEncodings = null; if (this.textEditControl.TextStorageFactory != null) { permittedEncodings = this.textEditControl.TextStorageFactory.PermittedEncodings; } if (permittedEncodings != null) { if (Array.FindIndex(permittedEncodings, delegate (Type candidate) { return candidate.IsInstanceOfType(encodingInfo.Encoding); }) < 0) { MessageBox.Show("Specified encoding is not permitted by specified backing store. Falling back to 'String' backing store.", "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); TextEditorWindow replacementWindow = new TextEditorWindow(false/*createBackingStore*/); ITextStorageFactory stringStorageFactory = replacementWindow.GetBackingStore(BackingStore.String); replacementWindow.textEditControl.Reload(stringStorageFactory, stringStorageFactory.New()); replacementWindow.LoadFile(path, encodingInfo); replacementWindow.Show(); throw new ApplicationException(); // cancel the old window } } LoadFile(path, encodingInfo); } else { switch (qualifier.ToLower()) { default: throw new Exception(String.Format("Encoding qualifier '{0}' is not recognized - should be one of 'ansi', 'utf8', 'utf16', or 'utf16be'", qualifier)); case "ansi": LoadFile(path, new EncodingInfo(Encoding_ANSI, 0)); break; case "utf8": LoadFile(path, new EncodingInfo(Encoding_UTF8, 0)); break; case "utf16": LoadFile(path, new EncodingInfo(Encoding_UTF16, 0)); break; case "utf16be": LoadFile(path, new EncodingInfo(Encoding_UTF16BigEndian, 0)); break; } } }