Hello,

Attached is the latest version of the patch:

* uses family name for directory name
* map can now be uninstalled from "Add/Remove Programs" (WinXP) or "Programs and Features" (Vista/Win7) * uninstalls map if already installed (NEW: silently force uninstall if silently installing) * installer and license files are now generated from templates for easier maintenance

Thanks,

N.
Index: build.xml
===================================================================
--- build.xml   (revision 1877)
+++ build.xml   (working copy)
@@ -116,6 +116,7 @@
                                <include name="**/*.trans"/>
                                <include name="styles/**"/>
                                <include name="help/**"/>
+                               <include name="installer/**"/>
                                <include name="sort/**"/>
                                <exclude name="**/.*"/>
                        </fileset>
@@ -202,6 +203,7 @@
                        <include name="styles/**"/>
                        <include name="sort/**"/>
                        <include name="help/**"/>
+                       <include name="installer/**"/>
                </jar>
 
                <copy todir="${dist}/doc" >
Index: resources/installer/installer_template.nsi
===================================================================
--- resources/installer/installer_template.nsi  (revision 0)
+++ resources/installer/installer_template.nsi  (revision 0)
@@ -0,0 +1,96 @@
+; INSERT_DEFINES_HERE
+
+SetCompressor /SOLID lzma
+
+; Includes
+!include "MUI2.nsh"
+
+; Installer pages
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_LICENSE Test_license.txt
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+!insertmacro MUI_PAGE_FINISH
+
+; Uninstaller pages
+!define MUI_UNPAGE_INSTFILES
+
+!insertmacro MUI_LANGUAGE "English"
+
+Name "${INSTALLER_DESCRIPTION}"
+OutFile "${INSTALLER_NAME}.exe"
+InstallDir "${DEFAULT_DIR}"
+
+Function .onInit
+  ; Uninstall before installing (code from 
http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new )
+  ReadRegStr $R0 HKLM \
+  "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REG_KEY}" 
"UninstallString"
+  StrCmp $R0 "" done
+ 
+  IfSilent silent
+  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${INSTALLER_NAME} is already 
installed. $\n$\nClick `OK` to remove the previous version or `Cancel` to 
cancel this upgrade." IDOK uninst
+  Abort
+
+  ;Run the uninstaller
+  uninst:
+  ClearErrors
+  ExecWait '"$R0" _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
+ 
+  IfErrors no_remove_uninstaller done
+    ;You can either use Delete /REBOOTOK in the uninstaller or add some code
+    ;here to remove the uninstaller. Use a registry key to check
+    ;whether the user has chosen to uninstall. If you are using an uninstaller
+    ;components page, make sure all sections are uninstalled.
+  no_remove_uninstaller:
+  
+  Goto done
+ 
+  silent:
+  ExecWait '"$R0" /S _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
+ 
+  done:
+ 
+FunctionEnd
+
+Section "MainSection" SectionMain
+; Files to be installed
+  SetOutPath "$INSTDIR"
+; INSERT_ADDED_FILES_HERE
+
+; Create MapSource registry keys
+; INSERT_REGBIN_HERE
+  WriteRegStr HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "IDX" 
"$INSTDIR\${MAPNAME}.mdx"
+  WriteRegStr HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "MDR" 
"$INSTDIR\${MAPNAME}_mdr.img"
+  WriteRegStr HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "BMAP" 
"$INSTDIR\${MAPNAME}.img"
+  WriteRegStr HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "LOC" "$INSTDIR"
+  WriteRegStr HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "TDB" 
"$INSTDIR\${MAPNAME}.tdb"
+  
+; Write uninstaller
+  WriteUninstaller "$INSTDIR\Uninstall.exe"
+
+; Create uninstaller registry keys
+  WriteRegStr HKLM 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_KEY}" "DisplayName" 
"$(^Name)"
+  WriteRegStr HKLM 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_KEY}" 
"UninstallString" "$INSTDIR\Uninstall.exe"
+  WriteRegDWORD HKLM 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_KEY}" "NoModify" 1
+  
+SectionEnd
+
+Section "Uninstall"
+; Files to be uninstalled
+; INSERT_REMOVED_FILES_HERE
+
+  RmDir "$INSTDIR"
+
+; Registry cleanup
+  DeleteRegValue HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "ID"
+  DeleteRegValue HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "IDX"
+  DeleteRegValue HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}" "MDR"
+  DeleteRegValue HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "BMAP"
+  DeleteRegValue HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "LOC"
+  DeleteRegValue HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}" "TDB"
+  DeleteRegKey /IfEmpty HKLM 
"SOFTWARE\Garmin\MapSource\Families\${REG_KEY}\${PRODUCT_ID}"
+  DeleteRegKey /IfEmpty HKLM "SOFTWARE\Garmin\MapSource\Families\${REG_KEY}"
+  
+  DeleteRegKey HKLM 
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${REG_KEY}"
+
+SectionEnd
Index: resources/installer/license_template.txt
===================================================================
--- resources/installer/license_template.txt    (revision 0)
+++ resources/installer/license_template.txt    (revision 0)
@@ -0,0 +1,6 @@
+OSM Street map
+http://www.openstreetmap.org/
+
+Map data licenced under Creative Commons Attribution ShareAlike 2.0
+http://creativecommons.org/licenses/by-sa/2.0/
+
Index: src/uk/me/parabola/mkgmap/combiners/NsisBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/NsisBuilder.java        (revision 1877)
+++ src/uk/me/parabola/mkgmap/combiners/NsisBuilder.java        (working copy)
@@ -13,8 +13,11 @@
 
 package uk.me.parabola.mkgmap.combiners;
 
