Jump to content

FileInstall and GUI Progress


Recommended Posts

Hi, I have created an AutoIT script which includes about 1500 Resource Files and I'm using the FileInstall to extract them.
I have this all compiling and extracting correctly and now wanting to check the progress of each file as it Extracts and link this to the GUI Progress which is where I'm unsure.

I was thinking of simply continuing to check the output folder size to see how many files are there but if I run this in a loop it won't continue with the FileInstall?
I was also thinking of using GUIRegisterMsg but not what Windows Message I could use to trigger the function as it's doing the FileInstall?

Any ideas would be great, thanks!

Link to comment
Share on other sites

2 hours ago, DarkBoost said:

... about 1500 Resource Files ...

and you have 1500 FileInstall calls in your script ?!

how about this: compress them all to a 7z archive, and when extracting you can read the stdout of 7z.exe and parse the percentage indicator.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Yes there are many of ways of doing this however AutoIT has this feature and I would like to use it.

Here is a small example of my script - I and not sure how to get the Progress to Update after each file has been installed.
I do not want to hard code a Progress Update after each FileInstall if possible.

Thanks.

 

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_File_Add=D:\script\File_001.txt
#AutoIt3Wrapper_Res_File_Add=D:\script\File_002.txt
#AutoIt3Wrapper_Res_File_Add=D:\script\File_003.txt
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>

GUICreate("Title", 300, 120)
Global $PROGRESS = GUICtrlCreateProgress(10, 10, 280, 30)
Global $BUTTON = GUICtrlCreateButton("Install", 10, 50, 280, 60)
GUISetState(@SW_SHOW)

Global $MSG

While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

        Case $MSG = $BUTTON
            _install()
    EndSelect
WEnd

Func _install()

    Local $INSTALL = "D:\Install"

    DirCreate($INSTALL)

    FileInstall("D:\script\File_001.txt", $INSTALL & "\File_001.txt")
    FileInstall("D:\script\File_002.txt", $INSTALL & "\File_002.txt")
    FileInstall("D:\script\File_003.txt", $INSTALL & "\File_003.txt")

    MsgBox(0, "Finished", "Files have been installed...")

EndFunc

 

Link to comment
Share on other sites

write a wrapper function for FileInstall, which accepts the same parameters as FileInstall, performs the FileInstall exactly the same way, but in addition increases the progress bar by some percent. then replace all your FileInstall calls with that function.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Func FileInstallWithProgress($sSource, $sDest, $iFlag = 0)
    FileInstall($sSource, $sDest, $iFlag)
    GUICtrlSetData($PROGRESS, GUICtrlRead($PROGRESS) + 1) ; assuming you increase progress by 1%
EndFunc   ;==>FileInstallWithProgress

this function "wraps" the FileInstall call, hence "wrapper". call this function in your main script instead of calling FileInstall.

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

You can't use FileInstall with a variable as the source parameter.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

11 hours ago, BrewManNH said:

You can't use FileInstall with a variable as the source parameter.

Yeah this is why I posted here... I have just found a solution as shown below, thanks!

#include <Array.au3>

Global $array[1] = [0]
Global $path = "d:\install\"

_ArrayAdd($array, FileInstall("d:\file_001.txt", $path & "file_001.txt"))
_ArrayAdd($array, FileInstall("d:\file_002.txt", $path & "file_002.txt"))
_ArrayAdd($array, FileInstall("d:\file_003.txt", $path & "file_003.txt"))

DirCreate($path)

$array[0] = Ubound($array) - 1

For $a = 1 To $array[0]
    Execute($array[$a])
Next

 

Edited by DarkBoost
Link to comment
Share on other sites

Nope this isn't working as expected, it's doing the FileInstall as it's being added to the Array :(
Bit the bullet and hardcoded the progress which wasn't too bad since the code was being generated anyways.
 

Edited by DarkBoost
Link to comment
Share on other sites

Make it like this:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Global $array[1] = [0]
Global $path = "c:\install\"

_ArrayAdd($array, 'FileInstall("test.au3", $path & "file_001.txt")')
_ArrayAdd($array, 'FileInstall("test2.au3", $path & "file_002.txt")')
_ArrayAdd($array, 'FileInstall("test3.au3", $path & "file_003.txt")')

DirCreate($path)

$array[0] = UBound($array) - 1
;_ArrayDisplay($array)
$hGui = GUICreate("Fileinstall Test", 300, 125, 302, 218)
$idprgInfo = GUICtrlCreateProgress(8, 70, 285, 30)
$hGUI_c = GUICreate("", 184, 30, 8, 73, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGui)
GUISetBkColor(0x989898, $hGUI_c)
$idlblInfo = GUICtrlCreateLabel("0", 0, 0, 184, 25, $ES_CENTER)
GUICtrlSetFont(-1, 12, 1000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
_WinAPI_SetLayeredWindowAttributes($hGUI_c, 0x989898)
GUISetState(@SW_SHOW, $hGui)
GUISetState(@SW_SHOWNA, $hGUI_c)

For $a = 1 To $array[0]
    Sleep(Random(500,2000,1))
    Execute($array[$a])
    _ShowProgress($a*100/$array[0],$idprgInfo,$idlblInfo)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _ShowProgress($iPercent,$idPrg,$idLbl=0)
    ConsoleWrite($iPercent&@CRLF)
    Local Static $iOld
    if int($iPercent)=$iOld Then
        Return
    Else
        $iOld=Int($iPercent)
    EndIf
    GUICtrlSetData($idPrg,$iPercent)
    if $idLbl<>0 Then GUICtrlSetData($idLbl,$iPercent)
EndFunc

this works for me, the sleep is only that you can see the progress after each FileInstall, you can remove it or use a small fix sleeptime.

 

Edit: works only as script not as compiled exe.

Edited by AutoBert
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...