fix file access error and illegal path error
This commit is contained in:
parent
a35d77d51f
commit
a921072556
@ -41,20 +41,26 @@ Public Class ClassFileDrop
|
|||||||
'//
|
'//
|
||||||
'// set up to obtain the aryFileGroupDescriptor
|
'// set up to obtain the aryFileGroupDescriptor
|
||||||
'// and extract the file name
|
'// and extract the file name
|
||||||
Dim oStream As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
|
||||||
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[512]
|
|
||||||
oStream.Read(aryFileGroupDescriptor, 0, 512)
|
|
||||||
'// used to build the stbFileName from the aryFileGroupDescriptor block
|
|
||||||
Dim stbFileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
|
Dim stbFileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
|
||||||
'// this trick gets the stbFileName of the passed attached file
|
|
||||||
Dim intCnt As Integer = 76
|
Using oStream As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
||||||
Do While aryFileGroupDescriptor(intCnt) <> 0
|
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[512]
|
||||||
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
|
oStream.Read(aryFileGroupDescriptor, 0, 512)
|
||||||
intCnt += 1
|
'// used to build the stbFileName from the aryFileGroupDescriptor block
|
||||||
Loop
|
|
||||||
oStream.Close()
|
'// this trick gets the stbFileName of the passed attached file
|
||||||
|
Dim intCnt As Integer = 76
|
||||||
|
Do While aryFileGroupDescriptor(intCnt) <> 0
|
||||||
|
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
|
||||||
|
intCnt += 1
|
||||||
|
Loop
|
||||||
|
oStream.Close()
|
||||||
|
End Using
|
||||||
|
|
||||||
'Sonderzeichen entfernen
|
'Sonderzeichen entfernen
|
||||||
Dim oTempFileName = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(stbFileName.ToString)
|
Dim oTempFileName = DigitalData.Modules.Language.Utils.ConvertTextToSlug(stbFileName.ToString)
|
||||||
|
LOGGER.Info("Slug for Filename: [{0}]", oTempFileName)
|
||||||
|
|
||||||
Dim oAttachments = e.Data.GetDataPresent("FileContents")
|
Dim oAttachments = e.Data.GetDataPresent("FileContents")
|
||||||
Dim strOutFile As String = Path.Combine(Path.GetTempPath(), oTempFileName)
|
Dim strOutFile As String = Path.Combine(Path.GetTempPath(), oTempFileName)
|
||||||
'// create the full-path name
|
'// create the full-path name
|
||||||
@ -64,35 +70,37 @@ Public Class ClassFileDrop
|
|||||||
'// data for the attached file and copy it to disk so we work on it.
|
'// data for the attached file and copy it to disk so we work on it.
|
||||||
'//
|
'//
|
||||||
'// get the actual raw file into memory
|
'// get the actual raw file into memory
|
||||||
Dim oMemoryStreamInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
'Dim oMemoryStreamInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
||||||
If oMemoryStreamInput Is Nothing = False Then
|
Using oStream As MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream)
|
||||||
'// allocate enough bytes to hold the raw date
|
If oStream Is Nothing = False Then
|
||||||
Dim aryFileBytes(CType(oMemoryStreamInput.Length, Int32)) As Byte
|
'// allocate enough bytes to hold the raw date
|
||||||
'// set starting position at first byte and read in the raw data
|
Dim aryFileBytes(CType(oStream.Length, Int32)) As Byte
|
||||||
oMemoryStreamInput.Position = 0
|
'// set starting position at first byte and read in the raw data
|
||||||
oMemoryStreamInput.Read(aryFileBytes, 0, CType(oMemoryStreamInput.Length, Int32))
|
oStream.Position = 0
|
||||||
'// create a file and save the raw zip file to it
|
oStream.Read(aryFileBytes, 0, CType(oStream.Length, Int32))
|
||||||
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
|
'// create a file and save the raw zip file to it
|
||||||
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
|
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
|
||||||
fsOutput.Close() ' // close the file
|
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
|
||||||
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
fsOutput.Close() ' // close the file
|
||||||
If resultVersion <> "" Then
|
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
||||||
strOutFile = resultVersion
|
If resultVersion <> "" Then
|
||||||
End If
|
strOutFile = resultVersion
|
||||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
End If
|
||||||
'// always good to make sure we actually created the file
|
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||||
If (finTemp.Exists = True) Then
|
'// always good to make sure we actually created the file
|
||||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
If (finTemp.Exists = True) Then
|
||||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||||
|
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||||
|
|
||||||
'ReDim Preserve FilesDropped(0)
|
'ReDim Preserve FilesDropped(0)
|
||||||
'FilesDropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
'FilesDropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
||||||
|
|
||||||
Return True
|
Return True
|
||||||
Else
|
Else
|
||||||
LOGGER.Info("Attachment File from Outlook could not be created")
|
LOGGER.Info("Attachment File from Outlook could not be created")
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
End Using
|
||||||
End If
|
End If
|
||||||
If e.Data.GetDataPresent("FileGroupDescriptor") Then
|
If e.Data.GetDataPresent("FileGroupDescriptor") Then
|
||||||
Dim oApp As Outlook.Application
|
Dim oApp As Outlook.Application
|
||||||
@ -115,9 +123,11 @@ Public Class ClassFileDrop
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
'Sonderzeichen entfernen
|
'Sonderzeichen entfernen
|
||||||
subj = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(subj)
|
Dim oSubjectSlug = DigitalData.Modules.Language.Utils.ConvertTextToSlug(subj)
|
||||||
|
LOGGER.Info("Subject Slug for Filename: [{0}]", oSubjectSlug)
|
||||||
|
|
||||||
'hardcode a destination path for testing
|
'hardcode a destination path for testing
|
||||||
Dim oFilename As String = IO.Path.Combine(Path.GetTempPath, subj + ".msg")
|
Dim oFilename As String = IO.Path.Combine(Path.GetTempPath, oSubjectSlug + ".msg")
|
||||||
|
|
||||||
oFilename = oFilename.Replace("?", "")
|
oFilename = oFilename.Replace("?", "")
|
||||||
oFilename = oFilename.Replace("!", "")
|
oFilename = oFilename.Replace("!", "")
|
||||||
@ -146,6 +156,7 @@ Public Class ClassFileDrop
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
LOGGER.Error(ex)
|
||||||
MsgBox("Error in Drop-File" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
MsgBox("Error in Drop-File" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
|
|||||||
@ -6,21 +6,26 @@ Imports DigitalData.Modules.Language
|
|||||||
Imports Limilabs.Mail
|
Imports Limilabs.Mail
|
||||||
|
|
||||||
Public Class ClassFilehandle
|
Public Class ClassFilehandle
|
||||||
Public Shared Function Decide_FileHandle(pFilepath As String, pHandletype As String)
|
Public Shared Function Decide_FileHandle(pFilepath As String, pHandletype As String) As Boolean
|
||||||
Try
|
Try
|
||||||
'TODO: Before doing anything, clean the filename
|
''TODO: Before doing anything, clean the filename
|
||||||
Dim oFilename = IO.Path.GetFileName(pFilepath)
|
'Dim oFilename = IO.Path.GetFileName(pFilepath)
|
||||||
Dim oCleanFileName = Utils.RemoveInvalidCharacters(oFilename)
|
'Dim oCleanFileName = Utils.RemoveInvalidCharacters(oFilename)
|
||||||
Dim oTempDirectory = IO.Path.GetTempPath()
|
'Dim oTempDirectory = IO.Path.GetTempPath()
|
||||||
Dim oTempFilePath = IO.Path.Combine(oTempDirectory, oCleanFileName)
|
'Dim oTempFilePath = IO.Path.Combine(oTempDirectory, oCleanFileName)
|
||||||
|
|
||||||
Try
|
'Try
|
||||||
TEMP_FILES.Add(oTempFilePath)
|
' TEMP_FILES.Add(oTempFilePath)
|
||||||
IO.File.Copy(pFilepath, oTempFilePath, True)
|
' LOGGER.Debug("Copying file")
|
||||||
Catch ex As Exception
|
' LOGGER.Debug(pFilepath)
|
||||||
LOGGER.Error(ex)
|
' LOGGER.Debug(oTempFilePath)
|
||||||
Throw ex
|
' IO.File.Copy(pFilepath, oTempFilePath, True)
|
||||||
End Try
|
'Catch ex As Exception
|
||||||
|
' LOGGER.Error(ex)
|
||||||
|
' Throw ex
|
||||||
|
'End Try
|
||||||
|
|
||||||
|
Dim oTempFilePath = pFilepath
|
||||||
|
|
||||||
If oTempFilePath.ToUpper.EndsWith(".MSG") Or oTempFilePath.ToUpper.EndsWith(".EML") Then
|
If oTempFilePath.ToUpper.EndsWith(".MSG") Or oTempFilePath.ToUpper.EndsWith(".EML") Then
|
||||||
CURRENT_MESSAGEID = ""
|
CURRENT_MESSAGEID = ""
|
||||||
|
|||||||
@ -210,7 +210,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.4.7.10\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.7.13\lib\net45\NLog.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Oracle.ManagedDataAccess">
|
<Reference Include="Oracle.ManagedDataAccess">
|
||||||
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath>
|
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath>
|
||||||
|
|||||||
@ -713,7 +713,7 @@ Public Class frmIndex
|
|||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
Private Function Write_Indizes()
|
Private Function Write_Indizes() As Boolean
|
||||||
Try
|
Try
|
||||||
_Logger.NewBlock("Write_Indizes")
|
_Logger.NewBlock("Write_Indizes")
|
||||||
_Logger.Info("Indexing file [{0}]", CURRENT_NEWFILENAME)
|
_Logger.Info("Indexing file [{0}]", CURRENT_NEWFILENAME)
|
||||||
@ -906,7 +906,7 @@ Public Class frmIndex
|
|||||||
Dim oSubject As String = oMail.Subject
|
Dim oSubject As String = oMail.Subject
|
||||||
Dim oDateIn As Date = oMail.Date
|
Dim oDateIn As Date = oMail.Date
|
||||||
|
|
||||||
CURRENT_MESSAGEID = oMessageFrom
|
CURRENT_MESSAGEID = oMessageId
|
||||||
CURRENT_MESSAGEDATE = oDateIn
|
CURRENT_MESSAGEDATE = oDateIn
|
||||||
CURRENT_MESSAGESUBJECT = oSubject
|
CURRENT_MESSAGESUBJECT = oSubject
|
||||||
|
|
||||||
@ -2785,33 +2785,13 @@ Public Class frmIndex
|
|||||||
Me.Close()
|
Me.Close()
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Clear all temp files after indexing
|
|
||||||
Clear_Tempfiles()
|
|
||||||
EMAIL.Clear_TempFiles()
|
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
MsgBox("Uncaught error while indexing: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
|
MsgBox("Uncaught error while indexing: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
|
||||||
|
|
||||||
' Clear all temp files in case of an error
|
|
||||||
Clear_Tempfiles()
|
|
||||||
EMAIL.Clear_TempFiles()
|
|
||||||
Finally
|
Finally
|
||||||
Me.Cursor = Cursors.Default
|
Me.Cursor = Cursors.Default
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub Clear_Tempfiles()
|
|
||||||
'TempDateien löschen
|
|
||||||
For Each oFile In TEMP_FILES
|
|
||||||
Try
|
|
||||||
System.IO.File.Delete(oFile)
|
|
||||||
Catch ex As Exception
|
|
||||||
LOGGER.Error(ex)
|
|
||||||
End Try
|
|
||||||
Next
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Private Sub checkItemPreview_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles checkItemPreview.CheckedChanged
|
Private Sub checkItemPreview_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles checkItemPreview.CheckedChanged
|
||||||
SetFilePreview(checkItemPreview.Checked)
|
SetFilePreview(checkItemPreview.Checked)
|
||||||
CONFIG.Config.FilePreview = checkItemPreview.Checked
|
CONFIG.Config.FilePreview = checkItemPreview.Checked
|
||||||
|
|||||||
@ -136,9 +136,25 @@ Public Class frmStart
|
|||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
LOGGER.Error(ex)
|
LOGGER.Error(ex)
|
||||||
MsgBox("Unexpected Error in Check_Dropped_Files:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
MsgBox("Unexpected Error in Check_Dropped_Files:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||||
|
|
||||||
|
Finally
|
||||||
|
' Clear all temp files after indexing
|
||||||
|
Clear_Tempfiles()
|
||||||
|
EMAIL.Clear_TempFiles()
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub Clear_Tempfiles()
|
||||||
|
'TempDateien löschen
|
||||||
|
For Each oFile In TEMP_FILES
|
||||||
|
Try
|
||||||
|
System.IO.File.Delete(oFile)
|
||||||
|
Catch ex As Exception
|
||||||
|
LOGGER.Error(ex)
|
||||||
|
End Try
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
Sub Open_IndexDialog()
|
Sub Open_IndexDialog()
|
||||||
Try
|
Try
|
||||||
Hide()
|
Hide()
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="NLog" version="4.7.10" targetFramework="net461" />
|
<package id="NLog" version="4.7.13" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user