mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
use onedir packaging of hwi
This commit is contained in:
parent
ef5399008f
commit
9af17bcac8
4 changed files with 73 additions and 19 deletions
|
@ -37,13 +37,13 @@ public class MainApp extends Application {
|
||||||
appController.initializeView();
|
appController.initializeView();
|
||||||
|
|
||||||
Wallet wallet = new Wallet();
|
Wallet wallet = new Wallet();
|
||||||
wallet.setPolicyType(PolicyType.MULTI);
|
wallet.setPolicyType(PolicyType.SINGLE);
|
||||||
wallet.setScriptType(ScriptType.P2WPKH);
|
wallet.setScriptType(ScriptType.P2WPKH);
|
||||||
|
|
||||||
KeystoreImportDialog dlg = new KeystoreImportDialog(wallet);
|
// KeystoreImportDialog dlg = new KeystoreImportDialog(wallet);
|
||||||
dlg.showAndWait();
|
// dlg.showAndWait();
|
||||||
|
|
||||||
//stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -19,6 +19,8 @@ import java.nio.file.attribute.PosixFilePermissions;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class Hwi {
|
public class Hwi {
|
||||||
private static File hwiExecutable;
|
private static File hwiExecutable;
|
||||||
|
@ -85,14 +87,48 @@ public class Hwi {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized File getHwiExecutable() throws IOException {
|
private synchronized File getHwiExecutable() throws IOException {
|
||||||
if(hwiExecutable == null) {
|
try {
|
||||||
|
if (hwiExecutable == null) {
|
||||||
Platform platform = Platform.getCurrent();
|
Platform platform = Platform.getCurrent();
|
||||||
System.out.println("/external/" + platform.getPlatformId().toLowerCase() + "/hwi");
|
|
||||||
InputStream inputStream = Hwi.class.getResourceAsStream("/external/" + platform.getPlatformId().toLowerCase() + "/hwi");
|
|
||||||
Set<PosixFilePermission> ownerExecutableWritable = PosixFilePermissions.fromString("rwxr--r--");
|
Set<PosixFilePermission> ownerExecutableWritable = PosixFilePermissions.fromString("rwxr--r--");
|
||||||
|
|
||||||
|
//A PyInstaller --onefile expands into a new directory on every run triggering OSX Gatekeeper checks.
|
||||||
|
//To avoid doing these with every invocation, use a --onedir packaging and expand into a temp folder on OSX
|
||||||
|
//The check will still happen on first invocation, but will not thereafter
|
||||||
|
//See https://github.com/bitcoin-core/HWI/issues/327 for details
|
||||||
|
if(platform.getPlatformId().toLowerCase().equals("mac")) {
|
||||||
|
InputStream inputStream = Hwi.class.getResourceAsStream("/external/" + platform.getPlatformId().toLowerCase() + "/hwi-1.1.0-mac-amd64-signed.zip");
|
||||||
|
Path tempHwiDirPath = Files.createTempDirectory("hwi", PosixFilePermissions.asFileAttribute(ownerExecutableWritable));
|
||||||
|
File tempHwiDir = tempHwiDirPath.toFile();
|
||||||
|
tempHwiDir.deleteOnExit();
|
||||||
|
|
||||||
|
System.out.println(tempHwiDir.getAbsolutePath());
|
||||||
|
|
||||||
|
File tempExec = null;
|
||||||
|
ZipInputStream zis = new ZipInputStream(inputStream);
|
||||||
|
ZipEntry zipEntry = zis.getNextEntry();
|
||||||
|
while (zipEntry != null) {
|
||||||
|
File newFile = newFile(tempHwiDir, zipEntry, ownerExecutableWritable);
|
||||||
|
newFile.deleteOnExit();
|
||||||
|
FileOutputStream fos = new FileOutputStream(newFile);
|
||||||
|
ByteStreams.copy(zis, new FileOutputStream(newFile));
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
|
||||||
|
if (zipEntry.getName().equals("hwi")) {
|
||||||
|
tempExec = newFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
zipEntry = zis.getNextEntry();
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
zis.close();
|
||||||
|
|
||||||
|
hwiExecutable = tempExec;
|
||||||
|
} else {
|
||||||
|
InputStream inputStream = Hwi.class.getResourceAsStream("/external/" + platform.getPlatformId().toLowerCase() + "/hwi");
|
||||||
Path tempExecPath = Files.createTempFile("hwi", null, PosixFilePermissions.asFileAttribute(ownerExecutableWritable));
|
Path tempExecPath = Files.createTempFile("hwi", null, PosixFilePermissions.asFileAttribute(ownerExecutableWritable));
|
||||||
File tempExec = tempExecPath.toFile();
|
File tempExec = tempExecPath.toFile();
|
||||||
System.out.println(tempExec.getAbsolutePath());
|
|
||||||
tempExec.deleteOnExit();
|
tempExec.deleteOnExit();
|
||||||
OutputStream tempExecStream = new BufferedOutputStream(new FileOutputStream(tempExec));
|
OutputStream tempExecStream = new BufferedOutputStream(new FileOutputStream(tempExec));
|
||||||
ByteStreams.copy(new FramedLZ4CompressorInputStream(inputStream), tempExecStream);
|
ByteStreams.copy(new FramedLZ4CompressorInputStream(inputStream), tempExecStream);
|
||||||
|
@ -102,10 +138,28 @@ public class Hwi {
|
||||||
|
|
||||||
hwiExecutable = tempExec;
|
hwiExecutable = tempExec;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return hwiExecutable;
|
return hwiExecutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File newFile(File destinationDir, ZipEntry zipEntry, Set<PosixFilePermission> setFilePermissions) throws IOException {
|
||||||
|
String destDirPath = destinationDir.getCanonicalPath();
|
||||||
|
|
||||||
|
Path path = Path.of(destDirPath, zipEntry.getName());
|
||||||
|
File destFile = Files.createFile(path, PosixFilePermissions.asFileAttribute(setFilePermissions)).toFile();
|
||||||
|
|
||||||
|
String destFilePath = destFile.getCanonicalPath();
|
||||||
|
if (!destFilePath.startsWith(destDirPath + File.separator)) {
|
||||||
|
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return destFile;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean wasSuccessful(String output) throws ImportException {
|
private boolean wasSuccessful(String output) throws ImportException {
|
||||||
JsonObject result = JsonParser.parseString(output).getAsJsonObject();
|
JsonObject result = JsonParser.parseString(output).getAsJsonObject();
|
||||||
if(result.get("error") != null) {
|
if(result.get("error") != null) {
|
||||||
|
|
BIN
src/main/resources/external/mac/hwi
vendored
BIN
src/main/resources/external/mac/hwi
vendored
Binary file not shown.
BIN
src/main/resources/external/mac/hwi-1.1.0-mac-amd64-signed.zip
vendored
Normal file
BIN
src/main/resources/external/mac/hwi-1.1.0-mac-amd64-signed.zip
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue