|
|
|
@ -65,9 +65,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
*
|
|
|
|
|
* @return the properties of the object
|
|
|
|
|
*/
|
|
|
|
|
public Properties getProperties() {
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
public Properties getProperties() { return prop; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validates the user directory.
|
|
|
|
@ -89,7 +87,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
|
|
|
|
|
if (!userDirFile.getAbsolutePath().contains("Program Files")) {
|
|
|
|
|
if (!userDirFile.getAbsolutePath().equals(
|
|
|
|
|
userHomeFile.getAbsolutePath())) {
|
|
|
|
|
userHomeFile.getAbsolutePath())) {
|
|
|
|
|
logger.info("user.dir is not inconvenient");
|
|
|
|
|
if (userDirFile.exists()) {
|
|
|
|
|
logger.info("user.dir exists");
|
|
|
|
@ -287,7 +285,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @since 0.0.19
|
|
|
|
|
*/
|
|
|
|
|
protected String profileDirectory(String envVar, String browser, String base,
|
|
|
|
|
boolean app) {
|
|
|
|
|
boolean app) {
|
|
|
|
|
String profileDir = System.getenv(envVar);
|
|
|
|
|
if (profileDir != null && !profileDir.isEmpty()) {
|
|
|
|
|
File profileDirFile = new File(profileDir);
|
|
|
|
@ -309,9 +307,10 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @return description of return value
|
|
|
|
|
*/
|
|
|
|
|
protected String profileDir(String file, String browser, String base,
|
|
|
|
|
boolean app) {
|
|
|
|
|
boolean app) {
|
|
|
|
|
String appString = app ? ".app" : "";
|
|
|
|
|
String profileDirName = String.format("i2p.%s.profile.%s%s", browser, base, appString);
|
|
|
|
|
String profileDirName =
|
|
|
|
|
String.format("i2p.%s.profile.%s%s", browser, base, appString);
|
|
|
|
|
File profileDir = new File(file, profileDirName);
|
|
|
|
|
return profileDir.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
@ -325,11 +324,12 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @return true if the profile was successfully unpacked, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
protected boolean unpackProfile(String profileDirectory, String browser,
|
|
|
|
|
String base) {
|
|
|
|
|
String base) {
|
|
|
|
|
logger.info("Unpacking base profile to " + profileDirectory);
|
|
|
|
|
try {
|
|
|
|
|
final InputStream resources = this.getClass().getClassLoader().getResourceAsStream(
|
|
|
|
|
"i2p." + browser + "." + base + ".profile.zip");
|
|
|
|
|
final InputStream resources =
|
|
|
|
|
this.getClass().getClassLoader().getResourceAsStream(
|
|
|
|
|
"i2p." + browser + "." + base + ".profile.zip");
|
|
|
|
|
if (resources == null) {
|
|
|
|
|
logger.info("Could not find resources");
|
|
|
|
|
return false;
|
|
|
|
@ -379,7 +379,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @throws IOException if an I/O error occurs during copying
|
|
|
|
|
*/
|
|
|
|
|
protected void copyDirectory(File sourceDir, File destDir, String browser,
|
|
|
|
|
String base) throws IOException {
|
|
|
|
|
String base) throws IOException {
|
|
|
|
|
destDir = new File(destDir.toString().replace(
|
|
|
|
|
"i2p." + browser + "." + base + ".profile", ""));
|
|
|
|
|
if (!destDir.exists()) {
|
|
|
|
@ -387,7 +387,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
}
|
|
|
|
|
for (String file : sourceDir.list()) {
|
|
|
|
|
copyDirectoryCompatibilityMode(new File(sourceDir, file),
|
|
|
|
|
new File(destDir, file), browser, base);
|
|
|
|
|
new File(destDir, file), browser, base);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -401,8 +401,8 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @throws IOException if an I/O error occurs
|
|
|
|
|
*/
|
|
|
|
|
private void copyDirectoryCompatibilityMode(File sourceDirectory,
|
|
|
|
|
File destinationDirectory,
|
|
|
|
|
String browser, String base)
|
|
|
|
|
File destinationDirectory,
|
|
|
|
|
String browser, String base)
|
|
|
|
|
throws IOException {
|
|
|
|
|
if (sourceDirectory.isDirectory()) {
|
|
|
|
|
copyDirectory(sourceDirectory, destinationDirectory, browser, base);
|
|
|
|
@ -437,7 +437,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
private void copyFile(File sourceFile, File destinationFile)
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (InputStream in = new FileInputStream(sourceFile);
|
|
|
|
|
OutputStream out = new FileOutputStream(destinationFile)) {
|
|
|
|
|
OutputStream out = new FileOutputStream(destinationFile)) {
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int length;
|
|
|
|
|
while ((length = in.read(buffer)) > 0) {
|
|
|
|
@ -475,9 +475,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @return true if the proxy is ready, false if it is not.
|
|
|
|
|
* @since 0.0.1
|
|
|
|
|
*/
|
|
|
|
|
public boolean waitForProxy() {
|
|
|
|
|
return waitForProxy(CONFIGURED_TIMEOUT);
|
|
|
|
|
}
|
|
|
|
|
public boolean waitForProxy() { return waitForProxy(CONFIGURED_TIMEOUT); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Waits for an HTTP proxy on port 4444 to be ready.
|
|
|
|
@ -555,9 +553,7 @@ public class I2PCommonBrowser {
|
|
|
|
|
*
|
|
|
|
|
* @param time
|
|
|
|
|
*/
|
|
|
|
|
public void setProxyTimeoutTime(int time) {
|
|
|
|
|
CONFIGURED_TIMEOUT = time;
|
|
|
|
|
}
|
|
|
|
|
public void setProxyTimeoutTime(int time) { CONFIGURED_TIMEOUT = time; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Joins the elements of the given string array into a single string.
|
|
|
|
@ -594,6 +590,13 @@ public class I2PCommonBrowser {
|
|
|
|
|
* @return the found file or null if not found
|
|
|
|
|
*/
|
|
|
|
|
public File searchFile(File directory, String search) {
|
|
|
|
|
File hd = new File(System.getProperty("user.home"));
|
|
|
|
|
if (hd != null) {
|
|
|
|
|
if (directory.getAbsolutePath().equals(hd.getAbsolutePath()))
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (directory == null || !directory.exists() || !directory.canRead())
|
|
|
|
|
return null;
|
|
|
|
|
if (directory.isDirectory()) {
|
|
|
|
|
File[] files = directory.listFiles();
|
|
|
|
|
for (File file : files) {
|
|
|
|
@ -610,11 +613,16 @@ public class I2PCommonBrowser {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File userHomeDir() {
|
|
|
|
|
File hd = new File(System.getProperty("user.dir"));
|
|
|
|
|
if (hd == null || !hd.exists()) {
|
|
|
|
|
hd = new File(System.getProperty("user.home"));
|
|
|
|
|
File rd = new File(System.getProperty("user.dir"));
|
|
|
|
|
File hd = new File(System.getProperty("user.home"));
|
|
|
|
|
if (rd == null || !rd.exists()) {
|
|
|
|
|
if (hd == null || !hd.exists()) {
|
|
|
|
|
if (rd.getAbsolutePath().equals(hd.getAbsolutePath()))
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return rd;
|
|
|
|
|
}
|
|
|
|
|
logger.info("Runtime directory discovered at: "+ hd);
|
|
|
|
|
return hd;
|
|
|
|
|
logger.info("Runtime directory discovered at: " + rd);
|
|
|
|
|
return rd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|