Jump to content
DanielRossinsky

FileInstall doesn't extract .zip or .rar files - (Moved)

Recommended Posts

What i'm trying to achieve is to bundle a few folders within the executable script and from what I've read it can be done with:

#include <FileConstants.au3>

FileInstall(src, dest, $FC_OVERWRITE)

I know that src must be a literal string and cant be a variable or macro. However, I also learned that I cant just install a folder but there is a workaround that uses 7zip or winrar so that FileInstall extracts the folder to the desired location (e.g. to dest) so I wend and tried both variants: 

  1. I zipped a single folder just for testing.
  2. I winrared a single folder just for testing.

Keep in mind that both the .zip and .rar are the same folder with the same content.

The problem I ran into is that FileInstall simply moves the .rar or .zip folder to the desired location but it doesn't extract it!

#RequreAdmin

#include <FileConstants.au3>

Func installESPLibraries()
    Local Const $sLibrariesPath = @LocalAppDataDir & "\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries"

    FileInstall("esp-libraries\ESP32-ADXL345.rar", $sLibrariesPath & "\", $FC_OVERWRITE)
EndFunc   

installESPLibraries()

The result I'm left with is that ESP32-ADXL345.rar just gets moved to $sLibrariesPath (so it does kinda work). The result I want is to have ESP32-ADXL345.rar extracted to the same location so that I have only a folder with the name ESP32-ADXL345 without any winrar files. Is there a way to achieve such a thing ? (because i'm sure there is).

NOTE: I already did search the forum for such a solution:

  1. how to use fileinstall
  2. want to bundle my exe foldersfiles
  3. embedding images folders in exe

However, They all show practical examples with files and none with folders (the third link mentions folders but has no examples) so I am at a loss as to how it should be done.

 

EDIT:

Thanks to @Musashi and @Nine for pointing out what I was missing! Also, I would like to add my solution:

#RequreAdmin

#include <FileConstants.au3>

; Create a local constant string to hold a path to the folder where we will be installing the libraries
Local Const $sLibrariesPath = @LocalAppDataDir & "\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\"

; Unpack libraries.rar to the path we defined
FileInstall("libraries.rar", $sLibrariesPath, $FC_OVERWRITE)

; Run the batch script to extract libraries.rar at the path we defined
RunWait("unrar.bat " & $sLibrariesPath & " libraries.rar", "", @SW_HIDE)

; Deletes libraries.rar
FileDelete($sLibrariesPath & "libraries.rar")

I attached the .bat file I wrote to make it work. The reasoning for this solution is to show how its done cleanly with .rar files as I didn't see anyone do it this way. Hope it helps people in the future!

unrar.bat

Edited by DanielRossinsky
A solution has been found

Share this post


Link to post
Share on other sites

The function name FileInstall can, in my opinion, be a bit misleading. As you have already discovered yourself, FileInstall will embed a file into the .exe and copy it to the specified destination directory when the .exe get's started.

To unzip the file (let's take a .zip as an example), you need an additional step. One possibility would be to additionally embed the standalone command line variant of 7-Zip (7za.exe) into your script and use it to extract the .zip. 


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

You will need to unzip the the files/folders from the zip file after FileInstall.  You can Run the extractor or use Shell.Application COM object to extract the .zip without external application. 

Edit : Also remember that there is a size limit of 2GB on FileInstall

Edited by Nine

Share this post


Link to post
Share on other sites
4 minutes ago, DanielRossinsky said:

I thought that FileInstall should extracts the archives from its help page.

Here an example with 7za.exe :

$s7ZipDir = @ScriptDir
$sFile    = "Testfile.zip" ; the file, that was embedded via FileInstall
$sDestDir = @ScriptDir & "\mysoftware"
$sCommand = $s7ZipDir & '\7za.exe x "' & $sFile & '" -o"' & $sDestDir & '" -aoa -y'
RunWait ($sCommand, "", @SW_HIDE) ; or @SW_SHOW

 


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

@Nine is of course right when he says, that you can also use the Windows built-in zip functionality. I usually take the standalone versions of 7Zip, but this is just my personal preference :).

