improve resource installer ability to update torrc

This commit is contained in:
Nathan Freitas 2014-06-13 12:59:36 -04:00
parent c0f7d754dd
commit f3d21eec4f
1 changed files with 9 additions and 11 deletions

View File

@ -116,34 +116,32 @@ public class TorResourceInstaller implements TorServiceConstants {
return true; return true;
} }
public boolean installTorrc (String extraLines) throws IOException, FileNotFoundException, TimeoutException public boolean updateTorConfig (File fileTorRc, String extraLines) throws IOException, FileNotFoundException, TimeoutException
{ {
InputStream is; InputStream is;
File outFile;
Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath()); Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath());
is = context.getResources().openRawResource(R.raw.torrc); is = context.getResources().openRawResource(R.raw.torrc);
outFile = new File(installFolder, TORRC_ASSET_KEY); shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish(); streamToFile(is,fileTorRc, false, false);
streamToFile(is,outFile, false, false);
if (extraLines != null && extraLines.length() > 0) if (extraLines != null && extraLines.length() > 0)
{ {
StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n'); StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
streamToFile(sbis,outFile,true,false); streamToFile(sbis,fileTorRc,true,false);
} }
is = context.getResources().openRawResource(R.raw.torrcdiag); is = context.getResources().openRawResource(R.raw.torrcdiag);
outFile = new File(installFolder, TORRCDIAG_ASSET_KEY); fileTorRc = new File(installFolder, TORRCDIAG_ASSET_KEY);
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish(); shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, false); streamToFile(is,fileTorRc, false, false);
if (extraLines != null && extraLines.length() > 0) if (extraLines != null && extraLines.length() > 0)
{ {
StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n'); StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
streamToFile(sbis,outFile,true,false); streamToFile(sbis,fileTorRc,true,false);
} }
shell.close(); shell.close();