diff options
| author | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 13:35:58 +0200 | 
|---|---|---|
| committer | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 13:35:58 +0200 | 
| commit | 0bf35bebed61c8efc92e9dd25e80c97e9616c00c (patch) | |
| tree | 04974bc92c7256cd1a0cbc6fa8d02089e36415aa /src | |
| parent | 5281cc9f8dbb3a326a287c7b52d9317f385a4058 (diff) | |
Writing the Minivpn binary on start.
It is small enough to not care about writing it over and over again.
Diffstat (limited to 'src')
| -rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 39 | 
1 files changed, 37 insertions, 2 deletions
| 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()); | 
