Skip to content

Commit

Permalink
new website 0-4-8-24
Browse files Browse the repository at this point in the history
8.8
  • Loading branch information
lcy0x1 committed Jul 29, 2019
2 parents 98110d5 + 3b82cf0 commit b041727
Show file tree
Hide file tree
Showing 42 changed files with 937 additions and 252 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/raw/
/replay/
/res/
/res*/
/url/
/user/
/backup/
Expand All @@ -15,5 +16,6 @@
**/.DS_Store
/assets/
/libs/
/BCU_lib/
/libs-sources/
/target/
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -137,6 +138,16 @@
<artifactId>gluegen-rt-main</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-drive</artifactId>
<version>v3-rev105-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.23.0</version>
</dependency>
</dependencies>


Expand Down
13 changes: 13 additions & 0 deletions src/decode/ZipAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

public class ZipAdmin {

public static void main(String[] args) throws IOException {
File f = new File("./assets/custom/org/");
if (f.exists()) {
Files.walk(f.toPath()).forEach(path -> {
if (Files.isDirectory(path))
return;
String str = "." + path.toString().substring(15);

System.out.println(str);
});
}
}

protected static void addFile() throws IOException {
File f0 = new File("./assets/assets.zip");
File f1 = new File("./assets/080503.verinfo");
Expand Down
36 changes: 28 additions & 8 deletions src/decode/ZipLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import common.CommonStatic;
import common.system.files.AssetData;
import common.system.files.VFile;
import io.Writer;
import main.Opts;
import page.LoadPage;

public class ZipLib {

public static final String[] LIBREQS = { "000001", "000002", "000003", "080602", "080603" };
public static final String[] OPTREQS = { "080504", "080604" };
public static final String[] LIBREQS = { "000001", "000002", "000003", "080602", "080603", "080504", "080604",
"080700", "080705", "080706" };
public static final String[] OPTREQS = {};

public static FileSystem lib;
public static LibInfo info;
Expand All @@ -28,8 +32,7 @@ public static void check() {
for (String req : LIBREQS)
if (info == null || !info.merge.set.contains(req)) {
Opts.loadErr("this version requires lib " + req);
Writer.logClose(false);
System.exit(0);
CommonStatic.def.exit(false);
}
}

Expand All @@ -43,13 +46,12 @@ public static void init() {
try {
lib = FileSystems.newFileSystem(f.toPath(), null);
info = new LibInfo(lib);
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
Opts.loadErr("cannot access ./assets/assets.zip");
if (Opts.conf("do you want to re-download assets?"))
new File("./assets/assets.zip").deleteOnExit();
Writer.logClose(false);
System.exit(0);
CommonStatic.def.exit(false);
}
f = new File("./assets/custom.zip");
if (f.exists())
Expand Down Expand Up @@ -97,6 +99,24 @@ public static void read() {
LoadPage.prog("reading assets " + i++ + "/" + tot);
}

File f = new File("./assets/custom/org/");
if (f.exists()) {
List<Path> l = new ArrayList<Path>();
Files.walk(f.toPath()).forEach(path -> {
if (Files.isDirectory(path))
return;
if (path.getFileName().toString().startsWith("."))
return;
l.add(path);
});
for (Path path : l) {
String str = "." + path.toString().substring(15);
byte[] data = Files.readAllBytes(path);
VFile.root.build(str, AssetData.getAsset(data));
LoadPage.prog("reading assets " + i++ + "/" + tot);
}
}

VFile.root.sort();
VFile.root.getIf(p -> {
if (p.list() == null)
Expand Down
64 changes: 46 additions & 18 deletions src/io/BCJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@

public class BCJSON extends WebFileIO {

public static final String WEBSITE = "http://battle-cats-ultimate.000webhostapp.com";
public static final String GITRES = "https://github.com/battlecatsultimate/bcu-resources/raw/master/resources/";

public static int ID = 0;
public static int cal_ver = 0;

private static final String req = "http://battlecatsultimate.cf/api/java/";
private static final String ast = "http://battlecatsultimate.cf/api/resources/";
private static final String req = WEBSITE + "/api/java/";
private static final String path = "./assets/";

private static boolean DOWNLOAD_LIBS = true;

private static final String[] cals;

static {
Expand Down Expand Up @@ -81,13 +85,13 @@ public static void checkDownload() {
LoadPage.prog("check download");
File f;
JSONObject data = null;
JSONObject lib = null;
try {
data = getJSON("getupdate.php");
lib = getJSON("getAssets.php");
} catch (IOException e) {
}
checkLib(lib);
checkAssets(data);
if (DOWNLOAD_LIBS)
checkLibs(data);

if (data != null && data.length() >= 7) {
LoadPage.prog("check jar update...");
Expand All @@ -96,22 +100,21 @@ public static void checkDownload() {
int ver = data.getInt("jar");
String name = "BCU" + (ver >= 40800 ? "-" : " ");
name += Data.revVer(ver) + ".jar";
if (download(ast + "jar/" + name, new File("./" + name), LoadPage.lp)) {
Writer.logClose(false);
System.exit(0);
} else
if (download(GITRES + "jar/" + name, new File("./" + name), LoadPage.lp))
CommonStatic.def.exit(false);
else
Opts.dloadErr(name);
}

}
LoadPage.prog("check text update...");
for (int i = 0; i < cals.length; i++)
if (!(f = new File(path + cals[i])).exists() && !download(ast + cals[i], f, null))
if (!(f = new File(path + cals[i])).exists() && !download(GITRES + cals[i], f, null))
Opts.dloadErr(cals[i]);
if (cal_ver < data.getInt("cal")) {
if (Opts.updateCheck("text", "")) {
for (int i = 0; i < cals.length; i++)
if (!download(ast + cals[i], new File(path + cals[i]), null))
if (!download(GITRES + cals[i], new File(path + cals[i]), null))
Opts.dloadErr(cals[i]);
cal_ver = data.getInt("cal");
}
Expand All @@ -128,7 +131,7 @@ public static void checkDownload() {
for (int i = 0; i < music; i++)
if (mus[i]) {
LoadPage.prog("download musics: " + i + "/" + mus.length);
if (!download(ast + "music/" + Data.trio(i) + ".ogg", fs[i], LoadPage.lp))
if (!download(GITRES + "music/" + Data.trio(i) + ".ogg", fs[i], LoadPage.lp))
Opts.dloadErr("music #" + i);
}
}
Expand All @@ -141,8 +144,7 @@ public static void checkDownload() {
need |= !new File(path + cals[i]).exists();
if (need) {
Opts.pop(Opts.REQITN);
Writer.logClose(false);
System.exit(0);
CommonStatic.def.exit(false);
}
}

Expand Down Expand Up @@ -360,7 +362,7 @@ public static boolean uploadImg(int pid, String iid, File f) {
}
}

private static void checkLib(JSONObject lib) {
private static void checkAssets(JSONObject lib) {
if (lib != null && lib.length() > 1) {
Map<String, String> libmap = new TreeMap<>();
JSONArray ja = lib.getJSONArray("assets");
Expand All @@ -375,17 +377,24 @@ private static void checkLib(JSONObject lib) {
else
libs = new ArrayList<String>(libmap.keySet());
boolean updated = false;
for (String str : libs) {
while (libs.size() > 0) {
String str = libs.get(0);
libs.remove(str);
String desc = libmap.get(str);
libmap.remove(str);
if (!Arrays.asList(ZipLib.LIBREQS).contains(str))
if (!Opts.conf("do you want to download lib update " + str + "? " + libmap.get(str)))
if (!Opts.conf("do you want to download lib update " + str + "? " + desc))
continue;
LoadPage.prog("downloading asset: " + str + ".zip");
File temp = new File(path + (ZipLib.lib == null ? "assets.zip" : "temp.zip"));
if (download(ast + "assets/" + str + ".zip", temp, LoadPage.lp))
boolean downl = download(GITRES + "assets/" + str + ".zip", temp, LoadPage.lp);
if (downl) {
if (ZipLib.info == null)
ZipLib.init();
else
ZipLib.merge(temp);
libs = ZipLib.info.update(libmap.keySet());
}
updated = true;
}
if (updated) {
Expand All @@ -402,6 +411,25 @@ private static void checkLib(JSONObject lib) {

}

private static void checkLibs(JSONObject lib) {
if (lib != null && lib.length() > 1) {
List<String> list = new ArrayList<>();
JSONArray ja = lib.getJSONArray("pc-libs");
for (int i = 0; i < ja.length(); i++)
list.add(ja.getString(i));
File flib = new File("./BCU_lib/");
if (!flib.exists())
flib.mkdirs();
for (File fi : flib.listFiles())
list.remove(fi.getName());
for (String str : list) {
LoadPage.prog("download " + str);
File temp = new File("./BCU_lib/" + str);
download(GITRES + "jar/BCU_lib/" + str, temp, LoadPage.lp);
}
}
}

private static JSONObject getJSON(String url) throws IOException {
JSONObject inp = new JSONObject();
inp.put("bcuver", MainBCU.ver);
Expand Down
11 changes: 8 additions & 3 deletions src/io/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,18 @@ private static int[] parseInts(int n, String str) {
}

private static void readCustom() {
LoadPage.prog("reading custom data");
alt = null;
try {
ZipAccess.getList();
alt = ZipAccess.extractAllList();
} catch (Exception e1) {
e1.printStackTrace();
Opts.loadErr("error in reading: reading backup");
} catch (Exception e) {
e.printStackTrace();
Opts.loadErr("cannot access ./user/backup.zip");
if (Opts.conf("do you want to delete broken backups?"))
new File("./user/backup.zip").deleteOnExit();
Writer.logClose(false);
System.exit(0);
}
try {
DIYAnim.read();
Expand Down
14 changes: 11 additions & 3 deletions src/io/WebFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

public class WebFileIO {

private static final int CHUNK_SIZE = 131072;
public static final int SMOOTH = 1 << 17, FAST = 1 << 23, MAX = 1 << 25;

private static HttpTransport transport;

public static boolean download(String url, File file, Consumer<Progress> c) {
public static boolean download(int size, String url, File file, Consumer<Progress> c) {
Writer.check(file);
try {
if (transport == null)
Expand All @@ -46,7 +46,7 @@ public static boolean download(String url, File file, Consumer<Progress> c) {
GenericUrl gurl = new GenericUrl(url);

MediaHttpDownloader downloader = new MediaHttpDownloader(transport, new Handler());
downloader.setChunkSize(CHUNK_SIZE);
downloader.setChunkSize(size);
downloader.setProgressListener(new Progress(c));
downloader.download(gurl, out);

Expand All @@ -61,6 +61,14 @@ public static boolean download(String url, File file, Consumer<Progress> c) {
}
}

public static boolean download(String url, File file) {
return download(MAX, url, file, null);
}

public static boolean download(String url, File file, Consumer<Progress> c) {
return download(FAST, url, file, c);
}

public static boolean upload(File file, String url) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
Expand Down
3 changes: 2 additions & 1 deletion src/io/WebPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static class WebImg implements Runnable, Consumer<Progress> {
public WebImg(String str) {
url = str;
if (str.length() > 0) {
url = "http://battlecatsultimate.cf/packs/res/" + str;
url = BCJSON.WEBSITE + "/packs/res/" + str;
tmp = new File("./pack/img/" + str);
if (tmp.exists()) {
try {
Expand Down Expand Up @@ -251,6 +251,7 @@ protected WebPack(int pack) {
rate = new int[2][6];
packlist.put(pid, this);
icon = new WebImg("");
time = "";
}

protected WebPack(JSONObject pack) {
Expand Down
Loading

0 comments on commit b041727

Please sign in to comment.