Skip to content

Commit e121c9e

Browse files
committed
Added a clause to prevent discarding of the filename provided by the user
1 parent 590a534 commit e121c9e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponent.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,27 @@ public bool HasDesigner
107107
/// <param name="folder">Destination folder for the resulting source file.</param>
108108
/// <param name="isTempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
109109
/// <param name="specialCaseDocumentModules">If reimport of a document file is required later, it has to receive special treatment.</param>
110-
public string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true)
110+
public string ExportAsSourceFile(string folderOrPath, bool isTempFile = false, bool specialCaseDocumentModules = true)
111111
{
112112
//TODO: this entire thign needs to be reworked. IO is not the class' concern.
113113
//We probably need to leverage IPersistancePathProvider? ITempSourceFileHandler?
114114
//Just not here.
115-
var fullPath = isTempFile
116-
? _fileSystem.Path.Combine(folder, _fileSystem.Path.GetRandomFileName())
117-
: _fileSystem.Path.Combine(folder, SafeName + Type.FileExtension());
115+
string fullPath;
116+
if (_fileSystem.Path.HasExtension(folderOrPath))
117+
{
118+
fullPath = folderOrPath;
119+
}
120+
else
121+
{
122+
fullPath = isTempFile
123+
? _fileSystem.Path.Combine(folderOrPath, _fileSystem.Path.GetRandomFileName())
124+
: _fileSystem.Path.Combine(folderOrPath, SafeName + Type.FileExtension());
125+
}
118126

119-
if (!_fileSystem.Directory.Exists(folder))
127+
var dir = _fileSystem.Path.GetDirectoryName(fullPath);
128+
if (!_fileSystem.Directory.Exists(dir))
120129
{
121-
_fileSystem.Directory.CreateDirectory(folder);
130+
_fileSystem.Directory.CreateDirectory(dir);
122131
}
123132

124133
switch (Type)

0 commit comments

Comments
 (0)