Skip to content

Commit

Permalink
FutureRestore GUI — v1.96
Browse files Browse the repository at this point in the history
- New FutureRestore beta naming scheme
- Update dependencies
- Refactoring
  • Loading branch information
CoocooFroggy authored Mar 3, 2022
2 parents de51fc3 + 16239eb commit 94bb0c0
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 367 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-pack-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ jobs:
env:
RUN_NUMBER: ${{ github.run_number }}
VERSION: ${{ steps.output-version.outputs.version }}
run: jpackage --input ./input --name "FutureRestore GUI" --main-jar "FutureRestore GUI-1.0-all.jar" --main-class Main --type msi --icon ./.github/workflows/windows/FRWindows.ico --copyright "© CoocooFroggy 2021" --vendor "CoocooFroggy" --verbose --name "FutureRestore GUI" --win-shortcut --win-menu --module-path ./.github/workflows/windows/javafx-jmods-11.0.2 --add-modules javafx.swing,java.logging,java.sql,java.base,jdk.crypto.ec,java.naming --app-version %VERSION%
run: jpackage --input ./input --name "FutureRestore GUI" --main-jar "FutureRestore GUI-1.0-all.jar" --main-class Main --type msi --icon ./.github/workflows/windows/FRWindows.ico --copyright "© CoocooFroggy 2021" --vendor "CoocooFroggy" --verbose --name "FutureRestore GUI" --win-shortcut --win-menu --win-console --module-path ./.github/workflows/windows/javafx-jmods-11.0.2 --add-modules javafx.swing,java.logging,java.sql,java.base,jdk.crypto.ec,java.naming --app-version %VERSION%
shell: cmd

- name: Find MSI name
Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ repositories {
}

dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.formdev:flatlaf:2.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.formdev:flatlaf:2.0.1'
implementation group: 'org.tukaani', name: 'xz', version: '1.8'
implementation group: 'org.rauschig', name: 'jarchivelib', version: '0.7.1'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
implementation 'com.github.Dansoftowner:jSystemThemeDetector:3.6'
implementation 'com.github.oshi:oshi-core:6.0.0'
implementation 'com.github.oshi:oshi-core:6.1.2'
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation 'com.github.rjeschke:txtmark:0.13'
// https://mvnrepository.com/artifact/com.intellij/forms_rt
implementation group: 'com.intellij', name: 'forms_rt', version: '7.0.3'
}

