Esempio n. 1
0
  @Override
  public void executeTask() throws Exception {
    HMCLog.log("Extracting install profiles...");

    ZipFile zipFile = new ZipFile(forgeInstaller);
    ZipEntry entry = zipFile.getEntry("install_profile.json");
    String content = NetUtils.getStreamContent(zipFile.getInputStream(entry));
    InstallProfile profile = C.gsonPrettyPrinting.fromJson(content, InstallProfile.class);

    File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
    if (!from.exists())
      if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
        if (!mp.version().install(profile.install.minecraft, null))
          throw new IllegalStateException(C.i18n("install.no_version"));
      } else throw new IllegalStateException(C.i18n("install.no_version"));

    File to = new File(gameDir, "versions" + File.separator + profile.install.target);
    to.mkdirs();

    HMCLog.log(
        "Copying jar..."
            + profile.install.minecraft
            + ".jar to "
            + profile.install.target
            + ".jar");
    FileUtils.copyFile(
        new File(from, profile.install.minecraft + ".jar"),
        new File(to, profile.install.target + ".jar"));
    HMCLog.log("Creating new version profile..." + profile.install.target + ".json");
    /*
     * for (MinecraftLibrary library : profile.versionInfo.libraries)
     * if (library.name.startsWith("net.minecraftforge:forge:"))
     * library.url = installerVersion.universal;
     */
    FileUtils.write(
        new File(to, profile.install.target + ".json"),
        C.gsonPrettyPrinting.toJson(profile.versionInfo));

    HMCLog.log("Extracting universal forge pack..." + profile.install.filePath);

    entry = zipFile.getEntry(profile.install.filePath);
    InputStream is = zipFile.getInputStream(entry);

    MinecraftLibrary forge = new MinecraftLibrary(profile.install.path);
    forge.init();
    File file = new File(gameDir, "libraries/" + forge.formatted);
    file.getParentFile().mkdirs();
    try (FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos)) {
      int c;
      while ((c = is.read()) != -1) bos.write((byte) c);
    }
  }
  @Override
  public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
    UserProfileProvider result = new UserProfileProvider();
    result.setUserType("mojang");
    if (ua.canPlayOnline()) {
      result.setUserName(info.username);
      result.setUserId(UUIDTypeAdapter.fromUUID(ua.getSelectedProfile().id));
    } else {
      String usr = info.username;
      if (info.username == null || !info.username.contains("@"))
        throw new AuthenticationException(C.i18n("login.not_email"));
      String pwd = info.password;

      if (!ua.isLoggedIn()) ua.setPassword(pwd);
      ua.setUsername(usr);
      ua.logIn();
      if (!ua.isLoggedIn()) throw new AuthenticationException(C.i18n("login.wrong_password"));
      GameProfile selectedProfile = ua.getSelectedProfile();
      GameProfile[] profiles = ua.getAvailableProfiles();
      String username;
      if (selectedProfile == null)
        if (ArrayUtils.isNotEmpty(profiles)) {
          String[] names = new String[profiles.length];
          for (int i = 0; i < profiles.length; i++) names[i] = profiles[i].name;
          Selector s = new Selector(null, names, C.i18n("login.choose_charactor"));
          s.setVisible(true);
          selectedProfile = profiles[s.sel];
          username = names[s.sel];
        } else username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
      else username = selectedProfile.name;
      result.setUserName(username);
      result.setUserId(
          selectedProfile == null
              ? OfflineAuthenticator.getUUIDFromUserName(username)
              : UUIDTypeAdapter.fromUUID(selectedProfile.id));
    }
    result.setUserProperties(
        new GsonBuilder()
            .registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer())
            .create()
            .toJson(ua.getUserProperties()));
    result.setUserPropertyMap(
        new GsonBuilder()
            .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
            .create()
            .toJson(ua.getUserProperties()));
    result.setAccessToken(ua.getAuthenticatedToken());
    result.setSession(ua.getAuthenticatedToken());
    return result;
  }
 @Override
 public UserProfileProvider loginBySettings() throws AuthenticationException {
   UserProfileProvider result = new UserProfileProvider();
   ua.logIn();
   if (!ua.isLoggedIn()) throw new AuthenticationException(C.i18n("login.wrong_password"));
   GameProfile profile = ua.getSelectedProfile();
   result.setUserName(profile.name);
   result.setUserId(profile.id.toString());
   result.setUserProperties(
       new GsonBuilder()
           .registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer())
           .create()
           .toJson(ua.getUserProperties()));
   result.setUserPropertyMap(
       new GsonBuilder()
           .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
           .create()
           .toJson(ua.getUserProperties()));
   result.setAccessToken(ua.getAuthenticatedToken());
   result.setSession(ua.getAuthenticatedToken());
   return result;
 }
Esempio n. 4
0
 @Override
 public String getInfo() {
   return C.i18n("install.forge.install");
 }
 @Override
 public String getName() {
   return C.i18n("login.methods.yggdrasil");
 }