Jump to content

AutoItHelp v3.3.16.1 and v3.3.18.0 with external CSS loading


Go to solution Solved by argumentum,

Recommended Posts

Posted
2 hours ago, WildByDesign said:

I always call it right after the includes.

The earlier, the better. There is no need to first load #includes. But before creating any GUI stuff.
If you have an experience that pushed you to the advise please share it.

P.S.: where is your update / bettered / 2026 edition of the darkMode_mod.au3 ????, I will need it ( I've grown lazy ) :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
1 minute ago, argumentum said:

The earlier, the better. There is no need to first load #includes. But before creating any GUI stuff.
If you have an experience that pushed you to the advise please share it.

You are 100% right. The earlier during process init the better. I think the only reason why I had it after includes was more a matter of keeping everything at the top looking clean and tidy. But realistically it should be right at the top, you are right.

5 minutes ago, argumentum said:

P.S.: where is your update / bettered / 2026 edition of the darkMode_mod.au3 ????, I will need it ( I've grown lazy ) :)

This is something that should be done. Needs to be done, really. I’m just afraid to step on any “toes” because I believe NoNameCode mentioned getting back into it for another version but also UEZ shared some incredible subclassing code for dark mode. I’m not sure which code would be the best “base code” to start with.

It got much more complicated when it came to applying dark mode to statusbar, menubar, and a few other things. Trying to figure out how to add those methods to a UDF makes my brain start to smoke a bit. Plus having to overpaint that white line in a dark mode menubar.  If organized and done right, it could be really incredible.

We have all of those individual, beautiful pieces to the puzzle. But figuring out how to put that complex puzzle together in a single UDF is something that I may not be skilled enough for.

But I am definitely willing to jump in and help with the dark mode stuff. Even light mode theming has improvements there too, so technically it would be good to run it and have the choice between applying light or dark. 

Posted

Take a look at https://www.autoitscript.com/forum/topic/201673-json-http-post-serverlistener/page/2/#comment-1447447 for a how to JSON - AJAX ( the example on top when running the script ) to give you an idea for the example button(s) that is enclosed in "if (document.URL.match(/^mk:@MSITStore:/i)) {"  :sorcerer:

Global $tcp_Port = 80   ; if 80 is in use, try 81, as in http://127.0.0.1:81/home/

that port should read from your ini file for now ( in the example I linked above )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
2 minutes ago, WildByDesign said:

I’m just afraid to step on any “toes” because I believe NoNameCode mentioned getting back into it for another version but also UEZ shared some incredible subclassing code for dark mode. I’m not sure which code would be the best “base code” to start with.

Yes it will be the best, because you are the best :) ( don't tell anyone I said that )

An in regards to toes, fvk'em. There are no toes but if any toes popup, add a mention like: "..thanks to the crying baby @userName for parts of the code" :P 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
On 2/16/2026 at 9:49 AM, bladem2003 said:

If you want, you can help me with your suggestion for DPI example scripts.

Yeah I can probably help with that. I'm still trying to think of the best way to do it.

By the way, I'm wondering if we should use GDI Scaling instead of the System DPI scaling. System DPI is better and sharper but can alter the size of controls more. And since it is other, older example scripts we don't exactly want to mess with sizes so much. GDI Scaling will make the text sharp but maintain original sizes.

; High-DPI GDI Scaling to sharper text but keep control size as expected
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -5)

Try that and let me know what you think.

Posted

@bladem2003 I have put quite a lot of thought into how we could add DPI to the examples. I don't think that we should change anything system-wide with the DPI compatibility settings. Also, writing the DPI line to all of the example files would not be great. I don't like the idea of altering the original files.

So have a look at this:

#include <FileConstants.au3>
#include <File.au3>

$sTemplate = _TempFile(@TempDir, "~", ".au3")
ConsoleWrite("temp file: " & $sTemplate & @CRLF)

; DPI line as string
$sDPI = '; High-DPI GDI Scaling to sharper text but keep control size as expected' & @CRLF
$sDPI &= 'DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -5)'

; template file
;$sTemplate = @ScriptDir & "\DPI-template.au3"
$sPath = @ScriptDir & "\AutoitHelpDark2\Examples\Helpfile\GUICtrlCreateListView.au3"

$iFileExists = FileExists($sTemplate)
If Not $iFileExists Then FileWrite($sTemplate, "")

$sFileRead = FileRead($sPath)

; open DPI template
$hFileOpen = FileOpen($sTemplate, $FO_APPEND)

FileWrite($hFileOpen, $sDPI)
FileWrite($hFileOpen, @CRLF & @CRLF)
FileWrite($hFileOpen, $sFileRead)

; close file after writing
FileClose($hFileOpen)

; run Example with DPI
$iPID = ShellExecute($sTemplate)

; wait for Example to be closed
ProcessWaitClose($iPID)

; delete temporary Example file with DPI
FileDelete($sTemplate)

 

Posted
1 hour ago, bladem2003 said:

High-DPI scaling for the GUI and examples thanks

You're welcome. There was a bug in my implementation though.

We need to set the working directory, since the scripts assume they are working from AutoIt3\Examples\Helpfile. If they come from some of the other folders, we may need to make more changes.

There is also a problem with scripts that have #include "Extras\HelpFileInternals.au3" or #include "Extras\WM_NOTIFY.au3" because they fail to run since we are running from a different directory.

The following example sets the current directory and also replaces the "#include "Extras\" with the appropriate install dir stuff:

(and the example _GUICtrlStatusBar_Resize previously failed. So this should fix that issue.)

#include <FileConstants.au3>
#include <File.au3>

$sTemplate = _TempFile(@TempDir, "~", ".au3")
$sHelpfileDir = StringRegExpReplace(@AutoItExe, '\\[^\\]+$', "") & "\Examples\Helpfile"
$sReplace = '#include "' & $sHelpfileDir & '\Extras\'

; DPI line as string
$sDPI = '; High-DPI GDI Scaling to sharper text but keep control size as expected' & @CRLF
$sDPI &= 'DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -5)' & @CRLF
$sDPI &= "$sHelpfileDir = StringRegExpReplace(@AutoItExe, '\\[^\\]+$', "
$sDPI &= '"") & "\Examples\Helpfile"' & @CRLF
$sDPI &= 'FileChangeDir ($sHelpfileDir)'

; helpfile
$sPath = @ScriptDir & "\AutoitHelpDark2\Examples\Helpfile\_GUICtrlStatusBar_Resize.au3"

$iFileExists = FileExists($sTemplate)
If Not $iFileExists Then FileWrite($sTemplate, "")

$sFileRead = FileRead($sPath)
$sFileRead = StringReplace($sFileRead, '#include "Extras\', $sReplace)

; open DPI template
$hFileOpen = FileOpen($sTemplate, $FO_APPEND)

FileWrite($hFileOpen, $sDPI)
FileWrite($hFileOpen, @CRLF & @CRLF)
FileWrite($hFileOpen, $sFileRead)

; close file after writing
FileClose($hFileOpen)

; run Example with DPI
$iPID = ShellExecute($sTemplate)

; wait for Example to be closed
ProcessWaitClose($iPID)

; delete temporary Example file with DPI
FileDelete($sTemplate)

 

By the way, 0.3 is awesome. I love that you can resize it now. Your GUI is sharp. The examples are sharper also with the GDI scaling. We could apply the regular High DPI but it could mess with control sizes and so on. I think it's perfect the way you have it.

Suggestion: Have a way to resize the font size in your GUI and the web content. Although I would imagine the web content part might be tricky.

The only last remaining concern that I have is how the separator in the web content blanks out anytime you move it (only while it is moving). I don't think that is something that you can fix within your GUI though. Since that separator is part of the web content (javascript I believe), the fix would have to be done there. I personally would not know how to fix it. But something to keep in mind, although certainly a lower priority issue.

Posted

...I don't mind doing it here or in it's own thread. But @bladem2003's initiative is very different and will confuse future people reading this thread, so in that regard, would be advisable to open threads as needed for the concept of: embedding a website in a embedded browser that interacts with the PC**.

And there a separate aspects to his project, being:
1) The html/JavaScript runs on a HTTP daemon. That will take a TCP hat.
2) The html/JavaScript will need heavy work. That will take a JavaScript hat.
3) The AJAX ( or what not ) and the SciTE interaction, will take an IPC hat.
4) The embedded browser will need options for Win7 ( and XP would be great ) but default to the better technology available on the OS, in case WebView2 is not possible on the user's PC, and that will take that hat.

