Writing Your Own Installer?

Started by
16 comments, last by RomSteady 18 years, 11 months ago
Quote:Original post by ace_lovegrove
Quote:Original post by petewood
I really would recommend NSIS. It'll let you explore the questions you're asking and you can see what it does and how.
Quote:Well slap my thy and call it Henry there is alot an installer does.

It's 'thigh'. Took me ages to remember how to spell it. After seeing you spell it 'thy', I had a total mental block. Had to type in "connected to the knee bone" in google. [smile]


well it should be thy dammit!!

:)

ACE


I wouldnt get too daunted about this. Most of the stuff mentioned here is only for installing advanced programs (such as the updating locked files stuff).

YOUR installer need do only the things YOu want to to do.

Here is a disription of what my installer that im working on right now does (or will do), so you can see what a amiture half-assed installer does (not half the stuff mentioned above, And lots of things here you could do away with so it can be as simple as you like):

-Read contents of package (e.g what am I?, Title? How much disc space etc?)
-Display EULA if one is included in the package
-Let user choose path/paths to install to
(Note: Start menu shortcuts are files that live in a folder like normal files)
-Display a registration form (if enabled)
-Create required folders
-Unpacks files to the destination folder
-Creates shortcuts as required
-Copies itself into the windows directory (if its a newer version)*
-Adds a registry key for uninstall. The regkey points to the copy of setup in the windows dir with a command line containing uninstall info for the program.
-Dispatch a notification email to myself.
-Launch application if user asks
-Launch read me file if user asks
-Quit


Anyway heres someting to play with to get started a shortcut creator
(I didnt make this btw, so dont blame me for anything!)
#include "shlobj.h"HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc) {     HRESULT hres;     IShellLink* psl; 	 CoInitialize(0);    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,                             IID_IShellLink, (LPVOID*)&psl);     if (SUCCEEDED(hres))     {         IPersistFile* ppf;         psl->SetPath(lpszPathObj);         psl->SetDescription(lpszDesc); 		  hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);         if (SUCCEEDED(hres))         {             WCHAR wsz[MAX_PATH]; 				MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);             hres = ppf->Save(wsz, TRUE);             ppf->Release();         }         psl->Release();     }     return hres; }
Advertisement
Quote:YOUR installer need do only the things YOu want to to do.


No. YOUR installer needs do only the things YOUR CUSTOMERS want it to do. Which is all of the above things, and then some.

Really, installers these days should use the MSIS (Microsoft Installer Services). This means that your installer creator outputs a .msi archive, and then you let Microsoft actually do the installation using the given API. This ensures that permissions, registry, roll-back, user permissions and all that other stuff has reasonable handling.

In fact, InstallShield and friends, these days, are advanced interfaces on top of the MSI engine, and generate .msi output archives. Only NullSoft doesn't, and there are signs that Microsoft is internally debating whether to break those installers in Longhorn.
enum Bool { True, False, FileNotFound };
Well i agree with both of those points but it depends on the target audience. If i am writing an installer that other people will use for their own projects then it needs to do alot, but if its just for me to install a program rudely then i can make it simple.

ace
Quote:Original post by ace_lovegrove
f its just for me to install a program rudely then i can make it simple.


I pray to the coding gods that I never have to test anything you write.

I agree with hplus0603. If you use MSIS, you get a lot of advanced functionality available to you like Install-On-Demand, integrated patch uninstallation, and the ability to repair an installation.

However, while MSIS is extremely powerful, it has some issues. First, the documentation is as cryptic as a Dennis Miller monologue after drinking absinthe. Second, with the exception of WiX (http://wix.sourceforge.net), most of the decent tools are overpriced. Third, the Windows Installer prerequisites are still 3MB+ for the full set. Finally, installation testing tools are piecemeal at best.

If you're doing something quick and dirty, use NSIS or WiX. For professional installations, use InstallShield or WISE.

I appreciate that you want to learn how to write your own installer (based on your original post), but if you aren't going to learn how to do something right, then don't bother learning how to do it at all.
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.
Quote:Original post by RomSteady
I pray to the coding gods that I never have to test anything you write.


Dont then.

ace

Quote:Original post by hplus0603
There are signs that Microsoft is internally debating whether to break those installers in Longhorn.


How do you suggest they do that? By explicitly keeping a list of all known installers and disallow them? That's the only way, unless they want to break backwards compatibility for other apps too - those installers after all just use normal windows API functions, no?

Quote:Original post by hplus0603
No. YOUR installer needs do only the things YOUR CUSTOMERS want it to do. Which is all of the above things, and then some.


Sorry the original post implied he wanted to write his own for his own software.
Perhaps I should refrase it a bit

"An installer for HIM need only the things HE needs it to do"

:D
I'm actually going to debate you on this one.

There are two stated purposes here, both of which are mutually exclusive. One stated purpose is to learn how installers work in order to more fully understand the actions of the production code (refer back to the original post). The other stated purpose is to make something for personal use.

Now when I'm doing something for myself that I know will only ever be run by myself in certain circumstances, I don't mind taking shortcuts. I don't mind hardcoding SQL connection strings in my internal testing tools because I know for a fact that my tools will never exist outside of this network.

However, when I'm writing something to learn, I have to hold myself to a higher standard than that. The focus is not "get it done," it's to make something as functional as possible in order to not only learn the "how," but to also learn the "why" of the project.

Now while none of the "learning" code may ever become public, I have something I can refer back to should I have to write similar code in the future. I can go back and see that I had to shift certain prerequisites to the back of the install chain because their redist didn't have a silent option. I can go back and see that if my patches don't register with MSIS that the uninstaller will leave files and folders behind. I can see why rollback order is so important.

Make no mistake about my intentions...I want people to learn. Learning by doing is not only admirable, but desirable. But building an installer that just copies files without handling these other cases and saying, "Okay, I've learned enough," is like building a miniature cardboard fort and saying that qualifies you to build a skyscraper.
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.

This topic is closed to new replies.

Advertisement