primes.nsi 1.5 KB

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