So that will be a few threads to be called ( in my way of naming things ) : "CHMless Help: The site", "CHMless Help: The browser", "CHMless Help: The integration". Am just thinking on my feet right now but that would keep each thread for each aspect clear and concise for anyone reading and collaborating on the project on it's own area of expertise

I tend to over engineer stuff and uselessly complicate everything so, you all that are actively dedicating time to bring the idea to fruition, have a chat, maybe via PM/DM and ask each other what each will be participating in, because this is a larger, more involved project.***
Or open a thread in "AutoIt Projects and Collaboration" and announce the project, the pressing reasons behind it, and the need for talented people to bring it to life ( newbies accepted ) :) 

At the high CPU/time price of single file, a ZIP ( of sorts ) that contains all the files and is read by the HTTP daemon. And that too would be nice but it may take ASM to work fast in AutoIt. But that is a project of it's own. Responsiveness at the speed of the current CHM is the goal for now.

**The PC interaction would benefit if a gray-hat is worn. Once this is a product, can it be easily abused ( hacked ) from outside the local PC ?, about from the inside, what are the risks ?. That too needs attention in this project.

***So, if you don't know how to do something, but are willing to learn, just go at it. Anyone would benefit from gaining experience in new things ( that are likely to expand one's previous capabilities ) ;) 

