Skip to content

Commit 3e6b9ff

Browse files
committed
Changed file encoding when exporting user forms to the current windows codepage, both on read and write.
1 parent c9763e5 commit 3e6b9ff

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

RetailCoder.VBE/Common/ModuleExporter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
32
using System.Reflection;
43
using Rubberduck.Parsing.VBA;
54
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponent.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ private void ExportUserFormModule(string path)
114114

115115
var tempFile = ExportToTempFile();
116116
var tempFilePath = Directory.GetParent(tempFile).FullName;
117-
var contents = File.ReadAllLines(tempFile, System.Text.Encoding.UTF7);
117+
var fileEncoding = System.Text.Encoding.Default; //We use the current ANSI codepage because that is what the VBE does.
118+
var contents = File.ReadAllLines(tempFile, fileEncoding);
118119
var nonAttributeLines = contents.TakeWhile(line => !line.StartsWith("Attribute")).Count();
119120
var attributeLines = contents.Skip(nonAttributeLines).TakeWhile(line => line.StartsWith("Attribute")).Count();
120121
var declarationsStartLine = nonAttributeLines + attributeLines + 1;
@@ -130,7 +131,7 @@ private void ExportUserFormModule(string path)
130131
contents.Skip(declarationsStartLine + emptyLineCount - legitEmptyLineCount))
131132
.ToArray();
132133
}
133-
File.WriteAllLines(path, code);
134+
File.WriteAllLines(path, code, fileEncoding);
134135

135136
// LINQ hates this search, therefore, iterate the long way
136137
foreach (string line in contents)
@@ -165,8 +166,10 @@ private void ExportDocumentModule(string path)
165166
var lineCount = CodeModule.CountOfLines;
166167
if (lineCount > 0)
167168
{
169+
//One cannot reimport document modules as such in the VBE; so we simply export and import the contents of the code pane.
170+
//Because of this, it is OK, and actually preferable, to use the standard UTF8 encoding.
168171
var text = CodeModule.GetLines(1, lineCount);
169-
File.WriteAllText(path, text);
172+
File.WriteAllText(path, text);
170173
}
171174
}
172175

0 commit comments

Comments
 (0)