unprotected file scenario

This commit is contained in:
nedlir 2022-04-22 00:45:05 +02:00
parent 7ad223b981
commit a08ca53a0d
1 changed files with 27 additions and 15 deletions

View File

@ -43,13 +43,13 @@ public class Controller {
private Image powerpointImage;
private Image progressOnGoing;
private Image progressFinished;
@FXML
private Text fileText;
@FXML
private Text invalidFileText;
@FXML
private ImageView progressBarBrowse;
@ -60,19 +60,19 @@ public class Controller {
public void initialize() {
anchorPane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
invalidFileText.setVisible(false);
invalidFileText.setVisible(false);
progressBarBrowse.setVisible(false);
progressBarRemove.setVisible(false);
try {
wordImage = new Image(getClass().getResourceAsStream("img/word.png"));
powerpointImage = new Image(getClass().getResourceAsStream("img/powerpoint.png"));
excelImage = new Image(getClass().getResourceAsStream("img/excel.png"));
progressOnGoing = new Image(getClass().getResourceAsStream("img/prog-bar-ongoing.gif"));
progressFinished = new Image(getClass().getResourceAsStream("img/prog-bar-complete.png"));
} catch (Exception e) {
@ -84,14 +84,20 @@ public class Controller {
void browsePressed(ActionEvent event) {
invalidFileText.setVisible(false);
progressBarRemove.setVisible(false);
progressBarBrowse.setVisible(true);
progressBarBrowse.setImage(progressOnGoing);
filePathText.setVisible(false);
try {
fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null);
filePath = file.toString();
fileName = file.getName();
filePathText.setVisible(true);
filePathText.setText(filePath);
fileType = getFileType();
@ -106,6 +112,7 @@ public class Controller {
@FXML
void removePasswordPressed(ActionEvent event) {
if (file == null) {
return;
}
@ -118,14 +125,14 @@ public class Controller {
// show progress
progressBarRemove.setVisible(true);
progressBarRemove.setImage(progressOnGoing);
FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file
manipulator.extractFile(); // extract XML from file
XMLParser parser = new XMLParser(manipulator); // create new object to parse the XML
if (parser.isExistSecurityElement()) // if the file has a password
if (parser.isExistSecurityElement()) // if the file has a password protection as a read-only file
{
parser.removeElementOfSecurity(); // remove hash node from XML file
@ -133,17 +140,17 @@ public class Controller {
manipulator.insertFile(); // write back to file
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
fileText.setText(fileFinishedMessage());
progressBarRemove.setImage(progressFinished);
}
else // if there is no security element in the xml file, there is no read-only protection on it
} else // if there is no security element in the xml file, there is no read-only protection on it
{
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
fileText.setText(notReadOnlyMessage());
}
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
progressBarRemove.setImage(progressFinished);
} catch (Exception e) {
e.printStackTrace();
}
@ -219,4 +226,9 @@ public class Controller {
return messageOnScreen;
}
private String notReadOnlyMessage() {
String messageOnScreen = "Officer Breaker couldn't find any \"read-only\" restriction on the file. \n \nTry another file?";
return messageOnScreen;
}
}