Advertisement
SoKnight

Untitled

May 7th, 2023
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.03 KB | None | 0 0
  1.                   File versionJsonFile = new File(versionTarget, VersionInfo.getVersionTarget() + ".json");
  2.  
  3.                   try {
  4.                      ByteArrayOutputStream bos = new ByteArrayOutputStream();
  5.                      Writer writer = new OutputStreamWriter(bos, Charsets.UTF_8);
  6.                      PrettyJsonFormatter.fieldOrderPreservingPrettyJsonFormatter().format(versionJson, writer);
  7.                      writer.close();
  8.                      byte[] output = bos.toByteArray();
  9.                      List<AppendInfo> lst = Lists.newArrayList();
  10.                      Iterator var23 = VersionInfo.getOptionals().iterator();
  11.  
  12.                      while(var23.hasNext()) {
  13.                         OptionalLibrary opt = (OptionalLibrary)var23.next();
  14.                         if (optionals.apply(opt.getArtifact()) && opt.isInjected()) {
  15.                            lst.add(new ClientInstall.AppendInfo(opt.getArtifact(), opt.getMaven()));
  16.                         }
  17.                      }
  18.  
  19.                      var23 = transforms.iterator();
  20.  
  21.                      while(var23.hasNext()) {
  22.                         TransformInfo info = (TransformInfo)var23.next();
  23.                         if (info.append) {
  24.                            lst.add(new ClientInstall.AppendInfo(info.output.getDescriptor(), info.maven));
  25.                         }
  26.                      }
  27.  
  28.                      if (lst.size() > 0) {
  29.                         BufferedReader reader = new BufferedReader(new StringReader(new String(output, Charsets.UTF_8)));
  30.                         bos = new ByteArrayOutputStream();
  31.                         PrintWriter printer = new PrintWriter(new OutputStreamWriter(bos, Charsets.UTF_8));
  32.                         String line = null;
  33.                         String prefix = null;
  34.                         boolean added = false;
  35.  
  36.                         while(true) {
  37.                            while((line = reader.readLine()) != null) {
  38.                               if (added) {
  39.                                  printer.println(line);
  40.                               } else {
  41.                                  if (line.contains("\"libraries\": [")) {
  42.                                     prefix = line.substring(0, line.indexOf(34));
  43.                                  } else if (prefix != null && line.startsWith(prefix + "]")) {
  44.                                     printer.println(prefix + "\t,");
  45.  
  46.                                     for(int x = 0; x < lst.size(); ++x) {
  47.                                        ClientInstall.AppendInfo info = (ClientInstall.AppendInfo)lst.get(x);
  48.                                        printer.println(prefix + "\t{");
  49.                                        printer.println(prefix + "\t\t\"name\": \"" + info.artifact + "\"" + info.maven == null ? "" : ",");
  50.                                        if (info.maven != null) {
  51.                                           printer.println(prefix + "\t\t\"url\": \"" + info.maven + "\"");
  52.                                        }
  53.  
  54.                                        if (x < lst.size() - 1) {
  55.                                           printer.println(prefix + "\t},");
  56.                                        } else {
  57.                                           printer.println(prefix + "\t}");
  58.                                        }
  59.                                     }
  60.  
  61.                                     added = true;
  62.                                  }
  63.  
  64.                                  printer.println(line);
  65.                               }
  66.                            }
  67.  
  68.                            printer.close();
  69.                            output = bos.toByteArray();
  70.                            break;
  71.                         }
  72.                      }
  73.  
  74.                      Files.write(output, versionJsonFile);
  75.                   } catch (Exception var33) {
  76.                      JOptionPane.showMessageDialog(null, "There was a problem writing the launcher version data,  is it write protected?", "Error", 0);
  77.                      return false;
  78.                   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement