Installer Package using Haskell and NSIS [For other languages]

Scenario : You have created a great software using xyz technology.

The app needs to be shipped now. You/Your firm dont have money to pay to Microsoft for buying visual studio and use the graphical installer [I have it but I really dont like it]

You either know a bit Haskell or ready to explore it.

Procedure:

1. Install NSIS executable from sourceforge. [Its free and lot of professional applications uses it. ]

2. Install haskell NSIS package from cabal. As the description says it provide alternative “Haskellish” syntax to NSIS script.

3. Start building ——->

Problems that you might face.

Problem 1: The given example at the hackage site dont work you get error about expected String and [Char]

Solution: Use the compiler directive {-# LANGUAGE OverloadedStrings #-}

Problem 2: The example in Hackage was too simplistic.

I am posting one sample installer (Intermediate difficulty here to help the beginners who might not be very happy with the example provided in the package. (Best way is to look through source code but this is for a guy who has to deliver the solution in say 2 days (Actually like me) )

import Development.NSIS
main = writeFile "Your cool app.nsi” $ nsis $ do
name “Your cool app” -- The name of the installer
outFile “Your cool app.exe” -- Where to produce the installer
installDir “$APPDATA/registryTree” -- The default installation directory
requestExecutionLevel User -- Request application privileges for Windows Vista
setCompressor LZMA [Solid]
-- EyeCandies
installIcon “pathtoiconfile/icon.ico”
headerImage $ Just “icon.ico”
-- Pages to display
page Components
page Directory -- Pick where to install
page InstFiles -- Give a progress bar while installing
unpage Confirm
unpage InstFiles
-- Groups fo files to install
section “Your cool app” [Required] $ do
setOutPath “$INSTDIR” -- Install Loc
file [Recursive] “Your cool app/*” -- This is from where it will pick files
writeRegStr HKCU “Software/VB and VBA Program Settings/somehting” “PATH” “$INSTDIR/dlls”
-- Write the uninstall keys for Windows
writeRegStr HKCU “Software/Microsoft/Windows/CurrentVersion/Uninstall/Your cool app” “DisplayName” “Cool app's cool name”
writeRegStr HKCU “Software/Microsoft/Windows/CurrentVersion/Uninstall/Your cool app” “UninstallString” “\”$INSTDIR/uninstall.exe\”“
writeRegDWORD HKCU “Software/Microsoft/Windows/CurrentVersion/Uninstall/Your cool app” “NoModify” 1
writeRegDWORD HKCU “Software/Microsoft/Windows/CurrentVersion/Uninstall/Your cool app” “NoRepair” 1
writeUninstaller “uninstall.exe”
section “Start Menu Shortcuts” [] $ do
createDirectory “$SMPROGRAMS/Your cool app dir”
createShortcut “$SMPROGRAMS/Your cool app/Uninstall.lnk” [Target “$INSTDIR/uninstall.exe”, IconFile “$INSTDIR/uninstall.exe”,IconIndex 0]
uninstall $ do
deleteRegKey HKCU “Software/Microsoft/Windows/CurrentVersion/Uninstall”
deleteRegKey HKCU “Software/VB and VBA Program Settings/”
delete [] “$INSTDIR/You Cool app dir/*”
delete [] “$INSTDIR/uninstall.exe”
delete [] “$SMPROGRAMS/Your cool app/*.*”
rmdir [Recursive] “$SMPROGRAMS/Your cool app”
rmdir [Recursive] “$INSTDIR”

That’s all from script part.

There are couple of steps that you need to do after this as well.

I have built a batch file to do that work for me, feel free to use it.

 Tasks that are required after this:
1. Compile this file
2. Run the .exe created by it
3. call makensis on the otherexe that would be created
4. Cleanup (If required )
[Here I am assuming your file name is install.hs]
so here goes the batch script to automate this work

@echo off
call :startInstaller > InstallLog.txt
goto:eof

:startInstaller
ghc Install.hs
rem now comes the name of your file
Your cool app.exe.exe
echo "Creating the new installer now"
"C:\Program Files\NSIS\makensis.exe" Your cool app.exe.nsi
del Your cool app.exe.nsi
del Installer.o
del Installer.exe
del Installer.hi

:eof
echo "Installer generated at location:"
echo %CD%
pause
Advertisements

Building haskell package without cabal

The situation is that you are working under (non- constructive) restricted environment where you can’t use cabal:

So here it goes ( I am trying to install a package called nsis for building microsoft installer .msi files)

1. Download the zip file. 

2. Check dependancies for the package (In this case a) Base (4.*), transformer, uniplate)

3. So for my case I dont have transformer (So goto step 1)

4. unzip the tar and go to the directory there via cmd

5. Run (in the order) runHaskell Setup.hs configure, then runHaskell Setup.hs build, then runHaskell Setup.hs install

Hopefull everything goes right and you get the package installed 🙂

Emacs and GVim

I am trying to learn Emacs while I am quite proficient in Gvim. The reason for learning Emacs is it has inbuilt support for Lisp.

I am planning to compile my version of commands that I use a lot in Vi

1. Basic movement (Skipping as pretty easy to fine on net )

2. Go to line number — VI — [n] + G —- Emacs — Meta + g + g + [n]

3. In line reach to the 2nd occurance of char ‘c'[Forward/Backward] — VI — 2[f/F]’c’ — Emacs (you can only do incremental search and press that twice Ctrl + [s/r] + ‘c’, Ctrl + [s/r]

4. Abbrevations sm–> small text — Vi —– Esc + :ab sm small text —— Emacs

a. Write sm in text mode

b Ctrl + x + [a i l] / [a i g ] (add inverse global/local)

5. Undo — Vi — Have registers and a specific undo/kill is stored in that register can be used by typing “+[Register name] — Emacs has something called kill ring which can be accessed by first using Ctrl-y and then after this Alt+y (Note that first you have to use Ctrl+ y otherwise it just does not work )

6. Split screen working — Vi — use vsplit or hsplit for vertical or horizontal splitting. Navigation use Ctrl + w + w , Closing uses :bd– Emacs uses Ctrl + x + 2/3 (Horizontal/ Vertical) splitting and Closing uses Ctrl + x + 1(All except this one) or Ctrl + x + 0 (This one )

Navigation uses Ctrl + x + o (Emacs have frames which are Ctrl+ x + 5 + Filename/buffer name)

7 Macro Recording and usage — Vi— Start recording by q[a-z] stop by pressing q

Repeat by pressing @@ for last reorded and @[a-z] for named

–Emacs—Start recording by pressing F3 and stop by pressing F4

Repeat by pressing F4 for last recorded and

Edit by using Ctrl-x Ctrl-k e (edit-kbd-macro)

bind by Ctrl-x Ctrlk b then [0-9][A-Z]

Cycle Ctrl-c Ctrl-k Ctrl-p/n [Previous/Next]
8. Indentation — Vi — Does not uses any command but you can install plugins to do auto indentation Cmd-Mode:set auto-indent on —-
Emacs- Ctrl+Space to select the area –> Ctrl-Alt+\
9. Multi line tab — Vi — In cmd Mode press shift+V [Visual mode] –>
select lines to add/remove tab press > or select region –> press Ctrl + x + Tab

10.Changing the special charecters to unix style than dos style (applicable for emacs MS version)

C-x RET f then unix