11package org .mcphackers .mcp .tasks ;
22
3- import java .io .BufferedWriter ;
4- import java .io .FileWriter ;
53import java .net .URI ;
64import java .nio .file .Files ;
75import java .nio .file .Path ;
@@ -71,54 +69,32 @@ public void doTask() throws Exception {
7169 }
7270
7371 FileUtil .createDirectories (Paths .get (MCPConfig .CONF ));
74- try (BufferedWriter writer = new BufferedWriter (new FileWriter (MCPConfig .VERSION ))) {
75- writer .write (chosenVersion );
76- }
72+ VersionsParser .setCurrentVersion (chosenVersion );
7773
7874 long startTime = System .currentTimeMillis ();
7975 MCP .logger .info (" Downloading mappings" );
80- FileUtil .downloadFile (VersionsParser .downloadVersion (chosenVersion ), Paths .get (MCPConfig .CONF , "conf.zip" ));
76+ FileUtil .downloadFile (VersionsParser .downloadVersion (), Paths .get (MCPConfig .CONF , "conf.zip" ));
8177 FileUtil .unzip (Paths .get (MCPConfig .CONF , "conf.zip" ), Paths .get (MCPConfig .CONF ), true );
8278
83- // Create Eclipse workspace
8479 MCP .logger .info (" Setting up workspace" );
8580 FileUtil .deleteDirectoryIfExists (Paths .get ("workspace" ));
8681 FileUtil .copyResource (MCP .class .getClassLoader ().getResourceAsStream ("workspace.zip" ), Paths .get ("workspace.zip" ));
8782 FileUtil .unzip (Paths .get ("workspace.zip" ), Paths .get ("workspace" ), true );
88-
89- // Create Intellij workspace
90- String [] projects = { "Client" , "Server" };
91- for (String project : projects ) {
92- Path launch = Paths .get ("eclipse" , ".metadata" , ".plugins" , "org.eclipse.debug.core" , ".launches" , project + ".launch" );
93- if (Files .exists (launch )) {
94- List <String > lines = Files .readAllLines (launch );
95- String replace = "-Dhttp.proxyPort=%s" ;
96- for (int i = 0 ; i < lines .size (); i ++) {
97- lines .set (i , lines .get (i ).replace (replace , String .format (replace , VersionsParser .getProxyPort (chosenVersion ))));
98- }
99- Files .write (launch , lines );
100- }
101- Path imlPath = Paths .get ("eclipse" , project , project + ".iml" );
102- if (Files .exists (imlPath )) {
103- List <String > lines = Files .readAllLines (imlPath );
104- for (int i = 0 ; i < lines .size (); i ++) {
105- lines .set (i , lines .get (i ).replace ("$MCP_LOC$" , Paths .get (System .getProperty ("user.dir" )).toAbsolutePath ().toString ().replace ("\\ " , "/" )));
106- }
107- Files .write (imlPath , lines );
108- }
109- }
83+
84+ setWorkspace ();
11085 MCP .logger .info (" Done in " + Util .time (System .currentTimeMillis () - startTime ));
11186
11287 // Delete Minecraft.jar and Minecraft_server.jar if they exist.
11388 Files .deleteIfExists (Paths .get (MCPConfig .CLIENT ));
11489 Files .deleteIfExists (Paths .get (MCPConfig .SERVER ));
11590
11691 // Download Minecraft
117- if (!chosenVersion .equals ("custom" )) {
118- for (int side = 0 ; side <= (VersionsParser .hasServer (chosenVersion ) ? 1 : 0 ); side ++) {
92+ //if (!chosenVersion.equals("custom")) TODO
93+ {
94+ for (int side = 0 ; side <= (VersionsParser .hasServer () ? 1 : 0 ); side ++) {
11995 startTime = System .currentTimeMillis ();
12096 MCP .logger .info (" Downloading Minecraft " + (side == CLIENT ? "client" : "server" ) + "..." );
121- String url = VersionsParser .getDownloadURL (chosenVersion , side );
97+ String url = VersionsParser .getDownloadURL (side );
12298 // TODO Classic server zips
12399 Path pathOut = Paths .get (side == CLIENT ? MCPConfig .CLIENT : MCPConfig .SERVER );
124100 FileUtil .downloadFile (new URI (url ).toURL (), pathOut );
@@ -139,6 +115,47 @@ public void doTask() throws Exception {
139115 FileUtil .unzip (Paths .get (MCPConfig .LIB + "natives.zip" ), Paths .get (MCPConfig .NATIVES ), true );
140116 }
141117
118+ private void setWorkspace () throws Exception {
119+ String [] projects = { "Client" , "Server" };
120+ for (String project : projects ) {
121+ Path [] filetoRead = new Path [] {
122+ Paths .get ("workspace" , ".metadata" , ".plugins" , "org.eclipse.debug.core" , ".launches" , project + ".launch" ),
123+ Paths .get ("workspace" , project , ".idea" , "workspace.xml" ),
124+ Paths .get ("workspace" , project , project + ".iml" ),
125+ Paths .get ("workspace" , ".metadata" , ".plugins" , "org.eclipse.debug.ui" , "launchConfigurationHistory.xml" )};
126+ for (int j = 0 ; j < filetoRead .length ; j ++) {
127+ if (Files .exists (filetoRead [j ])) {
128+ List <String > lines = Files .readAllLines (filetoRead [j ]);
129+ String replace = "-Dhttp.proxyPort=%s" ;
130+ for (int i = 0 ; i < lines .size (); i ++) {
131+ switch (j ) {
132+ case 0 :
133+ case 1 :
134+ lines .set (i , lines .get (i ).replace (replace , String .format (replace , VersionsParser .getProxyPort ())));
135+ break ;
136+ case 2 :
137+ lines .set (i , lines .get (i ).replace ("$MCP_LOC$" , Paths .get (System .getProperty ("user.dir" )).toAbsolutePath ().toString ().replace ("\\ " , "/" )));
138+ break ;
139+ case 3 :
140+ if (!VersionsParser .hasServer () && lines .get (i ).contains ("path="Server"" )) {
141+ lines .remove (i );
142+ }
143+ break ;
144+ }
145+ }
146+ Files .write (filetoRead [j ], lines );
147+ }
148+ }
149+ }
150+ if (!VersionsParser .hasServer ()) {
151+ FileUtil .deleteDirectoryIfExists (Paths .get ("workspace" , "Server" ));
152+ FileUtil .deleteDirectoryIfExists (Paths .get ("workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Server" ));
153+ Files .deleteIfExists (Paths .get ("workspace/.metadata/.plugins/org.eclipse.debug.core/.launches/Server.launch" ));
154+ Files .deleteIfExists (Paths .get ("workspace/.metadata/.plugins/org.eclipse.core.resources/.root/0.tree" ));
155+ FileUtil .copyResource (MCP .class .getClassLoader ().getResourceAsStream ("0.tree" ), Paths .get ("workspace/.metadata/.plugins/org.eclipse.core.resources/.root/0.tree" ));
156+ }
157+ }
158+
142159 private static String getTable (List <String > versions ) {
143160 int rows = (int )Math .ceil (versions .size () / 3D );
144161 List <String >[] tableList = new List [rows ];
0 commit comments