From 0bf35bebed61c8efc92e9dd25e80c97e9616c00c Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 9 May 2012 13:35:58 +0200 Subject: Writing the Minivpn binary on start. It is small enough to not care about writing it over and over again. --- src/de/blinkt/openvpn/LaunchVPN.java | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/de/blinkt/openvpn') diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index 88c14da3..17313cd5 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -16,6 +16,11 @@ package de.blinkt.openvpn; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Collection; import java.util.Vector; @@ -203,6 +208,32 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { // } } + + private boolean writeMiniVPN() { + try { + InputStream mvpn = getAssets().open("minivpn"); + File mvpnout = new File(getCacheDir(),"minivpn"); + FileOutputStream fout = new FileOutputStream(mvpnout); + + byte buf[]= new byte[4096]; + + int lenread = mvpn.read(buf); + while(lenread> 0) { + fout.write(buf, 0, lenread); + lenread = mvpn.read(buf); + } + fout.close(); + + if(!mvpnout.setExecutable(true)) + return false; + + + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } private void askForPW(final String type) { @@ -309,8 +340,12 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { void startOpenVpn() { Intent startLW = new Intent(getBaseContext(),LogWindow.class); startActivity(startLW); - - + + OpenVPN.logMessage(0, "", "Writing minivpn binary"); + if(!writeMiniVPN()) { + OpenVPN.logMessage(0, "", "Error writing minivpn binary"); + return; + } OpenVPN.logMessage(0, "", "Building configration..."); Intent startVPN = mSelectedProfile.prepareIntent(getBaseContext()); -- cgit v1.2.3