From c14e53775591cb4d75b486d21f4849552d5c7c8c Mon Sep 17 00:00:00 2001 From: JJ Date: Mon, 26 Dec 2022 21:38:32 -0800 Subject: Remove garbage serialization/logging code --- src/main/ui/BrowserApp.java | 110 -------------------------------------------- 1 file changed, 110 deletions(-) (limited to 'src/main/ui/BrowserApp.java') diff --git a/src/main/ui/BrowserApp.java b/src/main/ui/BrowserApp.java index c4bbf99..520cac8 100644 --- a/src/main/ui/BrowserApp.java +++ b/src/main/ui/BrowserApp.java @@ -4,11 +4,7 @@ import model.html.ElementNode; import model.html.HtmlParser; import model.html.TextNode; import model.html.Node; -import org.json.JSONArray; -import org.json.JSONObject; -import persistance.JsonUtils; -import java.io.File; import java.nio.file.*; import java.util.*; @@ -18,7 +14,6 @@ import java.util.*; public class BrowserApp { private Scanner input; private static final String border = "==============================================="; - private static final String storagePath = "data/apus.cache"; private String pathString; private ArrayList parsed; private ArrayDeque tabs; @@ -30,38 +25,9 @@ public class BrowserApp { println("apus: currently a barebones html/css renderer"); this.input = new Scanner(System.in); this.tabs = new ArrayDeque<>(); - - askToRestoreTabs(); mainLoop(); } - /** - * EFFECTS: Asks the user if they'd like to restore previously closed tabs. - */ - private void askToRestoreTabs() { - if (new File(storagePath).length() > 2) { - println("Would you like to restore your previously closed tabs? (Y/N)"); - String answer; - while (true) { - answer = this.input.next(); - if (answer.equalsIgnoreCase("y")) { - restoreClosedTabs(); - break; - } else if (answer.equalsIgnoreCase("n")) { - JsonUtils.writeToFile(new JSONArray(), storagePath); - println("please provide a path to a file (examples located in data/*):"); - pathString = this.input.next(); - break; - } else { - println("Sorry, I didn't quite get that. Please try again."); - } - } - } else { - println("please provide a path to a file (examples located in data/*):"); - pathString = this.input.next(); - } - } - /** * EFFECTS: Runs the main loop */ @@ -86,23 +52,6 @@ public class BrowserApp { } } - /** - * EFFECTS: restores previous closed tabs from a cache file. - */ - private void restoreClosedTabs() { - try { - JSONArray state = JsonUtils.readFromFile(storagePath); - for (int i = 0; i < state.length(); i++) { - println(state.get(i).getClass().getName()); - tabs.add((String) state.get(i)); - } - pathString = tabs.removeLast(); - } catch (Exception e) { - println("Restoring state from disk failed with " + e.toString()); - System.exit(0); - } - } - /** * EFFECTS: Barebones HTML rendering. Iterates through a list of Nodes and their children and prints any text. */ @@ -135,7 +84,6 @@ public class BrowserApp { pathString = this.tabs.removeFirst(); break; case "quit": - handleQuit(); System.exit(0); break; default: @@ -144,64 +92,6 @@ public class BrowserApp { } } - /** - * Helper function for the quit() case. - * EFFECTS: Asks a user whether they'd like to save their tabs, and exists the program. - */ - private void handleQuit() { - println("Would you like to save your currently opened tabs to disk? (Y/N)"); - String answer; - while (true) { - answer = this.input.next(); - if (answer.equalsIgnoreCase("y")) { - this.tabs.add(pathString); - JsonUtils.writeToFile(new JSONArray(tabs), storagePath); - break; - } else if (answer.equalsIgnoreCase("n")) { - JsonUtils.writeToFile(new JSONArray(), storagePath); - break; - } else { - println("Sorry, I didn't quite get that. Please try again."); - } - } - } - - /** - * EFFECTS: writes the current program configuration to the disk - */ - private void writeToDisk() { - ArrayList> jsonArray = new ArrayList<>(); - for (String p : tabs) { - ArrayList jsonArrayII = new ArrayList<>(); - try { - Path path = Paths.get(pathString); - String file = new String(Files.readAllBytes(path)); - HtmlParser parser = new HtmlParser(); - for (Node n : parser.parseHtml(file)) { - jsonArrayII.add(n.serialize()); - } - } catch (Exception e) { - System.out.printf("Failed to write to disk with %s", e); - } - jsonArray.add(jsonArrayII); - } - JsonUtils.writeToFile(new JSONArray(jsonArray), storagePath); - } - - /** - * EFFECTS: restores program state from a last written to state - */ - private void restoreFromDisk(JSONArray state) { - for (int i = 0; i < state.length(); i++) { - Object tab = state.get(i); - if (tab instanceof JSONArray) { - for (int j = 0; j < ((JSONArray) tab).length(); j++) { - tabs.add(((JSONArray) tab).toString()); - } - } - } - } - private void print(String toPrint) { System.out.print(toPrint); } -- cgit v1.2.3-70-g09d2