Statistiques
| Révision :

root / tmp / org.txm.setups / nsis / Examples / primes.nsi @ 3079

Historique | Voir | Annoter | Télécharger (1,62 ko)

1 728 mdecorde
; primes.nsi
2 728 mdecorde
;
3 728 mdecorde
; This is an example of the possibities of the NSIS Script language.
4 728 mdecorde
; It calculates prime numbers.
5 728 mdecorde
6 728 mdecorde
;--------------------------------
7 728 mdecorde
8 728 mdecorde
Name "primes"
9 728 mdecorde
AllowRootDirInstall true
10 728 mdecorde
OutFile "primes.exe"
11 728 mdecorde
Caption "Prime number generator"
12 728 mdecorde
ShowInstDetails show
13 728 mdecorde
AllowRootDirInstall true
14 728 mdecorde
InstallDir "$EXEDIR"
15 728 mdecorde
RequestExecutionLevel user
16 728 mdecorde
17 728 mdecorde
DirText "Select a directory to write primes.txt. $_CLICK"
18 728 mdecorde
19 728 mdecorde
;--------------------------------
20 728 mdecorde
21 728 mdecorde
;Pages
22 728 mdecorde
23 728 mdecorde
Page directory
24 728 mdecorde
Page instfiles
25 728 mdecorde
26 728 mdecorde
;--------------------------------
27 728 mdecorde
28 728 mdecorde
Section ""
29 728 mdecorde
  SetOutPath $INSTDIR
30 728 mdecorde
  Call DoPrimes
31 728 mdecorde
SectionEnd
32 728 mdecorde
33 728 mdecorde
;--------------------------------
34 728 mdecorde
35 728 mdecorde
Function DoPrimes
36 728 mdecorde
37 728 mdecorde
; we put this in here so it doesn't update the progress bar (faster)
38 728 mdecorde
39 728 mdecorde
!define PPOS $0 ; position in prime searching
40 728 mdecorde
!define PDIV $1 ; divisor
41 728 mdecorde
!define PMOD $2 ; the result of the modulus
42 728 mdecorde
!define PCNT $3 ; count of how many we've printed
43 728 mdecorde
  FileOpen $9 $INSTDIR\primes.txt w
44 728 mdecorde
45 728 mdecorde
  DetailPrint "2 is prime!"
46 728 mdecorde
  FileWrite $9 "2 is prime!$\r$\n"
47 728 mdecorde
  DetailPrint "3 is prime!"
48 728 mdecorde
  FileWrite $9 "3 is prime!$\r$\n"
49 728 mdecorde
  Strcpy ${PPOS} 3
50 728 mdecorde
  Strcpy ${PCNT} 2
51 728 mdecorde
outerloop:
52 728 mdecorde
   StrCpy ${PDIV} 3
53 728 mdecorde
   innerloop:
54 728 mdecorde
     IntOp ${PMOD} ${PPOS} % ${PDIV}
55 728 mdecorde
     IntCmp ${PMOD} 0 notprime
56 728 mdecorde
     IntOp ${PDIV} ${PDIV} + 2
57 728 mdecorde
     IntCmp ${PDIV} ${PPOS} 0 innerloop 0
58 728 mdecorde
       DetailPrint "${PPOS} is prime!"
59 728 mdecorde
       FileWrite $9 "${PPOS} is prime!$\r$\n"
60 728 mdecorde
       IntOp ${PCNT} ${PCNT} + 1
61 728 mdecorde
       IntCmp ${PCNT} 100 0 innerloop
62 728 mdecorde
       StrCpy ${PCNT} 0
63 728 mdecorde
       MessageBox MB_YESNO "Process more?" IDNO stop
64 728 mdecorde
     notprime:
65 728 mdecorde
       IntOp ${PPOS} ${PPOS} + 2
66 728 mdecorde
     Goto outerloop
67 728 mdecorde
   stop:
68 728 mdecorde
  FileClose $9
69 728 mdecorde
70 728 mdecorde
FunctionEnd