M src/main/java/com/civfanatics/storyarchiver/StoryArchiver.java +11 -1
@@ 3,6 3,7 @@ package com.civfanatics.storyarchiver;
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 @@ public class StoryArchiver {
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) {
M src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressConfig.java +8 -2
@@ 14,15 14,17 @@ public class WordpressConfig {
private final String pageFolder;
private final String pageName;
private final Stack<DownloadResource> 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 class WordpressConfig {
public String getPageFileName() {
return pageName;
}
+
+ public int getDepth() {
+ return depth;
+ }
public void addToStack(WordpressPage page) {
stackRef.add(page);
@@ 54,6 60,6 @@ public class WordpressConfig {
}
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);
}
}
M src/main/java/com/civfanatics/storyarchiver/wordpress/WordpressPage.java +7 -3
@@ 89,10 89,14 @@ public class WordpressPage implements Do
//TODO: Shouldn't we validate the response code is not >= 400?
Utils.downloadFromHttpConnection(conn, wpConfig.getResourcesFolder() + "/css" + cssCount + ".css");
- fw.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\""
+ fw.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\"");
//TODO: Dynamically link up based on depth
- + "../../resources/"
- + "css" + cssCount + ".css\" />\n");
+ String dots = "";
+ for (int i = 0; i < wpConfig.getDepth(); i++) {
+ dots = dots + "../";
+ }
+ fw.write(dots
+ + "resources/css" + cssCount + ".css\" />\n");
cssCount++;
}