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
|
||||
'// 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("")
|
||||
'// 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()
|
||||
|
||||
Using 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
|
||||
|
||||
'// 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
|
||||
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 strOutFile As String = Path.Combine(Path.GetTempPath(), oTempFileName)
|
||||
'// 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.
|
||||
'//
|
||||
'// 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
|
||||
If oMemoryStreamInput Is Nothing = False Then
|
||||
'// allocate enough bytes to hold the raw date
|
||||
Dim aryFileBytes(CType(oMemoryStreamInput.Length, Int32)) As Byte
|
||||
'// set starting position at first byte and read in the raw data
|
||||
oMemoryStreamInput.Position = 0
|
||||
oMemoryStreamInput.Read(aryFileBytes, 0, CType(oMemoryStreamInput.Length, Int32))
|
||||
'// create a file and save the raw zip file to it
|
||||
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
|
||||
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
|
||||
fsOutput.Close() ' // close the file
|
||||
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
||||
If resultVersion <> "" Then
|
||||
strOutFile = resultVersion
|
||||
End If
|
||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||
'// always good to make sure we actually created the file
|
||||
If (finTemp.Exists = True) Then
|
||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||
'Dim oMemoryStreamInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
||||
Using oStream As MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream)
|
||||
If oStream Is Nothing = False Then
|
||||
'// allocate enough bytes to hold the raw date
|
||||
Dim aryFileBytes(CType(oStream.Length, Int32)) As Byte
|
||||
'// set starting position at first byte and read in the raw data
|
||||
oStream.Position = 0
|
||||
oStream.Read(aryFileBytes, 0, CType(oStream.Length, Int32))
|
||||
'// create a file and save the raw zip file to it
|
||||
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
|
||||
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
|
||||
fsOutput.Close() ' // close the file
|
||||
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
||||
If resultVersion <> "" Then
|
||||
strOutFile = resultVersion
|
||||
End If
|
||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||
'// always good to make sure we actually created the file
|
||||
If (finTemp.Exists = True) Then
|
||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||
|
||||
'ReDim Preserve FilesDropped(0)
|
||||
'FilesDropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
||||
'ReDim Preserve FilesDropped(0)
|
||||
'FilesDropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
||||
|
||||
Return True
|
||||
Else
|
||||
LOGGER.Info("Attachment File from Outlook could not be created")
|
||||
Return True
|
||||
Else
|
||||
LOGGER.Info("Attachment File from Outlook could not be created")
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Using
|
||||
End If
|
||||
If e.Data.GetDataPresent("FileGroupDescriptor") Then
|
||||
Dim oApp As Outlook.Application
|
||||
@ -115,9 +123,11 @@ Public Class ClassFileDrop
|
||||
End If
|
||||
|
||||
'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
|
||||
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("!", "")
|
||||
@ -146,6 +156,7 @@ Public Class ClassFileDrop
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
MsgBox("Error in Drop-File" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
@ -6,21 +6,26 @@ Imports DigitalData.Modules.Language
|
||||
Imports Limilabs.Mail
|
||||
|
||||
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
|
||||
'TODO: Before doing anything, clean the filename
|
||||
Dim oFilename = IO.Path.GetFileName(pFilepath)
|
||||
Dim oCleanFileName = Utils.RemoveInvalidCharacters(oFilename)
|
||||
Dim oTempDirectory = IO.Path.GetTempPath()
|
||||
Dim oTempFilePath = IO.Path.Combine(oTempDirectory, oCleanFileName)
|
||||
''TODO: Before doing anything, clean the filename
|
||||
'Dim oFilename = IO.Path.GetFileName(pFilepath)
|
||||
'Dim oCleanFileName = Utils.RemoveInvalidCharacters(oFilename)
|
||||
'Dim oTempDirectory = IO.Path.GetTempPath()
|
||||
'Dim oTempFilePath = IO.Path.Combine(oTempDirectory, oCleanFileName)
|
||||
|
||||
Try
|
||||
TEMP_FILES.Add(oTempFilePath)
|
||||
IO.File.Copy(pFilepath, oTempFilePath, True)
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
'Try
|
||||
' TEMP_FILES.Add(oTempFilePath)
|
||||
' LOGGER.Debug("Copying file")
|
||||
' LOGGER.Debug(pFilepath)
|
||||
' LOGGER.Debug(oTempFilePath)
|
||||
' IO.File.Copy(pFilepath, oTempFilePath, True)
|
||||
'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
|
||||
CURRENT_MESSAGEID = ""
|
||||
|
||||
@ -210,7 +210,7 @@
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<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 Include="Oracle.ManagedDataAccess">
|
||||
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath>
|
||||
|
||||
@ -713,7 +713,7 @@ Public Class frmIndex
|
||||
End Try
|
||||
|
||||
End Function
|
||||
Private Function Write_Indizes()
|
||||
Private Function Write_Indizes() As Boolean
|
||||
Try
|
||||
_Logger.NewBlock("Write_Indizes")
|
||||
_Logger.Info("Indexing file [{0}]", CURRENT_NEWFILENAME)
|
||||
@ -906,7 +906,7 @@ Public Class frmIndex
|
||||
Dim oSubject As String = oMail.Subject
|
||||
Dim oDateIn As Date = oMail.Date
|
||||
|
||||
CURRENT_MESSAGEID = oMessageFrom
|
||||
CURRENT_MESSAGEID = oMessageId
|
||||
CURRENT_MESSAGEDATE = oDateIn
|
||||
CURRENT_MESSAGESUBJECT = oSubject
|
||||
|
||||
@ -2785,33 +2785,13 @@ Public Class frmIndex
|
||||
Me.Close()
|
||||
End If
|
||||
End If
|
||||
|
||||
' Clear all temp files after indexing
|
||||
Clear_Tempfiles()
|
||||
EMAIL.Clear_TempFiles()
|
||||
|
||||
Catch ex As Exception
|
||||
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
|
||||
Me.Cursor = Cursors.Default
|
||||
End Try
|
||||
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
|
||||
SetFilePreview(checkItemPreview.Checked)
|
||||
CONFIG.Config.FilePreview = checkItemPreview.Checked
|
||||
|
||||
@ -136,9 +136,25 @@ Public Class frmStart
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
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 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()
|
||||
Try
|
||||
Hide()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.7.10" targetFramework="net461" />
|
||||
<package id="NLog" version="4.7.13" targetFramework="net461" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user