11package net .kyrptonaught .ToolBox ;
22
3+ import com .google .gson .JsonArray ;
4+ import com .google .gson .JsonObject ;
35import net .kyrptonaught .ToolBox .IO .ConfigLoader ;
46import net .kyrptonaught .ToolBox .IO .FileHelper ;
57import net .kyrptonaught .ToolBox .IO .GithubHelper ;
@@ -102,9 +104,12 @@ private static void installDependencies(InstalledServerInfo serverInfo) {
102104 String hash = dependency .autoGeneratedHash ;
103105
104106 if (hash != null && (installedDependency == null || !hash .equals (installedDependency .hash ))) {
105- System .out .print ("downloading..." );
106- installFile (serverInfo , new InstalledDependencyInfo (dependency ), hash );
107- System .out .println ("installed" );
107+ if (dependency .ignore != null && dependency .ignore ) System .out .println ("skipping..." );
108+ else {
109+ System .out .print ("downloading..." );
110+ installFile (serverInfo , new InstalledDependencyInfo (dependency ), hash );
111+ System .out .println ("installed" );
112+ }
108113 } else {
109114 System .out .println ("Already exists" );
110115 }
@@ -117,16 +122,19 @@ private static void installFile(InstalledServerInfo serverInfo, InstalledDepende
117122 Path destination = serverInfo .getDependencyInstallPath (dependency );
118123 FileHelper .createDir (destination );
119124
120- if (dependency .gitRepo ) {
125+ if (dependency .type == BranchConfig . TYPE . GIT ) {
121126 FileHelper .download (GithubHelper .convertRepoToZipball (dependency .url ), downloadPath );
127+ } else if (dependency .type == BranchConfig .TYPE .MODRINTH ) {
128+ JsonObject urlOBJ = ConfigLoader .gson .fromJson (dependency .url , JsonObject .class );
129+ FileHelper .download (urlOBJ .get ("url" ).getAsString (), downloadPath );
122130 } else {
123131 FileHelper .download (dependency .url , downloadPath );
124132 }
125133
126134 clearOldFiles (serverInfo , dependency .installedFiles );
127135
128136 List <String > installedFiles ;
129- if (dependency .unzip ) {
137+ if (dependency .type == BranchConfig . TYPE . ZIP ) {
130138 installedFiles = FileHelper .unzipFile (downloadPath , destination , true );
131139 } else {
132140 installedFiles = FileHelper .copyFile (downloadPath , destination .resolve (dependency .name ));
@@ -142,7 +150,7 @@ private static void replaceMissingFiles(InstalledServerInfo serverInfo, Installe
142150 Path destination = serverInfo .getDependencyInstallPath (dependency );
143151 FileHelper .createDir (destination );
144152
145- if (dependency .unzip ) {
153+ if (dependency .type == BranchConfig . TYPE . ZIP ) {
146154 List <String > installedFiles = new ArrayList <>(List .copyOf (dependency .installedFiles ));
147155 if (installedFiles != null ) {
148156 Path unzipPath = serverInfo .getTempPath (dependency );
@@ -204,4 +212,23 @@ private static InstalledDependencyInfo getInstalledDependency(InstalledServerInf
204212 }
205213 return null ;
206214 }
215+
216+ public static void checkForModrinthUpdate (BranchConfig .Dependency dependency , String gameVersion , String loader ) {
217+ if (dependency .type == BranchConfig .TYPE .MODRINTH ) {
218+ JsonObject urlOBJ = ConfigLoader .gson .fromJson (dependency .url , JsonObject .class );
219+ String id = urlOBJ .get ("id" ).getAsString ();
220+ String version = urlOBJ .get ("version" ).getAsString ();
221+
222+ JsonArray obj = FileHelper .download ("https://api.modrinth.com/v2/project/" + id + "/version?game_versions=[%22" + gameVersion + "%22]&loaders=[%22" + loader .toLowerCase () + "%22]&include_changelog=false" , JsonArray .class );
223+ if (obj .isEmpty ()) {
224+ System .out .println (dependency .name + "(" + id + "): Skipping" );
225+ return ;
226+ }
227+ urlOBJ .addProperty ("version" , obj .get (0 ).getAsJsonObject ().get ("id" ).getAsString ());
228+
229+ System .out .println (dependency .name + "(" + id + "): " + version + " -> " + obj .get (0 ).getAsJsonObject ().get ("version_number" ).getAsString () + "(" + urlOBJ .get ("version" ).getAsString () + ")" );
230+
231+ dependency .url = ConfigLoader .serializeToolboxInstall (urlOBJ );
232+ }
233+ }
207234}
0 commit comments