Fix filesystem refs

This commit is contained in:
Jonathan Jenne
2023-09-05 10:47:37 +02:00
parent af90bb9efe
commit 6f33261101
25 changed files with 132 additions and 1527 deletions

View File

@@ -1,5 +1,7 @@
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
Imports System.Runtime.Remoting.Messaging
Imports DigitalData.Modules.Logging
Imports GdPicture14
@@ -91,6 +93,64 @@ Public Class PDFEmbeds
End Try
End Function
Public Function RemoveEmbeddedFiles(pFilePath As String) As Boolean
Dim oFile As New List(Of EmbeddedFile)
Dim oFileInfo As FileInfo
Logger.Debug("Removing embedded files from [{0}]", pFilePath)
Try
oFileInfo = New FileInfo(pFilePath)
Logger.Debug("Filename: {0}", oFileInfo.Name)
Logger.Debug("Filesize: {0} bytes", oFileInfo.Length)
Logger.Debug("Exists: {0}", oFileInfo.Exists)
Catch ex As Exception
Logger.Warn("File information for [{0}] could not be read!", pFilePath)
Logger.Error(ex)
End Try
Try
Using oGDPicturePDF As New GdPicturePDF()
If oGDPicturePDF.LoadFromFile(pFilePath, False) <> GdPictureStatus.OK Then
Dim oMessage = String.Format("The file [{0}] can't be loaded. Status: [{1}]", pFilePath, oGDPicturePDF.GetStat().ToString())
Throw New ApplicationException(oMessage)
End If
If DoRemove(oGDPicturePDF) = False Then
Dim oMessage = String.Format("Attachments for file [{0}] can't be removed. Status: [{1}]", pFilePath, oGDPicturePDF.GetStat().ToString())
Throw New ApplicationException(oMessage)
End If
End Using
Return True
Catch ex As Exception
Logger.Warn("Unexpected Error while Extracting attachments from File [{0}]", pFilePath)
Logger.Error(ex)
Return False
End Try
End Function
Private Function DoRemove(GDPicturePDF As GdPicturePDF) As Boolean
Dim oStatus As GdPictureStatus
Dim oEmbeddedFileCount As Integer = GDPicturePDF.GetEmbeddedFileCount()
If oStatus <> GdPictureStatus.OK Then
Logger.Warn("Embedded files could not be removed. Status: [{0}]", oStatus.ToString)
Return False
End If
If oEmbeddedFileCount = 0 Then
Return True
End If
While GDPicturePDF.GetEmbeddedFileCount() > 0
GDPicturePDF.DeleteEmbeddedFile(0)
End While
End Function
Private Function DoExtract(GDPicturePDF As GdPicturePDF, pExtensions As List(Of String)) As List(Of EmbeddedFile)
Dim oResults As New List(Of EmbeddedFile)
Dim oEmbeddedFileCount As Integer = GDPicturePDF.GetEmbeddedFileCount()