Commit 792cf5b9eb5951573f5387ef677fa2f281e91814
1 parent
3c957d78
removing RealmsJsonUpdateThread since it's no longer needed
Showing
3 changed files
with
0 additions
and
310 deletions
java/common/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
... | ... | @@ -27,12 +27,9 @@ import com.mumfrey.liteloader.api.manager.APIRegistry; |
27 | 27 | import com.mumfrey.liteloader.common.LoadingProgress; |
28 | 28 | import com.mumfrey.liteloader.core.api.LiteLoaderCoreAPI; |
29 | 29 | import com.mumfrey.liteloader.interfaces.LoaderEnumerator; |
30 | -import com.mumfrey.liteloader.launch.ClassPathUtilities; | |
31 | -import com.mumfrey.liteloader.launch.LiteLoaderTweaker; | |
32 | 30 | import com.mumfrey.liteloader.launch.LoaderBootstrap; |
33 | 31 | import com.mumfrey.liteloader.launch.LoaderEnvironment; |
34 | 32 | import com.mumfrey.liteloader.launch.LoaderProperties; |
35 | -import com.mumfrey.liteloader.launch.RealmsJsonUpdateThread; | |
36 | 33 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
37 | 34 | |
38 | 35 | /** |
... | ... | @@ -141,8 +138,6 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP |
141 | 138 | */ |
142 | 139 | private EnabledModsList enabledModsList; |
143 | 140 | |
144 | - private RealmsJsonUpdateThread realmsJsonUpdateThread; | |
145 | - | |
146 | 141 | /** |
147 | 142 | * @param gameDirectory |
148 | 143 | * @param assetsDirectory |
... | ... | @@ -177,8 +172,6 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP |
177 | 172 | this.initAPIs(apisToLoad); |
178 | 173 | this.apiProvider = this.apiRegistry.getProvider(); |
179 | 174 | this.apiAdapter = this.apiRegistry.getAdapter(); |
180 | - | |
181 | - this.setupRealmsVersionCheck(profile); | |
182 | 175 | } |
183 | 176 | |
184 | 177 | /** |
... | ... | @@ -328,8 +321,6 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP |
328 | 321 | if (this.enumerator == null) return; |
329 | 322 | |
330 | 323 | LiteLoader.invokePostInit(); |
331 | - | |
332 | - this.runRealmsVersionCheck(); | |
333 | 324 | } |
334 | 325 | |
335 | 326 | /** |
... | ... | @@ -688,36 +679,4 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP |
688 | 679 | { |
689 | 680 | return this.apiAdapter.getPacketTransformers(); |
690 | 681 | } |
691 | - | |
692 | - private void setupRealmsVersionCheck(String profile) | |
693 | - { | |
694 | - if (!this.getAndStoreBooleanProperty(LoaderProperties.OPTION_UPDATE_REALMS, true)) | |
695 | - { | |
696 | - return; | |
697 | - } | |
698 | - | |
699 | - try | |
700 | - { | |
701 | - File realmsContainer = ClassPathUtilities.getPathToResource(LiteLoaderTweaker.class, "/net/minecraft/realms/Realms.class"); | |
702 | - if (realmsContainer == null) return; | |
703 | - | |
704 | - File versionsDir = realmsContainer.getParentFile().getParentFile(); | |
705 | - if (versionsDir.exists() && "versions".equals(versionsDir.getName())) | |
706 | - { | |
707 | - this.realmsJsonUpdateThread = new RealmsJsonUpdateThread(versionsDir, profile, LiteLoaderTweaker.VERSION); | |
708 | - } | |
709 | - } | |
710 | - catch (Exception ex) | |
711 | - { | |
712 | - ex.printStackTrace(); | |
713 | - } | |
714 | - } | |
715 | - | |
716 | - private void runRealmsVersionCheck() | |
717 | - { | |
718 | - if (this.realmsJsonUpdateThread != null) | |
719 | - { | |
720 | - this.realmsJsonUpdateThread.start(); | |
721 | - } | |
722 | - } | |
723 | 682 | } | ... | ... |
java/common/com/mumfrey/liteloader/launch/LoaderProperties.java
... | ... | @@ -69,7 +69,6 @@ public interface LoaderProperties |
69 | 69 | public static final String OPTION_NO_HIDE_TAB = "tabAlwaysExpanded"; |
70 | 70 | public static final String OPTION_BRAND = "brand"; |
71 | 71 | public static final String OPTION_LOADING_BAR = "loadingbar"; |
72 | - public static final String OPTION_UPDATE_REALMS = "realmsUpdateCheck"; | |
73 | 72 | |
74 | 73 | // Enumerator properties |
75 | 74 | public static final String OPTION_SEARCH_MODS = "search.mods"; | ... | ... |
java/common/com/mumfrey/liteloader/launch/RealmsJsonUpdateThread.java deleted
100644 → 0
1 | -package com.mumfrey.liteloader.launch; | |
2 | - | |
3 | -import java.io.File; | |
4 | -import java.io.FileReader; | |
5 | -import java.io.FileWriter; | |
6 | -import java.net.URI; | |
7 | -import java.util.List; | |
8 | -import java.util.Map; | |
9 | -import java.util.Map.Entry; | |
10 | - | |
11 | -import org.apache.commons.io.IOUtils; | |
12 | - | |
13 | -import com.google.common.base.Strings; | |
14 | -import com.google.gson.Gson; | |
15 | -import com.google.gson.GsonBuilder; | |
16 | -import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | |
17 | -import com.mumfrey.liteloader.util.net.HttpStringRetriever; | |
18 | - | |
19 | -/** | |
20 | - * Attempt to keep the version JSON we were launched from in sync with the latest lib version for this version of MC | |
21 | - * | |
22 | - * @author Adam Mummery-Smith | |
23 | - */ | |
24 | -public class RealmsJsonUpdateThread extends Thread | |
25 | -{ | |
26 | - private static final String DOWNLOAD_BASE_URL = "http://s3.amazonaws.com/Minecraft.Download/"; | |
27 | - | |
28 | - private static final String REALMS_LIB_PATH = "com.mojang:realms"; | |
29 | - | |
30 | - private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |
31 | - | |
32 | - private final File versionsDir; | |
33 | - | |
34 | - private final String version; | |
35 | - | |
36 | - private final URI uri; | |
37 | - | |
38 | - public RealmsJsonUpdateThread(File versionsDir, String version, String parentVersion) | |
39 | - { | |
40 | - this.versionsDir = versionsDir; | |
41 | - this.version = version; | |
42 | - this.uri = URI.create(String.format("%sversions/%2$s/%2$s.json", RealmsJsonUpdateThread.DOWNLOAD_BASE_URL, parentVersion)); | |
43 | - | |
44 | - this.setName("Realms JSON update thread"); | |
45 | - this.setDaemon(true); | |
46 | - } | |
47 | - | |
48 | - @Override | |
49 | - public void run() | |
50 | - { | |
51 | - if (this.isLocalJsonUpToDate()) | |
52 | - { | |
53 | - LiteLoaderLogger.info("Realms JSON thread is skipping update check, version JSON file was recently modified"); | |
54 | - return; | |
55 | - } | |
56 | - | |
57 | - Map<String, ?> localJson = this.getLocalVersionJson(); | |
58 | - if (localJson == null) | |
59 | - { | |
60 | - LiteLoaderLogger.info("Realms JSON thread failed to locate the local version JSON for version %s. The realms library reference can not be updated", this.version); | |
61 | - return; | |
62 | - } | |
63 | - | |
64 | - Map<String, ?> remoteJson = this.getRemoteVersionJson(); | |
65 | - if (remoteJson == null) | |
66 | - { | |
67 | - LiteLoaderLogger.info("Realms JSON thread failed to fetch the vanilla JSON. The realms library reference will not be updated"); | |
68 | - return; | |
69 | - } | |
70 | - | |
71 | - String realmsVersionRemote = this.getLibraryVersion(remoteJson, RealmsJsonUpdateThread.REALMS_LIB_PATH); | |
72 | - if (realmsVersionRemote == null) | |
73 | - { | |
74 | - LiteLoaderLogger.info("Realms JSON thread failed to parse remote version JSON. The realms library reference can not be updated"); | |
75 | - return; | |
76 | - } | |
77 | - | |
78 | - String realmsVersionLocal = this.getLibraryVersion(localJson, RealmsJsonUpdateThread.REALMS_LIB_PATH); | |
79 | - if (realmsVersionLocal == null) | |
80 | - { | |
81 | - LiteLoaderLogger.info("Realms JSON thread failed to parse local version JSON. The realms library reference can not be updated"); | |
82 | - return; | |
83 | - } | |
84 | - | |
85 | - if (realmsVersionRemote.equals(realmsVersionLocal)) | |
86 | - { | |
87 | - LiteLoaderLogger.info("Realms library reference is up-to-date. Current version is %s", realmsVersionRemote); | |
88 | - return; | |
89 | - } | |
90 | - | |
91 | - LiteLoaderLogger.info("Realms library reference is out of date. Current version %s, found remote version %s. Attempting to update version JSON.", realmsVersionLocal, realmsVersionRemote); | |
92 | - if (!this.setLibraryVersion(localJson, RealmsJsonUpdateThread.REALMS_LIB_PATH, realmsVersionRemote)) | |
93 | - { | |
94 | - LiteLoaderLogger.warning("Could not update the realms library version in the version JSON"); | |
95 | - return; | |
96 | - } | |
97 | - | |
98 | - if (!this.writeLocalVersionJson(localJson)) | |
99 | - { | |
100 | - LiteLoaderLogger.warning("Could not write the updated version JSON"); | |
101 | - return; | |
102 | - } | |
103 | - | |
104 | - LiteLoaderLogger.info("Realms library reference was successfully updated. Current version is now %s", realmsVersionRemote); | |
105 | - } | |
106 | - | |
107 | - private boolean writeLocalVersionJson(Map<String, ?> localJson) | |
108 | - { | |
109 | - File versionJsonFile = this.getLocalVersionJsonFile(); | |
110 | - FileWriter writer = null; | |
111 | - | |
112 | - try | |
113 | - { | |
114 | - writer = new FileWriter(versionJsonFile); | |
115 | - this.gson.toJson(localJson, writer); | |
116 | - } | |
117 | - catch (Exception ex) | |
118 | - { | |
119 | - ex.printStackTrace(); | |
120 | - } | |
121 | - finally | |
122 | - { | |
123 | - IOUtils.closeQuietly(writer); | |
124 | - } | |
125 | - | |
126 | - return true; | |
127 | - } | |
128 | - | |
129 | - @SuppressWarnings("unchecked") | |
130 | - private String getLibraryVersion(Map<String, ?> json, String libraryName) | |
131 | - { | |
132 | - for (Map<String, String> library : (List<Map<String, String>>)json.get("libraries")) | |
133 | - { | |
134 | - try | |
135 | - { | |
136 | - for (Entry<String, ?> entry : library.entrySet()) | |
137 | - { | |
138 | - String keyName = entry.getKey(); | |
139 | - if ("name".equals(keyName)) | |
140 | - { | |
141 | - String libName = entry.getValue().toString(); | |
142 | - if (libName.startsWith(libraryName)) | |
143 | - { | |
144 | - return libName.substring(libraryName.length() + 1); | |
145 | - } | |
146 | - } | |
147 | - } | |
148 | - } | |
149 | - catch (Exception ex) {} | |
150 | - } | |
151 | - | |
152 | - return null; | |
153 | - } | |
154 | - | |
155 | - @SuppressWarnings("unchecked") | |
156 | - private boolean setLibraryVersion(Map<String, ?> json, String libraryName, String newVersion) | |
157 | - { | |
158 | - int libraryIndex = this.getLibraryIndex(json, libraryName); | |
159 | - if (libraryIndex > -1) | |
160 | - { | |
161 | - List<Map<String, Object>> libraries = (List<Map<String, Object>>)json.get("libraries"); | |
162 | - Map<String, Object> library = libraries.get(libraryIndex); | |
163 | - library.put("name", String.format("%s:%s", libraryName, newVersion)); | |
164 | - return true; | |
165 | - } | |
166 | - | |
167 | - return false; | |
168 | - } | |
169 | - | |
170 | - /** | |
171 | - * @param json | |
172 | - * @param libraryName | |
173 | - * @return | |
174 | - */ | |
175 | - @SuppressWarnings("unchecked") | |
176 | - private int getLibraryIndex(Map<String, ?> json, String libraryName) | |
177 | - { | |
178 | - List<Map<String, ?>> libraries = (List<Map<String, ?>>)json.get("libraries"); | |
179 | - for (int index = 0; index < libraries.size(); index++) | |
180 | - { | |
181 | - try | |
182 | - { | |
183 | - Map<String, ?> library = libraries.get(index); | |
184 | - for (Entry<String, ?> entry : library.entrySet()) | |
185 | - { | |
186 | - String keyName = entry.getKey(); | |
187 | - if ("name".equals(keyName)) | |
188 | - { | |
189 | - String libName = entry.getValue().toString(); | |
190 | - if (libName.startsWith(libraryName)) | |
191 | - { | |
192 | - return index; | |
193 | - } | |
194 | - } | |
195 | - } | |
196 | - } | |
197 | - catch (Exception ex) {} | |
198 | - } | |
199 | - | |
200 | - return -1; | |
201 | - } | |
202 | - | |
203 | - @SuppressWarnings("unchecked") | |
204 | - private Map<String, ?> getRemoteVersionJson() | |
205 | - { | |
206 | - try | |
207 | - { | |
208 | - HttpStringRetriever http = new HttpStringRetriever(); | |
209 | - String json = http.fetch(this.uri.toURL()); | |
210 | - if (!Strings.isNullOrEmpty(json)) | |
211 | - { | |
212 | - return this.gson.fromJson(json, Map.class); | |
213 | - } | |
214 | - } | |
215 | - catch (Exception ex) | |
216 | - { | |
217 | - ex.printStackTrace(); | |
218 | - } | |
219 | - | |
220 | - return null; | |
221 | - } | |
222 | - | |
223 | - @SuppressWarnings("unchecked") | |
224 | - private Map<String, ?> getLocalVersionJson() | |
225 | - { | |
226 | - File versionJsonFile = this.getLocalVersionJsonFile(); | |
227 | - if (versionJsonFile == null || !versionJsonFile.exists()) return null; | |
228 | - | |
229 | - FileReader reader = null; | |
230 | - | |
231 | - try | |
232 | - { | |
233 | - reader = new FileReader(versionJsonFile); | |
234 | - return this.gson.fromJson(reader, Map.class); | |
235 | - } | |
236 | - catch (Exception ex) | |
237 | - { | |
238 | - ex.printStackTrace(); | |
239 | - } | |
240 | - finally | |
241 | - { | |
242 | - IOUtils.closeQuietly(reader); | |
243 | - } | |
244 | - | |
245 | - return null; | |
246 | - } | |
247 | - | |
248 | - private boolean isLocalJsonUpToDate() | |
249 | - { | |
250 | - File versionJsonFile = this.getLocalVersionJsonFile(); | |
251 | - if (versionJsonFile == null || !versionJsonFile.exists()) return false; | |
252 | - | |
253 | - long deltaTime = System.currentTimeMillis() - versionJsonFile.lastModified(); | |
254 | - return deltaTime < 86400000; | |
255 | - } | |
256 | - | |
257 | - /** | |
258 | - * @return | |
259 | - */ | |
260 | - private File getLocalVersionJsonFile() | |
261 | - { | |
262 | - File versionDir = new File(this.versionsDir, this.version); | |
263 | - if (!versionDir.exists() || !versionDir.isDirectory()) return null; | |
264 | - | |
265 | - File versionJsonFile = new File(versionDir, this.version + ".json"); | |
266 | - return versionJsonFile; | |
267 | - } | |
268 | -} |