Menu

#561 Compile time way to create constant for file size

3.0 Series
open
nobody
None
5
2021-12-20
2021-12-17
Greg Smith
No

I have an extra file to include with the setup.exe for a project that cannot be added to the build, but needs to be included for size information. Currently I must make an estimate of the size and set it as a constant (and remember to modify it whenever it changes). However, would it be possible to create a !define constant that is the size of a nominated file?

I guess there are other items in the compile time environment that would be useful to grab as constants.

Discussion

  • Anders

    Anders - 2021-12-18

    Use !system to execute a FOR or DIR|FIND command and redirect the output to a .nsh file you can include.

     
    • Greg Smith

      Greg Smith - 2021-12-20

      On 18/12/2021 18:22, Anders wrote:

      Use |!system| to execute a FOR or DIR|FIND command and redirect the
      output to a .nsh file you can include.


      Thank you for taking the time to reply.

      Yes, I had thought of that, but it is such an ugly solution. I
      appreciate that you want to keep everything small, but this must be
      quite a common need...

      Anyhow, many thanks for the great tool.

       
      • Anders

        Anders - 2021-12-20

        I don't know how common it is.

        It is easy enough to do yourself so I'm not sure I see the need for native support.

        !macro GetFileSizeLocal path define
        !tempfile GetFileSizeLocal_
        !system 'for %A in ("${path}") do @echo !define ${define} %~zA > "${GetFileSizeLocal_}"'
        !include "${GetFileSizeLocal_}"
        !delfile "${GetFileSizeLocal_}"
        !undef GetFileSizeLocal_
        !macroend
        
        !insertmacro GetFileSizeLocal "$%windir%\explorer.exe" expsize
        !define /math expsizemb ${expsize} / 1048576
        !warning "Explorer is ${expsize} bytes (~${expsizemb} MiB)."
        
         

        Last edit: Anders 2021-12-20

Log in to post a comment.