MS DocumentViewer

This commit is contained in:
Developer01
2025-11-28 09:23:48 +01:00
parent b87995221f
commit 07332a4990
17 changed files with 838 additions and 181 deletions

View File

@@ -2,6 +2,7 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Language
Imports System.IO
Imports DigitalData.Services.EDMIService.Security
Namespace Methods.IDB.GetFileObject
Public Class GetFileObjectMethod
@@ -69,6 +70,29 @@ Namespace Methods.IDB.GetFileObject
End Function
Private Function LoadFileContents(pFilePath As String) As Byte()
Try
Dim password = Environment.GetEnvironmentVariable("DD_FILE_ENCRYPTION_PASSWORD")
If String.IsNullOrWhiteSpace(password) Then
Logger.Warn("No encryption password set (DD_FILE_ENCRYPTION_PASSWORD). Attempting legacy plain read for file [{0}]", pFilePath)
Return ReadPlain(pFilePath)
End If
Try
' Try decrypt first (preferred path)
Logger.Debug("Attempting AES decrypt for file [{0}]", pFilePath)
Return SecureFileHandler.DecryptFileToBytes(pFilePath, password)
Catch exDec As Exception
Logger.Warn("Decrypt failed for file [{0}]. Falling back to plain read. Reason: {1}", pFilePath, exDec.Message)
Logger.Error(exDec)
Return ReadPlain(pFilePath)
End Try
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Private Function LoadFileContents_Old(pFilePath As String) As Byte()
Try
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read)
Using oMemoryStream As New MemoryStream()
@@ -85,6 +109,15 @@ Namespace Methods.IDB.GetFileObject
End Try
End Function
Private Function ReadPlain(pFilePath As String) As Byte()
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
Using oMemoryStream As New MemoryStream()
oFileStream.CopyTo(oMemoryStream)
Return oMemoryStream.ToArray()
End Using
End Using
End Function
End Class
End Namespace