Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit bf335e8

Browse files
author
Explv
committed
Download resources from GitHub as a .zip and extract, for faster first time start-up.
Cache downloaded OSBot.jar when building the script, for faster build times. Update README with clearer build instructions.
1 parent 9df10c2 commit bf335e8

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ Pass the name of your saved .config file as the script parameter:
1111
## Development
1212
Intellij is the recommended IDE of choice:[https://www.jetbrains.com/idea/download/](here)
1313

14-
Select File -> New -> Project From Version Control -> Git
14+
Select `File -> New -> Project From Version Control -> Git`
1515

1616
Enter https://github.com/Explv/Explvs-AIO.git
1717

1818
And then follow the setup wizard.
1919

20-
To build the script, just run maven install.
20+
If you're building the script for the first time, run: `mvn initialize`
21+
22+
This will download OSBot, and allow you to build the script.
23+
24+
To build the script, run: `mvn install`
25+
26+
The script will be built to your scripts directory `<home_dir>/OSBot/Scripts`
27+
28+
If / when OSBot updates, you will need to delete the `osbot.jar` that maven downloads, and re-run `mvn intialize` to get the latest version.
2129

2230
## Issues
2331
If you find any bugs with the project, feel free to make a pull request fixing them. Alternatively, you can make an issue on this project and they will be addressed when possible.

pom.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.explv.explv_osbot_manager</groupId>
88
<artifactId>explvs_aio</artifactId>
9-
<version>v3.1.11</version>
9+
<version>v3.1.12</version>
1010
<repositories>
1111
<repository>
1212
<id>local-repo</id>
@@ -19,6 +19,11 @@
1919
<artifactId>json-simple</artifactId>
2020
<version>1.1.1</version>
2121
</dependency>
22+
<dependency>
23+
<groupId>net.lingala.zip4j</groupId>
24+
<artifactId>zip4j</artifactId>
25+
<version>2.6.1</version>
26+
</dependency>
2227
<dependency>
2328
<groupId>org.osbot</groupId>
2429
<artifactId>osbot</artifactId>
@@ -44,8 +49,6 @@
4449
<unpack>false</unpack>
4550
<outputDirectory>${project.build.directory}/osbot/</outputDirectory>
4651
<outputFileName>osbot.jar</outputFileName>
47-
<overwrite>true</overwrite>
48-
<skipCache>true</skipCache>
4952
</configuration>
5053
</execution>
5154
</executions>

src/main/java/script/AIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@ScriptManifest(author = "Explv", name = "Explv's AIO " + AIO.VERSION, info = "AIO", version = 0, logo = "http://i.imgur.com/58Zz0fb.png")
2929
public class AIO extends Script {
3030

31-
static final String VERSION = "v3.1.11";
31+
static final String VERSION = "v3.1.12";
3232

3333
private Gui gui;
3434
private Paint paint;

src/main/java/util/file_managers/ResourceManager.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package util.file_managers;
22

3+
import net.lingala.zip4j.ZipFile;
4+
35
import java.io.*;
46
import java.net.URL;
57
import java.nio.channels.Channels;
@@ -26,22 +28,18 @@ public static InputStream loadFile(final String relativeFilePath) {
2628
return loadFileFromDataDir(relativeFilePath);
2729
}
2830

31+
InputStream jarInputStream = loadFileFromJar(relativeFilePath);
32+
33+
if (jarInputStream != null) {
34+
saveFileToDataDirectory(jarInputStream, relativeFilePath);
35+
return loadFileFromDataDir(relativeFilePath);
36+
}
37+
2938
// TODO: Loading files from local .jars currently seems to be broken
3039
// As a stop-gap, we download the files from GitHub if they don't exist locally
3140
// or are empty.
32-
saveFileFromGitHubToDataDirectory(relativeFilePath);
41+
downloadResourcesFromGitHubToDataDirectory();
3342
return loadFileFromDataDir(relativeFilePath);
34-
35-
36-
// InputStream jarInputStream = loadFileFromJar(relativeFilePath);
37-
//
38-
// if (jarInputStream != null) {
39-
// saveFileToDataDirectory(jarInputStream, relativeFilePath);
40-
// return loadFileFromDataDir(relativeFilePath);
41-
// }
42-
//
43-
// System.out.println("Failed to load file");
44-
// return null;
4543
}
4644

4745
private static InputStream loadFileFromJar(final String relativeFilePath) {
@@ -76,23 +74,31 @@ private static InputStream loadFileFromDataDir(final String relativeFilePath) {
7674
return null;
7775
}
7876

79-
private static void saveFileFromGitHubToDataDirectory(final String relativeFilePath) {
77+
private static void downloadResourcesFromGitHubToDataDirectory() {
8078
try {
81-
URL url = new URL(GITHUB_URL + "/blob/master/src/main/resources/" + relativeFilePath + "?raw=true");
82-
System.out.println("Saving file from url: " + url.toString());
79+
URL url = new URL(GITHUB_URL + "/blob/master/resources-archive.zip?raw=true");
80+
System.out.println("Downloading file from url: " + url.toString() + ", to: " + DIRECTORY);
8381

8482
ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
8583

86-
File outputFile = Paths.get(DIRECTORY, relativeFilePath).toFile();
84+
File outputFile = Paths.get(DIRECTORY, "resources-archive.zip").toFile();
8785

8886
outputFile.getParentFile().mkdirs();
8987
outputFile.createNewFile();
9088

9189
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
9290
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
91+
92+
System.out.println(String.format("Extracting file: %s, to: %s", outputFile.getAbsolutePath(), DIRECTORY));
93+
94+
ZipFile zipFile = new ZipFile(outputFile);
95+
zipFile.extractAll(DIRECTORY);
96+
97+
outputFile.delete();
9398
} catch (IOException e) {
9499
e.printStackTrace();
95100
}
101+
96102
}
97103

98104
private static synchronized boolean saveFileToDataDirectory(final InputStream inputStream, final String relativeFilePath) {

0 commit comments

Comments
 (0)