I have attached the required 7Zip modules. You have to embed them into your script using FileInstall. A nice feature is that with 7zG.exe a progress bar is displayed.

Example :

$s7ZipDir = @ScriptDir
$sFile    = "Testfile.zip" ; the file, that was embedded via FileInstall
$sDestDir = @ScriptDir & "\mysoftware"
$sCommand = $s7ZipDir & '\7zG.exe x "' & $sFile & '" -o"' & $sDestDir & '" -aoa -y'
RunWait ($sCommand, "", @SW_SHOW)

 

7ZipPrograms.zip


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

@Musashi It is true that I always try to avoid downloading stuff if I can easily use built-in functionality (old fashion way).  So to give OP a perspective of choices, here the unzip function that I use :

#include <Constants.au3>
#include <String.au3>

Opt("MustDeclareVars", 1)

Const $sZipFile = @ScriptDir & "\Test.zip"
Const $sFolder = @ScriptDir & "\Temp"

DirRemove ($sFolder, $DIR_REMOVE)
UnZip($sZipFile, $sFolder)
If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error unzipping files : " & @error)

Func UnZip($sZipFile, $sDestFolder)
  If Not FileExists($sZipFile) Then Return SetError (1) ; source file does not exists
  If Not FileExists($sDestFolder) Then
    If Not DirCreate($sDestFolder) Then Return SetError (2) ; unable to create destination
  Else
    If Not StringInStr(FileGetAttrib($sDestFolder), "D") Then Return SetError (3) ; destination not folder
  EndIf
  Local $oShell = ObjCreate("shell.application")
  Local $oZip = $oShell.NameSpace($sZipFile)
  Local $iZipFileCount = $oZip.items.Count
  If Not $iZipFileCount Then Return SetError (4) ; zip file empty
  For $oFile In $oZip.items
    $oShell.NameSpace($sDestFolder).copyhere($ofile)
  Next
EndFunc   ;==>UnZip

 

Share this post


Link to post
Share on other sites

Moved to the appropriate forum.

Moderation Team


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
3 hours ago, Skysnake said:

Added to the Wiki

:) Also got the zip counterpart of it if you want for the Wiki (which I find quite interesting indeed).

Edited by Nine

Share this post


Link to post
Share on other sites
2 hours ago, Skysnake said:

Please send?

Here the full example :

#include <Constants.au3>
#include <String.au3>

Opt("MustDeclareVars", 1)

Const $sZipFile = @ScriptDir & "\Test.zip"
Const $sFolder = @ScriptDir & "\Temp"
Const $sZipNew = @ScriptDir & "\Test2.zip"

DirRemove ($sFolder, $DIR_REMOVE)
UnZip($sZipFile, $sFolder)
If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error unzipping files : " & @error)
FileDelete ($sZipNew)
Zip ($sZipNew, $sFolder)
If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error zipping files : " & @error)

Func UnZip($sZipFile, $sDestFolder)
  If Not FileExists($sZipFile) Then Return SetError (1) ; source file does not exists
  If Not FileExists($sDestFolder) Then
    If Not DirCreate($sDestFolder) Then Return SetError (2) ; unable to create destination
  Else
    If Not StringInStr(FileGetAttrib($sDestFolder), "D") Then Return SetError (3) ; destination not folder
  EndIf
  Local $oShell = ObjCreate("shell.application")
  Local $oZip = $oShell.NameSpace($sZipFile)
  Local $iZipFileCount = $oZip.items.Count
  If Not $iZipFileCount Then Return SetError (4) ; zip file empty
  For $oFile In $oZip.items
    $oShell.NameSpace($sDestFolder).copyhere($ofile)
  Next
EndFunc   ;==>UnZip