+import java.io.BufferedReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.util.ArrayList;
@@ -31,7 +34,7 @@
        private String nsisFilename;
        private String licenseFilename;
        private String outputDir;
-       private String seriesName;
+       private String familyName;
        private String id;
        private int productId;
 
@@ -39,7 +42,6 @@
        private boolean hasTyp;
 
        private final List<String> mapList = new ArrayList<String>();
-       private static final String HKLM_FAMILIES = "HKLM 
\"SOFTWARE\\Garmin\\MapSource\\Families\\${REG_KEY}";
        private String typName;
 
        public void init(CommandArgs args) {
@@ -47,7 +49,7 @@
                productId = args.get("product-id", 1);
 
                baseFilename = args.get("overview-mapname", "osmmap");
-               seriesName = args.get("series-name", "OSM map");
+               familyName = args.get("family-name", "OSM map");
 
                String tmpId = Integer.toHexString(0x10000 | familyId);
 
@@ -85,48 +87,51 @@
 
        private void writeNsisFile() {
                Writer w = null;
+               InputStream is = 
getClass().getResourceAsStream("/installer/installer_template.nsi");           
+               if (is == null) {
+                       System.err.println("Could not find the installer 
template.");
+                       return;
+               }
                try {
+                       BufferedReader br = new BufferedReader(new 
InputStreamReader(is));
                        w = new FileWriter(Utils.joinPath(outputDir, 
nsisFilename));
                        PrintWriter pw = new PrintWriter(w);
-
-                       pw.format(Locale.ROOT, "!define DEFAULT_DIR 
\"C:\\Garmin\\Maps\\%s\"\n", seriesName);
-                       pw.format(Locale.ROOT, "!define INSTALLER_DESCRIPTION 
\"%s\"\n", seriesName);
-                       pw.format(Locale.ROOT, "!define INSTALLER_NAME 
\"%s\"\n", seriesName);
+                       
+                   String strLine;
+                   while ((strLine = br.readLine()) != null)   {
+                       if (strLine.contains("INSERT_DEFINES_HERE"))
+                               writeDefines(pw);
+                       else if (strLine.contains("INSERT_REGBIN_HERE"))
+                               writeRegBin(pw);
+                       else if (strLine.contains("INSERT_ADDED_FILES_HERE"))
+                               writeAddedFiles(pw);
+                       else if (strLine.contains("INSERT_REMOVED_FILES_HERE"))
+                               writeRemovedFiles(pw);
+                       else 
+                               pw.format(Locale.ROOT, strLine + "\n");
+                   }
+               } catch (IOException e) {
+                       System.err.println("Could not write NSIS file");
+               } finally {
+                       Utils.closeFile(w);
+               }                       
+       }
+       
+       private void writeDefines(PrintWriter pw) {
+                       pw.format(Locale.ROOT, "!define DEFAULT_DIR 
\"C:\\Garmin\\Maps\\%s\"\n", familyName);
+                       pw.format(Locale.ROOT, "!define INSTALLER_DESCRIPTION 
\"%s\"\n", familyName);
+                       pw.format(Locale.ROOT, "!define INSTALLER_NAME 
\"%s\"\n", familyName);
                        pw.format(Locale.ROOT, "!define MAPNAME \"%s\"\n", 
baseFilename);
                        pw.format(Locale.ROOT, "!define PRODUCT_ID \"%s\"\n", 
productId);
-                       pw.format(Locale.ROOT, "!define REG_KEY \"%s\"\n", 
seriesName);
-                       pw.println();
+                       pw.format(Locale.ROOT, "!define REG_KEY \"%s\"\n", 
familyName);
+       }
 
-                       pw.format(Locale.ROOT, "SetCompressor /SOLID lzma\n");
-                       pw.println();
-
-                       pw.format(Locale.ROOT, "; Includes\n");
-                       pw.format(Locale.ROOT, "!include \"MUI2.nsh\"\n");
-                       pw.println();
-
-                       pw.format(Locale.ROOT, "; Installer pages\n");
-                       pw.format(Locale.ROOT, "!insertmacro 
MUI_PAGE_WELCOME\n");
-                       pw.format(Locale.ROOT, "!insertmacro MUI_PAGE_LICENSE 
%s\n", licenseFilename);
-                       pw.format(Locale.ROOT, "!insertmacro 
MUI_PAGE_DIRECTORY\n");
-                       pw.format(Locale.ROOT, "!insertmacro 
MUI_PAGE_INSTFILES\n");
-                       pw.format(Locale.ROOT, "!insertmacro 
MUI_PAGE_FINISH\n");
-                       pw.println();
-
-                       pw.format(Locale.ROOT, "; Uninstaller pages\n");
-                       pw.format(Locale.ROOT, "!define 
MUI_UNPAGE_INSTFILES\n");
-                       pw.println();
-
-                       pw.format(Locale.ROOT, "!insertmacro MUI_LANGUAGE 
\"English\"\n");
-                       pw.println();
-
-                       pw.format(Locale.ROOT, "Name 
\"${INSTALLER_DESCRIPTION}\"\n");
-                       pw.format(Locale.ROOT, "OutFile 
\"${INSTALLER_NAME}.exe\"\n");
-                       pw.format(Locale.ROOT, "InstallDir 
\"${DEFAULT_DIR}\"\n");
-                       pw.println();
-
-                       // Install files
-                       pw.format(Locale.ROOT, "Section \"MainSection\" 
SectionMain\n");
-                       pw.format(Locale.ROOT, "  SetOutPath \"$INSTDIR\"\n");
+       private void writeRegBin(PrintWriter pw) {
+               // Ideally we should have a define for the family value but 
NSIS won't allow "hexadecimal" variables
+               pw.format(Locale.ROOT, "  WriteRegBin HKLM 
\"SOFTWARE\\Garmin\\MapSource\\Families\\${REG_KEY}\" \"ID\" %s\n", id);
+}      
+                       
+       private void writeAddedFiles(PrintWriter pw) {
                        pw.format(Locale.ROOT, "  File \"${MAPNAME}.img\"\n");
                        if (hasIndex) {
                                pw.format(Locale.ROOT, "  File 
\"${MAPNAME}_mdr.img\"\n");
@@ -138,30 +143,11 @@
                        pw.format(Locale.ROOT, "  File \"${MAPNAME}.tdb\"\n");
                        for (String file : mapList)
                                pw.format(Locale.ROOT, "  File \"%s.img\"\n", 
file);
+       }
 
 
-                       // Registry values
-                       pw.println();
-                       pw.format(Locale.ROOT, "  WriteRegBin " + HKLM_FAMILIES 
+ "\" \"ID\" %s\n", id);
-                       if (hasIndex) {
-                               pw.format(Locale.ROOT, "  WriteRegStr " + 
HKLM_FAMILIES + "\" \"IDX\" \"$INSTDIR\\${MAPNAME}.mdx\"\n");
-                               pw.format(Locale.ROOT, "  WriteRegStr " + 
HKLM_FAMILIES + "\" \"MDR\" \"$INSTDIR\\${MAPNAME}_mdr.img\"\n");
-                       }
-                       if (hasTyp)
-                               pw.format(Locale.ROOT, "  WriteRegStr " + 
HKLM_FAMILIES + "\" \"TYP\" \"$INSTDIR\\%s\"\n", typName);
 
-                       pw.format(Locale.ROOT, "  WriteRegStr " + HKLM_FAMILIES 
+ "\\${PRODUCT_ID}\" \"BMAP\" \"$INSTDIR\\${MAPNAME}.img\"\n");
-                       pw.format(Locale.ROOT, "  WriteRegStr " + HKLM_FAMILIES 
+ "\\${PRODUCT_ID}\" \"LOC\" \"$INSTDIR\"\n");
-                       pw.format(Locale.ROOT, "  WriteRegStr " + HKLM_FAMILIES 
+ "\\${PRODUCT_ID}\" \"TDB\" \"$INSTDIR\\${MAPNAME}.tdb\"\n");
-
-                       pw.println();
-                       pw.format(Locale.ROOT, "  WriteUninstaller 
\"$INSTDIR\\Uninstall.exe\"\n");
-                       pw.println();
-                       pw.format(Locale.ROOT, "SectionEnd\n");
-                       pw.println();
-
-                       // Un-install files
-                       pw.format(Locale.ROOT, "Section \"Uninstall\"\n");
+       private void writeRemovedFiles(PrintWriter pw) {
                        pw.format(Locale.ROOT, "  Delete 
\"$INSTDIR\\${MAPNAME}.img\"\n");
                        if (hasIndex) {
                                pw.format(Locale.ROOT, "  Delete 
\"$INSTDIR\\${MAPNAME}_mdr.img\"\n");
@@ -174,50 +160,29 @@
                                pw.format(Locale.ROOT, "  Delete 
\"$INSTDIR\\%s.img\"\n", file);
                        }
                        pw.format(Locale.ROOT, "  Delete 
\"$INSTDIR\\Uninstall.exe\"\n");
-                       pw.println();
-                       pw.format(Locale.ROOT, "  RmDir \"$INSTDIR\"\n");
-
-                       // Remove registry entries
-                       pw.println();
-                       pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\" \"ID\"\n");
-                       if (hasIndex) {
-                               pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\" \"IDX\"\n");
-                               pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\" \"MDR\"\n");
-                       }
-                       if (hasTyp)
-                               pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\" \"TYP\"\n");
-                       pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\\${PRODUCT_ID}\" \"BMAP\"\n");
-                       pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\\${PRODUCT_ID}\" \"LOC\"\n");
-                       pw.format(Locale.ROOT, "  DeleteRegValue " + 
HKLM_FAMILIES + "\\${PRODUCT_ID}\" \"TDB\"\n");
-                       pw.format(Locale.ROOT, "  DeleteRegKey /IfEmpty " + 
HKLM_FAMILIES + "\\${PRODUCT_ID}\"\n");
-                       pw.format(Locale.ROOT, "  DeleteRegKey /IfEmpty " + 
HKLM_FAMILIES + "\"\n");
-
-                       pw.println();
-                       pw.format(Locale.ROOT, "SectionEnd\n");
-
-               } catch (IOException e) {
-                       System.err.println("Could not write NSIS file");
-               } finally {
-                       Utils.closeFile(w);
-               }
        }
 
+
        /**
-        * We write out a licence file that is included in the installer.
-        * TODO get a file from the resource directory of something similar.
+        * We write out a license file that is included in the installer.
         */
        private void writeLicenceFile() {
                Writer w = null;
+               InputStream is = 
getClass().getResourceAsStream("/installer/license_template.txt");
+               if (is == null) {
+                       System.err.println("Could not find the license 
template.");
+                       return;
+               }
                try {
+                       BufferedReader br = new BufferedReader(new 
InputStreamReader(is));
                        w = new FileWriter(Utils.joinPath(outputDir, 
licenseFilename));
                        PrintWriter pw = new PrintWriter(w);
-
-                       pw.format(Locale.ROOT, "OSM Street map\n");
-                       pw.format(Locale.ROOT, 
"http://www.openstreetmap.org/\n";);
-                       pw.println();
-                       pw.format(Locale.ROOT, "Map data licenced under 
Creative Commons Attribution ShareAlike 2.0\n");
-                       pw.format(Locale.ROOT, 
"http://creativecommons.org/licenses/by-sa/2.0/\n";);
-                       pw.println();
+                       
+                   String strLine;
+                   while ((strLine = br.readLine()) != null)   {
+                       pw.format(Locale.ROOT, strLine + "\n");
+                   }
+       
                        pw.format(Locale.ROOT, "Map created with mkgmap-r" + 
Version.VERSION +"\n");
                } catch (IOException e) {
                        System.err.println("Could not write license file");
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to