Ok. I guess I just loaded you with the fear of god coding :lol:

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

Q: How do we press F1 in SciTE and have our script do the helping ?
A:

#cs ----------------------------------------------------------------------------

    The script does not need to be compiled and I think that it shouldn't be just for clarity. But it all depends on what's faster. I haven't tested yet.
    That below is what PatchTheExtensionProperites() does for you:

    # Commands to for Help F1 # ..look for this in "\SciTE\Properties\au3.properties", and change the default to the script, that in this case is in the same folder as Autoit3Help.exe
    command.help.$(au3)=$(SciteDefaultHome)\..\Autoit3Help.exe "$(CurrentWord)"
    #~ command.help.$(au3)=$(SciteDefaultHome)\..\Autoit3_x64.exe ..\Autoit3HelpWeb.au3 "$(CurrentWord)"
    #~ command.help.$(au3)=$(SciteDefaultHome)\..\Autoit3HelpWeb.exe "$(CurrentWord)"

#ce ----------------------------------------------------------------------------

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

#Region Patch au3.properties

;~ Exit PatchTheExtensionProperites(0) ; default ; restore to original help handler
;~ Exit PatchTheExtensionProperites(1) ; this script will be the help handler
Func PatchTheExtensionProperites($iProperty = 0)
    
    ; This function is to add/restore the help handler
    
    Local $sPropertyFilename = @ScriptDir & "\SciTE\Properties\au3.properties"
    If Not FileGetSize($sPropertyFilename) Then
        Exit MsgBox($MB_TOPMOST, @ScriptName, "File is not there or script not here. Bye.", 120)
    EndIf
    Local $sData = "", $iInx_Original = 0, $n, $aArray = FileReadToArray($sPropertyFilename)

    ; find the original entry
    For $n = 0 To UBound($aArray) - 1
        If StringInStr($aArray[$n], 'command.help.$(au3)=$(SciteDefaultHome)\..\Autoit3Help.exe') Then
            $iInx_Original = $n ; remove the comment "#" if there
            $aArray[$n] = StringTrimLeft($aArray[$n], StringInStr($aArray[$n], "command.help.") - 1)
            ExitLoop
        EndIf
    Next

    ; if not found then... now what ?. Exit this and let the user figure it out =(
    If Not $iInx_Original Then Return SetError(1, 0, 1)

    ; remove others
    For $n = UBound($aArray) - 1 To 0 Step -1
        If StringInStr($aArray[$n], 'command.help.$(au3)=') And $iInx_Original <> $n Then
            _ArrayDelete($aArray, $n)
        EndIf
    Next

    ; lets work on what this code does:
    Switch $iProperty
        Case 0
            ; do nothing, leave it default
        Case 1
            ; lets comment out the original
            $aArray[$iInx_Original] = '#~ ' & $aArray[$iInx_Original]

            ; and a new line
            $aArray[$iInx_Original] &= @CRLF

            ; add our command
            If StringRight(@ScriptName, 4) = ".exe" Then
                $aArray[$iInx_Original] &= 'command.help.$(au3)=$(SciteDefaultHome)\..\' & @ScriptName & ' "$(CurrentWord)"'
            Else
                $aArray[$iInx_Original] &= 'command.help.$(au3)=$(SciteDefaultHome)\..\Autoit3_x64.exe ..\' & @ScriptName & ' "$(CurrentWord)"'
            EndIf
        Case Else
            Exit MsgBox($MB_TOPMOST, @ScriptName, "Read the code. Bye.", 120)
    EndSwitch

    ; testing to see if it looks good
    ConsoleWrite(@CRLF)
    For $n = $iInx_Original - 1 To $iInx_Original + 1
        If $iInx_Original = $n Then
            ConsoleWrite('>>>')
        EndIf
        ConsoleWrite($aArray[$n] & @CRLF)
    Next
    ConsoleWrite(@CRLF)
    ; ..yes, it looks good.

    ; Lets reassemble the file:
    For $n = 0 To UBound($aArray) - 1
        $sData &= $aArray[$n] & @CRLF
    Next
    $sData = StringTrimRight($sData, 2)

    ; 1st, a backup
    FileCopy($sPropertyFilename, $sPropertyFilename & "Backup", $FC_NOOVERWRITE)

    ; and now we replace the old with the updated one
    Local $hFileOpen = FileOpen($sPropertyFilename, (FileGetEncoding($sPropertyFilename, $FE_PARTIALFIRST_UTF8) + $FO_OVERWRITE))
    If $hFileOpen = -1 Then
        Local $iRet = FileCopy($sPropertyFilename & "Backup", $sPropertyFilename, $FC_OVERWRITE)
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred on FileOpen for this file. " & _
                ($iRet ? "Backup restored" : "Backup fail to restore") & ". Bye.", 120)
        Return SetError(2, 0, 2)
    EndIf
    FileWrite($hFileOpen, $sData)
    FileClose($hFileOpen)
