@@ -29,8 +29,8 @@ public static void run(String[] args) {
2929 }
3030 args = Arrays .stream (args ).skip (2 ).toArray (String []::new );
3131 if (cmd .equalsIgnoreCase ("install" )) install (args );
32- else if (cmd .equalsIgnoreCase ("update" )) update (args );
33- else if (cmd .equalsIgnoreCase ("repair" )) repair (args );
32+ else if (cmd .equalsIgnoreCase ("update" )) update (args , false );
33+ else if (cmd .equalsIgnoreCase ("repair" )) update (args , true );
3434 else if (cmd .equalsIgnoreCase ("delete" )) delete (args );
3535 else if (cmd .equalsIgnoreCase ("convert" )) convert (args );
3636 else Utils .invalid ();
@@ -318,7 +318,7 @@ private static void list() {
318318 System .out .println (Ansi .ansi ().fg (Ansi .Color .RED ).a ("No modpack installed." ).reset ());
319319 return ;
320320 }
321- List <String > modpack = new ArrayList <>();
321+ List <Ansi > modpack = new ArrayList <>();
322322 for (Map .Entry <Integer , String > entry : modpacks .entrySet ()) {
323323 String folderName = entry .getValue () + "_" + entry .getKey ();
324324 File manifest = new File (Config .modpackDir .getPath () + File .separator + folderName + File .separator + "manifest.json" );
@@ -328,16 +328,16 @@ private static void list() {
328328 String name = (String ) json .get ("name" );
329329 String version = (String ) json .get ("version" );
330330 String mcVer = (String ) ((JSONObject ) json .get ("minecraft" )).get ("version" );
331- modpack .add (String . format ( "%s | %s | %s" , name , version , mcVer ));
331+ modpack .add (Ansi . ansi (). fg ( Ansi . Color . YELLOW ). a ( name ). reset (). a ( " | " ). fg ( Ansi . Color . CYAN ). a ( version ). reset (). a ( " | " ). fg ( Ansi . Color . MAGENTA ). a ( mcVer ). reset (). a ( " | " ). fg ( Ansi . Color . MAGENTA ). a ( entry . getKey () ));
332332 } catch (Exception ignored ) {
333333 }
334334 }
335335 System .out .println (Ansi .ansi ().fg (Ansi .Color .CYAN ).a ("Installed modpacks:" ));
336- modpack .forEach (s -> System .out . println ( Ansi . ansi (). fg ( Ansi . Color . YELLOW ). a ( s )) );
336+ modpack .forEach (System .out :: println );
337337 System .out .println (modpack .size () + " modpacks in total." );
338338 }
339339
340- private static void update (String [] ids ) {
340+ private static void update (String [] ids , boolean force ) {
341341 Map <Integer , String > modpacks = Config .loadModpacks ();
342342 for (String id : ids ) {
343343 try {
@@ -371,53 +371,9 @@ private static void update(String[] ids) {
371371 if (!success ) throw new FileSystemException ("Failed to extract modpack content of " + name );
372372 File manifest = new File (packFolder + File .separator + "manifest.json" );
373373 if (!manifest .exists ()) throw new FileNotFoundException ("Cannot find modpack manifest of " + name );
374- FileUtils .cleanDirectory (new File (packFolder .getPath () + File .separator + "mods" ));
374+ if ( force ) FileUtils .cleanDirectory (new File (packFolder .getPath () + File .separator + "mods" ));
375375 copyFromOverride (packFolder .getPath (), (String ) ((JSONObject ) parser .parse (new FileReader (manifest ))).get ("overrides" ));
376- downloadMods (packFolder .getPath ());
377- System .out .println (Ansi .ansi ().fg (Ansi .Color .GREEN ).a ("Finished download of " + name ).reset ());
378- } catch (Exception e ) {
379- e .printStackTrace ();
380- }
381- }
382- }
383-
384- private static void repair (String [] ids ) {
385- Map <Integer , String > modpacks = Config .loadModpacks ();
386- for (String id : ids ) {
387- try {
388- String slug = null , key = null ;
389- if (Utils .isInteger (id )) {
390- String ss = modpacks .getOrDefault (Integer .parseInt (id ), null );
391- if (ss == null ) throw new NoSuchObjectException ("Cannot find modpack with ID " + id );
392- slug = ss ;
393- key = id ;
394- } else {
395- for (Map .Entry <Integer , String > entry : modpacks .entrySet ())
396- if (entry .getValue ().equalsIgnoreCase (id )) {
397- slug = entry .getValue ();
398- key = entry .getKey ().toString ();
399- break ;
400- }
401- if (slug == null ) throw new NoSuchObjectException ("Cannot find modpack with name " + id );
402- }
403- String finalKey = key ;
404- JSONObject json = Utils .runRetry (() -> (JSONObject ) Utils .readJsonFromUrl (Constants .CURSEFORGE_API + finalKey ));
405- if (json == null || ((long ) ((JSONObject ) json .get ("categorySection" )).get ("gameCategoryId" )) != 4471 )
406- throw new NoSuchObjectException ("The ID " + id + " does not represent a modpack." );
407- String name = (String ) json .get ("name" );
408- System .out .println (Ansi .ansi ().fg (Ansi .Color .YELLOW ).a ("Repairing " ).a (name ).a ("..." ).reset ());
409- File packFolder = new File (Config .modpackDir .getPath () + File .separator + slug + "_" + key );
410- JSONObject latest = (JSONObject ) Utils .getLast ((JSONArray ) json .get ("latestFiles" ));
411- String downloadUrl = ((String ) latest .get ("downloadUrl" )).replaceFirst ("edge" , "media" );
412- String loc = Utils .downloadFile (downloadUrl , packFolder .getPath ());
413- if (loc == null ) throw new SyncFailedException ("Failed to download modpack " + name );
414- boolean success = Utils .unzip (loc );
415- if (!success ) throw new FileSystemException ("Failed to extract modpack content of " + name );
416- File manifest = new File (packFolder + File .separator + "manifest.json" );
417- if (!manifest .exists ()) throw new FileNotFoundException ("Cannot find modpack manifest of " + name );
418- FileUtils .cleanDirectory (new File (packFolder .getPath () + File .separator + "mods" ));
419- copyFromOverride (packFolder .getPath (), (String ) ((JSONObject ) parser .parse (new FileReader (manifest ))).get ("overrides" ));
420- downloadMods (packFolder .getPath (), true );
376+ downloadMods (packFolder .getPath (), force );
421377 System .out .println (Ansi .ansi ().fg (Ansi .Color .GREEN ).a ("Finished download of " + name ).reset ());
422378 } catch (Exception e ) {
423379 e .printStackTrace ();
0 commit comments