-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" exported="" name="google.code.gson" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: tech.tenamen.Main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: tech.tenamen.Main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package tech.tenamen; | ||
|
||
import tech.tenamen.client.Client; | ||
import tech.tenamen.ide.IDE; | ||
import tech.tenamen.ide.InteliJIDE; | ||
import tech.tenamen.property.OS; | ||
|
||
import java.io.File; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static IDE IDE = new InteliJIDE(); | ||
public static Client client; | ||
|
||
public static File WORKING_DIR = new File(System.getProperty("user.dir")), | ||
ASSETS_DIR = new File(WORKING_DIR, "assets"), | ||
LIBRARIES_DIR = new File(WORKING_DIR, "libraries"), | ||
OBJECTS_DIR = new File(ASSETS_DIR, "objects"), | ||
INDEXES_DIR = new File(ASSETS_DIR, "indexes"), | ||
SRC_DIR = new File(WORKING_DIR, "src"), | ||
NATIVES_DIR = new File(LIBRARIES_DIR, "natives"); | ||
|
||
public static void main(String[] main) throws Exception { | ||
final Scanner scanner = new Scanner(System.in); | ||
System.out.println("ClientCoderPack"); | ||
System.out.print("Version<<"); | ||
final File versionFile = new File(String.format("%s\\.minecraft\\versions\\%s", System.getenv("APPDATA"), scanner.next())); | ||
if (!versionFile.exists()) { | ||
System.out.printf("File %s not found%n", versionFile.getAbsolutePath()); | ||
return; | ||
} | ||
ASSETS_DIR.mkdirs(); | ||
LIBRARIES_DIR.mkdirs(); | ||
OBJECTS_DIR.mkdirs(); | ||
INDEXES_DIR.mkdirs(); | ||
SRC_DIR.mkdirs(); | ||
NATIVES_DIR.mkdirs(); | ||
client = new Client(versionFile); | ||
System.out.println("Downloading dependencies"); | ||
client.parseDependencies(); | ||
client.download(getOs()); | ||
System.out.println("Making IDE property file"); | ||
IDE.createProperties(); | ||
System.out.println("Process has finished!"); | ||
|
||
} | ||
|
||
private static OS getOs() { | ||
final String OS_NAME = System.getProperty("os.name").toLowerCase(); | ||
if (OS_NAME.startsWith("linux")) return OS.LINUX; | ||
if (OS_NAME.startsWith("mac")) return OS.MAC; | ||
return OS.WINDOWS; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package tech.tenamen.client; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonObject; | ||
import tech.tenamen.Main; | ||
import tech.tenamen.property.OS; | ||
import tech.tenamen.util.NetUtil; | ||
|
||
import java.io.File; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Asset implements Downloadable { | ||
|
||
private final String ID; | ||
private final String SHA1; | ||
private final long SIZE; | ||
private final long TOTAL_SIZE; | ||
private final String URL; | ||
|
||
public Asset(final String ID, final String SHA1, final long SIZE, final long TOTAL_SIZE, final String URL) { | ||
this.ID = ID; | ||
this.SHA1 = SHA1; | ||
this.SIZE = SIZE; | ||
this.TOTAL_SIZE = TOTAL_SIZE; | ||
this.URL = URL; | ||
} | ||
|
||
@Override | ||
public void download(OS os) { | ||
JsonObject object = null; | ||
object = new GsonBuilder().setPrettyPrinting().create().fromJson(new StringReader(NetUtil.download(this.URL)), JsonObject.class); | ||
if (object == null) return; | ||
List<Resource> resources = new ArrayList<>(); | ||
if (object.has("objects")) { | ||
final JsonObject objects = object.getAsJsonObject("objects"); | ||
int tabIndex = 0; | ||
final StringBuilder tempBuilder = new StringBuilder(); | ||
final String raw = objects.toString(); | ||
for (int i = 0, l = raw.length(); i < l; i++) { | ||
final char c = raw.charAt(i); | ||
switch (c) { | ||
case '{': | ||
tabIndex++; | ||
break; | ||
case '}': | ||
if (tabIndex == 2) { | ||
resources.add(new Resource(NetUtil.clip(tempBuilder.toString(), "\"hash\":\"", "\","), | ||
Long.parseLong(NetUtil.clip(tempBuilder.toString(), "\"size\":", tempBuilder.length())))); | ||
tempBuilder.setLength(0); | ||
} | ||
tabIndex--; | ||
break; | ||
default: | ||
if (tabIndex == 2) { | ||
tempBuilder.append(c); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
resources.forEach(r -> { | ||
threads.add(new Thread(() -> r.download(os))); | ||
}); | ||
threads.add(new Thread(() -> NetUtil.download(this.URL, new File(Main.INDEXES_DIR, String.format("%s.json", this.ID))))); | ||
} | ||
|
||
public final List<Thread> threads = new ArrayList<>(); | ||
|
||
private static class Resource implements Downloadable { | ||
|
||
private static final String RESOURCE_URL = "https://resources.download.minecraft.net/"; | ||
private final String HASH; | ||
private final long SIZE; | ||
|
||
public Resource(final String HASH, final long SIZE) { | ||
this.HASH = HASH; | ||
this.SIZE = SIZE; | ||
} | ||
|
||
@Override | ||
public void download(OS os) { | ||
final String head = this.HASH.substring(0, 2); | ||
final StringBuilder url = new StringBuilder(RESOURCE_URL); | ||
url.append(head); | ||
url.append('/'); | ||
url.append(this.HASH); | ||
final File downloadFile = new File(Main.OBJECTS_DIR, head); | ||
downloadFile.mkdirs(); | ||
final File desFile = new File(downloadFile, HASH); | ||
if (!NetUtil.checkExist(desFile, this.SIZE)) { | ||
NetUtil.download(url.toString(), desFile); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |