Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. package net.minecraft.launcher.versions;
  2.  
  3. import java.io.File;
  4. import java.net.MalformedURLException;
  5. import java.net.Proxy;
  6. import java.net.URL;
  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.Date;
  10. import java.util.HashSet;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.Set;
  14.  
  15. import net.minecraft.launcher.OperatingSystem;
  16. import net.minecraft.launcher.updater.download.ChecksummedDownloadable;
  17. import net.minecraft.launcher.updater.download.Downloadable;
  18.  
  19. public class CompleteVersion
  20. implements Version
  21. {
  22. private String id;
  23. private Date time;
  24. private Date releaseTime;
  25. private ReleaseType type;
  26. private String minecraftArguments;
  27. private List<Library> libraries;
  28. private String mainClass;
  29. private int minimumLauncherVersion;
  30. private String incompatibilityReason;
  31. private String assets;
  32. private List<Rule> rules;
  33. private transient boolean synced = false;
  34.  
  35. public CompleteVersion() {}
  36.  
  37. public CompleteVersion(String id, Date releaseTime, Date updateTime, ReleaseType type, String mainClass, String minecraftArguments)
  38. {
  39. if ((id == null) || (id.length() == 0)) {
  40. throw new IllegalArgumentException("ID cannot be null or empty");
  41. }
  42. if (releaseTime == null) {
  43. throw new IllegalArgumentException("Release time cannot be null");
  44. }
  45. if (updateTime == null) {
  46. throw new IllegalArgumentException("Update time cannot be null");
  47. }
  48. if (type == null) {
  49. throw new IllegalArgumentException("Release type cannot be null");
  50. }
  51. if ((mainClass == null) || (mainClass.length() == 0)) {
  52. throw new IllegalArgumentException("Main class cannot be null or empty");
  53. }
  54. if (minecraftArguments == null) {
  55. throw new IllegalArgumentException("Process arguments cannot be null or empty");
  56. }
  57. this.id = id;
  58. this.releaseTime = releaseTime;
  59. this.time = updateTime;
  60. this.type = type;
  61. this.mainClass = mainClass;
  62. this.libraries = new ArrayList();
  63. this.minecraftArguments = minecraftArguments;
  64. }
  65.  
  66. public CompleteVersion(CompleteVersion version)
  67. {
  68. this(version.getId(), version.getReleaseTime(), version.getUpdatedTime(), version.getType(), version.getMainClass(), version.getMinecraftArguments());
  69. this.minimumLauncherVersion = version.minimumLauncherVersion;
  70. this.incompatibilityReason = version.incompatibilityReason;
  71. for (Library library : version.getLibraries()) {
  72. this.libraries.add(new Library(library));
  73. }
  74. }
  75.  
  76. public CompleteVersion(Version version, String mainClass, String minecraftArguments)
  77. {
  78. this(version.getId(), version.getReleaseTime(), version.getUpdatedTime(), version.getType(), mainClass, minecraftArguments);
  79. }
  80.  
  81. public String getId()
  82. {
  83. return this.id;
  84. }
  85.  
  86. public ReleaseType getType()
  87. {
  88. return this.type;
  89. }
  90.  
  91. public Date getUpdatedTime()
  92. {
  93. return this.time;
  94. }
  95.  
  96. public Date getReleaseTime()
  97. {
  98. return this.releaseTime;
  99. }
  100.  
  101. public List<Library> getLibraries()
  102. {
  103. return this.libraries;
  104. }
  105.  
  106. public String getMainClass()
  107. {
  108. return this.mainClass;
  109. }
  110.  
  111. public void setUpdatedTime(Date time)
  112. {
  113. if (time == null) {
  114. throw new IllegalArgumentException("Time cannot be null");
  115. }
  116. this.time = time;
  117. }
  118.  
  119. public void setReleaseTime(Date time)
  120. {
  121. if (time == null) {
  122. throw new IllegalArgumentException("Time cannot be null");
  123. }
  124. this.releaseTime = time;
  125. }
  126.  
  127. public void setType(ReleaseType type)
  128. {
  129. if (type == null) {
  130. throw new IllegalArgumentException("Release type cannot be null");
  131. }
  132. this.type = type;
  133. }
  134.  
  135. public void setMainClass(String mainClass)
  136. {
  137. if ((mainClass == null) || (mainClass.length() == 0)) {
  138. throw new IllegalArgumentException("Main class cannot be null or empty");
  139. }
  140. this.mainClass = mainClass;
  141. }
  142.  
  143. public Collection<Library> getRelevantLibraries()
  144. {
  145. List result = new ArrayList();
  146. for (Library library : this.libraries) {
  147. if (library.appliesToCurrentEnvironment()) {
  148. result.add(library);
  149. }
  150. }
  151. return result;
  152. }
  153.  
  154. public Collection<File> getClassPath(OperatingSystem os, File base)
  155. {
  156. Collection<Library> libraries = getRelevantLibraries();
  157. Collection<File> result = new ArrayList();
  158. for (Library library : libraries) {
  159. if (library.getNatives() == null) {
  160. result.add(new File(base, "libraries/" + library.getArtifactPath()));
  161. }
  162. }
  163. result.add(new File(base, "versions/" + getId() + "/" + getId() + ".jar"));
  164.  
  165. return result;
  166. }
  167.  
  168. public Collection<String> getExtractFiles(OperatingSystem os)
  169. {
  170. Collection<Library> libraries = getRelevantLibraries();
  171. Collection<String> result = new ArrayList();
  172. for (Library library : libraries)
  173. {
  174. Map natives = library.getNatives();
  175. if ((natives != null) && (natives.containsKey(os))) {
  176. result.add("libraries/" + library.getArtifactPath((String)natives.get(os)));
  177. }
  178. }
  179. return result;
  180. }
  181.  
  182. public Set<String> getRequiredFiles(OperatingSystem os)
  183. {
  184. Set neededFiles = new HashSet();
  185. for (Library library : getRelevantLibraries()) {
  186. if (library.getNatives() != null)
  187. {
  188. String natives = (String)library.getNatives().get(os);
  189. if (natives != null) {
  190. neededFiles.add("libraries/" + library.getArtifactPath(natives));
  191. }
  192. }
  193. else
  194. {
  195. neededFiles.add("libraries/" + library.getArtifactPath());
  196. }
  197. }
  198. return neededFiles;
  199. }
  200.  
  201. public Set<Downloadable> getRequiredDownloadables(OperatingSystem os, Proxy proxy, File targetDirectory, boolean ignoreLocalFiles)
  202. throws MalformedURLException
  203. {
  204. Set neededFiles = new HashSet();
  205. for (Library library : getRelevantLibraries())
  206. {
  207. String file = null;
  208. if (library.getNatives() != null)
  209. {
  210. String natives = (String)library.getNatives().get(os);
  211. if (natives != null) {
  212. file = library.getArtifactPath(natives);
  213. }
  214. }
  215. else
  216. {
  217. file = library.getArtifactPath();
  218. }
  219. if (file != null)
  220. {
  221. URL url = new URL(library.getDownloadUrl() + file);
  222. File local = new File(targetDirectory, "libraries/" + file);
  223. if ((!local.isFile()) || (!library.hasCustomUrl())) {
  224. neededFiles.add(new ChecksummedDownloadable(proxy, url, local, ignoreLocalFiles));
  225. }
  226. }
  227. }
  228. return neededFiles;
  229. }
  230.  
  231. public String toString()
  232. {
  233. return "CompleteVersion{id='" + this.id + '\'' + ", time=" + this.time + ", type=" + this.type + ", libraries=" + this.libraries + ", mainClass='" + this.mainClass + '\'' + ", minimumLauncherVersion=" + this.minimumLauncherVersion + '}';
  234. }
  235.  
  236. public String getMinecraftArguments()
  237. {
  238. return this.minecraftArguments;
  239. }
  240.  
  241. public void setMinecraftArguments(String minecraftArguments)
  242. {
  243. if (minecraftArguments == null) {
  244. throw new IllegalArgumentException("Process arguments cannot be null or empty");
  245. }
  246. this.minecraftArguments = minecraftArguments;
  247. }
  248.  
  249. public int getMinimumLauncherVersion()
  250. {
  251. return this.minimumLauncherVersion;
  252. }
  253.  
  254. public void setMinimumLauncherVersion(int minimumLauncherVersion)
  255. {
  256. this.minimumLauncherVersion = minimumLauncherVersion;
  257. }
  258.  
  259. public boolean appliesToCurrentEnvironment()
  260. {
  261. if (this.rules == null) {
  262. return true;
  263. }
  264. Rule.Action lastAction = Rule.Action.DISALLOW;
  265. for (Rule rule : this.rules)
  266. {
  267. Rule.Action action = rule.getAppliedAction();
  268. if (action != null) {
  269. lastAction = action;
  270. }
  271. }
  272. return lastAction == Rule.Action.ALLOW;
  273. }
  274.  
  275. public void setIncompatibilityReason(String incompatibilityReason)
  276. {
  277. this.incompatibilityReason = incompatibilityReason;
  278. }
  279.  
  280. public String getIncompatibilityReason()
  281. {
  282. return this.incompatibilityReason;
  283. }
  284.  
  285. public boolean isSynced()
  286. {
  287. return this.synced;
  288. }
  289.  
  290. public void setSynced(boolean synced)
  291. {
  292. this.synced = synced;
  293. }
  294.  
  295. public String getAssets()
  296. {
  297. return this.assets;
  298. }
  299.  
  300. public void setAssets(String assets)
  301. {
  302. this.assets = assets;
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement