SchreiberM a30112bc0e MS
2017-01-25 13:21:40 +01:00

148 lines
7.3 KiB
VB.net

Imports DD_LIB_Standards
Imports System.IO
Imports System.Text
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
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
ClassLogger.Add("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
If LogErrorsOnly = False Then ClassLogger.Add(" ...Unicode is used (Encoding.GetEncoding(1252))", False)
Else
If LogErrorsOnly = False Then ClassLogger.Add(" ...UTF8 (Encoding.GetEncoding(65001))", False)
EncodingFormat = Encoding.GetEncoding(65001)
End If
If LogErrorsOnly = False Then ClassLogger.Add(" ...ReadAlltext: " & BaseSearch, False)
fileContents = My.Computer.FileSystem.ReadAllText(BaseSearch, EncodingFormat) ', System.Text.Encoding.Unicode
If LogErrorsOnly = False Then ClassLogger.Add(" ...fileContents geladen", False)
fileContents = fileContents.Replace("Í", "Ö")
fileContents = fileContents.Replace("@Clipboard", 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)
If LogErrorsOnly = False Then ClassLogger.Add(" ...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)
If LogErrorsOnly = False Then ClassLogger.Add(" ...Xml Generiert: " & windream_temp_search, False)
Catch ex As Exception
ClassLogger.Add("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
ClassLogger.Add(" ...Top-Position: " & rctMain.Top.ToString, False)
ClassLogger.Add(" ...Left-Position: " & rctMain.Left.ToString, False)
ClassLogger.Add(" ...Right-Position: " & rctMain.Right.ToString, False)
ClassLogger.Add(" ...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:")
ClassLogger.Add("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
ClassLogger.Add("Unexpected error while Setting foreground: " & ex.Message, True)
End Try
Return ""
Catch ex As Exception
ClassLogger.Add("Unexpected error in Create Search: " & ex.Message, True)
MsgBox("Error in Create Search:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return "Unexpected error in Create Search"
End Try
Catch ex As Exception
ClassLogger.Add("Unexpected error in RUN_WD_SEARCH: " & ex.Message, True)
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