diff --git a/src/main/java/se/lantz/gui/ScreenshotsPanel.java b/src/main/java/se/lantz/gui/ScreenshotsPanel.java index 3182b5d..db2a38f 100644 --- a/src/main/java/se/lantz/gui/ScreenshotsPanel.java +++ b/src/main/java/se/lantz/gui/ScreenshotsPanel.java @@ -53,6 +53,7 @@ public class ScreenshotsPanel extends JPanel private String currentCoverFile = ""; private String currentScreen1File = ""; private String currentScreen2File = ""; + private BufferedImage currentCoverImage = null; private ImageIcon missingSceenshotIcon = null; private ImageIcon missingCoverIcon = null; @@ -124,15 +125,29 @@ public class ScreenshotsPanel extends JPanel private void reloadScreens() { - String modelCoverFile = model.getCoverFile(); - if (modelCoverFile.isEmpty()) + BufferedImage coverImage = model.getCoverImage(); + if (coverImage != null) { - getCoverImageLabel().setIcon(getMissingCoverImageIcon()); + if (!coverImage.equals(currentCoverImage)) + { + logger.debug("SETTING NEW COVER IMAGE"); + Image newImage = coverImage.getScaledInstance(130, 200, Image.SCALE_DEFAULT); + getCoverImageLabel().setIcon(new ImageIcon(newImage)); + currentCoverImage = coverImage; + } } - else if (!modelCoverFile.equals(currentCoverFile)) + else { - loadCover(modelCoverFile); - currentCoverFile = modelCoverFile; + String modelCoverFile = model.getCoverFile(); + if (modelCoverFile.isEmpty()) + { + getCoverImageLabel().setIcon(getMissingCoverImageIcon()); + } + else if (!modelCoverFile.equals(currentCoverFile)) + { + loadCover(modelCoverFile); + currentCoverFile = modelCoverFile; + } } String modelScreen1File = model.getScreens1File(); if (modelScreen1File.isEmpty()) diff --git a/src/main/java/se/lantz/gui/VersionDownloadDialog.java b/src/main/java/se/lantz/gui/VersionDownloadDialog.java index 15d80cf..7699e30 100644 --- a/src/main/java/se/lantz/gui/VersionDownloadDialog.java +++ b/src/main/java/se/lantz/gui/VersionDownloadDialog.java @@ -12,6 +12,8 @@ public class VersionDownloadDialog extends BaseDialog setTitle("New version available"); addContent(getVersionDownloadPanel()); getOkButton().setText("Exit"); + getCancelButton().setText("Continue"); + this.setResizable(false); } private VersionDownloadPanel getVersionDownloadPanel() { diff --git a/src/main/java/se/lantz/gui/VersionDownloadPanel.java b/src/main/java/se/lantz/gui/VersionDownloadPanel.java index fa3479f..761a4a6 100644 --- a/src/main/java/se/lantz/gui/VersionDownloadPanel.java +++ b/src/main/java/se/lantz/gui/VersionDownloadPanel.java @@ -40,7 +40,7 @@ public class VersionDownloadPanel extends JPanel String downloadUrl = VersionChecker.getDownloadUrl(); String info = "There is a new version of PCU Game Manager available: " + VersionChecker.getLatestVersion() + "

" + "Go to " + downloadUrl + - " and download PCUGameManager.exe.
" + + " and download PCUGameManager.exe.

" + "Exit PCU Game Manager and replace the existing PCUGameManager.exe with the downloaded file to upgrade."; editorPane = new JEditorPane("text/html", info); diff --git a/src/main/java/se/lantz/model/MainViewModel.java b/src/main/java/se/lantz/model/MainViewModel.java index 9f3ce56..8a58fc5 100644 --- a/src/main/java/se/lantz/model/MainViewModel.java +++ b/src/main/java/se/lantz/model/MainViewModel.java @@ -457,6 +457,10 @@ public class MainViewModel extends AbstractModel infoModel.setGenre(genre); } } + if (fields.isCover()) + { + infoModel.setCoverImage(scraper.scrapeCover()); + } //TODO: cover, screenshots } } diff --git a/src/main/java/se/lantz/util/MobyGamesScraper.java b/src/main/java/se/lantz/util/MobyGamesScraper.java index a2279ec..ac16717 100644 --- a/src/main/java/se/lantz/util/MobyGamesScraper.java +++ b/src/main/java/se/lantz/util/MobyGamesScraper.java @@ -202,7 +202,7 @@ public class MobyGamesScraper return value; } - private void scrapeCover() + public BufferedImage scrapeCover() { Document doc; try @@ -214,29 +214,53 @@ public class MobyGamesScraper if (coverElements.first() != null) { Element coverElement = coverElements.first(); - String absoluteUrl = coverElement.absUrl("src"); - String srcValue = coverElement.attr("src"); - - URL url = new URL(absoluteUrl); - BufferedImage c = ImageIO.read(url); - ImageIcon image = new ImageIcon(c); - - saveImage(absoluteUrl, game + ".jpg"); - - //TODO: big cover: - String bigCoverUrl = coverElement.parent().attr("href"); - scrapeBigCover(bigCoverUrl); - System.out.println("Cover art: " + absoluteUrl); + return scrapeBigCover(bigCoverUrl); } } catch (IOException e) { - e.printStackTrace(); + ExceptionHandler.handleException(e, "Could not scrape cover"); } + return null; } + + +// private void scrapeCoverTest() +// { +// Document doc; +// try +// { +// Connection.Response result = Jsoup.connect(mobyGamesGameUrl).method(Connection.Method.GET).execute(); +// doc = result.parse(); +// //Fetch the right element +// Elements coverElements = doc.select(coverCssQuery); +// if (coverElements.first() != null) +// { +// Element coverElement = coverElements.first(); +// String absoluteUrl = coverElement.absUrl("src"); +// String srcValue = coverElement.attr("src"); +// +// URL url = new URL(absoluteUrl); +// BufferedImage c = ImageIO.read(url); +// ImageIcon image = new ImageIcon(c); +// +// saveImage(absoluteUrl, game + ".jpg"); +// +// //TODO: big cover: +// +// String bigCoverUrl = coverElement.parent().attr("href"); +// return scrapeBigCover(bigCoverUrl); +// System.out.println("Cover art: " + absoluteUrl); +// } +// } +// catch (IOException e) +// { +// e.printStackTrace(); +// } +// } - private void scrapeBigCover(String url) + private BufferedImage scrapeBigCover(String url) { String cssQuery = "#main > div > div:eq(1) > center > img"; //*[@id="main"]/div/div[2]/center/img Document doc; @@ -252,18 +276,14 @@ public class MobyGamesScraper String absoluteUrl = coverElement.absUrl("src"); URL imageUrl = new URL(absoluteUrl); - BufferedImage c = ImageIO.read(imageUrl); - ImageIcon image = new ImageIcon(c); - - saveImage(absoluteUrl, game + "-large.jpg"); - - System.out.println("Big Cover art: " + absoluteUrl); + return ImageIO.read(imageUrl); } } catch (IOException e) { - e.printStackTrace(); + ExceptionHandler.handleException(e, "Could not scrape cover"); } + return null; } public static void saveImage(String imageUrl, String destinationFile) throws IOException diff --git a/src/main/java/se/lantz/util/VersionChecker.java b/src/main/java/se/lantz/util/VersionChecker.java index a8705fb..ba8cab7 100644 --- a/src/main/java/se/lantz/util/VersionChecker.java +++ b/src/main/java/se/lantz/util/VersionChecker.java @@ -40,9 +40,7 @@ public class VersionChecker reader.setLenient(true); JsonElement root = new JsonParser().parse(reader); latestVersion = root.getAsJsonObject().get("tag_name").getAsString(); - System.out.println("tagName = " + latestVersion); downloadUrl = root.getAsJsonObject().get("html_url").getAsString(); - System.out.println("html url = " + downloadUrl); } catch (IOException ex) {