From a94055b6abb963714571239c4aa4c0e423bc9845 Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Tue, 23 Oct 2012 16:31:58 +0000 Subject: [PATCH] Changes to store the file encoding of loaded files, so that they can be saved the same way. This means we'll need an 'export' feature to overide the setting. --- trunk/EditForm.cs | 2 +- trunk/Editor/SyntaxRichTextBox.cs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/trunk/EditForm.cs b/trunk/EditForm.cs index 919dfb2..d833609 100644 --- a/trunk/EditForm.cs +++ b/trunk/EditForm.cs @@ -289,7 +289,7 @@ namespace LSLEditor this.FullPathName = Path.GetFileName(strPath); else this.FullPathName = strPath; - this.numberedTextBoxUC1.TextBox.LoadFile(strPath); + this.encodedAs = this.numberedTextBoxUC1.TextBox.LoadFile(strPath); if (!this.IsScript) return; diff --git a/trunk/Editor/SyntaxRichTextBox.cs b/trunk/Editor/SyntaxRichTextBox.cs index 0e24d0b..f7d8287 100644 --- a/trunk/Editor/SyntaxRichTextBox.cs +++ b/trunk/Editor/SyntaxRichTextBox.cs @@ -2228,8 +2228,9 @@ namespace LSLEditor } } - public new void LoadFile(string path) + public new Encoding LoadFile(string path) { + Encoding fileEncoding = null; if (path.StartsWith("http://")) { System.Net.WebClient webClient = new System.Net.WebClient(); @@ -2240,14 +2241,21 @@ namespace LSLEditor if (File.Exists(path)) { // TODO needs to be refactored to read the file in once and pass the byte array to be checked. - Encoding fileEncoding = TextFileEncodingDetector.DetectTextFileEncoding(path, Encoding.UTF8); - StreamReader sr = new StreamReader(path, fileEncoding); - this.Text = sr.ReadToEnd(); - sr.Close(); + fileEncoding = TextFileEncodingDetector.DetectTextFileEncoding(path, Encoding.UTF8); + try + { + StreamReader sr = new StreamReader(path, fileEncoding); + this.Text = sr.ReadToEnd(); + sr.Close(); + } + catch + { + } } } // Fresh files can not be dirty ClearUndoStack(); + return fileEncoding; } } }