Added default router.config based on I2P Android

This commit is contained in:
str4d
2014-06-14 11:07:32 +00:00
parent d0f34d165a
commit a1af1874fe
2 changed files with 135 additions and 0 deletions

View File

@@ -2,10 +2,22 @@ package i2p.bote.android.service;
import net.i2p.android.router.service.IRouterState;
import net.i2p.client.I2PClient;
import net.i2p.data.DataHelper;
import net.i2p.util.OrderedProperties;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import i2p.bote.android.R;
public class Init {
private final Context ctx;
private final String myDir;
@@ -33,6 +45,8 @@ public class Init {
System.setProperty("i2p.dir.config", myDir);
System.setProperty("wrapper.logfile", myDir + "/wrapper.log");
mergeResourceToFile(R.raw.router_config, "router.config", null);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
RouterChoice routerChoice;
String i2cpHost, i2cpPort;
@@ -71,4 +85,47 @@ public class Init {
return routerChoice;
}
/**
* Load defaults from resource,
* then add props from settings,
* and write back
*
* @param f relative to base dir
* @param props local overrides or null
*/
public void mergeResourceToFile(int resID, String f, Properties overrides) {
InputStream in = null;
InputStream fin = null;
try {
in = ctx.getResources().openRawResource(resID);
Properties props = new OrderedProperties();
try {
fin = new FileInputStream(new File(myDir, f));
DataHelper.loadProps(props, fin);
} catch (IOException ioe) {
}
// write in default settings
DataHelper.loadProps(props, in);
// override with user settings
if (overrides != null)
props.putAll(overrides);
File path = new File(myDir, f);
DataHelper.storeProps(props, path);
} catch (IOException ioe) {
} catch (Resources.NotFoundException nfe) {
} finally {
if (in != null) try {
in.close();
} catch (IOException ioe) {
}
if (fin != null) try {
fin.close();
} catch (IOException ioe) {
}
}
}
}