Skip to content

Commit

Permalink
better logs and no more download threads
Browse files Browse the repository at this point in the history
  • Loading branch information
koxx12-dev committed May 13, 2021
1 parent da3125b commit 5ad548c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
25 changes: 3 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,9 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# intellij stuff
.idea/**


# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
Expand Down
18 changes: 18 additions & 0 deletions src/io/github/koxx12_dev/skyclient_installer_java/LogType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.koxx12_dev.skyclient_installer_java;

public enum LogType {
INFO ("INFO"),
WARNING ("WARNING"),
ERROR ("ERROR"),
FATAL ("FATAL");

private final String name;

LogType(String s) {
name = s;
}

public String toString() {
return this.name;
}
}
13 changes: 9 additions & 4 deletions src/io/github/koxx12_dev/skyclient_installer_java/MainCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -50,7 +51,9 @@ public void code(List<String> mods, List<String> packs, String mc) throws IOExce
JOptionPane.showMessageDialog(null, "Failed to detect \"" + mc + "\"\nExiting", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
System.out.println(mc + " exists");

sendLog(mc + " exists",MainCode.class,LogType.INFO);

if (!new File(mc + "/versions/1.8.9").exists()) {
JOptionPane.showMessageDialog(null, "Failed to detect \"" + mc + "\"\nExiting", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
Expand Down Expand Up @@ -128,7 +131,7 @@ public void code(List<String> mods, List<String> packs, String mc) throws IOExce

Download(Url, mc + "/skyclient/mods/" + Name);

System.out.println("Downloaded: " + Url + " , " + Name);
sendLog("Downloaded: " + Url + " , " + Name,MainCode.class,LogType.INFO);

}

Expand All @@ -139,7 +142,7 @@ public void code(List<String> mods, List<String> packs, String mc) throws IOExce

Download(Url, mc + "/skyclient/resourcepacks/" + Name);

System.out.println("Downloaded: " + Url + " , " + Name);
sendLog("Downloaded: " + Url + " , " + Name,MainCode.class,LogType.INFO);

}

Expand All @@ -162,7 +165,9 @@ public void code(List<String> mods, List<String> packs, String mc) throws IOExce
file.flush();

} catch (IOException e) {
e.printStackTrace();

sendLog(Arrays.toString(e.getStackTrace()),MainCode.class,LogType.ERROR);

}
File mf = new File(mc + "/libraries/net/minecraftforge");
File f = new File(mc + "/libraries/net/minecraftforge/forge");
Expand Down
34 changes: 19 additions & 15 deletions src/io/github/koxx12_dev/skyclient_installer_java/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -68,7 +69,7 @@ public static void main(String[] args) throws IOException {

}

System.out.println(displayed);
sendLog(displayed+"",MainGui.class,LogType.INFO);

GuiInit(displayed, modsjson, packsjson);
}
Expand Down Expand Up @@ -157,15 +158,15 @@ public static void Gui(Container truepane, List<String> list, JSONArray modsjson

String loc = "resources/images/icons/" + modsjson.getJSONObject(i).get("icon");

System.out.println("loc: " + loc);
sendLog("loc: " + loc,MainGui.class,LogType.INFO);

BufferedImage myPicture;
JarEntry entry = null;
JarFile jar = null;

InputStream is = MainGui.class.getResourceAsStream("./" + loc);

System.out.println("is: " + is);
sendLog("is: " + is,MainGui.class,LogType.INFO);

try {
jar = new JarFile(new java.io.File(MainGui.class.getProtectionDomain()
Expand All @@ -178,8 +179,8 @@ public static void Gui(Container truepane, List<String> list, JSONArray modsjson

}

System.out.println("jar: " + jar);
System.out.println("entry: " + entry);
sendLog("jar: " + jar,MainGui.class,LogType.INFO);
sendLog("entry: " + entry,MainGui.class,LogType.INFO);

if (entry != null && is != null) {
myPicture = ImageIO.read(is);
Expand Down Expand Up @@ -245,15 +246,16 @@ public static void Gui(Container truepane, List<String> list, JSONArray modsjson
try {
String loc = "resources/images/icons/" + packsjson.getJSONObject(i).get("icon");

System.out.println("loc: " + loc);
sendLog("loc: " + loc,MainGui.class,LogType.INFO);

JarEntry entry = null;
JarFile jar = null;
BufferedImage myPicture;

InputStream is = MainGui.class.getResourceAsStream("/" + loc);

System.out.println("is: " + is);
sendLog("is: " + is,MainGui.class,LogType.INFO);

try {
jar = new JarFile(new java.io.File(MainGui.class.getProtectionDomain()
.getCodeSource()
Expand All @@ -264,8 +266,9 @@ public static void Gui(Container truepane, List<String> list, JSONArray modsjson
} catch (Exception ignored) {

}
System.out.println("jar: " + jar);
System.out.println("entry: " + entry);

sendLog("jar: " + jar,MainGui.class,LogType.INFO);
sendLog("entry: " + entry,MainGui.class,LogType.INFO);

if (entry != null && is != null) {
myPicture = ImageIO.read(is);
Expand Down Expand Up @@ -373,8 +376,8 @@ public void mousePressed(MouseEvent e) {
lab.setSelected(false);
try {
selected = Warning(json);
} catch (MalformedURLException malformedURLException) {
malformedURLException.printStackTrace();
} catch (MalformedURLException ex) {
sendLog(Arrays.toString(ex.getStackTrace()),MainGui.class,LogType.ERROR);
}

lab.setSelected(selected);
Expand Down Expand Up @@ -519,7 +522,7 @@ public void mousePressed(MouseEvent e) {
try {
main.code(mods, packs, finalMc);
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
sendLog(Arrays.toString(e.getStackTrace()),MainGui.class,LogType.ERROR);
}

});
Expand Down Expand Up @@ -563,7 +566,7 @@ public static void Guide(String text) {
c.gridy = i;
gridbag.setConstraints(label, c);
pane.add(label);
System.out.println(label);
sendLog(label+"",MainGui.class,LogType.INFO);
}

JScrollPane sp = new JScrollPane(pane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Expand Down Expand Up @@ -603,7 +606,8 @@ public void mouseReleased(MouseEvent e) {
try {
Guide(request(md));
} catch (Exception ex) {
ex.printStackTrace();

sendLog(Arrays.toString(ex.getStackTrace()),MainGui.class,LogType.ERROR);
}
}
});
Expand All @@ -623,7 +627,7 @@ public void mouseReleased(MouseEvent e) {

java.awt.Desktop.getDesktop().browse(uri);
} catch (Exception ex) {
ex.printStackTrace();
sendLog(Arrays.toString(ex.getStackTrace()),MainGui.class,LogType.ERROR);
}
}
});
Expand Down
44 changes: 26 additions & 18 deletions src/io/github/koxx12_dev/skyclient_installer_java/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
Expand All @@ -31,24 +33,21 @@ public static String request(String URL) throws IOException {
}

public static void Download(String URL, String Loc) {
Runnable downloadThread = () -> {
try {
java.net.URL url = new URL(URL);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", "NING/1.0");
BufferedInputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
FileOutputStream fileOS = new FileOutputStream(Loc);
byte[] data = new byte[1024];
int byteContent;
while ((byteContent = inputStream.read(data, 0, 1024)) != -1) {
fileOS.write(data, 0, byteContent);
}
} catch (Exception e) {
e.printStackTrace();
try {
java.net.URL url = new URL(URL);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", "NING/1.0");
BufferedInputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
FileOutputStream fileOS = new FileOutputStream(Loc);
byte[] data = new byte[1024];
int byteContent;
while ((byteContent = inputStream.read(data, 0, 1024)) != -1) {
fileOS.write(data, 0, byteContent);
}
};
} catch (Exception e) {
sendLog(Arrays.toString(e.getStackTrace()),Utils.class,LogType.ERROR);

new Thread(downloadThread).start();
}

}

Expand All @@ -70,7 +69,8 @@ public static String replaceWithOsPath(String path) {
} else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
plc = "/";
} else {
System.out.println("HOW TF DID YOU GOT HERE WITH " + System.getProperty("os.name") + "\nIT SHOULDN'T BE POSSIBLE");

sendLog("HOW TF DID YOU GOT HERE WITH " + System.getProperty("os.name") + "\nIT SHOULDN'T BE POSSIBLE",Utils.class,LogType.FATAL);
System.exit(-1);
}

Expand Down Expand Up @@ -194,7 +194,9 @@ public static java.util.List<JLabel> mdToList(String mdString) {
String textParsed = Processor.process(mdString);

java.util.List<String> lines = Arrays.asList(textParsed.split("\n"));
System.out.println(lines);

sendLog(lines+"",Utils.class,LogType.INFO);

for (String line : lines) {

if (line.contains("img")) {
Expand Down Expand Up @@ -230,6 +232,12 @@ public static java.util.List<JLabel> mdToList(String mdString) {

}

public static void sendLog(String Message,Class<?> _class,LogType type) {

System.out.println("["+ DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now())+"] ["+_class.getSimpleName()+" / "+type+"]: "+Message);

}

}


0 comments on commit 5ad548c

Please sign in to comment.