Implement Github API file size detection.
This commit is contained in:
parent
254d82d3e2
commit
57932c58a3
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -38,6 +38,7 @@ public class UpdateEvent implements ActionListener{
|
|||||||
public void run() {
|
public void run() {
|
||||||
JSONObject data = GetSubEmoteJson();
|
JSONObject data = GetSubEmoteJson();
|
||||||
sigIRC.downloadSubEmotes(data);
|
sigIRC.downloadSubEmotes(data);
|
||||||
|
sigIRC.subEmotesCompleted=true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
downloadThread.start();
|
downloadThread.start();
|
||||||
|
@ -50,7 +50,7 @@ public class ChatLogModule extends Module{
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
super.run();
|
super.run();
|
||||||
if (delay>0) {
|
if (delay>0 && sigIRC.subEmotesCompleted) {
|
||||||
delay--;
|
delay--;
|
||||||
} else
|
} else
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
|
@ -19,6 +19,7 @@ import sig.modules.TwitchModule;
|
|||||||
import sig.modules.ChatLog.ChatLogMessage;
|
import sig.modules.ChatLog.ChatLogMessage;
|
||||||
import sig.modules.ChatLog.ChatLogTwitchEmote;
|
import sig.modules.ChatLog.ChatLogTwitchEmote;
|
||||||
import sig.utils.FileUtils;
|
import sig.utils.FileUtils;
|
||||||
|
import sig.utils.GithubUtils;
|
||||||
import sig.utils.TextUtils;
|
import sig.utils.TextUtils;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@ -124,11 +125,13 @@ public class sigIRC{
|
|||||||
public final static String SUBEMOTELISTFILE = "sigIRC/subemotes.json";
|
public final static String SUBEMOTELISTFILE = "sigIRC/subemotes.json";
|
||||||
public static long channel_id = -1;
|
public static long channel_id = -1;
|
||||||
public static int lastSubEmoteUpdate = -1;
|
public static int lastSubEmoteUpdate = -1;
|
||||||
|
public static boolean autoUpdateProgram = true;
|
||||||
|
|
||||||
public static int subchannelCount = 0;
|
public static int subchannelCount = 0;
|
||||||
public static HashMap<Long,String> subchannelIds = new HashMap<Long,String>();
|
public static HashMap<Long,String> subchannelIds = new HashMap<Long,String>();
|
||||||
|
|
||||||
public static boolean downloadedSubEmotes=false;
|
public static boolean downloadedSubEmotes=false;
|
||||||
|
public static boolean subEmotesCompleted=false;
|
||||||
|
|
||||||
static int lastWindowX = 0;
|
static int lastWindowX = 0;
|
||||||
static int lastWindowY = 0;
|
static int lastWindowY = 0;
|
||||||
@ -181,6 +184,7 @@ public class sigIRC{
|
|||||||
chatlogmodule_height = config.getInteger("CHATLOG_module_height",312);
|
chatlogmodule_height = config.getInteger("CHATLOG_module_height",312);
|
||||||
chatlogMessageHistory = config.getInteger("CHATLOG_module_MessageHistory",50);
|
chatlogMessageHistory = config.getInteger("CHATLOG_module_MessageHistory",50);
|
||||||
hardwareAcceleration = config.getBoolean("hardware_acceleration",true);
|
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));
|
lastSubEmoteUpdate = config.getInteger("lastSubEmote_APIUpdate",Calendar.getInstance().get(Calendar.DAY_OF_YEAR));
|
||||||
manager.setClientId("o4c2x0l3e82scgar4hpxg6m5dfjbem");
|
manager.setClientId("o4c2x0l3e82scgar4hpxg6m5dfjbem");
|
||||||
//System.out.println(manager.auth().hasAccessToken());
|
//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/logs/",true); manager.verifyAndFetchFileFromServer();
|
||||||
manager = new FileManager("sigIRC/sounds/",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/sounds/Glaceon_cry.wav"); 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/Glaceon_cry.wav"); manager.verifyAndFetchFileFromServer();
|
||||||
manager = new FileManager("sigIRC/follower_sounds/README.txt"); manager.verifyAndFetchFileFromServer();
|
manager = new FileManager("sigIRC/follower_sounds/README.txt"); manager.verifyAndFetchFileFromServer();
|
||||||
|
}
|
||||||
manager = new FileManager("sigIRC/record"); manager.verifyAndFetchFileFromServer();
|
manager = new FileManager("sigIRC/record"); manager.verifyAndFetchFileFromServer();
|
||||||
manager = new FileManager("sigIRC/glaceon_follower.png"); manager.verifyAndFetchFileFromServer();
|
manager = new FileManager("sigIRC/glaceon_follower.png"); manager.verifyAndFetchFileFromServer();
|
||||||
manager = new FileManager("sigIRC/sigIRCicon.png"); manager.verifyAndFetchFileFromServer();
|
manager = new FileManager("sigIRC/sigIRCicon.png"); manager.verifyAndFetchFileFromServer();
|
||||||
@ -253,9 +260,15 @@ public class sigIRC{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void DownloadProgramUpdate() {
|
private static void DownloadProgramUpdate() {
|
||||||
|
//System.out.println("Last commit size was "+GithubUtils.getSizeOfFileFromLatestGithubCommit("sigIRCv2.jar")+"B");
|
||||||
|
if (autoUpdateProgram) {
|
||||||
File updatedir = new File(sigIRC.BASEDIR+"sigIRC/updates/");
|
File updatedir = new File(sigIRC.BASEDIR+"sigIRC/updates/");
|
||||||
updatedir.mkdirs();
|
updatedir.mkdirs();
|
||||||
File programFile = new File(sigIRC.BASEDIR+"sigIRC/updates/sigIRCv2.jar");
|
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 {
|
try {
|
||||||
if (programFile.exists()) {
|
if (programFile.exists()) {
|
||||||
programFile.delete();
|
programFile.delete();
|
||||||
@ -265,6 +278,8 @@ public class sigIRC{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void InitializeModules() {
|
private static void InitializeModules() {
|
||||||
try {
|
try {
|
||||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -187,6 +188,10 @@ public class FileUtils {
|
|||||||
return readJsonFromUrl(url,null,false);
|
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 {
|
public static JSONObject readJsonFromFile(String file) throws IOException, JSONException {
|
||||||
InputStream is = new FileInputStream(new File(file));
|
InputStream is = new FileInputStream(new File(file));
|
||||||
try {
|
try {
|
||||||
@ -215,6 +220,21 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public static void logToFile(String message, String filename) {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
try {
|
try {
|
||||||
|
35
src/sig/utils/GithubUtils.java
Normal file
35
src/sig/utils/GithubUtils.java
Normal file
@ -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<data_array.length();i++) {
|
||||||
|
JSONObject file_data = data_array.getJSONObject(i);
|
||||||
|
if (file_data.getString("path").equals(filename)) {
|
||||||
|
return file_data.getInt("size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user