@@ -240,6 +240,47 @@ else if (e.getMessage().contains("520"))
240
240
}
241
241
}
242
242
243
+ /**
244
+ * Create symbolic links for a downloaded resource
245
+ */
246
+ public void links ()
247
+ {
248
+ // Loop through each resource
249
+ var resourcesPath = new File (dataDir , "pkgs/spiget" );
250
+ var files = resourcesPath .listFiles ();
251
+ if (files == null ) return ;
252
+
253
+ Arrays .stream (files ).forEach (res -> {
254
+ // Loop through each version
255
+ var versions = res .listFiles ();
256
+ if (versions == null ) return ;
257
+
258
+ Arrays .stream (versions ).forEach (ver -> {
259
+ // Read plugin.yml
260
+ try
261
+ {
262
+ var meta = PluginYml .fromYml (Files .readString (new File (ver , "plugin.yml" ).toPath ()));
263
+
264
+ // Compute link path
265
+ var linkPath = new File (dataDir , format ("pkgs/links/%s/%s" , meta .getName (), meta .getVersion ()));
266
+
267
+ // Delete old link
268
+ if (Files .isSymbolicLink (linkPath .toPath ()) || linkPath .exists ()) linkPath .delete ();
269
+
270
+ // Create new link
271
+ linkPath .getParentFile ().mkdirs ();
272
+ Files .createSymbolicLink (linkPath .toPath (), linkPath .getParentFile ().toPath ().relativize (ver .toPath ()));
273
+ }
274
+ catch (IOException e )
275
+ {
276
+ // TODO: Better error handling
277
+ //e.printStackTrace();
278
+ throw new RuntimeException (e );
279
+ }
280
+ });
281
+ });
282
+ }
283
+
243
284
public static void main (String [] args )
244
285
{
245
286
var crawler = new SpigetCrawler (new File (".mcpm" ));
@@ -255,5 +296,7 @@ public static void main(String[] args)
255
296
256
297
//safeSleep(crawler.mtDelay);
257
298
});
299
+
300
+ crawler .links ();
258
301
}
259
302
}
0 commit comments