Digital Data - Marlon Schreiber 6d9f41ea09 DocCount und anderes
2019-07-12 11:03:46 +02:00

155 lines
7.5 KiB
VB.net

Imports DD_LIB_Standards
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Public Class clsSearch
'Fenster position ermitteln/auslesen
'Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Int32
Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
<DllImport("user32.dll")>
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Private Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Private Shared fileContents As String
Public Shared Function RUN_WD_SEARCH(BaseSearch As String)
Try
Dim extension = Path.GetExtension(BaseSearch)
Dim windream_temp_search As String = ""
If IO.File.Exists(BaseSearch) = False Then
Logger.Info("Die Windream-Suche existiert nicht oder ist nicht zugreifbar!", True)
MsgBox("Die Windream-Suche existiert nicht oder ist nicht zugreifbar!", MsgBoxStyle.Critical)
Return Nothing
End If
fileContents = ""
'Eine tempfile generieren
Dim tempFilename1 = My.Computer.FileSystem.GetTempFileName()
'Nur den Filenamen ohne Erweiterung
Dim tempName = Path.GetFileNameWithoutExtension(tempFilename1)
'tempfile löschen
If My.Computer.FileSystem.FileExists(tempFilename1) Then
My.Computer.FileSystem.DeleteFile(tempFilename1)
End If
Dim temppath = Path.GetTempPath
Dim EncodingFormat As Encoding
If WD_UNICODE = True Then
EncodingFormat = Encoding.GetEncoding(1252) '1252
Logger.Debug(" ...Unicode is used (Encoding.GetEncoding(1252))", False)
Else
Logger.Debug(" ...UTF8 (Encoding.GetEncoding(65001))", False)
EncodingFormat = Encoding.GetEncoding(65001)
End If
Logger.Debug(" ...ReadAlltext: " & BaseSearch, False)
fileContents = My.Computer.FileSystem.ReadAllText(BaseSearch, EncodingFormat) ', System.Text.Encoding.Unicode
Logger.Debug(" ...fileContents geladen", False)
fileContents = fileContents.Replace("Í", "Ö")
fileContents = fileContents.Replace("@Clipboard", CURR_MATCH_RESULT)
fileContents = fileContents.Replace("@CLIPBOARD", CURR_MATCH_RESULT)
fileContents = fileContents.Replace("@Zwischenablage", CURR_MATCH_RESULT)
fileContents = fileContents.Replace("123456789", CURR_MATCH_RESULT)
fileContents = fileContents.Replace("4711", CURR_MATCH_RESULT)
Try
'Die windream File zusammensetzen
windream_temp_search = temppath & tempName & extension
Try
'Die File schreiben
My.Computer.FileSystem.WriteAllText(windream_temp_search, fileContents, False, EncodingFormat)
Logger.Debug(" ...wrote Text to windream_temp_search: " & windream_temp_search, False)
' XML-Datei öffnen und laden
Dim Stream As New IO.StreamReader(CStr(windream_temp_search), EncodingFormat)
Dim Reader As New System.Xml.XmlTextReader(Stream)
' XML-Datei initialisieren
Dim xml As New System.Xml.XmlDocument()
' XML-Datei öffnen und laden
xml.Load(Reader)
Reader.Close()
xml.Save(windream_temp_search)
Logger.Debug(" ...Xml Generiert: " & windream_temp_search, False)
Catch ex As Exception
Logger.Info("TempFile could not be created: " & ex.Message, True)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unerwarteter Fehler in Write XmlSearch:")
End Try
CURRENT_WD_TEMPSEARCH = windream_temp_search
TEMP_FILES.Add(CURRENT_WD_TEMPSEARCH)
Try
Dim myhWnd As IntPtr
Dim p As New Process()
p.StartInfo.FileName = windream_temp_search
If My.Settings.WDSearch_maximized = True Then
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
Else
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal
End If
p.Start()
myhWnd = p.MainWindowHandle
Threading.Thread.Sleep(1000)
Dim rctMain As RECT
GetWindowRect(p.MainWindowHandle, rctMain)
If LogErrorsOnly = False Then
Logger.Debug(" ...Top-Position: " & rctMain.Top.ToString, False)
Logger.Debug(" ...Left-Position: " & rctMain.Left.ToString, False)
Logger.Debug(" ...Right-Position: " & rctMain.Right.ToString, False)
Logger.Debug(" ...Bottom-Position: " & rctMain.Bottom.ToString, False)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in Ausführen der windream-Suche:")
Logger.Info("Unexpected error while executing search: " & ex.Message, True)
Return "Unexpected error while executing search"
End Try
Dim psList() As Process
Try
psList = Process.GetProcesses()
For Each p As Process In psList
Console.WriteLine(p.Id.ToString() + " " + p.ProcessName)
If p.ProcessName.Contains("indream.Find") Then
AppActivate(p.Id)
If My.Settings.WDSearch_maximized = False Then
Dim rctMain As RECT
GetWindowRect(p.MainWindowHandle, rctMain)
If rctMain.Left = 0 Or rctMain.Right = 0 Then
ShowWindow(p.MainWindowHandle, 3) ' SW_MAXIMIZE
End If
End If
SetForegroundWindow(p.MainWindowHandle)
End If
Next p
Catch ex As Exception
Logger.Info("Unexpected error while Setting foreground: " & ex.Message)
End Try
'CURR_MATCH_WM_SEARCH = Nothing
CURR_MATCH_RESULT = Nothing
Return ""
Catch ex As Exception
Logger.Info("Unexpected error in Create Search: " & ex.Message)
MsgBox("Error in Create Search:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return "Unexpected error in Create Search"
End Try
Catch ex As Exception
Logger.Info("Unexpected error in RUN_WD_SEARCH: " & ex.Message)
MsgBox("Error in RUN_WD_SEARCH:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return "Unerwarteter Unexpected error in RUN_WD_SEARCH"
End Try
End Function
End Class