EndFunc   ;==>PatchTheExtensionProperites

#EndRegion Patch au3.properties


; Script Start - Add your code below here

; TODO: everything

MsgBox(262144, @ScriptName, $CmdLine[$CmdLine[0]], 120)

Looks like a long answer but is quite short. At least this part of the project was simple :D 

Q: I run the function and something is wrong 🥵
A: Either close and open SciTE again or, load au3.properties in SciTE and save it. By just saving the file in SciTE, it'll know that it should reload the values from the file even if there is nothing different.

Q: Can't you just tell SciTE to do the "reloadproperties" with code ?!
A: Yes 😅

#Region taken from SciteConfig.au3

Reload_Config()
Func Reload_Config()
    Opt("WinSearchChildren", 1)
    Local $SciTE_hwnd = WinGetHandle("DirectorExtension")
    ;Send SciTE Director my GUI handle so it will report info back from SciTE
    SendSciTE_Command(0, $SciTE_hwnd, "reloadproperties:")
EndFunc   ;==>Reload_Config

Func SendSciTE_Command($My_Hwnd, $SciTE_hwnd, $sCmd)
    Local $WM_COPYDATA = 74
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    ;ConsoleWrite('-->' & $sCmd & @lf )
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $SciTE_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))
EndFunc   ;==>SendSciTE_Command

#EndRegion taken from SciteConfig.au3

 

