forked from orphan-oss/launch4j-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request orphan-oss#341 from Lilianne-Blaze/patch3-require-…
…admin1 "Require admin rights" option for Windows exes
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/com/akathist/maven/plugins/launch4j/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.akathist.maven.plugins.launch4j; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedOutputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
|
||
public final class FileUtils { | ||
|
||
public static final int DEF_BUF_SIZE = 4 * 1024; | ||
|
||
public static byte[] readResourceAsBytes(String resName) throws IOException { | ||
ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4 * 1024); | ||
InputStream is = cl.getResourceAsStream(resName); | ||
|
||
return readAllBytes(is); | ||
} | ||
|
||
public static byte[] readBytes(File inFile) throws IOException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
FileInputStream fis = new FileInputStream(inFile); | ||
BufferedInputStream bis = new BufferedInputStream(fis); | ||
|
||
return readAllBytes(bis); | ||
} | ||
|
||
public static byte[] readAllBytes(InputStream is) throws IOException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
|
||
byte buf[] = new byte[DEF_BUF_SIZE]; | ||
int bytesRead = 0; | ||
while ((bytesRead = is.read(buf)) != -1) { | ||
baos.write(buf, 0, bytesRead); | ||
} | ||
|
||
return baos.toByteArray(); | ||
} | ||
|
||
public static void writeBytesIfDiff(File outFile, byte[] outBytes) throws IOException { | ||
if (outFile.exists()) { | ||
byte[] existingBytes = readBytes(outFile); | ||
if (Arrays.equals(outBytes, existingBytes)) { | ||
return; | ||
} | ||
} | ||
writeBytes(outFile, outBytes); | ||
} | ||
|
||
public static void writeBytes(File outFile, byte[] outBytes) throws IOException { | ||
try ( | ||
FileOutputStream fos = new FileOutputStream(outFile, false); | ||
BufferedOutputStream bos = new BufferedOutputStream(fos)) { | ||
bos.write(outBytes); | ||
bos.flush(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/resources/META-INF/resources/manifest-requireAdminRights-v1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | ||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
<security> | ||
<requestedPrivileges> | ||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> | ||
</requestedPrivileges> | ||
</security> | ||
</trustInfo> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters