# HG changeset patch # User Andrew # Date 1728526904 14400 # Wed Oct 09 22:21:44 2024 -0400 # Node ID e8bd6ad43aeaf4adb68b9a94e8abce274937e009 # Parent b1bdd5289fb72b17bcb57555bde192db9c657a83 Fix relative pathing to CSS files. Implement the progress bar for Wordpress. diff --git a/src/main/java/com/civfanatics/storyarchiver/StoryArchiver.java b/src/main/java/com/civfanatics/storyarchiver/StoryArchiver.java --- a/src/main/java/com/civfanatics/storyarchiver/StoryArchiver.java +++ b/src/main/java/com/civfanatics/storyarchiver/StoryArchiver.java @@ -3,6 +3,7 @@ import com.civfanatics.storyarchiver.DBObjects.Database; import com.civfanatics.storyarchiver.download.DownloadResource; import com.civfanatics.storyarchiver.download.DownloadRunnable; +import com.civfanatics.storyarchiver.metrics.Progress; import com.civfanatics.storyarchiver.metrics.ThreadStatus; import com.civfanatics.storyarchiver.wordpress.WordpressConfig; import com.civfanatics.storyarchiver.wordpress.WordpressPage; @@ -155,19 +156,28 @@ Files.createDirectories(Paths.get(resourcesFolder)); WordpressConfig wpConfig = new WordpressConfig(Options.destinationFolder, resourcesFolder, - pageFolder, pageFolder + "index.html", stack); + pageFolder, pageFolder + "index.html", stack, 2); wpConfig.setAsRoot(); WordpressPage cfc = new WordpressPage("https://www.civfanatics.com", wpConfig); stack.add(cfc); + Progress.setMaxProgress(1); + int expectedStackSize = 1; //Runnable it. Use a Stack to track what remains to be downloaded. while (!stack.empty()) { logger.info("Items remaining: " + stack.size()); + if (stack.size() != expectedStackSize) { + Progress.setMaxProgress(Progress.getMaxProgress() + (stack.size() - expectedStackSize)); + expectedStackSize = stack.size(); + } DownloadResource resource = stack.pop(); DownloadRunnable runnable = new DownloadRunnable("", resource); runnable.run(); + + Progress.incrementProgress(); + expectedStackSize--; } } catch(Exception ex) { diff --git a/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressConfig.java b/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressConfig.java --- a/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressConfig.java +++ b/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressConfig.java @@ -14,15 +14,17 @@ private final String pageFolder; private final String pageName; private final Stack stackRef; + private int depth; //Only pages marked as root will search for menu links private boolean isRoot = false; - public WordpressConfig(String rootFolder, String resourcesFolder, String pageFolder, String pageName, Stack stackRef) { + public WordpressConfig(String rootFolder, String resourcesFolder, String pageFolder, String pageName, Stack stackRef, int depth) { this.rootFolder = rootFolder; this.resourcesFolder = resourcesFolder; this.pageFolder = pageFolder; this.pageName = pageName; this.stackRef = stackRef; + this.depth = depth; } public String getRootFolder() { @@ -40,6 +42,10 @@ public String getPageFileName() { return pageName; } + + public int getDepth() { + return depth; + } public void addToStack(WordpressPage page) { stackRef.add(page); @@ -54,6 +60,6 @@ } public WordpressConfig cloneToChild(String childFolder, String childName) { - return new WordpressConfig(rootFolder, resourcesFolder, childFolder, childName, stackRef); + return new WordpressConfig(rootFolder, resourcesFolder, childFolder, childName, stackRef, depth + 1); } } diff --git a/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressPage.java b/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressPage.java --- a/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressPage.java +++ b/src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressPage.java @@ -89,10 +89,14 @@ //TODO: Shouldn't we validate the response code is not >= 400? Utils.downloadFromHttpConnection(conn, wpConfig.getResourcesFolder() + "/css" + cssCount + ".css"); - fw.write(" \n"); + String dots = ""; + for (int i = 0; i < wpConfig.getDepth(); i++) { + dots = dots + "../"; + } + fw.write(dots + + "resources/css" + cssCount + ".css\" />\n"); cssCount++; }