diff --git a/sigIRCv2.jar b/sigIRCv2.jar index 71ca907..f942a52 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/UpdateEvent.java b/src/sig/UpdateEvent.java index d4d34c4..8dac57a 100644 --- a/src/sig/UpdateEvent.java +++ b/src/sig/UpdateEvent.java @@ -15,7 +15,7 @@ public class UpdateEvent implements ActionListener{ final static int MSGTIMER = 300; final static int AUTOSAVETIMER = 600; int last_authentication_msg = MSGTIMER; - int last_autosave = AUTOSAVETIMER; + int last_autosave = AUTOSAVETIMER; long lasttime = System.currentTimeMillis(); int avgfps = 30; int counter = 0; @@ -38,6 +38,7 @@ public class UpdateEvent implements ActionListener{ public void run() { JSONObject data = GetSubEmoteJson(); sigIRC.downloadSubEmotes(data); + sigIRC.subEmotesCompleted=true; } }; downloadThread.start(); diff --git a/src/sig/modules/ChatLogModule.java b/src/sig/modules/ChatLogModule.java index 4c90db5..d48c88a 100644 --- a/src/sig/modules/ChatLogModule.java +++ b/src/sig/modules/ChatLogModule.java @@ -50,9 +50,9 @@ public class ChatLogModule extends Module{ public void run() { super.run(); - if (delay>0) { + if (delay>0 && sigIRC.subEmotesCompleted) { delay--; - } else + } else if (!initialized) { Initialize(); diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java index ace920e..32b2eb5 100644 --- a/src/sig/sigIRC.java +++ b/src/sig/sigIRC.java @@ -19,6 +19,7 @@ import sig.modules.TwitchModule; import sig.modules.ChatLog.ChatLogMessage; import sig.modules.ChatLog.ChatLogTwitchEmote; import sig.utils.FileUtils; +import sig.utils.GithubUtils; import sig.utils.TextUtils; import java.awt.Color; @@ -124,11 +125,13 @@ public class sigIRC{ public final static String SUBEMOTELISTFILE = "sigIRC/subemotes.json"; public static long channel_id = -1; public static int lastSubEmoteUpdate = -1; + public static boolean autoUpdateProgram = true; public static int subchannelCount = 0; public static HashMap subchannelIds = new HashMap(); public static boolean downloadedSubEmotes=false; + public static boolean subEmotesCompleted=false; static int lastWindowX = 0; static int lastWindowY = 0; @@ -181,6 +184,7 @@ public class sigIRC{ chatlogmodule_height = config.getInteger("CHATLOG_module_height",312); chatlogMessageHistory = config.getInteger("CHATLOG_module_MessageHistory",50); hardwareAcceleration = config.getBoolean("hardware_acceleration",true); + autoUpdateProgram = config.getBoolean("Automatically_Update_Program", true); lastSubEmoteUpdate = config.getInteger("lastSubEmote_APIUpdate",Calendar.getInstance().get(Calendar.DAY_OF_YEAR)); manager.setClientId("o4c2x0l3e82scgar4hpxg6m5dfjbem"); //System.out.println(manager.auth().hasAccessToken()); @@ -229,8 +233,11 @@ public class sigIRC{ manager = new FileManager("sigIRC/logs/",true); manager.verifyAndFetchFileFromServer(); manager = new FileManager("sigIRC/sounds/",true); manager.verifyAndFetchFileFromServer(); //manager = new FileManager("sigIRC/sounds/Glaceon_cry.wav"); manager.verifyAndFetchFileFromServer(); - manager = new FileManager("sigIRC/follower_sounds/Glaceon_cry.wav"); manager.verifyAndFetchFileFromServer(); - manager = new FileManager("sigIRC/follower_sounds/README.txt"); manager.verifyAndFetchFileFromServer(); + File follower_sounds_folder = new File(BASEDIR+"sigIRC/follower_sounds"); + if (!follower_sounds_folder.exists()) { + manager = new FileManager("sigIRC/follower_sounds/Glaceon_cry.wav"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/follower_sounds/README.txt"); manager.verifyAndFetchFileFromServer(); + } manager = new FileManager("sigIRC/record"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("sigIRC/glaceon_follower.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("sigIRC/sigIRCicon.png"); manager.verifyAndFetchFileFromServer(); @@ -253,16 +260,24 @@ public class sigIRC{ } private static void DownloadProgramUpdate() { - File updatedir = new File(sigIRC.BASEDIR+"sigIRC/updates/"); - updatedir.mkdirs(); - File programFile = new File(sigIRC.BASEDIR+"sigIRC/updates/sigIRCv2.jar"); - try { - if (programFile.exists()) { - programFile.delete(); + //System.out.println("Last commit size was "+GithubUtils.getSizeOfFileFromLatestGithubCommit("sigIRCv2.jar")+"B"); + if (autoUpdateProgram) { + File updatedir = new File(sigIRC.BASEDIR+"sigIRC/updates/"); + updatedir.mkdirs(); + File programFile = new File(sigIRC.BASEDIR+"sigIRC/updates/sigIRCv2.jar"); + System.out.println("File size is "+programFile.length()); + long fileSize = GithubUtils.getSizeOfFileFromLatestGithubCommit("sigIRCv2.jar"); + System.out.println("File size on Github is "+fileSize); + if ((programFile.exists() && fileSize!=programFile.length()) || !programFile.exists()) { + try { + if (programFile.exists()) { + programFile.delete(); + } + org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile); + } catch (IOException e) { + e.printStackTrace(); + } } - org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile); - } catch (IOException e) { - e.printStackTrace(); } } diff --git a/src/sig/utils/FileUtils.java b/src/sig/utils/FileUtils.java index f48bb15..95e06b8 100644 --- a/src/sig/utils/FileUtils.java +++ b/src/sig/utils/FileUtils.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -186,6 +187,10 @@ public class FileUtils { public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException { return readJsonFromUrl(url,null,false); } + + public static JSONArray readJsonArrayFromUrl(String url) throws IOException, JSONException { + return readJsonArrayFromUrl(url,null,false); + } public static JSONObject readJsonFromFile(String file) throws IOException, JSONException { InputStream is = new FileInputStream(new File(file)); @@ -214,6 +219,21 @@ public class FileUtils { is.close(); } } + + public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { + InputStream is = new URL(url).openStream(); + try { + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + String jsonText = readAll(rd); + if (writeToFile) { + writetoFile(new String[]{jsonText},file); + } + JSONArray json = new JSONArray(jsonText); + return json; + } finally { + is.close(); + } + } public static void logToFile(String message, String filename) { File file = new File(filename); diff --git a/src/sig/utils/GithubUtils.java b/src/sig/utils/GithubUtils.java new file mode 100644 index 0000000..127d081 --- /dev/null +++ b/src/sig/utils/GithubUtils.java @@ -0,0 +1,35 @@ +package sig.utils; + +import java.io.IOException; +import java.util.Arrays; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class GithubUtils { + public static int getSizeOfFileFromLatestGithubCommit(String filename) { + try { + JSONObject data = FileUtils.readJsonFromUrl("https://api.github.com/repos/sigonasr2/sigIRCv2"); + String url = data.getString("commits_url").replace("{/sha}", ""); + JSONArray data_array = FileUtils.readJsonArrayFromUrl(url); + JSONObject dat = data_array.getJSONObject(0); + JSONObject datapoint1 = dat.getJSONObject("commit"); + datapoint1 = datapoint1.getJSONObject("tree"); + url = datapoint1.getString("url"); + data = FileUtils.readJsonFromUrl(url); + data_array = data.getJSONArray("tree"); + for (int i=0;i