private static void tryResUrls(Picture picture) { String hi_res = ""; String url = picture.media_url.toString(); for (String ending : Main.endings) { try { hi_res = url.replace(url.substring(url.lastIndexOf("_"), url.lastIndexOf(".")), ending); URL hi_url = new URL(hi_res); File hi_name = Helper.extractMediaFileNameFromURL(hi_url); if (hi_name.equals(picture.media_name)) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; break; } else { boolean success = Helper.downloadFileFromURLToFileInTemp(hi_url, hi_name); if (success) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; Helper.moveTempImageToStore(hi_name, new File(Main.blogdir, picture.md5_id)); break; } } } catch (MalformedURLException ex) { Main.error(String.format("Attempted hi res url %s is a malformed URL.", hi_res)); } } }
/** * Set the mappings between staged files and respective blobs as well as the files this commit * tracks. */ public void setBlobs() { Commit parent = null; TreeSet<String> parentTracked = null; List<String> stagedFiles = Utils.plainFilenamesIn(Main.getStagedDir()); List<String> removedFiles = Utils.plainFilenamesIn(Main.getRemovedDir()); if (stagedFiles.size() == 0 && removedFiles.size() == 0 && _parent != null) { Main.error("No changes added to the commit."); } if (_parent != null) { parent = Utils.loadObj(this, Main.getCommitDir() + _parent); parentTracked = parent._tracked; for (String tracked : parentTracked) { if (!stagedFiles.contains(tracked) && !removedFiles.contains(tracked)) { _blobs.put(tracked, parent._blobs.get(tracked)); _tracked.add(tracked); } } } for (String file : stagedFiles) { File f = new File(Main.getStagedDir() + file); byte[] blob = Utils.readContents(f); String blobHash = Utils.sha1("blobs", blob); addBlob(blob, file, blobHash); f.delete(); } for (String remove : removedFiles) { File rm = new File(Main.getRemovedDir() + remove); rm.delete(); } }
public static void load() { Main.status("Loading databases."); File file = new File(blogdir, "picpic.db"); List<Object> objects = Helper.loadObjectFromFile(file); if (objects == null || objects.size() != 1) { Main.error("Unable to load database files so creating new database."); reset(); } else { Main.post_post_hash = (HashMap<Post, Post>) objects.get(0); Main.pic_pic_hash.clear(); Main.pic_post_hash.clear(); Main.dup_post_list.clear(); Main.setupPosts(); } Main.status("Done loading databases."); }