Edited by argumentum
more Q and A

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Q: What is going to serve the pages of the help file ?

Spoiler
#include-once

#include <MsgBoxConstants.au3>

Global $g__AHWD_sHtmPath = "C:\xampp_v8.2.12\htdocs\AutoitHelpDark\AutoitHelpDark02" ; the root of your help file
Global $g__AHWD_TCPListen_IPAddr = "127.0.0.1"
Global $g__AHWD_TCPListen_Port = 89 ; will add helper functions for these, later.
Global $g__AHWD_TCPListen_Socket = 0


ConsoleWrite("http://" & $g__AHWD_TCPListen_IPAddr & ":" & $g__AHWD_TCPListen_Port & "/index.htm < to load the index" & @CRLF)
ConsoleWrite("http://" & $g__AHWD_TCPListen_IPAddr & ":" & $g__AHWD_TCPListen_Port & "/quit      < to exit the script" & @CRLF)


AHWD_WebServer_Init()
Func AHWD_WebServer_Init()
    If WinExists("AHWD_WebServer_is_running") Then Return
    AutoItWinSetTitle("AHWD_WebServer_is_running")
    Local $iError
    Opt("TCPTimeout", 5) ; make the site more responsive. Is a local host.

    TCPStartup() ; Start the TCP service.
    If @error Then
        $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "TCPStartup failed, Error code: " & $iError, 60)
        Return SetError(1, $iError, 1)
    EndIf

    ; Assign a variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions.
    $g__AHWD_TCPListen_Socket = TCPListen($g__AHWD_TCPListen_IPAddr, $g__AHWD_TCPListen_Port, 100)

    If @error Then
        $iError = @error ; Someone is probably already listening on this IP Address and Port (script already running?).
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError, 60)
        Return SetError(1, $iError, 1)
    EndIf

    ; Register OnAutoItExit to be called when the script is closed.
    OnAutoItExitRegister(AHWD_OnAutoItExit)

    ConsoleWrite('- AHWD_WebServer_ServeLoop: ' & AHWD_WebServer_ServeLoop() & @CRLF)

EndFunc   ;==>AHWD_WebServer_Init

