From d7a4a4441d723e0736eb8984421c1de92f1d3b36 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 26 Mar 2019 16:17:56 +0100 Subject: [PATCH] Add My ExportFile function --- Modules.Windream/Windream2.vb | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Modules.Windream/Windream2.vb b/Modules.Windream/Windream2.vb index 46506857..27028518 100644 --- a/Modules.Windream/Windream2.vb +++ b/Modules.Windream/Windream2.vb @@ -1101,6 +1101,69 @@ Public Class Windream2 Return False End Try End Function + + Public Function ExportFile(WMObject As WMObject, ExportPath As String) As Boolean + Try + Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6) + + Dim oFilenameFull As String = oWMObject.aName + Dim oFilenameExport As String + Dim oSplitIndex = oFilenameFull.LastIndexOf(".") + Dim oVersion = 1 + + Dim oFilename = oFilenameFull.Substring(0, oSplitIndex) + Dim oExtension = oFilenameFull.Substring(oSplitIndex) + + _logger.Debug("Preparing export of file {0}..", oFilenameFull) + _logger.Debug("Filename: {0}", oFilename) + _logger.Debug("Extension: {0}", oExtension) + + ' build the file path in case the exported file doesn't already exist + oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension) + + ' Add version until we find the version that does NOT exist + Do While File.Exists(oFilenameExport) + oVersion += 1 + oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension, oVersion) + Loop + + _logger.Debug("File will be exported to {0}", oFilenameExport) + + _logger.Debug("Opening file stream..") + Dim oStream As WMStream = oWMObject.OpenStream("BinaryObject", WMObjectStreamOpenMode.WMObjectStreamOpenModeRead) + Dim oWMFileIO As New WMFileIO() With { + .aWMStreamEx = oStream, + .aWMStream = oStream, + .bstrOriginalFileName = oFilenameExport + } + + _logger.Debug("Exporting file..") + oWMFileIO.ExportOriginal(True) + + _logger.Debug("Cleaning up..") + oStream.Flush() + oStream.Close() + + _logger.Debug("File exported to {0}", oFilenameExport) + Return True + Catch ex As Exception + _logger.Error(ex) + Return False + End Try + End Function + + Private Function BuildExportPath(BasePath As String, FilenameWithoutExtension As String, Extension As String, Optional Version As Integer = 1) + Dim oFilename + + If Version = 1 Then + oFilename = FilenameWithoutExtension & Extension + Else + oFilename = FilenameWithoutExtension & "_" & Version & Extension + End If + + Return Path.Combine(BasePath, oFilename) + End Function + Public Function Export_WMFile(WMPath As String, Exportpath As String) Try If Not Exportpath.EndsWith("\") Then