130 Files.createDirectories(appDir); 131 Files.createDirectories(runtimeDir); 132 } 133 134 public WindowsAppImageBuilder(String jreName, Path imageOutDir) 135 throws IOException { 136 super(null, imageOutDir.resolve(jreName)); 137 138 Objects.requireNonNull(imageOutDir); 139 140 this.params = null; 141 this.root = imageOutDir.resolve(jreName); 142 this.appDir = null; 143 this.appModsDir = null; 144 this.runtimeDir = root; 145 this.mdir = runtimeDir.resolve("lib"); 146 this.binDir = null; 147 Files.createDirectories(runtimeDir); 148 } 149 150 private Path destFile(String dir, String filename) { 151 return runtimeDir.resolve(dir).resolve(filename); 152 } 153 154 private void writeEntry(InputStream in, Path dstFile) throws IOException { 155 Files.createDirectories(dstFile.getParent()); 156 Files.copy(in, dstFile); 157 } 158 159 private void writeSymEntry(Path dstFile, Path target) throws IOException { 160 Files.createDirectories(dstFile.getParent()); 161 Files.createLink(dstFile, target); 162 } 163 164 /** 165 * chmod ugo+x file 166 */ 167 private void setExecutable(Path file) { 168 try { 169 Set<PosixFilePermission> perms = 170 Files.getPosixFilePermissions(file); 171 perms.add(PosixFilePermission.OWNER_EXECUTE); 172 perms.add(PosixFilePermission.GROUP_EXECUTE); 173 perms.add(PosixFilePermission.OTHERS_EXECUTE); 174 Files.setPosixFilePermissions(file, perms); 175 } catch (IOException ioe) { 176 throw new UncheckedIOException(ioe); 177 } 178 } 179 180 private static void createUtf8File(File file, String content) 181 throws IOException { 182 try (OutputStream fout = new FileOutputStream(file); 183 Writer output = new OutputStreamWriter(fout, "UTF-8")) { 184 output.write(content); 185 } 186 } 187 188 public static String getLauncherName(Map<String, ? super Object> params) { 189 return APP_NAME.fetchFrom(params) + ".exe"; 190 } 191 192 // Returns launcher resource name for launcher we need to use. 193 public static String getLauncherResourceName( 194 Map<String, ? super Object> params) { 195 if (CONSOLE_HINT.fetchFrom(params)) { 196 return "jpackageapplauncher.exe"; 197 } else { 198 return "jpackageapplauncherw.exe"; 199 } 200 } 201 202 public static String getLauncherCfgName( 203 Map<String, ? super Object> params) { 204 return "app/" + APP_NAME.fetchFrom(params) +".cfg"; 205 } 206 207 private File getConfig_AppIcon(Map<String, ? super Object> params) { 267 268 private void copyMSVCDLLs() throws IOException { 269 AtomicReference<IOException> ioe = new AtomicReference<>(); 270 try (Stream<Path> files = Files.list(runtimeDir.resolve("bin"))) { 271 files.filter(p -> Pattern.matches( 272 "^(vcruntime|msvcp|msvcr|ucrtbase|api-ms-win-).*\\.dll$", 273 p.toFile().getName().toLowerCase())) 274 .forEach(p -> { 275 try { 276 Files.copy(p, binDir.resolve((p.toFile().getName()))); 277 } catch (IOException e) { 278 ioe.set(e); 279 } 280 }); 281 } 282 283 IOException e = ioe.get(); 284 if (e != null) { 285 throw e; 286 } 287 } 288 289 private boolean copyMSVCDLLs(String VS_VER) throws IOException { 290 final InputStream REDIST_MSVCR_URL = getResourceAsStream( 291 REDIST_MSVCR.replaceAll("VS_VER", VS_VER)); 292 final InputStream REDIST_MSVCP_URL = getResourceAsStream( 293 REDIST_MSVCP.replaceAll("VS_VER", VS_VER)); 294 295 if (REDIST_MSVCR_URL != null && REDIST_MSVCP_URL != null) { 296 Files.copy( 297 REDIST_MSVCR_URL, 298 binDir.resolve(REDIST_MSVCR.replaceAll("VS_VER", VS_VER))); 299 Files.copy( 300 REDIST_MSVCP_URL, 301 binDir.resolve(REDIST_MSVCP.replaceAll("VS_VER", VS_VER))); 302 return true; 303 } 304 305 return false; 306 } 307 308 private void validateValueAndPut( 309 Map<String, String> data, String key, 310 BundlerParamInfo<String> param, 311 Map<String, ? super Object> params) { 312 String value = param.fetchFrom(params); 313 if (value.contains("\r") || value.contains("\n")) { 314 Log.error("Configuration Parameter " + param.getID() 315 + " contains multiple lines of text, ignore it"); 316 data.put(key, ""); 317 return; 318 } 319 data.put(key, value); 320 } 321 322 protected void prepareExecutableProperties( 323 Map<String, ? super Object> params) throws IOException { 324 Map<String, String> data = new HashMap<>(); 325 | 130 Files.createDirectories(appDir); 131 Files.createDirectories(runtimeDir); 132 } 133 134 public WindowsAppImageBuilder(String jreName, Path imageOutDir) 135 throws IOException { 136 super(null, imageOutDir.resolve(jreName)); 137 138 Objects.requireNonNull(imageOutDir); 139 140 this.params = null; 141 this.root = imageOutDir.resolve(jreName); 142 this.appDir = null; 143 this.appModsDir = null; 144 this.runtimeDir = root; 145 this.mdir = runtimeDir.resolve("lib"); 146 this.binDir = null; 147 Files.createDirectories(runtimeDir); 148 } 149 150 private void writeEntry(InputStream in, Path dstFile) throws IOException { 151 Files.createDirectories(dstFile.getParent()); 152 Files.copy(in, dstFile); 153 } 154 155 public static String getLauncherName(Map<String, ? super Object> params) { 156 return APP_NAME.fetchFrom(params) + ".exe"; 157 } 158 159 // Returns launcher resource name for launcher we need to use. 160 public static String getLauncherResourceName( 161 Map<String, ? super Object> params) { 162 if (CONSOLE_HINT.fetchFrom(params)) { 163 return "jpackageapplauncher.exe"; 164 } else { 165 return "jpackageapplauncherw.exe"; 166 } 167 } 168 169 public static String getLauncherCfgName( 170 Map<String, ? super Object> params) { 171 return "app/" + APP_NAME.fetchFrom(params) +".cfg"; 172 } 173 174 private File getConfig_AppIcon(Map<String, ? super Object> params) { 234 235 private void copyMSVCDLLs() throws IOException { 236 AtomicReference<IOException> ioe = new AtomicReference<>(); 237 try (Stream<Path> files = Files.list(runtimeDir.resolve("bin"))) { 238 files.filter(p -> Pattern.matches( 239 "^(vcruntime|msvcp|msvcr|ucrtbase|api-ms-win-).*\\.dll$", 240 p.toFile().getName().toLowerCase())) 241 .forEach(p -> { 242 try { 243 Files.copy(p, binDir.resolve((p.toFile().getName()))); 244 } catch (IOException e) { 245 ioe.set(e); 246 } 247 }); 248 } 249 250 IOException e = ioe.get(); 251 if (e != null) { 252 throw e; 253 } 254 } 255 256 private void validateValueAndPut( 257 Map<String, String> data, String key, 258 BundlerParamInfo<String> param, 259 Map<String, ? super Object> params) { 260 String value = param.fetchFrom(params); 261 if (value.contains("\r") || value.contains("\n")) { 262 Log.error("Configuration Parameter " + param.getID() 263 + " contains multiple lines of text, ignore it"); 264 data.put(key, ""); 265 return; 266 } 267 data.put(key, value); 268 } 269 270 protected void prepareExecutableProperties( 271 Map<String, ? super Object> params) throws IOException { 272 Map<String, String> data = new HashMap<>(); 273 |