<?
// makensitemplate.phtml
// Copyright (C) 2001 Nullsoft, Inc.
// Author: Justin Frankel
// Version: 
           
$ver="0.21";
// last updated 12/17/01
// Note that the scripts this generates are designed for NSIS 1.8+
 
// This software is provided 'as-is', without any express or implied warranty.  In no 
// event will the authors be held liable for any damages arising from the use of this 
// software.
//
// Permission is granted to anyone to use this software for any purpose, including 
// commercial applications, and to alter it and redistribute it freely, subject to the 
// following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not claim that 
// you wrote the original software. If you use this software in a product, an 
// acknowledgment in the product documentation would be appreciated but is not 
// required.
// 2. Altered source versions must be plainly marked as such, and must not be 
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.

//
//
// Variables:
// $inst_name, $inst_company, $inst_exe, $inst_douninst,
// $inst_dolicense, $inst_licensetext, $inst_licensefile, $inst_dir,
// $inst_dodirpage, $inst_moresections, $inst_types, $inst_comptext,
// $inst_sectionnames, $inst_defsectionname, $inst_dirtext
//

function do_error($msg)
{
  die(
"<html><head><title>ERROR</title></head><body>error: $msg<BR></body></html>");
}



if (
$inst_name!="")
{
  
// do some basic error checking 
  
if ($inst_exe==""do_error("Output EXE name is required.");
  if (
$inst_dolicense == "on" && ($inst_licensetext == "" || $inst_licensefile == ""))
    
do_error("if license page turned on, you must specify license text and file.");
  if (
$inst_dodirpage == "on" && $inst_dirtext == ""
    
do_error("Directory text is required if showing directory page");
  if (
$iunst_douninst == "on" && ($inst_uninstexe == ""))
    
do_error("Uninstall exe name required if uninstall uspport enabled");
  if (
$inst_dir == ""do_error("Default installation directory is required.");
  if (
$inst_moresections == "on" && ($inst_comptext == "" || $inst_sectionnames == ""))
    
do_error("if optional sections are turned on, you must specify text for that page as well as section names.");
  
$inst_name stripslashes($inst_name);
  
$inst_company stripslashes($inst_company);
  
$inst_exe stripslashes($inst_exe);
  
$inst_licensetext stripslashes($inst_licensetext);
  
$inst_licensefile stripslashes($inst_licensefile);
  
$inst_uninsttext stripslashes($inst_uninsttext);
  
$inst_uninstexe stripslashes($inst_uninstexe);
  
$inst_dir stripslashes($inst_dir);
  
$inst_types stripslashes($inst_types);
  
$inst_dirtext stripslashes($inst_dirtext);
  
$inst_comptext stripslashes($inst_comptext);
  
$inst_sectionnames stripslashes($inst_sectionnames);
  
$inst_defsectionname stripslashes($inst_defsectionname);
  
  
  
  
// send headers

  
if (!isset($genastext) || $genastext != "on")
  {
    
header("Content-Type:misc/nsifile");
    
header("Content-Disposition: inline; filename=generated.nsi");
  }
  else
    
header("Content-Type:text/plain");

  
// send script

  
echo "; Generated NSIS script file (generated by makensitemplate.phtml $ver)\r\n";
  echo 
"; by $REMOTE_ADDR on " date("M d y @ H:i") . "\r\n";
  echo 
"\r\n; NOTE: this .NSI script is designed for NSIS v1.8+\r\n\r\n";

  echo 
"Name \"$inst_name\"\r\n";

  echo 
"OutFile \"$inst_exe\"\r\n\r\n";

  echo 
"; Some default compiler settings (uncomment and change at will):\r\n" 
       
"; SetCompress auto ; (can be off or force)\r\n" .
       
"; SetDatablockOptimize on ; (can be off)\r\n" .
       
"; CRCCheck on ; (can be off)\r\n" .
       
"; AutoCloseWindow false ; (can be true for the window go away automatically at end)\r\n" .
       
"; ShowInstDetails hide ; (can be show to have them shown, or nevershow to disable)\r\n" .
       
"; SetDateSave off ; (can be on to have files restored to their orginal date)\r\n\r\n";

  if (
$inst_dolicense == "on")
    echo 
"LicenseText \"$inst_licensetext\"\r\n" .
         
"LicenseData \"" $inst_licensefile "\"\r\n\r\n";

  echo 
"InstallDir \"" $inst_dir "\"\r\n";
  echo 
"InstallDirRegKey HKEY_LOCAL_MACHINE \"SOFTWARE\\";

  if (
$inst_company != "") echo $inst_company "\\";
  echo 
"$inst_name\" \"\"\r\n";
  if (
$inst_dodirpage != "on") echo "DirShow hide ; make this show to let the user change it)\r\n";
  else 
  {
    echo 
"DirShow show ; (make this hide to not let the user change it)\r\n";
    echo 
"DirText \"$inst_dirtext\"\r\n";
  }

  echo 
"\r\n";

  if (
$inst_moresections == "on"
  {
    
$tok strtok($inst_types":");
    while (
$tok && $tok != "")
    {
      echo 
"InstType \"$tok\"\r\n";
      
$tok strtok(":");
    }
    if (
$inst_types != "") echo "\r\n";

    echo 
"ComponentText \"$inst_comptext\"\r\n\r\n";
  
    echo 
"Section \"$inst_defsectionname\" ; (default, requried section)\r\n";
  }
  else echo 
"Section \"\" ; (default section)\r\n";

  echo 
"SetOutPath \"\$INSTDIR\"\r\n";
  echo 
"; add files / whatever that need to be installed here.\r\n";

  if (
$inst_moresections == "on")
  {
    echo 
"SectionEnd ; end of default section\r\n\r\n";
    
$tok strtok($inst_sectionnames,":");
    while (
$tok)
    {
      echo 
"Section \"$tok\"\r\n";
      echo 
"; SectionIn 12 ; (uncomment and change this to add it to install types)\r\n";
      echo 
"SetOutPath \"\$INSTDIR\"\r\n";
      echo 
"; Add optional commands here\r\n";
      echo 
"SectionEnd ; end of section '$tok'\r\n\r\n";
      
$tok strtok(":");
    }

    echo 
"\r\n";
    echo 
"Section \"-post\" ; (post install section, happens last after any optional sections)\r\n";
    echo 
"; add any commands that need to happen after any optional sections here\r\n";
  }

  echo 
"WriteRegStr HKEY_LOCAL_MACHINE \"SOFTWARE\\";
  if (
$inst_company != "") echo $inst_company "\\";
  echo 
"$inst_name\" \"\" \"\$INSTDIR\"\r\n";


  if (
$inst_douninst == "on")
  {
    echo 
"WriteRegStr HKEY_LOCAL_MACHINE \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$inst_name\" \"DisplayName\" \"$inst_name (remove only)\"\r\n";
    echo 
"WriteRegStr HKEY_LOCAL_MACHINE \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$inst_name\" \"UninstallString\" '\"\$INSTDIR\\$inst_uninstexe\"'\r\n";

  }
 
  if (
$inst_douninst == "on")
  {
    echo 
"; write out uninstaller\r\n";
    echo 
"WriteUninstaller \"\$INSTDIR\\$inst_uninstexe\"\r\n";
  }
 
  if (
$inst_moresections == "on") echo "SectionEnd ; end of -post section\r\n\r\n";
  else echo 
"SectionEnd ; end of default section\r\n\r\n";

  if (
$inst_douninst == "on")
  {
    echo 
"\r\n; begin uninstall settings/section\r\n";
  
    echo 
"UninstallText \"$inst_uninsttext\"\r\n";

    echo 
"\r\nSection Uninstall\r\n";
    echo 
"; add delete commands to delete whatever files/registry keys/etc you installed here.\r\n";
    echo 
"Delete \"\$INSTDIR\\$inst_uninstexe\"\r\n";
    echo 
"DeleteRegKey HKEY_LOCAL_MACHINE \"SOFTWARE\\";
    if (
$inst_company != "") echo $inst_company "\\"
    echo 
"$inst_name\"\r\n";
    echo 
"DeleteRegKey HKEY_LOCAL_MACHINE \"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$inst_name\"\r\n";
    echo 
"RMDir \"\$INSTDIR\"\r\n";

    echo 
"SectionEnd ; end of uninstall section\r\n";

  }

  echo 
"\r\n; eof\r\n";
  die;
}
?>


<html>
<head>
<title>.NSI Script Template Generator</title>
</head>
<body>
This script will generate a template .NSI file for your application 
(that will then need a bunch of editting to make it useful). The generated scripts require NSIS v1.3+. <BR>First, fill out the form the best you can, then save the script, then edit it while using <a href="makensis.htm">the documentation</a> to make it do what you want.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Love, Justin.
<BR><BR>
P.S. Don't use any double-quotes (") in your values here.<BR>
P.P.S. The PHP source for this script is <a href="makensitemplate.phps">here</a>.
<BR><BR><BR>
<FORM METHOD=POST ACTION="makensitemplate.phtml">

Application name (short, usually one or two words): 
<INPUT TYPE=text SIZE=40 NAME="inst_name" VALUE="myApp"><BR>
Company name (can be empty):
<INPUT TYPE=text SIZE=40 NAME="inst_company" VALUE="myCompany"><BR>
Output EXE name:
<INPUT TYPE=text SIZE=40 NAME="inst_exe" VALUE="InstallMyApp.exe"><BR>
<INPUT TYPE=checkbox NAME="inst_douninst" checked>Uninstall support<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Uninstall text: 
  <INPUT TYPE=text SIZE=40 NAME="inst_uninsttext" VALUE="This will uninstall myApp from your system"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Uninstall exe name: 
  <INPUT TYPE=text SIZE=40 NAME="inst_uninstexe" VALUE="uninst.exe"><BR>
<hr>
<INPUT TYPE=checkbox NAME="inst_dolicense">Show license page<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
License text (goes above the license):
  <INPUT TYPE=text SIZE=40 NAME="inst_licensetext" VALUE="You must agree to this license before installing."><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  License data filename of a .txt file on the compiling system<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  (note that the pathname can be relative (to where the script file will be saved) or absolute):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=text SIZE=70 NAME="inst_licensefile" VALUE=""><BR>
<hr>
Default installation directory (recommended name: $PROGRAMFILES\myApp):
<INPUT TYPE=text SIZE=40 NAME="inst_dir" VALUE="$PROGRAMFILES\myApp"><BR>
<INPUT TYPE=checkbox NAME="inst_dodirpage" checked>Show directory page<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Directory page text:
<INPUT TYPE=text SIZE=40 NAME="inst_dirtext" VALUE="Select the directory to install myApp in:"><BR>
<hr>
<INPUT TYPE=checkbox NAME="inst_moresections">Optional install sections<BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Description text (goes on top of page):
<INPUT TYPE=text SIZE=40 NAME="inst_comptext" VALUE="Select what you wish to install."><BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Install types (up to 8, colon delimited): 
<INPUT TYPE=text SIZE=40 NAME="inst_types" VALUE="Full:Typical:Minimial"><BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Name of default (required) section (blank for none)
<INPUT TYPE=text SIZE=40 NAME="inst_defsectionname" VALUE=""><BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Optional Sections (colon delimited):
<INPUT TYPE=text SIZE=40 NAME="inst_sectionnames" VALUE=""><BR>
 
<hr>
<input type=checkbox NAME="genastext">Generate as text for viewing (default is to generate an .nsi file for download).<BR>
<INPUT TYPE=submit VALUE="generate">
</FORM>
</body>
</html>