Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Added version checking and fixed a server shutdown issue
Browse files Browse the repository at this point in the history
Added version checking to ensure a user is on the most current version of sync,
Fixed issue where closing sync after starting a server would keep the program running.
Small changes to documentation.
  • Loading branch information
ajchili committed Jul 3, 2017
1 parent 6a10206 commit ee0c1e6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
22 changes: 14 additions & 8 deletions sync/src/com/kirinpatel/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.kirinpatel.net.Server;
import com.kirinpatel.util.Debug;
import com.kirinpatel.util.UIMessage;
import com.kirinpatel.util.VersionChecker;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -70,17 +71,22 @@ public Main() {
* @param args Command line arguments
*/
public static void main(String[] args) {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
if (VersionChecker.isUpdated()) {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {

}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
main = new Main();
} else {
Debug.Log("Outdated version of sync! Please update!", 2);
new UIMessage("Outdated version of sync!", "You have an outdated version of sync, please update sync!", 1);
}
main = new Main();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sync/src/com/kirinpatel/net/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public Server() {
new Thread(() -> {
try {
Thread.sleep(5000);
PortValidator.isAvailable(8000);
PortValidator.isAvailable(8080);
if(isRunning) PortValidator.isAvailable(8000);
if(isRunning) PortValidator.isAvailable(8080);
} catch(InterruptedException e) {
e.printStackTrace();
}
Expand Down
1 change: 1 addition & 0 deletions sync/src/com/kirinpatel/util/PortValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void isAvailable(int port) {
Debug.Log("Error testing connection on port (" + port + ").", 5);
if (port == 8000) new UIMessage("A port is not forwarded!", "Clients will be unable to connect to your sync server! Please open port " + port + ".", 1);
else new UIMessage("A port is not forwarded!", "You will be unable to use offline media! Please open port " + port + " to use offline media.", 1);
Server.stop();
} finally {
if (s != null) {
try {
Expand Down
51 changes: 51 additions & 0 deletions sync/src/com/kirinpatel/util/VersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.kirinpatel.util;

import jdk.nashorn.api.scripting.URLReader;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

public class VersionChecker {

private final static int VERSION = 1;
private final static int BUILD = 3;
private final static int REVISION = 1;

public static boolean isUpdated() {
try {
Scanner s = new Scanner(new URLReader(new URL("https://github.com/ajchili/sync/releases")));
String version = "";
while (s.hasNext()) {
String line = s.nextLine();
if (line.contains("tag-reference")) {
s.nextLine();
version = s.nextLine();
version = version.substring(version.indexOf("tree/") + 5, version.indexOf("tree/") + 10);
break;
}
}

for (int i = 0; i < 5; i += 2) {
int parsedInt = Integer.parseInt(version.substring(i, i + 1));
switch(i) {
case 0:
if (parsedInt != VERSION) return false;
break;
case 2:
if (parsedInt != BUILD) return false;
break;
case 4:
if (parsedInt != REVISION) return false;
break;
default:
break;
}
}
} catch(MalformedURLException e) {
e.printStackTrace();
}

return true;
}
}
11 changes: 11 additions & 0 deletions sync/src/com/kirinpatel/vlc/MediaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

/**
* Modified JPanel that will play media for the sync application.
*/
public class MediaPlayer extends JPanel {

private final int WIDTH;
Expand All @@ -40,6 +43,11 @@ public class MediaPlayer extends JPanel {
private boolean isScrubbing = false;
private boolean isFile = false;

/**
* Constructor that will return a MediaPlayer.
*
* @param playbackPanel Returns MediaPanel
*/
public MediaPlayer(PlaybackPanel playbackPanel) {
new NativeDiscovery().discover();
Debug.Log("Creating MediaPlayer...", 6);
Expand All @@ -65,6 +73,9 @@ protected RenderCallback onGetRenderCallback() {
Debug.Log("MediaPlayer created.", 6);
}

/**
* Initialize media controls or reset them after media is changed.
*/
private void initControls() {
Debug.Log("Initializing media player controls...", 3);
if (playbackPanel.type == 0 && playbackPanel.mediaPosition.getMaximum() != 1000) {
Expand Down

0 comments on commit ee0c1e6

Please sign in to comment.