fix unaltered FIREFOX vars in I2PChromiumProfileBuilder.java

This commit is contained in:
idk
2022-08-30 14:22:47 -04:00
parent 2a50bd38a1
commit 48ba47b274
7 changed files with 74 additions and 97 deletions

View File

@ -172,7 +172,7 @@ Linux(because the top command will be run and the script will exit).\n\nBoth det
<ant dir="src" target="jar" /> <ant dir="src" target="jar" />
</target> </target>
<target name="i2pFirefoxBaseProfileZip"> <target name="i2pFirefoxBaseProfileZip" depends="i2pFirefoxUsabilityProfileZip">
<exec executable="rm" failonerror="false" dir="src"> <exec executable="rm" failonerror="false" dir="src">
<arg value="-rf" /> <arg value="-rf" />
<arg value="i2p.firefox.base.profile.zip" /> <arg value="i2p.firefox.base.profile.zip" />
@ -183,6 +183,17 @@ Linux(because the top command will be run and the script will exit).\n\nBoth det
<arg value="i2p.firefox.base.profile"/> <arg value="i2p.firefox.base.profile"/>
</exec> </exec>
</target> </target>
<target name="i2pFirefoxUsabilityProfileZip">
<exec executable="rm" failonerror="false" dir="src">
<arg value="-rf" />
<arg value="i2p.firefox.usability.profile.zip" />
</exec>
<exec executable="zip" failonerror="true" dir="src">
<arg value="-r"/>
<arg value="i2p.firefox.usability.profile.zip"/>
<arg value="i2p.firefox.usability.profile"/>
</exec>
</target>
<target name="i2pChromiumBaseProfile"> <target name="i2pChromiumBaseProfile">
<exec executable="crx3" failonerror="true"> <exec executable="crx3" failonerror="true">

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Aug 27 18:59:34 EDT 2022 #Tue Aug 30 12:27:51 EDT 2022
build.number=89 build.number=90

View File

@ -43,6 +43,7 @@
<target name="jar" depends="builddep, compile"> <target name="jar" depends="builddep, compile">
<jar destfile="build/i2pfirefox.jar" basedir="./build/obj" includes="**/*.class" > <jar destfile="build/i2pfirefox.jar" basedir="./build/obj" includes="**/*.class" >
<fileset file="i2p.firefox.base.profile.zip" /> <fileset file="i2p.firefox.base.profile.zip" />
<fileset file="i2p.firefox.usability.profile.zip" />
<fileset file="i2p.chromium.base.profile.zip" /> <fileset file="i2p.chromium.base.profile.zip" />
</jar> </jar>
</target> </target>

View File

