Skip to content

Commit

Permalink
Pushing changes without testing
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Nov 1, 2022
1 parent 32dcf46 commit db94711
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 50 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up PATH
run: |
echo "${ANDROID_HOME}/build-tools/30.0.1" >> $GITHUB_PATH
- name: Set up JDK 16
uses: actions/setup-java@v1
run: echo "${ANDROID_HOME}/build-tools/30.0.1" >> $GITHUB_PATH

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 16
java-version: 17
distribution: temurin

- name: Build mod jar
run: ./gradlew deploy

- name: Upload built jar file
uses: actions/upload-artifact@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fooinstaller.title=Client Installer
fooinstaller.mobile=[scarlet]Foo's client isn't available on mobile!
fooinstaller.source=[accent]Enter the source repository for the download (leave blank if unsure)
fooinstaller.discord=Join Our Discord
fooinstaller.java.notfound=It seems that you don't have java installed, please click the button below then click the "latest release" button on the website. Follow the install prompts and reboot your computer.
fooinstaller.java.install=Install Java
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
99 changes: 56 additions & 43 deletions src/fooInstaller/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,38 @@
import mindustry.ui.dialogs.*;

import java.io.*;
import java.lang.reflect.*;
import java.net.*;

import static mindustry.Vars.*;

public class Main extends Mod{

@Override
public void init() {
Events.on(ClientLoadEvent.class, e -> {
if (Version.combined().contains("Client")) { // Disable mod when running on client (can't remove mod within mod)
Vars.mods.setEnabled(Vars.mods.getMod(this.getClass()), false);
return;
}
BaseDialog dialog = new BaseDialog("Client Installer");
// If the foo's field exists then we are already using the client and don't want to run the installer
if (Structs.contains(Version.class.getDeclaredFields(), var -> var.getName().equals("foos"))) return;

var d = new BaseDialog("@fooinstaller.title");

if (mobile) { // Client doesn't work on mobile, bail out
dialog.cont.add("[scarlet]Foo's client isn't available on mobile!");
d.cont.add("@fooinstaller.mobile");
Vars.mods.setEnabled(Vars.mods.getMod(this.getClass()), false);
} else {
dialog.cont.add("[accent]Select a version of the client to download").colspan(2).row();
dialog.cont.button("v6", () -> install("mindustry-antigrief/mindustry-client-v6-builds")).fillX();
dialog.cont.button("v7", () -> install("mindustry-antigrief/mindustry-client-v7-builds")).fillX();
d.cont.add("@fooinstaller.source").row();
var def = "mindustry-antigrief/mindustry-client-v7-builds";
d.cont.field("", s -> install(s.trim().isEmpty() ? def : s)).fillX().get().setMessageText(def);
}
dialog.addCloseButton();
dialog.buttons.button("Join Our Discord", Icon.discord, () -> Core.app.openURI("https://discord.gg/yp9ZW7j")).wrapLabel(false);
dialog.show();
d.addCloseButton();
d.buttons.button("@fooinstaller.discord", Icon.discord, () -> Core.app.openURI("https://discord.gg/yp9ZW7j")).wrapLabel(false);
d.show();
});
}

void install(String url) {
Method download = null;
try {
download = BeControl.class.getDeclaredMethod("download", String.class, Fi.class, Intc.class, Floatc.class, Boolp.class, Runnable.class, Cons.class);
download.setAccessible(true);
} catch (NoSuchMethodException e) { ui.showException(e); }
if (download == null) return;
Method finalDownload = download;

Http.get("https://api.github.com/repos/" + url + "/releases/latest").error(e -> {
ui.loadfrag.hide();
Log.err(e);
})
.submit(res -> {
}).submit(res -> {
Jval val = Jval.read(res.getResultAsString());
String newBuild = val.getString("tag_name", "0");
Jval asset = val.get("assets").asArray().find(v -> v.getString("name", "").toLowerCase().contains("desktop"));
Expand All @@ -73,39 +63,62 @@ void install(String url) {
Fi.get(OS.prop("becopy")) :
Fi.get(BeControl.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

BaseDialog dialog = new BaseDialog("@be.updating");
finalDownload.invoke(becontrol, updateUrl, file, (Intc) i -> length[0] = i, (Floatc) v -> progress[0] = v, (Boolp)() -> cancel[0], (Runnable)() -> {
var d = new BaseDialog("@be.updating");
download(updateUrl, file, i -> length[0] = i, v -> progress[0] = v, () -> cancel[0], () -> {
try{
var javaExe = new Fi(OS.prop("java.home")).child("bin").child("java").absolutePath(); // Locates the java executable, needed for itch and steam installs
javaExe = new Fi(javaExe).exists() ? javaExe : Core.files.local("jre/bin/java").absolutePath(); // Fallback to packaged java
javaExe = new Fi(javaExe).exists() ? javaExe : Core.files.local("jre/bin/java.exe").absolutePath(); // Fallback to packaged java (windows)
javaExe = new Fi(javaExe).exists() ? javaExe : "java"; // Fallback to java command
Runtime.getRuntime().exec(OS.isMac ?
new String[]{javaExe, "-XstartOnFirstThread", "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()} :
new String[]{javaExe, "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()}
new String[]{javaPath, "-XstartOnFirstThread", "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()} :
new String[]{javaPath, "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()}
);
Core.app.exit();
}catch(IOException e){
dialog.cont.clearChildren();
dialog.cont.add("It seems that you don't have java installed, please click the button below then click the \"latest release\" button on the website.").row();
dialog.cont.button("Install Java", () -> Core.app.openURI("https://adoptium.net/index.html?variant=openjdk16&jvmVariant=hotspot")).size(210f, 64f);
d.cont.clearChildren();
d.cont.add("@fooinstaller.java.notfound").row();
d.cont.button("@fooinstaller.java.install", () -> Core.app.openURI("https://adoptium.net/index.html?variant=openjdk16&jvmVariant=hotspot")).size(210f, 64f);
}
}, (Cons<Throwable>)e -> {
dialog.hide();
}, e -> {
d.hide();
ui.showException(e);
});

dialog.cont.add(new Bar(() -> length[0] == 0 ? Core.bundle.get("be.updating") : (int)(progress[0] * length[0]) / 1024/ 1024 + "/" + length[0]/1024/1024 + " MB", () -> Pal.accent, () -> progress[0])).width(400f).height(70f);
dialog.buttons.button("@cancel", Icon.cancel, () -> {
d.cont.add(new Bar(() -> length[0] == 0 ? Core.bundle.get("be.updating") : (int)(progress[0] * length[0]) / 1024/ 1024 + "/" + length[0]/1024/1024 + " MB", () -> Pal.accent, () -> progress[0])).width(400f).height(70f);
d.buttons.button("@cancel", Icon.cancel, () -> {
cancel[0] = true;
dialog.hide();
d.hide();
}).size(210f, 64f);
dialog.buttons.button("Join Our Discord", Icon.discord, () -> Core.app.openURI("https://discord.gg/yp9ZW7j")).size(210f, 64f);
dialog.setFillParent(false);
dialog.show();
d.buttons.button("@fooinstaller.discord", Icon.discord, () -> Core.app.openURI("https://discord.gg/yp9ZW7j")).size(210f, 64f);
d.setFillParent(false);
d.show();
}catch(Exception e){
ui.showException(e);
}
});
}

/** Copied from BeControl since that one isnt public and using it reflectively is horrible. */
void download(String furl, Fi dest, Intc length, Floatc progressor, Boolp canceled, Runnable done, Cons<Throwable> error){
mainExecutor.submit(() -> {
try{
HttpURLConnection con = (HttpURLConnection)new URL(furl).openConnection();
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
OutputStream out = dest.write(false, 4096);

byte[] data = new byte[4096];
long size = con.getContentLength();
long counter = 0;
length.get((int)size);
int x;
while((x = in.read(data, 0, data.length)) >= 0 && !canceled.get()){
counter += x;
progressor.get((float)counter / (float)size);
out.write(data, 0, x);
}
out.close();
in.close();
if(!canceled.get()) done.run();
}catch(Throwable e){
error.get(e);
}
});
}
}

0 comments on commit db94711

Please sign in to comment.