test {
Expand Down
71 changes: 23 additions & 48 deletions src/main/java/FRUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static File downloadFRGUI(MainMenu mainMenuInstance, String frguiDownload
JProgressBar logProgressBar = mainMenuInstance.getLogProgressBar();
JTextField currentTaskTextField = mainMenuInstance.getCurrentTaskTextField();

//Download synchronously
// Download synchronously
String frguiDownloadName = null;
String frguiDownloadUrl = null;
try {
Expand Down Expand Up @@ -151,19 +151,17 @@ public static File downloadFRGUI(MainMenu mainMenuInstance, String frguiDownload
String homeDirectory = System.getProperty("user.home");
File frGuiDir = new File(homeDirectory + "/FutureRestoreGUI/");

//Make directory to store files if not exists
// Make directory to store files if not exists
if (!frGuiDir.exists()) {
frGuiDir.mkdir();
}

String finalFrPath = homeDirectory + "/FutureRestoreGUI/";
String frguiDirPath = homeDirectory + "/FutureRestoreGUI/";
File downloadedFrgui;
try {
System.out.println("Downloading...");
SwingUtilities.invokeLater(() -> {
currentTaskTextField.setText("Downloading FutureRestore GUI...");
});
downloadedFrgui = downloadFile(frguiDownloadUrl, finalFrPath, mainMenuInstance);
SwingUtilities.invokeLater(() -> currentTaskTextField.setText("Downloading FutureRestore GUI..."));
downloadedFrgui = downloadFileWithProgress(frguiDownloadUrl, frguiDirPath, mainMenuInstance.getLogProgressBar());
SwingUtilities.invokeLater(() -> {
currentTaskTextField.setText("");
logProgressBar.setValue(0);
Expand Down Expand Up @@ -305,9 +303,7 @@ else if (disabledComponents.contains(component)) {
return;
}

SwingUtilities.invokeLater(() -> {
component.setEnabled(toSet);
});
SwingUtilities.invokeLater(() -> component.setEnabled(toSet));

if (component instanceof Container) {
for (Component child : ((Container) component).getComponents()) {
Expand All @@ -325,57 +321,28 @@ else if (disabledComponents.contains(component)) {
}
}

// public static void setMainMenuEnabled(JPanel mainMenuView, boolean toSet) {
// // If disabling, clear list before we start adding to list
// if (!toSet)
// disabledComponents.clear();
// for (Component component : mainMenuView.getComponents()) {
// // If disabling, add the previously disabled to this list
// if (!toSet) {
// if (!component.isEnabled())
// disabledComponents.add(component);
// }
// // Else if enabling, if the component was in the list, don't enable it
// else if (disabledComponents.contains(component)) {
// continue;
// }
// SwingUtilities.invokeLater(() -> {
// component.setEnabled(toSet);
// });
// }
// }

public static File downloadFile(String urlString, String frguiHomeDir, MainMenu mainMenuInstance) throws IOException {
JProgressBar logProgressBar = mainMenuInstance.getLogProgressBar();


public static File downloadFileWithProgress(String urlString, String frguiHomeDir, JProgressBar logProgressBar) throws IOException {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) (url.openConnection());

// For github actions downloads (for FR beta switch)
byte[] decoded = Base64.getDecoder().decode("Z2hwX1YySDBXOThEa3BZUWNaSkxsYUtrOTJocThYMGZCaTBsa1dTMg==");
String auth = "FutureRestore-GUI" + ":" + new String(decoded);
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
String authHeaderValue = "Basic " + new String(encodedAuth);
con.setRequestProperty("Authorization", authHeaderValue);
// For github actions downloads (for FR beta switch), we need to be logged in
githubAuthorizeWithAccount(con);

long completeFileSize = con.getContentLength();

String responseCode = String.valueOf(con.getResponseCode());
if (!responseCode.startsWith("3") && !responseCode.startsWith("2")) {
return null;
}
// If response does not start with 3 or 2, return
if (!(responseCode.startsWith("3") || responseCode.startsWith("2"))) return null;

String contentDisposition = con.getHeaderField("content-disposition");
Pattern filenamePattern = Pattern.compile("(?<=filename=).*?(?=;|$)");
Matcher filenameMatcher = filenamePattern.matcher(contentDisposition);
// Get first result
String filename = "futurerestore-download";
if (filenameMatcher.find()) {
if (filenameMatcher.find())
filename = filenameMatcher.group(0);
}

File downloadLocation = new File(frguiHomeDir + filename);
File downloadLocation = new File(frguiHomeDir + "/" + filename);

BufferedInputStream in = new BufferedInputStream(con.getInputStream());
FileOutputStream fos = new FileOutputStream(downloadLocation);
Expand All @@ -387,10 +354,10 @@ public static File downloadFile(String urlString, String frguiHomeDir, MainMenu
while ((x = in.read(data, 0, 1024)) >= 0) {
downloadedFileSize += x;

// calculate progress
// Calculate progress
final int currentProgress = (int) ((((double) downloadedFileSize) / ((double) completeFileSize)) * 100000d);

// update progress bar
// Update progress bar
SwingUtilities.invokeLater(() -> {
logProgressBar.setMaximum(100000);
logProgressBar.setValue(currentProgress);
Expand All @@ -403,4 +370,12 @@ public static File downloadFile(String urlString, String frguiHomeDir, MainMenu

return downloadLocation;
}

static void githubAuthorizeWithAccount(HttpURLConnection con) {
byte[] decoded = Base64.getDecoder().decode("Z2hwX1YySDBXOThEa3BZUWNaSkxsYUtrOTJocThYMGZCaTBsa1dTMg==");
String auth = "FutureRestore-GUI" + ":" + new String(decoded);
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
String authHeaderValue = "Basic " + new String(encodedAuth);
con.setRequestProperty("Authorization", authHeaderValue);
}
}
26 changes: 12 additions & 14 deletions src/main/java/FutureRestoreWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FutureRestoreWorker {
private static String logPath;
private static boolean hasRecoveryRestarted = false;

public static void runFutureRestore(String futureRestoreFilePath, ArrayList<String> allArgs, JPanel mainMenuView, JTextArea logTextArea, JProgressBar logProgressBar, JTextField currentTaskTextField, JButton startFutureRestoreButton, JButton stopFutureRestoreButton) throws IOException, InterruptedException, TimeoutException {
public static void runFutureRestore(String futureRestoreFilePath, ArrayList<String> allArgs, JPanel mainMenuView, JTextArea logTextArea, JProgressBar logProgressBar, JTextField currentTaskTextField, JButton startFutureRestoreButton, JButton stopFutureRestoreButton) throws IOException {
ArrayList<String> argsAndFR = (ArrayList<String>) allArgs.clone();
argsAndFR.add(0, futureRestoreFilePath);
allArgsArray = Arrays.copyOf(argsAndFR.toArray(), argsAndFR.toArray().length, String[].class);
Expand All @@ -47,7 +47,7 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
// Read Process Stream Output
BufferedReader reader = new BufferedReader(new InputStreamReader(futureRestoreProcess.getInputStream()));

//Log automatically
// Log automatically
File frGuiLogsDirectory = new File(homeDirectory + "/FutureRestoreGUI/logs");
if (!frGuiLogsDirectory.exists())
frGuiLogsDirectory.mkdir();
Expand All @@ -64,7 +64,7 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri

final Pattern progressBarPattern = Pattern.compile("\u001B\\[A\u001B\\[J([0-9]{3})");
final HashMap<String, String> parseableMessages = new HashMap<>() {{
//Normal status messages during restore
// Normal status messages during restore
put("[DOWN] downloading file", "Downloading firmwares.json...");
put("downloading SEP", "Downloading SEP...");
put("downloading SE firmware", "Downloading SE firmware...");
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
put("Connecting to ASR", "Connecting to ASR...");
// put("waiting for message", "Waiting for message from FDR...");

//Special messages
// Special messages
put("Status: Restore Finished", "Restore Finished!");
put("what=", null);
put("code=", null);
Expand All @@ -119,20 +119,20 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
else {
if (futureRestorePossibleMatch.equals("code=")) {
String code = line.replaceFirst("code=", "");
//Parse error codes
// Parse error codes
switch (code) {
//Unable to enter recovery mode
// Unable to enter recovery mode
case "9043985": {
if (!hasRecoveryRestarted) {
hasRecoveryRestarted = true;
//Ensure current process is killed
// Ensure current process is killed
if (FutureRestoreWorker.futureRestoreProcess != null && FutureRestoreWorker.futureRestoreProcess.isAlive())
futureRestoreProcess.destroy();
//Restart
// Restart
new Thread(() -> {
try {
runFutureRestore(futureRestoreFilePath, allArgs, mainMenuView, logTextArea, logProgressBar, currentTaskTextField, startFutureRestoreButton, stopFutureRestoreButton);
} catch (IOException | InterruptedException | TimeoutException e) {
} catch (IOException e) {
System.out.println("Unable to rerun FutureRestore.");
e.printStackTrace();
}
Expand All @@ -141,7 +141,7 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
}
break;
}
//iBEC Error
// iBEC Error
case "64684049": {
Object[] choices = {"Open link", "Ok"};

Expand Down Expand Up @@ -212,7 +212,7 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
if (line.contains("[A")) {
Matcher progressBarMatcher = progressBarPattern.matcher(line);
if (progressBarMatcher.find()) {
//Set progress bar to parsed value
// Set progress bar to parsed value
logProgressBar.setValue(Integer.parseInt(progressBarMatcher.group(1)));
}
} else {
Expand All @@ -222,8 +222,6 @@ public static void runFutureRestore(String futureRestoreFilePath, ArrayList<Stri
}
}


System.out.println("Done reading, closing reader");
reader.close();
writer.close();

Expand All @@ -248,7 +246,7 @@ public static void uploadLogsIfNecessary() throws IOException {
}

if (MainMenu.properties.getProperty("upload_logs").equals("true")) {
//Make all args into a String
// Make all args into a String
StringBuilder builder = new StringBuilder();
for (String value : allArgsArray) {
builder.append(value).append(" ");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/HTMLPresets.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public class HTMLPresets {
static String css = "" +
static final String css = "" +
"@font-face {" +
" font-family: octicons-anchor;" +
" src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQH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njLrEaEh9GmDdDGgL3B4JsrRPDU2hTOiMSuJUIdKQQayiAth69r6akSSFqIJuA19TrzCIaY8sIoxyrNIrL//pw7A2iMygkX5vDj+G+kuoLdX4GlGK/8Lnlz6/h9MpmoO9rafrz7ILXEHHaAx95s9lsI7AHNMBWEZHULnfAXwG9/ZqdzLI08iuwRloXE8kfhXYAvE23+23DU3t626rbs8/8adv+9DWknsHp3E17oCf+Z48rvEQNZ78paYM38qfk3v/u3l3u3GXN2Dmvmvpf1Srwk3pB/VSsp512bA/GG5i2WJ7wu430yQ5K3nFGiOqgtmSB5pJVSizwaacmUZzZhXLlZTq8qGGFY2YcSkqbth6aW1tRmlaCFs2016m5qn36SbJrqosG4uMV4aP2PHBmB3tjtmgN2izkGQyLWprekbIntJFing32a5rKWCN/SdSoga45EJykyQ7asZvHQ8PTm6cslIpwyeyjbVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');" +
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
public class Main {
public static void main(String[] args) {
MainMenu.futureRestoreGUIVersion = "1.95";
MainMenu.futureRestoreGUIVersion = "1.96";
MainMenu.main();
/*
|
— + —
|
"Too bad nobody used the RCE to pull me out"
|
— + —
|
"HAPPY BIRTHDAY ME :)"
*/
Expand Down
Loading

0 comments on commit 94bb0c0

Please sign in to comment.