bug fix and refactor

This commit is contained in:
arrase 2016-11-23 21:20:50 +01:00
parent 0b21dfc46a
commit f79d2d9005
3 changed files with 9 additions and 9 deletions

View File

@ -649,14 +649,14 @@ public class OrbotMainActivity extends AppCompatActivity
BackupUtils hsutils = new BackupUtils(getApplicationContext()); BackupUtils hsutils = new BackupUtils(getApplicationContext());
if(keyZipPath != null && keyZipPath.length() > 0) if(keyZipPath != null && keyZipPath.length() > 0)
{ {
hsutils.restoreOnionBackup(hsPort, keyZipPath); hsutils.restoreZipBackup(hsPort, keyZipPath);
requestTorRereadConfig(); requestTorRereadConfig();
} }
/* TODO /* TODO
if(doBackup) if(doBackup)
{ {
backupPath = hsutils.createOnionBackup(hsPort); backupPath = hsutils.createZipBackup(hsPort);
} }
*/ */
onion.close(); onion.close();

View File

@ -9,16 +9,16 @@ import org.torproject.android.storage.ExternalStorage;
import java.io.File; import java.io.File;
public class BackupUtils { public class BackupUtils {
private static File mHSBasePath; private File mHSBasePath;
public BackupUtils(Context context) { public BackupUtils(Context context) {
mHSBasePath = context.getDir( mHSBasePath = context.getDir(
TorServiceConstants.DIRECTORY_TOR_DATA + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR, TorServiceConstants.DIRECTORY_TOR_DATA,
Application.MODE_PRIVATE Application.MODE_PRIVATE
); );
} }
public String createOnionBackup(Integer port) { public String createZipBackup(Integer port) {
ExternalStorage storage = new ExternalStorage(); ExternalStorage storage = new ExternalStorage();
String storage_path = storage.createBackupDir(); String storage_path = storage.createBackupDir();
@ -28,8 +28,8 @@ public class BackupUtils {
String zip_path = storage_path + "/hs" + port + ".zip"; String zip_path = storage_path + "/hs" + port + ".zip";
String files[] = { String files[] = {
mHSBasePath + "/hs" + port + "/hostname", mHSBasePath + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR + "/hs" + port + "/hostname",
mHSBasePath + "/hs" + port + "/private_key" mHSBasePath + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR + "/hs" + port + "/private_key"
}; };
ZipIt zip = new ZipIt(files, zip_path); ZipIt zip = new ZipIt(files, zip_path);
@ -41,7 +41,7 @@ public class BackupUtils {
return zip_path; return zip_path;
} }
public void restoreOnionBackup(Integer port, String path) { public void restoreZipBackup(Integer port, String path) {
ZipIt zip = new ZipIt(null, path); ZipIt zip = new ZipIt(null, path);
zip.unzip(mHSBasePath + "/hs" + port); zip.unzip(mHSBasePath + "/hs" + port);
} }

View File

@ -50,7 +50,7 @@ public class HSActionsDialog extends DialogFragment {
} }
BackupUtils hsutils = new BackupUtils(mContext); BackupUtils hsutils = new BackupUtils(mContext);
String backupPath = hsutils.createOnionBackup(Integer.parseInt(arguments.getString("port"))); String backupPath = hsutils.createZipBackup(Integer.parseInt(arguments.getString("port")));
if (backupPath == null || backupPath.length() < 1) { if (backupPath == null || backupPath.length() < 1) {
Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show(); Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();