Old 15th January 2017, 14:15   #1
Kuppy
Junior Member
 
Join Date: Sep 2016
Posts: 34
Calculate size in decimal?

How do I calculate the size of a file or folder in decimal or bits, megabits, gigabits
PHP Code:
# Copyright CatsSoft

# ...:: INFO ::... #

Name "Test Calc Sise"
OutFile "Test Calc Sise.exe"
InstallDir "$TEMP\Test Calc Sise"

# ...:: COMPRESS ::... #

SetCompressor /SOLID /FINAL lzma

# ...:: RUN ::... #

RequestExecutionLevel user

# ...:: SHOW / HIDE ::... #

ShowInstDetails nevershow
ShowUninstDetails NeverShow

# ...:: INCLUDES ::... #

!include "MUI2.nsh"
!include "WinCore.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"

# ...:: BRANDING ::... #

BrandingText /TRIMRIGHT " "

# ...:: PAGE ::... #

Page custom page1.create
Page instfiles

# ...:: LANGUAGES ::... #

!insertmacro MUI_LANGUAGE "English" # first language

# ...:: INIT ::... #

Function .onInit
FunctionEnd

# ...:: PAGE 1 ::... #

Function page1.create

  
# ...:: VARIABLES ::... #

  
var /GLOBAL Dialog
  
var /GLOBAL Lbl.Sise.Files
  
var /GLOBAL Btn_Add_Files
  
var /GLOBAL Lbl.Sise.Folders
  
var /GLOBAL Btn_Add_Folders

  GetDlgItem 
$0 $HWNDPARENT 1
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 2
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 3
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1990
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1991
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1992
  ShowWindow 
$${SW_HIDE}

  
System::Call "user32::SetWindowPos(i$HWNDPARENT,i,i,i,i 632,i 466,i 0x16)"
  
nsDialogs::Create /NOUNLOAD 1044
  Pop $Dialog
  
${If} $Dialog == error
   Abort
  
${EndIf}
  
System::Call "user32::MoveWindow(i$Dialog,i0,i0,i 632,i 466,i0)"

  
# ...:: SHOW SIZE FILES ::... #

  
nsDialogs::CreateControl STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 5208510""
  
Pop $Lbl.Sise.Files

  
# ...:: BUTTON ADD FILES ::... #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 2075100u 25u ""
  
Pop $Btn_Add_Files
  Strcpy 
$1 $Btn_Add_Files
  GetFunctionAddress 
$".OnClick.Add.Files"
  
nsDialogs::onClick /NOUNLOAD $$3

  SendMessage $Btn_Add_Files 
'${WM_SETTEXT}' '0' "STR:$(^BrowseBtn) Files ..."

  
# ...:: SHOW SIZE FOLDERS ::... #

  
nsDialogs::CreateControl STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 5308510""
  
Pop $Lbl.Sise.Folders

  
# ...:: BUTTON ADD FOLDERS ::... #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 5075100u 25u ""
  
Pop $Btn_Add_Folders
  Strcpy 
$1 $Btn_Add_Folders
  GetFunctionAddress 
$".OnClick.Add.Folders"
  
nsDialogs::onClick /NOUNLOAD $$3

  SendMessage $Btn_Add_Folders 
'${WM_SETTEXT}' '0' "STR:$(^BrowseBtn) Folder ..."

  
nsDialogs::Show

FunctionEnd

# ...:: ADD FILES ::... #

var MYFILES
var MYFOLDERS

var PARENTFILES
var GETFILENAME 

Function ".OnClick.Add.Files"
  
nsDialogs::SelectFileDialog "open" "C:\" "All Files|*.*"
  Pop $0
  StrCmp $0 "
error" +3
    StrCpy 
$MYFILES "$0"

  
${GetParent} "$MYFILES$PARENTFILES
  
${GetFileName} "$MYFILES$GETFILENAME 
  
${GetSize} "$PARENTFILES" "/M=$GETFILENAME /S=0K" $0 $1 $2
    IfErrors 0 +2
    StrCpy $0 $0 * 1024
    IntCmp $0 100 +3 0 +3
      IntCmp $0 0 +2 +2 0
      IntOp $0 103 + 0
    IntOp $0 $0 * 10
    IntOp $0 $0 / 1024
    StrCpy $1 "
$0" "" -1
    IntCmp $0 9 +3 +3 0
      StrCpy $0 "
$0" -1 ""
      Goto +2
      StrCpy $0 "
0"

  
${If} $MYFILES != ""
    SendMessage 
$Lbl.Sise.Files '${WM_SETTEXT}' '0' "STR:Estimated Files Size $0.$1 Mib"
  
${EndIf}
FunctionEnd

# ...:: ADD FOLDERS ::... #

Function "
.OnClick.Add.Folders"
  NsDialogs::SelectFolderDialog "
Select directory" "C:\
  Pop $0 
  StrCmp $0 "
error" +3
    StrCpy 
$MYFOLDERS "$0"

  
${GetSize} "$MYFOLDERS" "/M=*.* /S=0K" $0 $1 $2
    IfErrors 0 +2
    StrCpy $0 $0 * 1024
    IntCmp $0 100 +3 0 +3
      IntCmp $0 0 +2 +2 0
      IntOp $0 103 + 0
    IntOp $0 $0 * 10
    IntOp $0 $0 / 1024
    StrCpy $1 "
$0" "" -1
    IntCmp $0 9 +3 +3 0
      StrCpy $0 "
$0" -1 ""
      Goto +2
      StrCpy $0 "
0"

  
${If} $MYFOLDERS != ""
    SendMessage 
$Lbl.Sise.Folders '${WM_SETTEXT}' '0' "STR:Estimated Folders Size $0.$1 Mib"
  
${EndIf} 
FunctionEnd  

# ...:: SECTION ::... #

Section "
Main" SEC01
SectionEnd

# ...:: END PAGE ::... #

Function .onGUIEnd
FunctionEnd 
Kuppy is offline   Reply With Quote
Old 15th January 2017, 16:39   #2
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 508
Send a message via ICQ to Pawel
You should maybe create some wiki page for this or something...
Btw, it can be done using math plugin... much more simple :P
Pawel is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump