MSNamenÄndern
This commit is contained in:
156
app/DD_Clipboard_Searcher/clsSearch.vb
Normal file
156
app/DD_Clipboard_Searcher/clsSearch.vb
Normal file
@@ -0,0 +1,156 @@
|
||||
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
|
||||
clsLogger.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 clsLogger.Add(" ...Unicode is used (Encoding.GetEncoding(1252))", False)
|
||||
Else
|
||||
If LogErrorsOnly = False Then clsLogger.Add(" ...UTF8 (Encoding.GetEncoding(65001))", False)
|
||||
EncodingFormat = Encoding.GetEncoding(65001)
|
||||
End If
|
||||
|
||||
If LogErrorsOnly = False Then clsLogger.Add(" ...ReadAlltext: " & BaseSearch, False)
|
||||
fileContents = My.Computer.FileSystem.ReadAllText(BaseSearch, EncodingFormat) ', System.Text.Encoding.Unicode
|
||||
If LogErrorsOnly = False Then clsLogger.Add(" ...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)
|
||||
If LogErrorsOnly = False Then clsLogger.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 clsLogger.Add(" ...Xml Generiert: " & windream_temp_search, False)
|
||||
Catch ex As Exception
|
||||
clsLogger.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
|
||||
clsLogger.Add(" ...Top-Position: " & rctMain.Top.ToString, False)
|
||||
clsLogger.Add(" ...Left-Position: " & rctMain.Left.ToString, False)
|
||||
clsLogger.Add(" ...Right-Position: " & rctMain.Right.ToString, False)
|
||||
clsLogger.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:")
|
||||
clsLogger.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
|
||||
clsLogger.Add("Unexpected error while Setting foreground: " & ex.Message)
|
||||
End Try
|
||||
CURR_MATCH_WM_SEARCH = Nothing
|
||||
CURR_MATCH_RESULT = Nothing
|
||||
Return ""
|
||||
Catch ex As Exception
|
||||
clsLogger.Add("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
|
||||
clsLogger.Add("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
|
||||
Reference in New Issue
Block a user