Func Zip ($sZipFile, $sSourceFolder)
  If FileExists($sZipFile) Then Return SetError (1) ; destination file already exists
  If Not FileExists($sSourceFolder) Then Return SetError (2) ; source does not exist
  Local $hFile = FileOpen ($sZipFile, $FO_CREATEPATH+$FO_OVERWRITE+$FO_BINARY)
  Local Const $sString = Chr(80) & Chr(75) & Chr(5) & Chr(6) & _StringRepeat (Chr(0), 18) ; create ZIP file signature
  FileWrite ($hFile, $sString)
  FileClose($hFile)
  Local $oShell = ObjCreate("shell.application")
  If Not $oShell.NameSpace ($sSourceFolder).items.count Then Return SetError (3) ; folder empty
  Local $iFiles = 0
  For $oFile In $oShell.NameSpace($sSourceFolder).items
    $oShell.NameSpace($sZipFile).copyhere($oFile)
    Do
      Sleep (100) ; let the file being copied to ZIP
    Until $oShell.NameSpace($sZipFile).items.count > $iFiles
    $iFiles = $oShell.NameSpace($sZipFile).items.count
  Next
EndFunc

 

Edited by Nine
corrected a small bug

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By lonardd
      Hi,
      I have a source Script where I inserted the following code lines to be able to extract the script source code anytime later if I run it with the /ExtractSourceCode:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
      #AutoIt3Wrapper_UseX64=n
      #AutoIt3Wrapper_Change2CUI=y
      #AutoIt3Wrapper_Res_SaveSource=Y
      #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
      If StringInStr($cmdlineRaw, "/ExtractSourceCode") Then
          FileInstall(@ScriptFullPath, @ScriptDir & "\" & @ScriptName & ".txt", 1)  
          ;FileInstall("C:\Test.txt", @ScriptDir & "\Test.txt")
          Exit
      EndIf
      I used to be able to compile it on another computer some years ago without problems.
      Now I wanted to modify the code, so I extracted it, renamed the file *.au3, performd my little modification and rebuild.
      Strangely, I get this popup with Caption: Aut2Exe Error and Invalid FileInstall() function.
      BEfore I hit the OK button on the Popup, I can see the file is actually Built as I can see that an EXE file is created, but as I hit OK in that error dialog, the EXE disappears.
      Any advice?
      Thanks
      David
      I can't remember if I did it with Autoit 2 
      EPP_NF_Replacer_UBI.au3
    • By Gowrisankar
      Dear members, 
      I am working on a project where, emails from outlook are to be read and moved to various folders within the mailbox, based on the content of the emails.
      I used the below code for moving mails. It works fine when I run it against individual mail ids. But when I run it on Shared mailbox, the mails are not moved to respective folders.
      _OL_ItemMove($oOutlook, $sEntryId, Default, $sDestinationFolder) The value of $sEntryId is saved in an excel report initially. The current process reads the $sEntryId from the excel and passes it to "_OL_ItemMove" statement.
      Requesting the guidance of the forum members in this issue.
    • By Gowrisankar
      Dear members,
      I'm trying to move unread mails from Inbox to a different folder using OutlookEx UDF.
      But its not working for me. I'm not sure what mistake I do.
      I get the error code 6 when the following is executed. From the UDF it is observed that  "No or an invalid item has been specified".
      Note : The UDF version is 1.3.3.1. AutoIt version (v3.3.14.2).
      #include <OutlookEX.au3> Global $oOutlook = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) Global $aOL_Item = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[UnRead]=True", "", "", "Subject", "", 1) If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Could not find a task item in folder 'Outlook-UDF-Test\SourceFolder\Tasks'. @error = " & @error) _ArrayDisplay($aOL_Item, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails") _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "*\Outlook-UDF-Test\TargetFolder\Mail") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Error moving specified task. @error = " & @error) Any help is deeply appreciated. Thanks in advance.
      Thanks and regards,
      Gowrisankar R.
    • By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
    • By Barrtrek
      I get the "Unable to add resources" error related to AppData\Local\AutoIt v3\Aut2Exe when compiling with a large FileInstall of a 1.5GB file.  Is there a size limit I need to be aware of?  I've also disabled or removed Trend from three different machines and had the same results.  I've had issues like this in the past but have compiled after the Aut2Exe folder was excluded in AV.  That doesn't seem to be the problem this time around.  If I comment out the FileInstall the script compiles successfully.
×
×
  • Create New...