@ -41,7 +41,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
* @return the profile directory, or null if it could not be created * @return the profile directory, or null if it could not be created
*/ */
public static String profileDirectory() { public static String profileDirectory() {
String pd = System.getenv("I2P_FIREFOX_PROFILE"); String pd = System.getenv("I2P_CHROMIUM_PROFILE");
if (pd != null && !pd.isEmpty()) { if (pd != null && !pd.isEmpty()) {
File pdf = new File(pd); File pdf = new File(pd);
if (pdf.exists() && pdf.isDirectory()) { if (pdf.exists() && pdf.isDirectory()) {
@ -73,7 +73,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
* @return the base profile directory, or null if it could not be created * @return the base profile directory, or null if it could not be created
*/ */
public static String baseProfileDirectory() { public static String baseProfileDirectory() {
String pd = System.getenv("I2P_FIREFOX_BASE_PROFILE"); String pd = System.getenv("I2P_CHROMIUM_BASE_PROFILE");
if (pd != null && !pd.isEmpty()) { if (pd != null && !pd.isEmpty()) {
File pdf = new File(pd); File pdf = new File(pd);
if (pdf.exists() && pdf.isDirectory()) { if (pdf.exists() && pdf.isDirectory()) {
@ -108,18 +108,18 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
* @since 0.0.1 * @since 0.0.1
*/ */
public static String runtimeDirectory() { public static String runtimeDirectory() {
// get the I2P_FIREFOX_DIR environment variable // get the I2P_CHROMIUM_DIR environment variable
String rtd = System.getenv("I2P_FIREFOX_DIR"); String rtd = System.getenv("I2P_CHROMIUM_DIR");
// if it is not null and not empty // if it is not null and not empty
if (rtd != null && !rtd.isEmpty()) { if (rtd != null && !rtd.isEmpty()) {
// check if the file exists // check if the file exists
File rtdFile = new File(rtd); File rtdFile = new File(rtd);
if (rtdFile.exists()) { if (rtdFile.exists()) {
// if it does, return it // if it does, return it
return runtimeDirectory(rtd) return runtimeDirectory(rtd);
} }
} }
return runtimeDirectory("") return runtimeDirectory("");
} }
/** /**
@ -147,6 +147,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
System.out.println("Copied base profile to profile directory"); System.out.println("Copied base profile to profile directory");
return copyStrictOptions(); return copyStrictOptions();
} }
private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException { private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
destinationDirectory = new File(destinationDirectory.toString().replace("i2p.chromium.base.profile", "")); destinationDirectory = new File(destinationDirectory.toString().replace("i2p.chromium.base.profile", ""));
if (!destinationDirectory.exists()) { if (!destinationDirectory.exists()) {

View File

@ -24,7 +24,7 @@ import java.util.zip.ZipInputStream;
* @author idk * @author idk
* @since 0.0.1 * @since 0.0.1
*/ */
public class I2PChromiumProfileUnpacker { public class I2PChromiumProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
@ -43,45 +43,7 @@ public class I2PChromiumProfileUnpacker {
*/ */
public boolean unpackProfile(String profileDirectory) { public boolean unpackProfile(String profileDirectory) {
System.out.println("Unpacking base profile to " + profileDirectory); System.out.println("Unpacking base profile to " + profileDirectory);
try { return unpackProfile(profileDirectory, "chromium", "base");
final InputStream resources = this.getClass().getClassLoader().getResourceAsStream("i2p.chromium.base.profile.zip");
if (resources == null) {
System.out.println("Could not find resources");
return false;
} }
System.out.println(resources.toString());
// InputStream corresponds to a zip file. Unzip it.
//Files.copy(r, new File(profileDirectory).toPath(), StandardCopyOption.REPLACE_EXISTING);
ZipInputStream zis = new ZipInputStream(resources);
ZipEntry entry;
// while there are entries I process them
while ((entry = zis.getNextEntry()) != null)
{
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
// consume all the data from this entry
if (entry.isDirectory()) {
System.out.println("Creating directory: " + entry.getName());
File dir = new File(profileDirectory + "/" + entry.getName());
dir.mkdirs();
} else {
System.out.println("Creating file: " + entry.getName());
File file = new File(profileDirectory + "/" + entry.getName());
file.createNewFile();
Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
while (zis.available() > 0)
zis.read();
// I could close the entry, but getNextEntry does it automatically
// zis.closeEntry()
}
// loop through the Enumeration
} catch (Exception e) {
System.out.println("Error copying profile files: " + e.getMessage());
return false;
}
return true;
}
} }

View File

@ -1,6 +1,11 @@
package net.i2p.i2pfirefox; package net.i2p.i2pfirefox;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class I2PCommonBrowser { public class I2PCommonBrowser {
@ -68,4 +73,46 @@ public class I2PCommonBrowser {
} }
return ""; return "";
} }
public boolean unpackProfile(String profileDirectory, String browser, String base) {
System.out.println("Unpacking base profile to " + profileDirectory);
try {
final InputStream resources = this.getClass().getClassLoader().getResourceAsStream("i2p."+browser+"."+base+".profile.zip");
if (resources == null) {
System.out.println("Could not find resources");
return false;
}
System.out.println(resources.toString());
// InputStream corresponds to a zip file. Unzip it.
//Files.copy(r, new File(profileDirectory).toPath(), StandardCopyOption.REPLACE_EXISTING);
ZipInputStream zis = new ZipInputStream(resources);
ZipEntry entry;
// while there are entries I process them
while ((entry = zis.getNextEntry()) != null)
{
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
// consume all the data from this entry
if (entry.isDirectory()) {
System.out.println("Creating directory: " + entry.getName());
File dir = new File(profileDirectory + "/" + entry.getName());
dir.mkdirs();
} else {
System.out.println("Creating file: " + entry.getName());
File file = new File(profileDirectory + "/" + entry.getName());
file.createNewFile();
Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
while (zis.available() > 0)
zis.read();
// I could close the entry, but getNextEntry does it automatically
// zis.closeEntry()
}
// loop through the Enumeration
} catch (Exception e) {
System.out.println("Error copying profile files: " + e.getMessage());
return false;
}
return true;
}
} }

View File

@ -1,12 +1,5 @@
package net.i2p.i2pfirefox; package net.i2p.i2pfirefox;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/** /**
* I2PFirefoxProfileUnpacker.java * I2PFirefoxProfileUnpacker.java
* Copyright (C) 2022 idk <hankhill19580@gmail.com> * Copyright (C) 2022 idk <hankhill19580@gmail.com>
@ -25,7 +18,7 @@ import java.util.zip.ZipInputStream;
* @author idk * @author idk
* @since 0.0.1 * @since 0.0.1
*/ */
public class I2PFirefoxProfileUnpacker { public class I2PFirefoxProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory();
@ -42,46 +35,8 @@ public class I2PFirefoxProfileUnpacker {
* @return true if the profile directory was successfully unpacked * @return true if the profile directory was successfully unpacked
* @since 0.0.1 * @since 0.0.1
*/ */
public boolean unpackProfile(String profileDirectory) { public boolean unpackProfile(String profileDirectory){
System.out.println("Unpacking base profile to " + profileDirectory); return unpackProfile(profileDirectory, "firefox", "base");
try {
final InputStream resources = this.getClass().getClassLoader().getResourceAsStream("i2p.firefox.base.profile.zip");
if (resources == null) {
System.out.println("Could not find resources");
return false;
}
System.out.println(resources.toString());
// InputStream corresponds to a zip file. Unzip it.
//Files.copy(r, new File(profileDirectory).toPath(), StandardCopyOption.REPLACE_EXISTING);
ZipInputStream zis = new ZipInputStream(resources);
ZipEntry entry;
// while there are entries I process them
while ((entry = zis.getNextEntry()) != null)
{
System.out.println("entry: " + entry.getName() + ", " + entry.getSize());
// consume all the data from this entry
if (entry.isDirectory()) {
System.out.println("Creating directory: " + entry.getName());
File dir = new File(profileDirectory + "/" + entry.getName());
dir.mkdirs();
} else {
System.out.println("Creating file: " + entry.getName());
File file = new File(profileDirectory + "/" + entry.getName());
file.createNewFile();
Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
while (zis.available() > 0)
zis.read();
// I could close the entry, but getNextEntry does it automatically
// zis.closeEntry()
}
// loop through the Enumeration
} catch (Exception e) {
System.out.println("Error copying profile files: " + e.getMessage());
return false;
}
return true;
} }