1+ package schembrowser ;
2+
3+ import arc .*;
4+ import arc .files .*;
5+ import arc .struct .*;
6+ import arc .util .*;
7+
8+ import static mindustry .Vars .*;
9+
10+ public class Migrations {
11+
12+ public static final String defaultRepoFrom = "bend-n/design-it" ;
13+ public static final String defaultRepoTo = "MindustryDesignIt/design-it" ;
14+
15+ public static void run (SchematicBrowser mod ) {
16+ // Change this mod's repo
17+ if (Core .settings .getString ("mod-schematic-browser-repo" , "" ).equals ("sbxte/mindustry-schematic-browser" )) {
18+ Core .settings .put ("mod-schematic-browser-repo" , "MindustryDesignIt/schematic-browser-mod" );
19+ }
20+
21+ // Remove copies of the browser that follow other ids
22+ for (var id : new String []{"scheme-browser" , "schematic-browser-v8" }){
23+ for (var setting : new String []{"autoupdate" , "massupdate" , "enabled" , "repo" }){
24+ Core .settings .remove ("mod-" + id + "-" + setting );
25+ }
26+ var otherMod = mods .list ().find (m -> m .name .equals (id ));
27+ if (otherMod != null ) {
28+ Log .info ("Schematic Browser: Removing oudated version @" , id );
29+ mods .removeMod (otherMod );
30+ }
31+ }
32+
33+ // Migrate bend-n/design-it repository
34+ var repos = Seq .with (Core .settings .getString ("schematicrepositories" , "" ).split (";" ));
35+ if (repos .contains (defaultRepoFrom )) {
36+ // Overwrite setting
37+ repos .replace (repo -> repo .equals (defaultRepoFrom ) ? defaultRepoTo : repo );
38+ Core .settings .put ("schematicrepositories" , String .join (";" , repos ));
39+
40+ // Rename file
41+ Fi origFile = mod .schematicRepoDirectory .child (defaultRepoFrom .replace ("/" ,"" ) + ".zip" );
42+ Fi nextFile = mod .schematicRepoDirectory .child (defaultRepoTo .replace ("/" ,"" ) + ".zip" );
43+ if (origFile .exists () && !nextFile .exists ()) {
44+ origFile .moveTo (nextFile );
45+ }
46+ Log .info ("Schematic Browser: Migrated @ to @." , defaultRepoFrom , defaultRepoTo );
47+ }
48+ }
49+ }
0 commit comments