Phreak87 / LeptonicaSharp

Full featured wrapper for leptonica 1.77.0
Other
8 stars 5 forks source link

Tweak to setLeptDebugOk #40

Closed fdncred closed 5 years ago

fdncred commented 5 years ago

This code allows you to have irfanview somewhere in your path instead of requiring it in a certain folder.

    Public Shared Sub setLeptDebugOK(
                 ByVal allow As Integer)

        'If My.Computer.FileSystem.FileExists("i_view32.exe") = False Then Throw New Exception("I_View32.exe missing")
        Dim irfan = GetFullPathFromWindows("i_view32.exe")
        If irfan Is Nothing Then Throw New Exception("I_View32.exe missing")
        LeptonicaSharp.Natives.setLeptDebugOK(allow)

    End Sub

Supporting code

    <DllImport("shlwapi.dll", CharSet:=CharSet.Unicode, SetLastError:=False, EntryPoint:="PathFindOnPath")>
    Friend Shared Function PathFindOnPath(
            ByVal pszFile As System.Text.StringBuilder,
            ByVal ppszOtherDirs As String()) As Boolean
    End Function

    Const MAX_PATH = 260
    Public Shared Function GetFullPathFromWindows(ByVal exeName As String) As String
        If exeName.Length > MAX_PATH Then
            Throw New ArgumentException("The exe name is longer than Max Path")
        End If
        Dim sb As Text.StringBuilder = New Text.StringBuilder(exeName, MAX_PATH)
        Dim retStr = If(Natives.PathFindOnPath(sb, Nothing) = True, sb.ToString(), Nothing)
        Return retStr
    End Function
Phreak87 commented 5 years ago

Good idea!

Are you sure leptonica knows the same path? Debug pix is external. Maybe there's a function to set the path

fdncred commented 5 years ago

I don't understand your question. The function PathFindOnPath looks on windows system for any file name you pass in that exists in the path environment variable. I'm not sure what leptonica or debug pix means in this context.

Phreak87 commented 5 years ago

Set setLeptDebugOK should be possible if i_view exists or not (because leptonica writes files too) for displaying the pix Leptonica needs to know the path. The Path in my Wrapper is irrelevant for Leptonica if i can not transmit and set the path. i will take a look if its possible to set the i_view path.

fdncred commented 5 years ago

I agree that setLeptDebugOK isn't dependent on i_view.exe existing, however that is what you coded. So, I just changed your code so that I could run my program.

You really just want to know if the user has i_view.exe and warn them that some viewing functionality may not work if i_view.exe isn't present. It really has nothing to do with setleptdebugok, but again, that's where you put the code so that's where I changed it.

Phreak87 commented 5 years ago

OK, changed.

modified i little bit to work for me too and replaced my bad throw event idea with a exclamation msgbox.

Dim retStr = If(Natives.PathFindOnPath(sb, {Environment.CurrentDirectory}) = True, sb.ToString(), Nothing)