Skip to content

Commit

Permalink
Implemented a simple update Notification.
Browse files Browse the repository at this point in the history
  • Loading branch information
LordH3lmchen committed May 29, 2015
1 parent 5a14927 commit fd44545
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 5 deletions.
1 change: 1 addition & 0 deletions TwitchVodLoaderInfo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TwitchVodLoader 0.1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
public class ChannelSyncController implements ChannelSyncControllerInterface {

public static final String FFMPEG_EXE_URL_STR = "http://trabauer.com/downloads/project_ressources/TwitchTools/ffmpeg.exe";
public static final String VERSION_INFO_URL_STR = "http://trabauer.com/downloads/TwitchVodLoaderInfo.txt";
public static final String PROGRAM_DOWNLOAD_URL_STR = "http://trabauer.com/downloads/TwitchVodLoader.jar";
public static final String PROJECT_PAGE_URL_STR = "http://lordh3lmchen.github.io/TwitchDownloader/";
public static final String PROGRAM_VERSION = "TwitchVodLoader 0.1";

private final JFrame mainFrame;
private final SyncChannelMainPanel mainPanel;
Expand All @@ -56,6 +60,8 @@ public class ChannelSyncController implements ChannelSyncControllerInterface {
private ArrayList<TwitchVideoPart> videoParts;




public ChannelSyncController() {
this.twitchVideoInfoList = new TwitchVideoInfoList();

Expand All @@ -82,7 +88,7 @@ public ChannelSyncController() {
if(OsValidator.isWindows()) {
ffmpegExecutable = new File(new File(getJarURI().getPath()).getParent().concat("/ffmpeg.exe"));
if (!ffmpegExecutable.exists()) {
int choice = JOptionPane.showConfirmDialog(mainFrame, "FFMPEG not found! Do you wnat to download it? FFMPEG is required to convert videos", "FFMPEG not found! Download it?", JOptionPane.YES_NO_OPTION);
int choice = JOptionPane.showConfirmDialog(mainFrame, "FFMPEG not found! Do you want to download it? FFMPEG is required to convert videos", "FFMPEG not found! Download it?", JOptionPane.YES_NO_OPTION);
if (choice == 0) { //YES
downloadFFMPEG();
} //else if(choice == 0) { //NO
Expand All @@ -100,6 +106,34 @@ public ChannelSyncController() {
} catch (URISyntaxException e) {
JOptionPane.showMessageDialog(mainPanel, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}

checkForUpdates();


}

private void checkForUpdates() {
URL VersionInfoUrl = null;
try {
VersionInfoUrl= new URL(VERSION_INFO_URL_STR);
InputStream is = VersionInfoUrl.openStream();
Scanner sc = new Scanner(is);
String line = null;
if(sc.hasNextLine()) line = sc.nextLine();
if(! line.equals(PROGRAM_VERSION)) {
System.out.println("Program isn't up to date. ");
int choice = JOptionPane.showConfirmDialog(mainFrame, "Update Available! Download latest Version?", "Update Available!", JOptionPane.YES_NO_OPTION);
if (choice == 0) { //YES
openUrlInBrowser(new URL(PROJECT_PAGE_URL_STR));
} //else if(choice == 0) { //NO
// Nothing right now
//}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Vector;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -182,25 +188,99 @@ private void moveQuality(int oldIndex, int newIndex) {



private class AboutThisProgramDialog extends JDialog {
private class AboutThisProgramDialog extends JDialog implements ActionListener {

private final JLabel visitProjectSiteLbl;
private JButton closeBtn, licenseBtn;

public AboutThisProgramDialog(Frame owner) {
super(owner, "About Twitch Downloader");

GridBagLayout layoutManager = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(layoutManager);

ImageIcon logoIcon = new ImageIcon(TwitchToolsImages.getTwitchDownloadToolImage());
JLabel programNameVersionLabel = new JLabel("TwitchDownloader 0.1", logoIcon, JLabel.CENTER);
JLabel programNameVersionLabel = new JLabel(controller.PROGRAM_VERSION, logoIcon, JLabel.CENTER);
Font origFont = programNameVersionLabel.getFont().deriveFont(Font.BOLD);
programNameVersionLabel.setFont(origFont.deriveFont(30.0F));
programNameVersionLabel.setVerticalTextPosition(JLabel.BOTTOM);
programNameVersionLabel.setHorizontalTextPosition(JLabel.CENTER);
add(programNameVersionLabel);

setVisible(true);
gc.gridx = 0;
gc.gridy = 0;
gc.insets = new Insets(5,5,5,5);
gc.gridwidth = 2;
add(programNameVersionLabel, gc);

JLabel copyrightLbl = new JLabel("Copyright 2014-2015 Florian Trabauer");
gc.gridy++;
add(copyrightLbl, gc);
visitProjectSiteLbl = new JLabel("Visit the TwitchDownloader website");
Font visitProjectSiteFont = visitProjectSiteLbl.getFont();
Map visitProjectSiteFontAttributes = visitProjectSiteFont.getAttributes();
visitProjectSiteFontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
visitProjectSiteLbl.setForeground(Color.BLUE);
visitProjectSiteLbl.setFont(visitProjectSiteFont.deriveFont(visitProjectSiteFontAttributes));
visitProjectSiteLbl.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
try {
controller.openUrlInBrowser(new URL("http://lordh3lmchen.github.io/TwitchDownloader/"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
});
gc.gridy++;
add(visitProjectSiteLbl, gc);
licenseBtn = new JButton("License");
licenseBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
try {
controller.openUrlInBrowser(new URL("http://trabauer.com/downloads/TwitchDownloader_LICENSE.txt"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
});
gc.gridy++;
gc.gridwidth = 1;
add(licenseBtn, gc);
closeBtn = new JButton("Close");
closeBtn.addActionListener(this);
gc.gridx++;
gc.anchor = GridBagConstraints.LINE_END;
add(closeBtn, gc);

pack();

}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==closeBtn) {
this.setVisible(false);
} else if(e.getSource()==licenseBtn) {
this.setVisible(false); //TODO show license instead
}
}
}

// private class licenseDialog extends JDialog { //STUB not used default browser is used instead.
// public licenseDialog(Frame owner) {
// super(owner, "License");
// GridBagLayout layout = new GridBagLayout();
// setLayout(layout);
// GridBagConstraints gc = new GridBagConstraints();
//
//
// }
// }

private File showDestinationDirChooser(String path) {
JFileChooser fileChooser = null;
File file = null;
Expand Down

0 comments on commit fd44545

Please sign in to comment.