@@ -188,8 +188,7 @@ public void processFile( FileCopyDetailsInternal details ) {
188188 addGUI ();
189189 addIcon ();
190190 addServices ();
191- addShortcuts ();
192- addProtocolHandler ();
191+ addShortcutsAndRegisterProtocols ();
193192 addRunBeforeUninstall ();
194193 addRunAfter ();
195194 addDeleteFiles ();
@@ -204,18 +203,6 @@ public void processFile( FileCopyDetailsInternal details ) {
204203 save ();
205204 }
206205
207- /**
208- * Add the scheme for globally defined protocol handler
209- */
210- private void addProtocolHandler () {
211- for ( ProtocolHandler handler : task .getProtocolHandler () ) {
212- registerSchemeDefinition ( handler );
213- }
214- for ( ProtocolHandler handler : task .getLaunch4js () ) {
215- registerSchemeDefinition ( handler );
216- }
217- }
218-
219206 /**
220207 * Add the scheme definitions for an application
221208 */
@@ -367,12 +354,16 @@ private String addFile( File file, String[] segments ) {
367354 Element parent = getDirectory ( segments );
368355
369356 String pathID = id ( segments , segments .length - 1 );
370- String compID = id ( pathID + "_Comp" );
357+ String compID = id ( ( pathID .length () > 0 ? pathID : "root" ) + "_Comp" );
358+
371359 Element component = getComponent ( parent , compID );
372360
373361 String name = segments [segments .length - 1 ];
374362 String id = addFile ( component , file , pathID , name );
375363
364+ // Debug Output of files that will be added
365+ task .getProject ().getLogger ().debug ( "adding file: '" +file .toString () + "' '" + name + "' '" + id + "' '" + pathID + "' '" + compID + "' '" + String .join ( "%" , segments ) + "'" );
366+
376367 // save the jvm.dll position
377368 if ( name .equals ( "jvm.dll" ) ) {
378369 StringBuilder jvm = new StringBuilder ();
@@ -410,7 +401,7 @@ private String addFile( Element component, File file, String pathID, String name
410401 * added to improve the performance.
411402 */
412403 private String addFile ( Element component , File file , String pathID , String name , boolean isAddFiles ) {
413- String id = id ( pathID + '_' + name );
404+ String id = id ( ( pathID . length () > 0 ? pathID + '_' : "" ) + name );
414405 if ( isAddFiles ) {
415406 Element fileEl = getOrCreateChildById ( component , "File" , id );
416407 addAttributeIfNotExists ( fileEl , "Source" , file .getAbsolutePath () );
@@ -827,80 +818,89 @@ private Element getShortcutComponent( DesktopStarter starter, Element product )
827818 *
828819 * @throws IOException If any I/O exception occur on icon loading
829820 */
830- private void addShortcuts () throws IOException {
831- List <DesktopStarter > starters = setup .getDesktopStarters ();
832- if ( starters .isEmpty () ) {
833- return ;
821+ private void addShortcutsAndRegisterProtocols () throws IOException {
822+ for ( DesktopStarter starter : setup .getDesktopStarters () ) {
823+ addShortcutsImpl ( starter );
834824 }
825+ for ( DesktopStarter starter : task .getLaunch4js () ) {
826+ addShortcutsImpl ( starter );
827+ }
828+ }
835829
836- for ( DesktopStarter starter : starters ) {
837- Element component = getShortcutComponent ( starter , product );
838- String id = id ( starter .getLocation () + "_" + starter .getDisplayName () );
839- Element shortcut = getOrCreateChildById ( component , "Shortcut" , id );
840- String name = starter .getDisplayName ().replace ( '[' , '_' ).replace ( ']' , '_' );
841- addAttributeIfNotExists ( shortcut , "Name" , name );
830+ private void addShortcutsImpl ( DesktopStarter starter ) throws IOException {
831+ Element component = getShortcutComponent ( starter , product );
842832
843- if ( !starter .getDescription ().isEmpty () ) {
844- addAttributeIfNotExists ( shortcut , "Description" , starter .getDescription () );
845- }
833+ String idSource = starter .getExecutable ();
834+ if ( idSource == null || idSource .isEmpty () ) {
835+ idSource = starter .getLocation () + "_" + starter .getDisplayName ();
836+ }
846837
847- addAttributeIfNotExists ( shortcut , "WorkingDirectory" , getWorkingDirID ( starter ) );
838+ String id = id ( idSource );
848839
849- // find the optional id for an icon
850- String target = starter .getExecutable ();
851- String iconID ;
852- if ( starter .getIcons () != null ) {
853- if ( starter .getIcons ().equals ( setup .getIcons () ) ) {
854- iconID = ICON_ID ;
855- } else {
856- File iconFile = starter .getIconForType ( buildDir , "ico" );
857- iconID = id ( starter .getDisplayName () + ".ico" );
858- Element icon = getOrCreateChildById ( product , "Icon" , iconID );
859- addAttributeIfNotExists ( icon , "SourceFile" , iconFile .getAbsolutePath () );
860- }
861- } else {
862- iconID = null ;
863- }
864- if ( target == null || target .isEmpty () ) {
865- // if target is empty then it must be a Java application
866- if ( iconID == null ) {
867- iconID = ICON_ID ;
868- }
869- }
840+ Element shortcut = getOrCreateChildById ( component , "Shortcut" , id );
841+ String name = starter .getDisplayName ().replace ( '[' , '_' ).replace ( ']' , '_' );
842+ addAttributeIfNotExists ( shortcut , "Name" , name );
870843
871- CommandLine cmd = new CommandLine ( starter , javaDir );
872- addAttributeIfNotExists ( shortcut , "Target" , cmd .target );
873- if ( !cmd .arguments .isEmpty () ) {
874- addAttributeIfNotExists ( shortcut , "Arguments" , cmd .arguments );
875- }
876- if ( iconID != null ) {
877- addAttributeIfNotExists ( shortcut , "Icon" , iconID );
878- }
844+ if ( !starter .getDescription ().isEmpty () ) {
845+ addAttributeIfNotExists ( shortcut , "Description" , starter .getDescription () );
846+ }
879847
880- String linkLocation ;
881- switch ( starter .getLocation () ) {
882- default :
883- case StartMenu :
884- linkLocation = "[ProgramMenuFolder]" ;
885- break ;
886- case ApplicationMenu :
887- linkLocation = "[ApplicationProgramsFolder]" ;
888- break ;
889- case InstallDir :
890- linkLocation = "[INSTALLDIR]" ;
891- break ;
892- case DesktopDir :
893- linkLocation = "[ApplicationDesktopShortcut]" ;
894- break ;
848+ addAttributeIfNotExists ( shortcut , "WorkingDirectory" , getWorkingDirID ( starter ) );
849+
850+ // find the optional id for an icon
851+ String target = starter .getExecutable ();
852+ String iconID ;
853+ if ( starter .getIcons () != null ) {
854+ if ( starter .getIcons ().equals ( setup .getIcons () ) ) {
855+ iconID = ICON_ID ;
856+ } else {
857+ File iconFile = starter .getIconForType ( buildDir , "ico" );
858+ iconID = id ( starter .getDisplayName () + ".ico" );
859+ Element icon = getOrCreateChildById ( product , "Icon" , iconID );
860+ addAttributeIfNotExists ( icon , "SourceFile" , iconFile .getAbsolutePath () );
895861 }
896- if ( starter .getWorkDir () != null ) {
897- linkLocation += starter .getWorkDir ();
862+ } else {
863+ iconID = null ;
864+ }
865+ if ( target == null || target .isEmpty () ) {
866+ // if target is empty then it must be a Java application
867+ if ( iconID == null ) {
868+ iconID = ICON_ID ;
898869 }
899- renameFileIfDynamic ( id , linkLocation , name + ".lnk" , starter . getDisplayName () + ".lnk" );
870+ }
900871
901- registerFileExtension ( starter , cmd );
902- registerSchemeDefinition ( starter );
872+ CommandLine cmd = new CommandLine ( starter , javaDir );
873+ addAttributeIfNotExists ( shortcut , "Target" , cmd .target );
874+ if ( !cmd .arguments .isEmpty () ) {
875+ addAttributeIfNotExists ( shortcut , "Arguments" , cmd .arguments );
876+ }
877+ if ( iconID != null ) {
878+ addAttributeIfNotExists ( shortcut , "Icon" , iconID );
903879 }
880+
881+ String linkLocation ;
882+ switch ( starter .getLocation () ) {
883+ default :
884+ case StartMenu :
885+ linkLocation = "[ProgramMenuFolder]" ;
886+ break ;
887+ case ApplicationMenu :
888+ linkLocation = "[ApplicationProgramsFolder]" ;
889+ break ;
890+ case InstallDir :
891+ linkLocation = "[INSTALLDIR]" ;
892+ break ;
893+ case DesktopDir :
894+ linkLocation = "[ApplicationDesktopShortcut]" ;
895+ break ;
896+ }
897+ if ( starter .getWorkDir () != null ) {
898+ linkLocation += starter .getWorkDir ();
899+ }
900+ renameFileIfDynamic ( id , linkLocation , name + ".lnk" , starter .getDisplayName () + ".lnk" );
901+
902+ registerFileExtension ( starter , cmd );
903+ registerSchemeDefinition ( starter );
904904 }
905905
906906 /**
@@ -918,7 +918,7 @@ private void registerFileExtension( DesktopStarter starter, CommandLine cmd ) th
918918 fileExtension = fileExtension .substring ( 1 );
919919 }
920920 String pID = id ( setup .getAppIdentifier () + "." + fileExtension );
921- Element component = getComponent ( installDir , "_file_extension" );
921+ Element component = getComponent ( installDir , pID + "_file_extension" );
922922 getOrCreateChild ( component , "CreateFolder" );
923923 Element progID = getOrCreateChildById ( component , "ProgId" , pID );
924924 if ( !docType .getName ().isEmpty () ) {
@@ -1198,6 +1198,11 @@ private Element addMultiStringRegistryValue( Element regkey, String name, List<S
11981198 * @return the segments of the path
11991199 */
12001200 String [] segments ( String path ) {
1201+ path = path .trim ();
1202+ // prevent empty first segment
1203+ if ( path .length () > 1 && path .charAt ( 0 ) == '/' || path .charAt ( 0 ) == '\\' ) {
1204+ path = path .substring ( 1 );
1205+ }
12011206 return path .split ( "[/\\ \\ ]" );
12021207 }
12031208
0 commit comments