Files
i2p.plugins.firefox/src/java/net/i2p/i2pfirefox/I2PChromiumProfileChecker.java

129 lines
3.8 KiB
Java
Raw Normal View History

package net.i2p.i2pfirefox;
import java.io.File;
2022-08-27 13:27:28 -04:00
/**
2022-08-21 23:49:08 -04:00
* I2PChromiumProfileChecker.java
* Copyright (C) 2022 idk <hankhill19580@gmail.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License. See LICENSE.md for details.
2022-08-30 15:49:44 -04:00
*
2022-08-21 23:49:08 -04:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
2022-08-30 15:49:44 -04:00
* I2PChromiumProfileChecker is a class that checks if the Chromium profile
* directory exists and is valid.
*
2022-08-21 23:49:08 -04:00
* @author idk
* @since 0.0.1
*/
public class I2PChromiumProfileChecker extends I2PCommonBrowser {
2022-08-30 15:49:44 -04:00
/**
* Output feedback if the profile directory is valid or invalid
*
* @description Output feedback if the profile directory is valid or invalid
* @args unused
* @since 0.0.1
*/
public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
if (profileDirectory == null) {
2022-09-11 01:42:07 -04:00
logger.info("No profile directory found");
2022-08-30 15:49:44 -04:00
return;
}
2022-09-11 01:42:07 -04:00
logger.info("Profile directory: " + profileDirectory);
2022-08-30 15:49:44 -04:00
boolean ok = validateProfileDirectory(profileDirectory);
if (ok) {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory is valid");
2022-08-30 15:49:44 -04:00
} else {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory is invalid");
2022-08-30 15:49:44 -04:00
}
}
/**
* Return true if the profile directory is valid.
*
* @param profileDirectory the profile directory to check
* @return true if the profile directory is valid, false otherwise
* @since 0.0.1
*/
public static boolean validateProfileDirectory(String profileDirectory) {
File profileDir = new File(profileDirectory);
if (!profileDir.exists()) {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory does not exist");
2022-08-30 15:49:44 -04:00
return false;
}
if (!profileDir.isDirectory()) {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory is not a directory");
2022-08-30 15:49:44 -04:00
return false;
}
if (!profileDir.canRead()) {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory is not readable");
2022-08-30 15:49:44 -04:00
return false;
}
if (!profileDir.canWrite()) {
2022-09-11 01:42:07 -04:00
logger.info("Profile directory is not writable");
2022-08-30 15:49:44 -04:00
return false;
}
if (!validateExtensionDirectory(profileDir + "/extensions")) {
2022-09-11 01:42:07 -04:00
logger.info("extensions directory is invalid");
2022-08-30 15:49:44 -04:00
return false;
}
return true;
}
/**
* Return true if the file is valid.
*
* @param file the file to check
* @return true if the file is valid, false otherwise
* @since 0.0.1
*/
public static boolean validateFile(String file) {
File f = new File(file);
if (!f.exists()) {
2022-09-11 01:42:07 -04:00
logger.info("User JavaScript file does not exist");
2022-08-30 15:49:44 -04:00
return false;
}
if (!f.isFile()) {
2022-09-11 01:42:07 -04:00
logger.info("User JavaScript file is not a file");
2022-08-30 15:49:44 -04:00
return false;
}
if (!f.canRead()) {
2022-09-11 01:42:07 -04:00
logger.info("User JavaScript file is not readable");
2022-08-30 15:49:44 -04:00
return false;
}
if (!f.canWrite()) {
2022-09-11 01:42:07 -04:00
logger.info("User JavaScript file is not writable");
2022-08-30 15:49:44 -04:00
return false;
}
return true;
}
/**
* Return true if the extension directory is valid.
*
* @param extensionDirectory the extension directory to check
* @return true if the extension directory is valid, false otherwise
* @since 0.0.1
*/
public static boolean validateExtensionDirectory(String extensionDirectory) {
File extensionDir = new File(extensionDirectory);
if (!extensionDir.exists()) {
2022-09-11 01:42:07 -04:00
logger.info("Extension directory does not exist");
2022-08-30 15:49:44 -04:00
return false;
}
if (!extensionDir.isDirectory()) {
2022-09-11 01:42:07 -04:00
logger.info("Extension directory is not a directory");
2022-08-30 15:49:44 -04:00
return false;
}
2022-08-30 15:49:44 -04:00
if (!extensionDir.canRead()) {
2022-09-11 01:42:07 -04:00
logger.info("Extension directory is not readable");
2022-08-30 15:49:44 -04:00
return false;
}
2022-08-30 15:49:44 -04:00
if (!extensionDir.canWrite()) {
2022-09-11 01:42:07 -04:00
logger.info("Extension directory is not writable");
2022-08-30 15:49:44 -04:00
return false;
}
2022-08-30 15:49:44 -04:00
return true;
}
}