Can "CleanUpAndPack" be changed so versions are optional?

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Can "CleanUpAndPack" be changed so versions are optional?

02 Mar 2020, 23:27

Hello, right now when you use "CleanUpAndPack.exe" it will complain when it can't find a version.
Can it be changed so each version is optional?
We have:
  • Win32a
  • Win32w
  • x64w
  • Win32a_MT
  • Win32w_MT
  • x64w_MT
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Can "CleanUpAndPack" be changed so versions are optional?

03 Mar 2020, 18:20

I made some changes, hope you like them:

Code: Select all

If (InStr(A_AhkVersion,"1")=1) {
  MsgBox Requires AutoHotkey V2 version, script will exit now!
  ExitApp
}

SetWorkingDir,% A_ScriptDir

dirs:=[A_ScriptDir "\bin"]

subs := {"Win32a": 0, "Win32w": 0, "x64w": 0, "Win32a_MT": 0, "Win32w_MT": 0, "x64w_MT": 0}
; Set True on existing Folders
Loop, Files, % A_ScriptDir "\bin\*", D
  subs[A_LoopFileName] := 1

exts:=["lib","exp","pdb","iobj","ipdb"]
for t1,dir in dirs
	for t2,ext in exts
		LoopFiles % dir "\*." ext,FR
			If subs.HasKey(SubStr(A_LoopFileDir,InStr(A_LoopFileDir,"\",1,-1)+1))
				FileDelete % A_LoopFileFullPath
for t1,dir in dirs
	LoopFiles % dir "\AutoHotkeyDll.dll",FR
		If subs.HasKey(SubStr(A_LoopFileDir,InStr(A_LoopFileDir,"\",1,-1)+1))
			FileMove,% A_LoopFileFullPath,% RegExReplace(A_LoopFileFullPath,"i)AutoHotkeyDll\.dll","AutoHotkey.dll"),1

; Add existing folders to Array
RCData := {}
Loop, Files, % A_ScriptDir "\bin\*", D
  RCData["bin\" A_LoopFileName] := ["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"]

for k,v in RCData
  LoopFiles % A_ScriptDir "\" k "\*.dll"
  {
    if !hUpdate:=BeginUpdateResource(A_LoopFileFullPath)
    {
      MsgBox % "Error Begin: " A_LoopFileFullPath "`n" ErrMsg()
      ExitApp
    }
    If !EndUpdateResource(hUpdate,0)
    {
      MsgBox % "End: " ErrMsg()
      ExitApp
    }
  }
Loop 2 {
  idx:=A_Index
  for k,o in RCData
  {
    sourcedir:=A_ScriptDir "\" k "\"
    exe:=sourcedir "AutoHotkey" (idx=1?".exe":"SC.bin")
    if !hUpdate:=BeginUpdateResource(exe)
    {
      MsgBox % "Error Begin: " exe "`n" ErrMsg()
      ExitApp
    }
    for k,v in o
    {
      FileRead, data,% "*c " sourcedir "\" v
	  FileGetSize, sz,% sourcedir "\" v
	  sz:=ZipRawMemory(&data, sz, var)
      vres:=v="AutoHotkey.dll"?"F903E44B8A904483A1732BA84EA6191F":v="AutoHotkeyMini.dll"?"FC2328B39C194A4788051A3B01B1E7D5":StrUpper(v)
      if FindResource(hUpdate,10,vres)
        If !UpdateResource(hUpdate,10,vres,1033)
          MsgBox % "Delete: " v "-" ErrMsg()
      If !UpdateResource(hUpdate,10,vres,1033,&var,sz)
        MsgBox % "Update: " v "-" ErrMsg()
      FileDelete,% A_ScriptDir "\temp\" v
      FileDelete,% A_ScriptDir "\temp\" v ".zip"
    }
    if idx=1
    LoopFiles,% A_ScriptDir "\source\resources\reslib\*.ahk"
    {
      FileRead, data,% "*c " A_ScriptDir "\source\resources\reslib\" A_LoopFileName
	  FileGetSize, sz,% A_ScriptDir "\source\resources\reslib\" A_LoopFileName
	  sz:=ZipRawMemory(&data, sz, var)
      if FindResource(hUpdate,"LIB",StrUpper(A_LoopFileName))
        If !UpdateResource(hUpdate,"LIB",StrUpper(A_LoopFileName),1033)
          MsgBox % "Delete: " StrUpper(A_LoopFileName) "-" ErrMsg()
      If !UpdateResource(hUpdate,"LIB",StrUpper(A_LoopFileName),1033,&var,sz)
        MsgBox % "Update: " StrUpper(A_LoopFileName) "-" ErrMsg()
    }
    If !EndUpdateResource(hUpdate,0)
      MsgBox End: %ErrMsg()%
  }
}

finalDone := "Done: "
finalMissing := "Missing: "
for k, v in subs
{
  if (v)
    finalDone .= "`n  " . k
  Else
    finalMissing .= "`n  " . k
}
MsgBox % finalDone "`n`n" finalMissing


;----------------------------------------------------------------
; Function:     ErrMsg
;               Get the description of the operating system error
;               
; Parameters:
;               ErrNum  - Error number (default = A_LastError)
;
; Returns:
;               String
;
ErrMsg(ErrNum:=""){ 
    if (ErrNum="")
        ErrNum := A_LastError
    VarSetCapacity(ErrorString, 1024) ;String to hold the error-message.    
    DllCall("FormatMessage" 
         , "UINT", 0x00001000     ;FORMAT_MESSAGE_FROM_SYSTEM: The function should search the system message-table resource(s) for the requested message. 
         , "UINT", 0              ;A handle to the module that contains the message table to search.
         , "UINT", ErrNum 
         , "UINT", 0              ;Language-ID is automatically retreived 
         , "Str",  ErrorString 
         , "UINT", 1024           ;Buffer-Length 
         , "str",  "")            ;An array of values that are used as insert values in the formatted message. (not used) 
    return return StrReplace(ErrorString,"`r`n",A_Space)      ;Replaces newlines by A_Space for inline-output   
}
Changes:
  • subs starts with all values on False, then the existing folders will be set to True.
  • RCData starts empty, then the existing folders are added as keys with value ["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"]
  • At the end it will display a msgbox showing what folders are done and what folders are missing.
PS: I wanted to make a Pull Request but I'm still trying to figure out how to use Git on windows.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Can "CleanUpAndPack" be changed so versions are optional?

03 Mar 2020, 19:04

Looks good, thanks ;)

Fork ahkdll in internet explorer and then set up git in windows and clone ahkdll to disk.
Then do the changes and create pull request
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Can "CleanUpAndPack" be changed so versions are optional?

04 Mar 2020, 01:10

HotKeyIt wrote:
03 Mar 2020, 19:04
Looks good, thanks ;)

Fork ahkdll in internet explorer and then set up git in windows and clone ahkdll to disk.
Then do the changes and create pull request
Done! I used Github Desktop, easier than command line ahhaha.

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 6 guests