private void InitializeProject(string productname, string productversion, string productpublisher, string productweb_site, string Outfile, Dir Directory, params object[] Actions) { this.product_name = productname; this.product_version = productversion; this.product_publisher = productpublisher; this.product_web_site = productweb_site; this.CreateUninstaller = true; //Default value = true. this.CreateStartMenuShortCut_Website = true; // Default value = true. this.CreateStartMenuShortCut_Uninstaller = true; // Default value = true. this.MUI_FILENAME = "MUI2.nsh"; this.InstallDirectory = "$INSTDIR"; //Deprecated. this.dir = Directory; //this.files = Files; /* Console.WriteLine(this.GetFileName(this.files[0].sourcepath)); Console.ReadLine(); */ this.MainAppName = this.GetFileName(this.dir.Files[0].sourcepath); this.write_product_dir_regkey = true; this.write_product_uninst_key = true; this.product_dir_regkey = @"Software\Microsoft\Windows\CurrentVersion\App Paths\" + this.MainAppName; this.product_uninst_key = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\" + this.product_name; this.product_uninst_root_key = "HKLM"; this.AbortWarning = true; this.InstallIcon = @"${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"; this.UnInstallIcon = @"${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"; this.pages = new List<Page>(); this.components = new List<Component>(); this.outfile = Outfile; this.GetDotNetFrameworkVersion = false; this.RunAppAfterInstall = true; //Checking if there are any custom actions set. if (Actions != null) { //Looping through each action and determine its type. for (int i = 0; i < Actions.Length; i++) { //Actions[i] could be an object array. Do some magic to workaround this. List<object> tempactionobjectlist = new List<object>(); if (Actions[i] is object[]) { foreach (object o in Actions[i] as object[]) { tempactionobjectlist.Add(o); } } else { tempactionobjectlist.Add(Actions[i]); } foreach (object ActionObject in tempactionobjectlist) { if (ActionObject is DotNetFrameworkVersion) { CheckDotNetFrameworkVersion.Add(ActionObject as DotNetFrameworkVersion); } else { if (ActionObject is Page) { pages.Add(ActionObject as Page); } else { if (ActionObject is Component) { Component c = ActionObject as Component; if (!c.IsGroup || c.ComponentList.Count > 0) { this.components.Add(ActionObject as Component); } } else { if (ActionObject is InstallType) { this.InstallTypes.Add(ActionObject as InstallType); } else { if (ActionObject is RegValue) { //Action = RegValue. //Add the RegValue to the RegistryValues List. This will be used for the compiler that will process each registry value. this.RegistryValues.Add(ActionObject as RegValue); } else { if (ActionObject is x64) { this.x64Actions.Add(ActionObject as x64); } else { if (ActionObject is x86) { this.x86Actions.Add(ActionObject as x86); } else { throw new Exception("Unexpected object type as among NSISProject constructor arguments is: " + ActionObject.GetType().Name); } } } } } } } } } } }
/// <summary> /// Creates a new NSIS project. /// </summary> /// <param name="productname">Name of your product/application.</param> /// <param name="productversion">Version of your product/application.</param> /// <param name="productpublisher">The publisher of your product/application.</param> /// <param name="productweb_site">Website of your product/application.</param> /// <param name="Outfile">Filename of the setup that will be created with this NSIS project.</param> /// <param name="Directory">Directories that contains all files that will be installed.</param> public NSISProject(string productname, string productversion, string productpublisher, string productweb_site, string Outfile, Dir Directory) { this.InitializeProject(productname, productversion, productpublisher, productweb_site, Outfile, Directory, null); }
/// <summary> /// Creates a new NSIS project. /// </summary> /// <param name="productname">Name of your product/application.</param> /// <param name="productversion">Version of your product/application.</param> /// <param name="productpublisher">The publisher of your product/application.</param> /// <param name="productweb_site">Website of your product/application.</param> /// <param name="Outfile">Filename of the setup that will be created with this NSIS project.</param> /// <param name="Directory">Directories that contains all files that will be installed.</param> /// <param name="Actions">All custom actions.</param> public NSISProject(string productname, string productversion, string productpublisher, string productweb_site, string Outfile, Dir Directory, params object[] Actions) { this.InitializeProject(productname, productversion, productpublisher, productweb_site, Outfile, Directory, Actions); }
static void Main(string[] args) { /* ----------------------------------------------------------------------------------------------- * Setup code for creating the NSISSharp installation file. * ----------------------------------------------------------------------------------------------- */ string NSISLocation = @"C:\Program Files (x86)\NSIS"; //Create installation directory, and add files, which will be installed. Dir Core = new Dir(); Core.Files.Add(new File(@"P:\Visual Studio\Projects\NSISSharp\NSISSharpTestApp\bin\Release\NSISSharp.dll")); Core.Files.Add(new File(@"P:\Visual Studio\Projects\NSISSharp\NSISSharpTestApp\bin\Release\NSISSharp.xml")); Core.Files.Add(new File(@"Z:\NSISSharp\readme.txt")); Core.Files.Add(new File(@"Z:\NSISSharp\changelog.txt")); Core.Files.Add(new File(@"Z:\NSISSharp\license.txt")); //Do the same as above, only for sub directories. Dir Scripts = Core.CreateSubDirectory("NSIS scripts"); Scripts.Files.Add(new File(@"C:\Program Files (x86)\NSIS\Include\DotNetVersionNumber.nsh")); Scripts.Files.Add(new File(@"C:\Program Files (x86)\NSIS\Include\DotNetVer.nsh")); //VS example files. Dir Examples = Core.CreateSubDirectory("Examples"); Examples.Files.Add(new File(@"Z:\NSISSharp\Examples\*.*", true)); //Create a NSIS project. NSISProject project = new NSISProject( "NSISSharp", "v0.3", "OrangePlanet.org", "http://orangeplanet.org", "NSISSharp_v0.3.exe", Core, //Adding pages for the installer. //The following pages are default, and this is the same when you're not specifying any pages (except the license and components page). //It is possible to use certain pages only, instead of all; PAGE_INSTFILES and PAGE_LANGUAGE are always required, however. new Page(Page.PAGE_WELCOME), new Page(Page.PAGE_LICENSE, @"Z:\NSISSharp\license.txt"), new Page(Page.PAGE_COMPONENTS, true), new Page(Page.PAGE_DIRECTORY), new Page(Page.PAGE_INSTFILES), new Page(Page.PAGE_FINISH), new Page(Page.PAGE_UNINSTALL), new Page(Page.PAGE_LANGUAGE, null, Page.LANGUAGE_FILE_ENGLISH), new InstallType("Full"), new InstallType("Lite"), new InstallType("Minimal"), new Component("NSISSharp", "Contains the NSISSharp dll and various txt files (e.g. the readme.txt).", false, true, false, new int[] {0,1,2}, Core, //x64/x86 specific actions. For now, only Registry related actions are supported. Future versions of NSISSharp should expand this to support more actions. new x64(Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v" + DotNetFramework.v40.Version + @"\AssemblyFoldersEx\NSISSharp").SetValue("", NSISProject.InstallDir)), new x86(Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\v" + DotNetFramework.v40.Version + @"\AssemblyFoldersEx\NSISSharp").SetValue("", NSISProject.InstallDir))), new Component("NSIS Scripts", "Contains custom NSIS header files, related to .NET.", false, false, false, new int[] {0,1}, Scripts), new Component("Examples", "NSISSharp VS2010 examples.", false, false, false, new int[] {0}, Examples), //Check if .NET Framework 4.0 is installed on the users system. DotNetFramework.CheckVersion(DotNetFramework.v40)); //Retrieving .NET Framework version numbers, necessary if you want to use the .NET Framework version numbers (e.g. DotNetFramework.v40.Version). project.GetDotNetFrameworkVersion = true; //The values of the following four properties are generally left unchanged. //Therefore, these properties could be omitted, unless you want to change the values. project.CreateUninstaller = true; project.write_product_dir_regkey = false; project.write_product_uninst_key = true; project.RunAppAfterInstall = false; project.CreateStartMenuShortCut_Uninstaller = false; project.CreateStartMenuShortCut_Website = false; //Set icons, images, etc. project.InstallIcon = NSISLocation + @"\Contrib\Graphics\Icons\orange-install.ico"; project.UnInstallIcon = NSISLocation + @"\Contrib\Graphics\Icons\orange-uninstall.ico"; project.SetHeaderImage(NSISLocation + @"\Contrib\Graphics\Header\orange-r.bmp", true, true); project.SetWelcomeFinishPage(NSISLocation + @"\Contrib\Graphics\Wizard\orange.bmp"); project.SetBrandingText(" "); //Path to the NSIS compiler. Compiler.NSISCompilerPath = NSISLocation + @"\makensis.exe"; //Save script file. Set to true when testing/debugging. Default value = false. //Normally, this property could be omitted. Compiler.SaveScriptFile = true; //Build the installer using the settings from the above created NSIS project. Compiler.BuildInstaller(project, project.pages, false); }
internal void AddDirectoryInstance(Dir dirinstance, bool root) { if (root) { //Root. instances.Add("root", dirinstance); } else { //Subdirectory. instances.Add(dirinstance.Path, dirinstance); } }
/// <summary> /// Create a new 'DirInstance' instance which will contain created 'Dir' instances. /// </summary> /// <param name="currentinstance"></param> public DirInstance(Dir currentinstance) { this.instances = new Dictionary<string, Dir>(); this.instances.Add("root", currentinstance); }
/// <summary> /// Creates a new subdirectory. /// </summary> /// <param name="path">Name or path of the subdirectory.</param> /// <returns>The created subdirectory.</returns> public Dir CreateSubDirectory(string path) { Dir subdir = new Dir(path) { Path = this.Path + "\\" + path, dirinstances = this.dirinstances, root = false, }; subdir.CheckIfCurrentDirectoryIsNotRoot(); return subdir; }