Skip to content

Commit

Permalink
Fixed issue with windows shortcuts in the programs menu not showing u…
Browse files Browse the repository at this point in the history
…p correctly. Turns out the .ico file output stream wasn't being closed by ICOEncoder so the .ico file wasn't ready for the shelllink to use it fully.
  • Loading branch information
shannah committed Feb 1, 2022
1 parent 3cc13a8 commit 2f0b7a7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .idea/libraries/Maven__com_profesorfalken_jPowerShell_3_1_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions installer/jdeploy-installer.iml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
<orderEntry type="library" name="Maven: org.xeustechnologies:jtar:1.1" level="project" />
<orderEntry type="library" name="Maven: ca.weblite.jdeploy:image4j:0.7.2" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20211205" level="project" />
<orderEntry type="library" name="Maven: com.profesorfalken:jPowerShell:3.1.1" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions installer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<version>20211205</version>
<scope>compile</scope>
</dependency>

</dependencies>
<repositories>
<repository>
Expand Down
70 changes: 57 additions & 13 deletions installer/src/main/java/ca/weblite/jdeploy/installer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.ResourceBundle;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -56,7 +54,7 @@ public class Main implements Runnable {
private Document appXMLDocument;
private AppInfo appInfo;
private JFrame frame;
private boolean addToDesktop=true, addToPrograms=true, addToStartMenu=false, addToDock=true, prerelease=false;
private boolean addToDesktop=true, addToPrograms=true, addToStartMenu=true, addToDock=true, prerelease=false;
private boolean overwriteApp=true;
private NPMPackageVersion npmPackageVersion;

Expand Down Expand Up @@ -673,9 +671,7 @@ public void run() {

JPanel checkboxesPanel = new JPanel();
if (Platform.getSystemPlatform().isWindows()) {
if (!Platform.getSystemPlatform().isWindows10OrHigher()) {
checkboxesPanel.add(addToStartMenuCheckBox);
}
checkboxesPanel.add(addToStartMenuCheckBox);
} else if (Platform.getSystemPlatform().isMac()) {
checkboxesPanel.add(addToDockCheckBox);
}
Expand Down Expand Up @@ -886,10 +882,23 @@ private void install() throws Exception {

private void convertWindowsIcon(File srcPng, File destIco) throws IOException, SAXException {
List<BufferedImage> images = new ArrayList<>();
for (int i : new int[]{16, 24, 32, 48, 256}) {
images.add(Thumbnails.of(srcPng).size(i, i).asBufferedImage());
List<Integer> bppList = new ArrayList<>();
for (int i : new int[]{16, 24, 32, 48, 64, 128, 256}) {
BufferedImage img = Thumbnails.of(srcPng).size(i, i).asBufferedImage();
images.add(img);
bppList.add(32);
if (i <= 48) {
images.add(img);
bppList.add(8);
images.add(img);
bppList.add(4);
}
}
int[] bppArray = bppList.stream().mapToInt(i->i).toArray();
try (FileOutputStream fileOutputStream = new FileOutputStream(destIco)) {
ICOEncoder.write(images,bppArray, fileOutputStream);
}
ICOEncoder.write(images, destIco);


}

Expand All @@ -905,21 +914,56 @@ private static Document parseXml(InputStream input) throws IOException, SAXExcep
}

private void installWindowsLink(int type, File exePath, File iconPath) throws Exception {


System.out.println("Installing windows link type "+type+" for exe "+exePath+" and icon "+iconPath);
ShellLink link = new ShellLink(type, appInfo.getTitle());
System.out.println("current user link path: "+link.getcurrentUserLinkPath());

link.setUserType(ShellLink.CURRENT_USER);
//ShellLink link = new ShellLink(exePath.getAbsolutePath(), ShellLink.CURRENT_USER);
//link.setLinkName(appTitle);
if (appInfo.getDescription() == null) {
link.setDescription("Windows application");
} else {
link.setDescription(appInfo.getDescription());
}
String iconPathString = iconPath.getCanonicalFile().getAbsolutePath();
File homeDir = new File(System.getProperty("user.home")).getCanonicalFile();


int homePathPos = iconPathString.indexOf(homeDir.getAbsolutePath());
/*
if (homePathPos == 0) {
String pathFromHome = iconPathString.substring(homeDir.getAbsolutePath().length());
if (pathFromHome.charAt(0) != '\\') {
pathFromHome = "\\" + pathFromHome;
}
iconPathString = "%USERPROFILE%" + pathFromHome;
}
*/
System.out.println("Setting icon path in link "+iconPathString);
link.setIconLocation(iconPathString, 0);

String exePathString = exePath.getCanonicalFile().getAbsolutePath();
/*
homePathPos = exePathString.indexOf(homeDir.getAbsolutePath());
if (homePathPos == 0) {
String pathFromHome = exePathString.substring(homeDir.getAbsolutePath().length());
if (pathFromHome.charAt(0) != '\\') {
pathFromHome = "\\" + pathFromHome;
}
exePathString = "%USERPROFILE%" + pathFromHome;
}
*/

System.out.println("Setting exePathString: "+exePathString);
link.setTargetPath(exePathString);

link.setIconLocation(iconPath.getCanonicalFile().getAbsolutePath(), 0);
link.setTargetPath(exePath.getCanonicalFile().getAbsolutePath());
link.setUserType(ShellLink.CURRENT_USER);

link.save();


}

private void installWindowsLinks(File exePath) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ public class ShellLink
* </ul>
* @param name The name that the link should display on a menu or on the desktop. Do not include
* a file extension.
* @param librarian the librarian
* @throws IllegalArgumentException if any of the call parameters are incorrect, or if no
* linkPaths are returned.
* @throws Exception if problems are encountered in initializing the native interface
Expand Down Expand Up @@ -611,7 +610,6 @@ protected void finalize() throws Throwable
*
* @param name the name of the library to free. Use only the name and extension but not the
* path.
* @see com.izforge.izpack.util.NativeLibraryClient#freeLibrary
*/
public void freeLibrary(String name)
{
Expand Down
8 changes: 8 additions & 0 deletions shared/src/main/java/ca/weblite/tools/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ public boolean isWindows10OrHigher() {
}
return false;
}

public boolean isWindows8OrHigher() {
if (isWindows()) {
// Reportedly some versions of Java report 8.1 for windows 10 version.
return getVersionInt() >= 8000;
}
return false;
}


}

0 comments on commit 2f0b7a7

Please sign in to comment.