14
14
import com .laeben .corelauncher .minecraft .modding .modrinth .entities .DependencyInfo ;
15
15
import com .laeben .corelauncher .minecraft .wrappers .optifine .OptiFine ;
16
16
import com .laeben .corelauncher .utils .EventHandler ;
17
+ import com .laeben .corelauncher .utils .Logger ;
17
18
import com .laeben .corelauncher .utils .NetUtils ;
19
+ import javafx .application .Platform ;
18
20
19
21
import java .io .FileNotFoundException ;
20
22
import java .util .List ;
@@ -42,16 +44,16 @@ public void installMods(Profile p, List<Mod> mods) throws NoConnectionException,
42
44
var path = p .getPath ().to ("mods" );
43
45
int i = 0 ;
44
46
int size = mods .size ();
45
- for (var a : mods ){
47
+ for (var a : mods .stream ().toList ()){
48
+ handler .execute (new KeyEvent ("," + a .name + ":.resource.progress;" + (++i ) + ";" + size ));
49
+
46
50
if (a .fileUrl == null )
47
51
continue ;
48
52
49
53
var pxx = path .to (a .fileName );
50
54
if (pxx .exists ())
51
55
continue ;
52
56
53
- handler .execute (new KeyEvent ("," + a .name + ":.resource.progress;" + (++i ) + ";" + size ));
54
-
55
57
String url = a .fileUrl ;
56
58
if (url .startsWith ("OptiFine" )){
57
59
var f = OptiFine .getOptiFine ().getVersion (p .getVersionId (), url );
@@ -63,8 +65,23 @@ public void installMods(Profile p, List<Mod> mods) throws NoConnectionException,
63
65
continue ;
64
66
}
65
67
68
+ if (NetUtils .download (url , path .to (a .fileName ), false ) != null )
69
+ continue ;
70
+
71
+ var up = update (p , a );
72
+ if (url .equals (up .fileUrl ))
73
+ continue ;
66
74
67
- if (NetUtils .download (url , path .to (a .fileName ), false ) == null ){
75
+ Platform .runLater (() -> {
76
+ remove (p , a );
77
+ try {
78
+ include (p , up );
79
+ } catch (NoConnectionException | HttpException e ) {
80
+ Logger .getLogger ().log (e );
81
+ }
82
+ });
83
+
84
+ if (NetUtils .download (up .fileUrl , path .to (up .fileName ), false ) == null ){
68
85
var x = Modrinth .getModrinth ().getProjectVersions (a .name , p .getVersionId (), p .getWrapper ().getIdentifier (), DependencyInfo .noDependencies ());
69
86
var s = x .stream ().flatMap (f -> f .getFiles ().stream ()).filter (f -> f .filename != null && f .filename .equals (a .fileName )).findFirst ();
70
87
@@ -76,6 +93,18 @@ public void installMods(Profile p, List<Mod> mods) throws NoConnectionException,
76
93
}
77
94
}
78
95
}
96
+ public CResource update (Profile p , CResource m ) throws NoConnectionException , HttpException {
97
+ if (m .id == null )
98
+ return m ;
99
+
100
+ List <CResource > all = List .of ();
101
+ if (m .isForge ())
102
+ all = CurseForge .getForge ().getResources (p .getVersionId (), List .of ((int )m .id ), p , true );
103
+ else if (m .isModrinth ())
104
+ all = Modrinth .getModrinth ().getCResources (List .of (m .id .toString ()), p .getVersionId (), p .getWrapper ().getIdentifier ());
105
+
106
+ return all .isEmpty () ? m : all .get (0 );
107
+ }
79
108
public void includeMods (Profile p , List <Mod > mods ){
80
109
for (var m : mods ){
81
110
if (p .getMods ().stream ().anyMatch (x -> x .equals (m )))
0 commit comments