Jump to content

Another Tool to update the #includes to the new ones


GEOSoft
 Share

Recommended Posts

I think this is foolproof but then again there may be a bigger fool than I accounted for hanging around someplace.

Changes the #includes to match the new version constants files including changing GUIConstants to GUIConstantsEx

This is commented enough for anyone to understand. I'm 99% sure that this script catches all of them but if you find it's missing some then let me know and I'll try to figure out why.

You will have to download 2 of the required include files from my web site. It's in my sig.

On the Left Sidebar Menu>> Code>>My Extra UDFs>> Stringx.au3 and Filex.au3. At the bottom of each page is a link to download the zip file.

DO NOT run this compiled unless you change the way I wrote $iPath. There is a backup created so you don't have to worry about the original script. Now it's back to work on the functions that fix the UDF function name changes from way back.

Enjoy

;
#include <stringx.au3>
#include <filex.au3>
#include <array.au3>
$aSep = Chr(32)
$tFldr = ""
$cfList = ""
$ini = @ScriptDir & "\Const.ini"
$iPath = StringLeft(@AutoItExe, StringInStr(@AutoItExe,"\", 0, -1)) & "include\"

If NOT FileExists($Ini) Then _CreateINI()
$File = @DeskTopDir & "\Test.au3"
;;  You could build an array of file names (with the path) here and
;;  and pass each element to the next line as $File

_CheckFile($File)
MsgBox(0, "Finished", "The #includes have been fixed")

Func _CreateINI()
  Local $sFile = FileFindFirstFile($iPath & "*constants*.au3"), $tArr, $iArr
  If $sFile <> -1 Then
    While NOT @Error
      $nFile = FileFindNextFile($sFile)
      $cfList &= $nFile & $aSep
    Wend
    $cfList = StringSplit(StringStripWS($cfList, 2), $aSep)
  Else
    Return SetError(1)
  EndIf
  
  For $I = 1 To Ubound($cfList)-1
    $tArr = __FileReadToArray($iPath & $cfList[$I])
    For $C = 1 To Ubound($tArr)-1
      If StringInStr($tArr[$C], "Global Const") Then
        $Cid = _StringGetWord($tArr[$C], 3)
        If StringLeft($Cid, 1) <> "$" Then ContinueLoop
        IniWrite($ini, "Default", $Cid, $cfList[$I])
      EndIf
    Next
  Next
  $iArr = __FileReadToArray($ini)
  _ArraySort($iArr, 0, 2)
  _ArrayReverse($iArr, 2)
  $oFile = FileOpen($Ini,2)
  
  For $I = 1 To Ubound($iArr)-1
    FileWriteLine($oFile, StringReplace($iArr[$I], "=", "= "))
  Next
  FileClose($oFile)
EndFunc;<==> _CreateINI()

Func _CheckFile($sFile = "")
  Local $cList = "", $fList = __FileReadToArray($Ini), $I
  If $sFile = "" Then
    $sFile = FileOpenDialog("Select the file to check", "", "AutoIt Files (*.au3)", 3)
    If @Error Then Return SetError(2)
  EndIf
  If $sFile = @ScriptFullPath Then
  MsgBox(0, "Error", "You can not run this script against itself.")
  Exit
  EndIf
  $cFile = FileRead($sFile)
  FileMove($sFile, StringReplace($sFile, ".au3", ".bak"));; Create a backup
;; Now lets prepare the file
  $cFile = StringReplace($cFile, "<GUIConstants.au3>", "<GUIConstantsEx.au3>")
  
  $cFile = StringReplace($cFile, "< ", "<")
  $cFile = StringReplace($cFile, " >", ">")
  $cFile = StringReplace($cFile, "#Include <", "#Include<")
  
;; Now we get down to work by determining what constants were used
;; and building the list of constants file that are required
  If _StringGetChrCount($cFile, "guiconstants") Then
    $cList &= "GUIConstantsEx.au3" & $aSep
    For $I = 2 To Ubound($fList) -1
      $var = StringTrimRight(_StringGetWord($fList[$I]), 1)
      If _StringGetChrCount($cFile, $Var) Then
        $Val = IniRead($Ini, "Default", $var, "")
        If $Val  = "" Then ContinueLoop
        If Not StringInStr($cList, $Val & $aSep) Then $cList &= $Val & $aSep
      EndIf
    Next
  EndIf
  
;; We have the list of required constants files se we turn it into an array
;; and build our output
  $out = ""
    $cList = StringSplit(StringStripWS($cList,2), $aSep)
    For $I = 1 To $cList[0]
      If $I > 1 Then $cFile = StringReplace($cFile, "#Include<" & $cList[$I] & ">", "")
      $out &= "#Include <" & $cList[$I] & ">" & @CRLF
    Next
  $cFile = StringReplace($cFile, "#Include<GUIConstantsEx.au3>", $Out)
  $cFile = StringReplace($cFile, "#Include<", "#Include <")
  $oFile = FileOpen($sFile, 2)
  FileWrite($oFile, StringStripWS($cFile, 2))
  FileClose($oFile)
EndFunc;<==> _CheckFile()
;

EDIT: I should have added that it may be slow on the first run because it has to build a huge INI file.

EDIT 2:

I have now uploaded a zip file that contains this script, both of the required includes and the current INI file.

The Ini file is current as of AutoIt 3.2.12.0 and I think it is the same back to 3.2.10.0

The file is on my site

Left Sidebar Menu >>Code>>Full Source >> Click "Download" at the bottom of the page.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hey George... I went to your site and clicked on some links :) .. LOL Apreciate ya man! lol will check this out.. Thanks

Thanks.

If you notice in edit 2 the whole thing can be downloaded in a single zip now. No messing aound getting the extra udfs and no waiting for it to build the INI.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...