binary installer now supports zipped raw files

This commit is contained in:
Nathan Freitas 2011-10-28 11:00:58 -04:00
parent ce804b7d65
commit 28bb6c3168
1 changed files with 21 additions and 18 deletions

View File

@ -9,8 +9,12 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.torproject.android.R; import org.torproject.android.R;
import org.torproject.android.TorConstants; import org.torproject.android.TorConstants;
@ -40,29 +44,20 @@ public class TorBinaryInstaller implements TorServiceConstants {
InputStream is; InputStream is;
is = context.getResources().openRawResource(R.raw.toraa); is = context.getResources().openRawResource(R.raw.tor);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false); streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false, true);
is = context.getResources().openRawResource(R.raw.torab);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torac);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torad);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torrc); is = context.getResources().openRawResource(R.raw.torrc);
streamToFile(is,installFolder, TORRC_ASSET_KEY, false); streamToFile(is,installFolder, TORRC_ASSET_KEY, false, false);
is = context.getResources().openRawResource(R.raw.privoxy); is = context.getResources().openRawResource(R.raw.privoxy);
streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false); streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false, false);
is = context.getResources().openRawResource(R.raw.privoxy_config); is = context.getResources().openRawResource(R.raw.privoxy_config);
streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false); streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false, false);
is = context.getResources().openRawResource(R.raw.geoip); is = context.getResources().openRawResource(R.raw.geoip);
streamToFile(is,installFolder, GEOIP_ASSET_KEY, false); streamToFile(is,installFolder, GEOIP_ASSET_KEY, false, true);
return true; return true;
} }
@ -71,7 +66,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
/* /*
* Write the inputstream contents to the file * Write the inputstream contents to the file
*/ */
private static boolean streamToFile(InputStream stm, File folder, String targetFilename, boolean append) throws IOException private static boolean streamToFile(InputStream stm, File folder, String targetFilename, boolean append, boolean zip) throws IOException
{ {
byte[] buffer = new byte[FILE_WRITE_BUFFER_SIZE]; byte[] buffer = new byte[FILE_WRITE_BUFFER_SIZE];
@ -80,7 +75,15 @@ public class TorBinaryInstaller implements TorServiceConstants {
File outFile = new File(folder, targetFilename); File outFile = new File(folder, targetFilename);
FileOutputStream stmOut = new FileOutputStream(outFile, append); OutputStream stmOut = new FileOutputStream(outFile, append);
if (zip)
{
ZipInputStream zis = new ZipInputStream(stm);
ZipEntry ze = zis.getNextEntry();
stm = zis;
}
while ((bytecount = stm.read(buffer)) > 0) while ((bytecount = stm.read(buffer)) > 0)