Func AHWD_WebServer_ServeLoop()
    If Not $g__AHWD_TCPListen_Socket Then Return SetError(1, 0, 1)

    Local $iSocket = -1, $sHead, $sBody, $sRequestMethod, $sHTTPVersion, $sRequestTarget
    Local $hTimerReqRcvd = TimerInit()
    Local $iTestSocketCount = 0
    Local $sContentTypeOfFile, $buffer, $errTCPRecv, $extTCPRecv

    ; ..testing. Let's see it in a browser
    ShellExecute("http://" & $g__AHWD_TCPListen_IPAddr & ":" & $g__AHWD_TCPListen_Port & "/index.htm")

    While 1

        If $iSocket = -1 Then
            $iSocket = TCPAccept($g__AHWD_TCPListen_Socket) ; here it will wait the declared "Opt('TCPTimeout', 20)"
            If @error Then ; If an error occurred display the error code and return False.
                $iError = @error
                MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError)
                Return SetError(2, $iError, 2)
            EndIf
            If $iSocket <> -1 Then ; SideNote: I would fork the socket right here but this is just an example
                $hTimerReqRcvd = TimerInit()  ;                        so is better to not over complicate it.
                $iTestSocketCount += 1
                ContinueLoop ; As there is a socket, lets attend to it ASAP.
            EndIf
        Else
            $buffer = StringToBinary("")
            Do
                If TimerDiff($hTimerReqRcvd) > 2000 Then Return
                $bReceived = TCPRecv($iSocket, 12288, 1) ; $TCP_DATA_BINARY (1) - return binary data
                $errTCPRecv = @error
                $extTCPRecv = @extended
                $buffer &= $bReceived
            Until $extTCPRecv Or $bReceived = "" ;    but since this is an example, it shows that there was a connection ( good for debugging )

            $hTimerReqRcvd = Round(TimerDiff($hTimerReqRcvd), 2)
            $hTimerResponse = TimerInit()
            $buffer = BinaryToString($buffer)
            If $errTCPRecv Then
                TCPCloseSocket($iSocket) ; Close the socket.
                $iSocket = -1
                ConsoleWrite(@CRLF & @TAB & "# " & $iTestSocketCount & " @error,@extended = " & $errTCPRecv & "," & $extTCPRecv & @CRLF & @CRLF)
                ContinueLoop
            ElseIf $buffer = "" Then
                TCPCloseSocket($iSocket) ; Close the socket.
                $iSocket = -1
                ContinueLoop
            EndIf
            AHWD_WebServer_GetTheHttpParts($buffer, $sHead, $sBody, $sRequestMethod, $sRequestTarget, $sHTTPVersion)
            Switch $sRequestTarget
                Case "/quit"
                    AHWD_HttpSender($iSocket, "Ok, bye bye.", "text")
                    TCPCloseSocket($iSocket) ; Close the socket.
                    $iSocket = -1
                    Exit

                Case Else
                    $sFilename = $g__AHWD_sHtmPath & StringReplace(StringReplace($sRequestTarget, "/", "\"), "%20", " ")
                    $sContentTypeOfFile = AHWD_WebServer_ContentTypeOfFile($sFilename)
                    If FileGetSize($sFilename) Then
                        Switch $sContentTypeOfFile
                            Case "au3"
                                ; ..could make a link here to load in SciTE.
                                ; It would not load from elsewhere because the path wouldn't be found among the help files.
                                ; food for thought for now
                            Case Else
                                AHWD_HttpSender($iSocket, FileRead($sFilename), $sContentTypeOfFile)
                        EndSwitch
                    Else
                        AHWD_HttpSender($iSocket, StringToBinary("404 ( Not Found )     =(" & @CRLF & @CRLF & $sRequestTarget & @CRLF & @CRLF & "( " & $sFilename & " ) Note to self: Don't show this. 😨 ", 4), "text/plain; charset=utf-8", "404 Not Found")
                    EndIf

            EndSwitch
            TCPCloseSocket($iSocket) ; Close the socket.
            $iSocket = -1
;~          ConsoleWrite('- ' & $hTimerReqRcvd & ' / ' & Round(TimerDiff($hTimerResponse), 2) & ' >' & $sFilename & '<' & @CRLF)
        EndIf
    WEnd
EndFunc   ;==>AHWD_WebServer_ServeLoop

Func AHWD_WebServer_ContentTypeOfFile($sFilename)
    Local $sExt = StringTrimLeft($sFilename, StringInStr($sFilename, ".", 0, -1))
;~  ConsoleWrite('= >' & $sExt & "<" & @CRLF)
    Switch $sExt
        Case "ico"
            Return "image/x-icon"
        Case "gif"
            Return "image/gif"
        Case "png"
            Return "image/png"
        Case "jpeg", "jpg"
            Return "image/jpeg"
        Case "webp"
            Return "image/webp"
        Case "svg"
            Return "image/svg+xml"
        Case "json"
            Return "application/json"
        Case "js"
            Return "text/javascript"
        Case "css"
            Return "text/css"
    EndSwitch
    Return "text/html"
EndFunc   ;==>AHWD_WebServer_ContentTypeOfFile


Func AHWD_WebServer_GetTheHttpParts(ByRef $sBuffer, ByRef $sHead, ByRef $sBody, ByRef $sRequestMethod, ByRef $sRequestTarget, ByRef $sHTTPVersion)
    If Not StringInStr($sBuffer, @CRLF & @CRLF) Then Return
    Local $iPosBody = StringInStr($sBuffer, @CRLF & @CRLF)
    $sHead = StringLeft($sBuffer, $iPosBody - 1)
    $sBody = StringTrimLeft($sBuffer, $iPosBody + 3)
    $sBuffer = ""
    Local $aHead = StringSplit($sHead, @CRLF, 1)
    Local $aRequestLine = StringSplit($aHead[1] & "  ", " ", 0)
    $sRequestMethod = $aRequestLine[1]
    $sRequestTarget = $aRequestLine[2]
    $sHTTPVersion = $aRequestLine[3]
;~  ConsoleWrite('>  $sRequestMethod >' & $sRequestMethod & '<' & @CRLF)
;~  ConsoleWrite('>    $sHTTPVersion >' & $sHTTPVersion & '<' & @CRLF)
;~  ConsoleWrite('>  $sRequestTarget >' & $sRequestTarget & '<' & @CRLF)
;~  ConsoleWrite('> Head >' & $sHead & '<' & @CRLF)
;~  ConsoleWrite('> Body >' & StringToBinary($sBody) & '<' & @CRLF)
EndFunc   ;==>AHWD_WebServer_GetTheHttpParts

; send back a response
Func AHWD_HttpSender(ByRef $iSocket, $sData, $ContentType = "text/html", $ResponseStatusCode = "200 OK")
    Local $bData = Binary($sData)
    Local $sHead = "HTTP/1.1 " & $ResponseStatusCode & @CRLF ; https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
    $sHead &= "Content-Type: " & $ContentType & @CRLF ; ..so the client knows what is getting.
    $sHead &= "Connection: close" & @CRLF ; SideNote: ..an interaction takes 10 ms., is there a need for "muti-concurrent" code ?   ;)
    $sHead &= "Content-Lenght: " & BinaryLen($bData) & @CRLF ; this is a must for binary file send. Might as well use it for everything.
    $sHead &= @CRLF ; end of header marker
    AHWD_TCPSendBinary($iSocket, Binary($sHead)) ; Send the head
    AHWD_TCPSendBinary($iSocket, $bData) ; Send the body ( html or file, as delimited by the header )
EndFunc   ;==>AHWD_HttpSender

Func AHWD_TCPSendBinary(ByRef $hSocket, ByRef $bData)
    Local $iBytesSent, $iBytesTotalSent = 0, $iBytesTotal = BinaryLen($bData)
    Do
        $iBytesSent = TCPSend($hSocket, $bData)
        If @error Then ExitLoop
        $iBytesTotalSent += $iBytesSent
        $bData = BinaryMid($bData, $iBytesSent + 1, BinaryLen($bData) - $iBytesSent)
    Until 0 = BinaryLen($bData)
    Return SetError(0, Int($iBytesTotalSent <> $iBytesTotal), $iBytesTotalSent)
EndFunc   ;==>AHWD_TCPSendBinary

Func AHWD_OnAutoItExit()
    OnAutoItExitUnRegister(AHWD_OnAutoItExit)

    ; Close the Listening socket to allow afterward binds.
    If $g__AHWD_TCPListen_Socket > 0 Then
        TCPCloseSocket($g__AHWD_TCPListen_Socket)
        $g__AHWD_TCPListen_Socket = 0
    EndIf

    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>AHWD_OnAutoItExit

#cs

    .well-known\appspecific\com.chrome.devtools.json

    {
      "workspace": {
        "uuid": "a-random-version-4-UUID",
        "root": "path/to/your/project/root/folder"
      }
    }

    https://developer.chrome.com/docs/devtools/workspaces

#ce

A: Looking around and thinking, I came to the idea of coding an HTTP daemon with AutoIt's TCP functions, because those I found in the WiKi have dependencies, and I wanted to have this be able to work in WinPE too.
And it needs a "server" to have the ability to interact with the pages in a portable way. The code above looks enough for what it'll be needed.

Spoiler

Next I'll code an HTML patcher to click-click and change all the help file files, no matter where they comes from, to be able to click in the help file and open a chosen editor ( that since all I use is SciTE, that'll be the example for those that use VSCode, Notepad++, etc. ) from an .ini file declaration.

After that, add the embedded browser code.

Then the correlation of a chosen word to html page, and we're done.

..then, make it SVN build-able. If the higher-ups agree with this project, it may become the one shipped with the installer. Looks nice.
One "break-from-work" at the time :)

..and yes, make it all CSS file selectable. ( that'll take some fiddling around )
I really like the buuf theme for light mode environments.

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...