Advertisement
Guest User

Source-Code SM64 R96&RTX Installer v3.0.4

a guest
May 14th, 2021
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.80 KB | None | 0 0
  1. package de.sm64pcrtx;
  2.  
  3. import java.awt.Desktop;
  4. import java.awt.EventQueue;
  5. import java.awt.HeadlessException;
  6. import javax.swing.JFileChooser;
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.border.EmptyBorder;
  10. import javax.swing.filechooser.FileNameExtensionFilter;
  11. import javax.imageio.ImageIO;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.io.BufferedReader;
  15. import java.io.File;
  16. import java.io.FileInputStream;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import java.net.URL;
  22. import java.nio.file.Files;
  23. import java.nio.file.StandardCopyOption;
  24. import java.security.MessageDigest;
  25. import java.security.NoSuchAlgorithmException;
  26. import java.util.Enumeration;
  27. import java.util.Scanner;
  28. import java.util.zip.ZipEntry;
  29. import java.util.zip.ZipFile;
  30. import java.awt.event.ActionEvent;
  31. import javax.swing.JLabel;
  32. import javax.swing.JOptionPane;
  33. import java.awt.Font;
  34. import javax.swing.JCheckBox;
  35.  
  36. public class Installer extends JFrame {
  37.     private static final long serialVersionUID = 1L;
  38.  
  39.     private String version = "v3.0.4";
  40.  
  41.     private String title = "Super Mario 64 Render96 & RayTracing Installer " + version;
  42.     private String titleShort = "SM64 R96 & RT Installer " + version;
  43.     private String notSelected = "None";
  44.  
  45.     private JPanel contentPane;
  46.     private JButton buttonCompile;
  47.  
  48.     private File msys2 = null;
  49.     private JLabel labelMsys2;
  50.     private JButton buttonMsys2;
  51.     private JButton buttonMsys2Download;
  52.     private JButton buttonMsys2Help;
  53.     private String selectedMsys2Prefix = "MSYS2-Path: ";
  54.  
  55.     private File rom = null;
  56.     private JLabel labelRom;
  57.     private JButton buttonRom;
  58.     private JButton buttonRomHelp;
  59.     private String selectedRomPrefix = "Base-ROM: ";
  60.  
  61.     private File path = null;
  62.     private JLabel labelPath;
  63.     private JButton buttonPath;
  64.     private JButton buttonPathHelp;
  65.     private String selectedPathPrefix = "Target-Path: ";
  66.  
  67.     private JCheckBox checkBoxRaytracing;
  68.     private JCheckBox checkBoxRender96Models;
  69.     private JCheckBox checkBoxRender96Textures;
  70.     private JCheckBox checkBoxHQMusic;
  71.  
  72.     private JCheckBox checkBoxSavegameFileA;
  73.     private JCheckBox checkBoxSavegameFileB;
  74.     private JCheckBox checkBoxSavegameFileC;
  75.     private JCheckBox checkBoxSavegameFileD;
  76.  
  77.     private String linkMediafireTos = "https://www.mediafire.com/policies/terms_of_service.php";
  78.     private String linkBuilder = "https://sm64pc.info/sm64pcbuilder2/";
  79.     private String linkMsys = "https://www.msys2.org/";
  80.     private String linkRender96 = "https://linktr.ee/Render96";
  81.     private String linkDiscordPcPort = "https://discord.gg/ZezK78p";
  82.     private String linkDiscordHqMusic = "https://discord.gg/fjkzzteKCe";
  83.    
  84.     private String linkGithubRender96 = "https://github.com/Render96/Render96ex/archive/refs/heads/alpha.zip";
  85.     private String linkGithubRender96Raytracing = "https://github.com/Render96/Render96ex/archive/refs/heads/tester_rt64alpha.zip";
  86.     private String linkGithubDxilDll = "https://github.com/DarioSamo/sm64rt/raw/master/lib/rt64/dxil.dll";
  87.     private String linkGithubRt64libDll = "https://github.com/DarioSamo/sm64rt/raw/master/lib/rt64/rt64lib.dll";
  88.     private String linkMediafireModels = "https://www.mediafire.com/file/apywibprrjfjz9u/models.zip/file";
  89.     private String linkMediafireTextures = "https://www.mediafire.com/file/d22kbfjsguvo57p/textures.zip/file";
  90.     private String linkMediafireMusic = "https://www.mediafire.com/file/l0gfz5b2t7k3o16/hqmusic.zip/file";
  91.  
  92.     public static void main(String[] args) {
  93.         EventQueue.invokeLater(new Runnable() {
  94.             public void run() {
  95.                 try {
  96.                     Installer frame = new Installer();
  97.                     frame.setVisible(true);
  98.                 } catch (Exception e) {
  99.                     e.printStackTrace();
  100.                 }
  101.             }
  102.         });
  103.     }
  104.  
  105.     public Installer() throws IOException {
  106.         setResizable(false);
  107.         File currentFolder = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath());
  108.  
  109.         setTitle(title);
  110.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  111.         setBounds(100, 100, 1300, 403);
  112.         contentPane = new JPanel();
  113.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  114.         setContentPane(contentPane);
  115.         contentPane.setLayout(null);
  116.         setIconImage(ImageIO.read(this.getClass().getResourceAsStream("icon.png")));
  117.         setLocationRelativeTo(null);
  118.  
  119.         labelMsys2 = new JLabel(selectedMsys2Prefix + notSelected);
  120.         labelMsys2.setBounds(240, 15, 624, 14);
  121.         contentPane.add(labelMsys2);
  122.         buttonMsys2 = new JButton("Select MSYS2-Path");
  123.         buttonMsys2.setBounds(10, 11, 220, 23);
  124.         File defaultMsys2Path = new File("C:\\msys64");
  125.         if (defaultMsys2Path.exists() && new File(defaultMsys2Path + File.separator + "msys2_shell.cmd").exists() && new File(defaultMsys2Path + File.separator + "mingw64.exe").exists()) {
  126.             msys2 = defaultMsys2Path;
  127.             labelMsys2.setText(selectedMsys2Prefix + defaultMsys2Path.getAbsolutePath());
  128.         }
  129.         buttonMsys2.addActionListener(new ActionListener() {
  130.             public void actionPerformed(ActionEvent e) {
  131.                 JFileChooser chooserMsys = new JFileChooser();
  132.                 chooserMsys.setCurrentDirectory(currentFolder);
  133.                 chooserMsys.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  134.                 int returnVal = chooserMsys.showOpenDialog(null);
  135.                 if (returnVal == JFileChooser.APPROVE_OPTION) {
  136.                     msys2 = chooserMsys.getSelectedFile();
  137.                     labelMsys2.setText(selectedMsys2Prefix + msys2.getAbsolutePath());
  138.                     checkValid();
  139.                 }
  140.             }
  141.         });
  142.         contentPane.add(buttonMsys2);
  143.  
  144.         labelRom = new JLabel(selectedRomPrefix + notSelected);
  145.         labelRom.setBounds(240, 49, 624, 14);
  146.         contentPane.add(labelRom);
  147.         buttonRom = new JButton("Select Base-ROM (US, z64)");
  148.         buttonRom.setBounds(10, 45, 220, 23);
  149.         buttonRom.addActionListener(new ActionListener() {
  150.             public void actionPerformed(ActionEvent e) {
  151.                 JFileChooser chooserRom = new JFileChooser();
  152.                 chooserRom.setCurrentDirectory(currentFolder);
  153.                 chooserRom.setFileSelectionMode(JFileChooser.FILES_ONLY);
  154.                 chooserRom.setFileFilter(new FileNameExtensionFilter("*.z64 Files", "z64"));
  155.                 int returnVal = chooserRom.showOpenDialog(null);
  156.                 if (returnVal == JFileChooser.APPROVE_OPTION) {
  157.                     rom = chooserRom.getSelectedFile();
  158.                     labelRom.setText(selectedRomPrefix + rom.getAbsolutePath());
  159.                     checkValid();
  160.                 }
  161.             }
  162.         });
  163.         contentPane.add(buttonRom);
  164.  
  165.         labelPath = new JLabel(selectedPathPrefix + notSelected);
  166.         labelPath.setBounds(240, 83, 624, 14);
  167.         contentPane.add(labelPath);
  168.         buttonPath = new JButton("Select Target-Path");
  169.         buttonPath.setBounds(10, 79, 220, 23);
  170.         buttonPath.addActionListener(new ActionListener() {
  171.             public void actionPerformed(ActionEvent e) {
  172.                 JFileChooser chooserPath = new JFileChooser();
  173.                 chooserPath.setCurrentDirectory(currentFolder);
  174.                 chooserPath.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  175.                 int returnVal = chooserPath.showOpenDialog(null);
  176.                 if (returnVal == JFileChooser.APPROVE_OPTION) {
  177.                     path = traceCompilingFolder(chooserPath.getSelectedFile());
  178.                     labelPath.setText(selectedPathPrefix + path.getAbsolutePath());
  179.                     checkValid();
  180.                 }
  181.             }
  182.         });
  183.         contentPane.add(buttonPath);
  184.  
  185.         buttonCompile = new JButton("Compile the Game!");
  186.         buttonCompile.setFont(new Font("Tahoma", Font.BOLD, 18));
  187.         buttonCompile.addActionListener(new ActionListener() {
  188.             public void actionPerformed(ActionEvent e) {
  189.                 compile(checkBoxRaytracing.isSelected(), checkBoxRender96Models.isSelected(), checkBoxRender96Textures.isSelected(), checkBoxHQMusic.isSelected(), checkBoxSavegameFileA.isSelected(),
  190.                         checkBoxSavegameFileB.isSelected(), checkBoxSavegameFileC.isSelected(), checkBoxSavegameFileD.isSelected());
  191.             }
  192.         });
  193.         buttonCompile.setEnabled(false);
  194.         buttonCompile.setBounds(10, 308, 1264, 46);
  195.         contentPane.add(buttonCompile);
  196.  
  197.         checkBoxRaytracing = new JCheckBox("Install Raytracing");
  198.         checkBoxRaytracing.setSelected(true);
  199.         checkBoxRaytracing.setBounds(10, 119, 1164, 23);
  200.         contentPane.add(checkBoxRaytracing);
  201.  
  202.         checkBoxRender96Models = new JCheckBox("Install Render96 Models");
  203.         checkBoxRender96Models.setSelected(true);
  204.         checkBoxRender96Models.setBounds(10, 145, 1164, 23);
  205.         contentPane.add(checkBoxRender96Models);
  206.  
  207.         checkBoxRender96Textures = new JCheckBox("Install Render96 Textures");
  208.         checkBoxRender96Textures.setSelected(true);
  209.         checkBoxRender96Textures.setBounds(10, 171, 1164, 23);
  210.         contentPane.add(checkBoxRender96Textures);
  211.  
  212.         checkBoxHQMusic = new JCheckBox("Install HQ Music");
  213.         checkBoxHQMusic.setSelected(true);
  214.         checkBoxHQMusic.setBounds(10, 197, 1164, 23);
  215.         contentPane.add(checkBoxHQMusic);
  216.  
  217.         checkBoxSavegameFileA = new JCheckBox("100% Savegame [FILE A]");
  218.         checkBoxSavegameFileA.setBounds(10, 232, 200, 23);
  219.         contentPane.add(checkBoxSavegameFileA);
  220.  
  221.         checkBoxSavegameFileB = new JCheckBox("100% Savegame [FILE B]");
  222.         checkBoxSavegameFileB.setBounds(230, 232, 200, 23);
  223.         contentPane.add(checkBoxSavegameFileB);
  224.  
  225.         checkBoxSavegameFileC = new JCheckBox("100% Savegame [FILE C]");
  226.         checkBoxSavegameFileC.setBounds(10, 258, 200, 23);
  227.         contentPane.add(checkBoxSavegameFileC);
  228.  
  229.         checkBoxSavegameFileD = new JCheckBox("100% Savegame [FILE D]");
  230.         checkBoxSavegameFileD.setSelected(true);
  231.         checkBoxSavegameFileD.setBounds(230, 258, 200, 23);
  232.         contentPane.add(checkBoxSavegameFileD);
  233.  
  234.         buttonMsys2Download = new JButton("Download MSYS2");
  235.         buttonMsys2Download.addActionListener(new ActionListener() {
  236.             public void actionPerformed(ActionEvent e) {
  237.                 try {
  238.                     Desktop.getDesktop().browse(new URL(linkMsys).toURI());
  239.                 } catch (Exception e1) {
  240.                 }
  241.             }
  242.         });
  243.         buttonMsys2Download.setBounds(974, 11, 190, 23);
  244.         contentPane.add(buttonMsys2Download);
  245.  
  246.         buttonRomHelp = new JButton("What is the Base-ROM?");
  247.         buttonRomHelp.addActionListener(new ActionListener() {
  248.             public void actionPerformed(ActionEvent e) {
  249.                 showMsgBox(
  250.                         "The Base-ROM is needed to compile the Project.\nYou have to extract the Base-ROM from your original Nintendo 64 Super Mario 64 cartridge (US version only) and save it as a \".z64\" file.",
  251.                         JOptionPane.INFORMATION_MESSAGE);
  252.             }
  253.         });
  254.         buttonRomHelp.setBounds(974, 45, 300, 23);
  255.         contentPane.add(buttonRomHelp);
  256.  
  257.         buttonPathHelp = new JButton("What is the Target-Path?");
  258.         buttonPathHelp.addActionListener(new ActionListener() {
  259.             public void actionPerformed(ActionEvent e) {
  260.                 showMsgBox("A new subfolder will be automatically created inside the Target-Path.\nThe project will be installed inside the new automatically created subfolder.",
  261.                         JOptionPane.INFORMATION_MESSAGE);
  262.             }
  263.         });
  264.         buttonPathHelp.setBounds(974, 79, 300, 23);
  265.         contentPane.add(buttonPathHelp);
  266.  
  267.         buttonMsys2Help = new JButton("Help");
  268.         buttonMsys2Help.addActionListener(new ActionListener() {
  269.             public void actionPerformed(ActionEvent e) {
  270.                 showMsgBox("Please select the Installation-Path of your MSYS2 installation (Default Installation-Path: \"C:\\msys64\")!", JOptionPane.INFORMATION_MESSAGE);
  271.             }
  272.         });
  273.         buttonMsys2Help.setBounds(1174, 11, 100, 23);
  274.         contentPane.add(buttonMsys2Help);
  275.  
  276.         checkValid();
  277.        
  278.         String msgMediafire = "Mediafire will record how many times the HD-Textures, the HD-Models and the HQ Music will be downloaded, etc.!"
  279.                 + "\nIf you are living in the european union you have to agree to Mediafire's ToS before continuing!\n\n";
  280.        
  281.         JButton jbt_mediafire_dontagree = new JButton("I DO NOT AGREE TO MEDIAFIRE'S ToS");
  282.         jbt_mediafire_dontagree.addActionListener(new ActionListener() {
  283.             @Override
  284.             public void actionPerformed(ActionEvent e) {
  285.                 try {
  286.                     System.exit(0);
  287.                 } catch (Exception e1) {
  288.                 }
  289.             }
  290.         });
  291.        
  292.         Font buttonFont = new Font(jbt_mediafire_dontagree.getFont().getName(), Font.ITALIC, jbt_mediafire_dontagree.getFont().getSize());
  293.        
  294.         JButton jbt_mediafire_tos = new JButton("Mediafire's ToS");
  295.         jbt_mediafire_tos.addActionListener(new ActionListener() {
  296.             @Override
  297.             public void actionPerformed(ActionEvent e) {
  298.                 try {
  299.                     Desktop.getDesktop().browse(new URL(linkMediafireTos).toURI());
  300.                 } catch (Exception e1) {
  301.                 }
  302.             }
  303.         });
  304.  
  305.         jbt_mediafire_tos.setFont(buttonFont);
  306.  
  307.         Object[] optionsMediafire = { "I AGREE TO MEDIAFIRE'S ToS / I DO NOT LIVE IN THE EUROPEAN UNION", jbt_mediafire_dontagree, jbt_mediafire_tos};
  308.        
  309.         int check_closed = JOptionPane.showOptionDialog(null, msgMediafire, titleShort, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, optionsMediafire, optionsMediafire[1]);
  310.  
  311.         if (check_closed == JOptionPane.CLOSED_OPTION) {
  312.             System.exit(0);
  313.         }
  314.  
  315.         JButton jbt_builder = new JButton("sm64pcBuilder2 Website");
  316.         jbt_builder.addActionListener(new ActionListener() {
  317.             @Override
  318.             public void actionPerformed(ActionEvent e) {
  319.                 try {
  320.                     Desktop.getDesktop().browse(new URL(linkBuilder).toURI());
  321.                 } catch (Exception e1) {
  322.                 }
  323.             }
  324.         });
  325.  
  326.         JButton jbt_render96 = new JButton("Render96 Website");
  327.         jbt_render96.addActionListener(new ActionListener() {
  328.             @Override
  329.             public void actionPerformed(ActionEvent e) {
  330.                 try {
  331.                     Desktop.getDesktop().browse(new URL(linkRender96).toURI());
  332.                 } catch (Exception e1) {
  333.                 }
  334.             }
  335.         });
  336.  
  337.         JButton jbt_discord_central = new JButton("SM64 PC Port Central Discord");
  338.         jbt_discord_central.addActionListener(new ActionListener() {
  339.             @Override
  340.             public void actionPerformed(ActionEvent e) {
  341.                 try {
  342.                     Desktop.getDesktop().browse(new URL(linkDiscordPcPort).toURI());
  343.                 } catch (Exception e1) {
  344.                 }
  345.             }
  346.         });
  347.  
  348.         JButton jbt_discord_music = new JButton("SM64 HQ Music Discord");
  349.         jbt_discord_music.addActionListener(new ActionListener() {
  350.             @Override
  351.             public void actionPerformed(ActionEvent e) {
  352.                 try {
  353.                     Desktop.getDesktop().browse(new URL(linkDiscordHqMusic).toURI());
  354.                 } catch (Exception e1) {
  355.                 }
  356.             }
  357.         });
  358.  
  359.         jbt_builder.setFont(buttonFont);
  360.         jbt_discord_central.setFont(buttonFont);
  361.         jbt_discord_music.setFont(buttonFont);
  362.         jbt_render96.setFont(buttonFont);
  363.  
  364.         Object[] options = { "CONTINUE THE INSTALLER", jbt_builder, jbt_render96, jbt_discord_central, jbt_discord_music };
  365.  
  366.         String msg = "This installer currently only works on windows operating systems!"
  367.                 + "\n\nThis installer This installer will build a playable technical preview version of Super Mario 64 Render96 & Raytracing."
  368.                 + "\nWhen it is finished it will be available in the sm64pcBuilder2." + "\n\nYou can also deselect raytracing in the installer for installing the normal Render96."
  369.                 + "\n\nI am not the author of sm64pcBuilder2 and have not developed on it. I also have not developed on everything else used in this installer!"
  370.                 + "\nPlease check out the Discords, the sm64pcBuilder2 and the Render96 Project and down below.\n\n";
  371.  
  372.         JOptionPane.showOptionDialog(null, msg, titleShort, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
  373.     }
  374.  
  375.     private File traceCompilingFolder(File rootPath) {
  376.         String pathDefault = rootPath.getAbsolutePath() + File.separator + "SM64_R96_RT_" + System.currentTimeMillis();
  377.         String pathString = pathDefault;
  378.         long number = 1;
  379.         while (new File(pathString).exists()) {
  380.             pathString = pathDefault + "_" + number;
  381.             number++;
  382.         }
  383.         return new File(pathString);
  384.     }
  385.  
  386.     private void compile(boolean raytracing, boolean installModels, boolean installTextures, boolean installHQMusic, boolean savegameA, boolean savegameB, boolean savegameC, boolean savegameD) {
  387.         new Thread(new Runnable() {
  388.             @Override
  389.             public void run() {
  390.                 if (checkValid()) {
  391.                     disableInput();
  392.                     int step = 1;
  393.                     int maxSteps = 7;
  394.                     String description = "";
  395.                     if (installModels) {
  396.                         maxSteps++;
  397.                     }
  398.                     if (installTextures) {
  399.                         maxSteps++;
  400.                     }
  401.                     if (installHQMusic) {
  402.                         maxSteps++;
  403.                     }
  404.                     if (savegameA || savegameB || savegameC || savegameD) {
  405.                         maxSteps++;
  406.                     }
  407.  
  408.                     String gitRepo = "";
  409.                     if (raytracing) {
  410.                         gitRepo = linkGithubRender96Raytracing;
  411.                     } else {
  412.                         gitRepo = linkGithubRender96;
  413.                     }
  414.  
  415.                     description = "Downloading GitHub Repository (~400MB)...";
  416.                     setInstallationProgress(step, maxSteps, description);
  417.                     if (downloadAndExtract(gitRepo, path, true)) {
  418.                         step++;
  419.                         description = "Copying Base-ROM...";
  420.                         setInstallationProgress(step, maxSteps, description);
  421.                         try {
  422.                             Files.copy(rom.toPath(), new File(path.getAbsolutePath() + File.separator + "baserom.us.z64").toPath(), StandardCopyOption.REPLACE_EXISTING);
  423.                             step++;
  424.                             description = "Downloading \"dxil.dll\"...";
  425.                             setInstallationProgress(step, maxSteps, description);
  426.                             try (InputStream in = new URL(linkGithubDxilDll).openStream()) {
  427.                                 File buildFolder = new File(path.getAbsolutePath() + File.separator + "build" + File.separator + "us_pc");
  428.                                 buildFolder.mkdirs();
  429.                                 Files.copy(in, new File(buildFolder.getAbsolutePath() + File.separator + "dxil.dll").toPath(), StandardCopyOption.REPLACE_EXISTING);
  430.                                 step++;
  431.                                 description = "Downloading \"rt64lib.dll\"...";
  432.                                 setInstallationProgress(step, maxSteps, description);
  433.                                 try (InputStream in2 = new URL(linkGithubRt64libDll).openStream()) {
  434.                                     Files.copy(in2, new File(buildFolder.getAbsolutePath() + File.separator + "rt64lib.dll").toPath(), StandardCopyOption.REPLACE_EXISTING);
  435.                                     in2.close();
  436.  
  437.                                     showMsgBox("Please close all MSYS2 programms before continuing!\nIf none are open or you just closed them click on \"OK\" or \"X\"!", JOptionPane.WARNING_MESSAGE);
  438.  
  439.                                     boolean msysClosed = false;
  440.  
  441.                                     Process process = Runtime.getRuntime().exec("tasklist.exe /FI \"IMAGENAME EQ mintty.exe\"");
  442.                                     Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
  443.                                     while (scanner.hasNext()) {
  444.                                         String line = scanner.nextLine();
  445.                                         if (line.contains(":")) {
  446.                                             msysClosed = true;
  447.                                             break;
  448.                                         }
  449.                                     }
  450.  
  451.                                     if (msysClosed) {
  452.                                         showMsgBox(
  453.                                                 "DO NOT CLOSE the upcoming three MSYS2 windows.\nThey will open and close automatically!\n\nThere will be some errors showing in the MSYS windows.\nJust ignore them, the installation will continue after a few seconds/minutes!",
  454.                                                 JOptionPane.INFORMATION_MESSAGE);
  455.  
  456.                                         step++;
  457.                                         description = "Updating MSYS2-Package \"pacman\"...";
  458.                                         setInstallationProgress(step, maxSteps, description);
  459.                                         Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -c \"pacman -Syuu --noconfirm\"");
  460.                                         waitForMysy();
  461.  
  462.                                         step++;
  463.                                         description = "Installing missing MSYS2-Dependencies...";
  464.                                         setInstallationProgress(step, maxSteps, description);
  465.                                         Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator
  466.                                                 + "msys2_shell.cmd -mingw64 -c \"pacman -Sy unzip make git mingw-w64-i686-gcc mingw-w64-x86_64-gcc mingw-w64-i686-glew mingw-w64-x86_64-glew mingw-w64-i686-SDL2 mingw-w64-i686-SDL mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL python3 --noconfirm\"");
  467.                                         waitForMysy();
  468.  
  469.                                         step++;
  470.                                         description = "Compiling the Project...";
  471.                                         setInstallationProgress(step, maxSteps, description);
  472.                                         if (raytracing) {
  473.                                             Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -where \"" + path.getAbsolutePath()
  474.                                                     + "\" -c \"make RENDER_API=RT64 EXTERNAL_DATA=1 -j16\"");
  475.                                         } else {
  476.                                             Runtime.getRuntime().exec(
  477.                                                     msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -where \"" + path.getAbsolutePath() + "\" -c \"make EXTERNAL_DATA=1 -j16\"");
  478.                                         }
  479.  
  480.                                         waitForMysy();
  481.  
  482.                                         if (installModels) {
  483.                                             step++;
  484.                                             description = "Downloading and Installing Render96 Models (~120MB)...";
  485.                                             setInstallationProgress(step, maxSteps, description);
  486.                                             downloadAndExtract(getDirectDownloadLink(linkMediafireModels, "models.zip"), buildFolder, false);
  487.                                         }
  488.                                         if (installTextures) {
  489.                                             step++;
  490.                                             description = "Downloading and Installing Render96 Textures (~540MB)...";
  491.                                             setInstallationProgress(step, maxSteps, description);
  492.                                             downloadAndExtract(getDirectDownloadLink(linkMediafireTextures, "textures.zip"), buildFolder, false);
  493.                                         }
  494.                                         if (installHQMusic) {
  495.                                             step++;
  496.                                             description = "Downloading and Installing HQ Music (~700MB)...";
  497.                                             setInstallationProgress(step, maxSteps, description);
  498.                                             downloadAndExtract(getDirectDownloadLink(linkMediafireMusic, "hqmusic.zip"), buildFolder, false);
  499.                                         }
  500.                                         if (savegameA || savegameB || savegameC || savegameD) {
  501.                                             step++;
  502.                                             description = "Installing Savegame(s)...";
  503.                                             setInstallationProgress(step, maxSteps, description);
  504.                                             String dataFolderPath = System.getenv("APPDATA") + File.separator + "sm64ex";
  505.                                             File dataFolder = new File(dataFolderPath);
  506.                                             if (!dataFolder.exists()) {
  507.                                                 dataFolder.mkdirs();
  508.                                             }
  509.                                             if (savegameA) {
  510.                                                 InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
  511.                                                 try {
  512.                                                     Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_0.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
  513.                                                 } catch (Exception e) {
  514.                                                 }
  515.                                                 is.close();
  516.                                             }
  517.                                             if (savegameB) {
  518.                                                 InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
  519.                                                 try {
  520.                                                     Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_1.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
  521.                                                 } catch (Exception e) {
  522.                                                 }
  523.                                                 is.close();
  524.                                             }
  525.                                             if (savegameC) {
  526.                                                 InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
  527.                                                 try {
  528.                                                     Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_2.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
  529.                                                 } catch (Exception e) {
  530.                                                 }
  531.                                                 is.close();
  532.                                             }
  533.                                             if (savegameD) {
  534.                                                 InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
  535.                                                 try {
  536.                                                     Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_3.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
  537.                                                 } catch (Exception e) {
  538.                                                 }
  539.                                                 is.close();
  540.                                             }
  541.                                         }
  542.  
  543.                                         showMsgBox("INSTALLATION COMPLETE!" + "\n\nYou can find the game inside the folder \"<Installation-Folder>\\build\\us_pc\\\""
  544.                                                 + "\nYou only need the content inside the \"us_pc\" folder for the game. You can delete everything else."
  545.                                                 + "\n\nYou have to manually enable the Render96 ModelPack ingame to see the Render96 models and textures"
  546.                                                 + "\n(Pause the game, go to DynOS, go to Model Pack, enable Render96 2.2)"
  547.                                                 + "\nAfter enabling the ModelPack you have to restart your game to see the reflective water."
  548.                                                 + "\n\nTo use a Gamecontroller, connect the controller to your PC before starting the game."
  549.                                                 + "\n\nTo play around with the raytracing settings open the menu for that with the F1-Key ingame.", JOptionPane.INFORMATION_MESSAGE);
  550.                                         Desktop.getDesktop().open(buildFolder);
  551.                                         for (File f : buildFolder.listFiles()) {
  552.                                             if (f.getName().toLowerCase().startsWith("sm64") && f.getName().toLowerCase().endsWith(".exe")) {
  553.                                                 Desktop.getDesktop().open(f);
  554.                                                 break;
  555.                                             }
  556.                                         }
  557.                                         System.exit(0);
  558.                                     } else {
  559.                                         showMsgBox("MSYS2 is currently running!\nPlease close all MSYS2 programs and try installing it again!", JOptionPane.ERROR_MESSAGE);
  560.                                         enableInput();
  561.                                     }
  562.                                 } catch (Exception e) {
  563.                                     defaultErrorMsgBox();
  564.                                     enableInput();
  565.                                 }
  566.                                 in.close();
  567.                             } catch (Exception e) {
  568.                                 defaultErrorMsgBox();
  569.                                 enableInput();
  570.                             }
  571.                         } catch (Exception e) {
  572.                             defaultErrorMsgBox();
  573.                             enableInput();
  574.                         }
  575.                     } else {
  576.                         defaultErrorMsgBox();
  577.                         enableInput();
  578.                     }
  579.                 } else {
  580.                     buttonCompile.setEnabled(false);
  581.                     showMsgBox("Please select the MSYS2-Folder, the ROM and the Target-Path before compiling!", JOptionPane.ERROR_MESSAGE);
  582.                 }
  583.             }
  584.         }).start();
  585.     }
  586.  
  587.     private String getDirectDownloadLink(String url, String filename) throws Exception {
  588.         BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
  589.  
  590.         String inputLine;
  591.  
  592.         while ((inputLine = in.readLine()) != null) {
  593.             String input = inputLine.replace(" ", "");
  594.             if (input.startsWith("href=") && input.endsWith("/" + filename + "\"")) {
  595.                 in.close();
  596.                 return input.split("\"")[1];
  597.             }
  598.         }
  599.  
  600.         in.close();
  601.         throw new Exception();
  602.     }
  603.  
  604.     private void disableInput() {
  605.         buttonCompile.setEnabled(false);
  606.         buttonMsys2.setEnabled(false);
  607.         buttonPath.setEnabled(false);
  608.         buttonRom.setEnabled(false);
  609.         buttonMsys2Download.setEnabled(false);
  610.         buttonMsys2Help.setEnabled(false);
  611.         buttonRomHelp.setEnabled(false);
  612.         buttonPathHelp.setEnabled(false);
  613.         labelMsys2.setEnabled(false);
  614.         labelPath.setEnabled(false);
  615.         labelRom.setEnabled(false);
  616.         checkBoxRaytracing.setEnabled(false);
  617.         checkBoxRender96Models.setEnabled(false);
  618.         checkBoxRender96Textures.setEnabled(false);
  619.         checkBoxHQMusic.setEnabled(false);
  620.         checkBoxSavegameFileA.setEnabled(false);
  621.         checkBoxSavegameFileB.setEnabled(false);
  622.         checkBoxSavegameFileC.setEnabled(false);
  623.         checkBoxSavegameFileD.setEnabled(false);
  624.         buttonCompile.setText("Installing...  (Do not close this window!)");
  625.     }
  626.  
  627.     private void enableInput() {
  628.         buttonCompile.setEnabled(true);
  629.         buttonMsys2.setEnabled(true);
  630.         buttonPath.setEnabled(true);
  631.         buttonRom.setEnabled(true);
  632.         buttonMsys2Download.setEnabled(true);
  633.         buttonMsys2Help.setEnabled(true);
  634.         buttonRomHelp.setEnabled(true);
  635.         buttonPathHelp.setEnabled(true);
  636.         labelMsys2.setEnabled(true);
  637.         labelPath.setEnabled(true);
  638.         labelRom.setEnabled(true);
  639.         checkBoxRaytracing.setEnabled(true);
  640.         checkBoxRender96Models.setEnabled(true);
  641.         checkBoxRender96Textures.setEnabled(true);
  642.         checkBoxHQMusic.setEnabled(true);
  643.         checkBoxSavegameFileA.setEnabled(true);
  644.         checkBoxSavegameFileB.setEnabled(true);
  645.         checkBoxSavegameFileC.setEnabled(true);
  646.         checkBoxSavegameFileD.setEnabled(true);
  647.         buttonCompile.setText("Compile the game!");
  648.     }
  649.  
  650.     private void setInstallationProgress(int step, int maxStep, String description) {
  651.         buttonCompile.setText("Installation Progress: " + description + " (" + step + "/" + maxStep + ")");
  652.     }
  653.  
  654.     private void waitForMysy() throws Exception {
  655.         Thread.sleep(10000);
  656.         boolean running = true;
  657.         while (running) {
  658.             Process process = Runtime.getRuntime().exec("tasklist.exe /FI \"IMAGENAME EQ mintty.exe\"");
  659.             Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
  660.             while (scanner.hasNext()) {
  661.                 String line = scanner.nextLine();
  662.                 if (line.contains(":")) {
  663.                     running = false;
  664.                     break;
  665.                 }
  666.             }
  667.             scanner.close();
  668.             Thread.sleep(500);
  669.         }
  670.         Thread.sleep(500);
  671.     }
  672.  
  673.     private boolean checkValid() {
  674.         try {
  675.             int amountOkay = 0;
  676.  
  677.             if (msys2 == null) {
  678.                 labelMsys2.setText(selectedMsys2Prefix + notSelected);
  679.             } else if (new File(msys2 + File.separator + "msys2_shell.cmd").exists() && new File(msys2 + File.separator + "mingw64.exe").exists()) {
  680.                 amountOkay++;
  681.             } else {
  682.                 msys2 = null;
  683.                 labelMsys2.setText(selectedMsys2Prefix + notSelected);
  684.                 showMsgBox("Selected MSYS2 Installation is invalid!", JOptionPane.ERROR_MESSAGE);
  685.             }
  686.  
  687.             if (rom == null) {
  688.                 labelRom.setText(selectedRomPrefix + notSelected);
  689.             } else if (getFileChecksum(rom).toLowerCase().equals("17ce077343c6133f8c9f2d6d6d9a4ab62c8cd2aa57c40aea1f490b4c8bb21d91")) {
  690.                 labelRom.setText(selectedRomPrefix + rom.getAbsolutePath());
  691.                 amountOkay++;
  692.             } else {
  693.                 rom = null;
  694.                 labelRom.setText(selectedRomPrefix + notSelected);
  695.                 showMsgBox("Selected ROM is invalid!", JOptionPane.ERROR_MESSAGE);
  696.             }
  697.  
  698.             if (path == null) {
  699.                 labelPath.setText(selectedPathPrefix + notSelected);
  700.             } else {
  701.                 if (path.exists()) {
  702.                     path = traceCompilingFolder(new File(path.getParent()));
  703.                     labelPath.setText(selectedPathPrefix + path.getAbsolutePath());
  704.                 }
  705.                 amountOkay++;
  706.             }
  707.  
  708.             if (amountOkay == 3) {
  709.                 buttonCompile.setEnabled(true);
  710.                 return true;
  711.             } else {
  712.                 buttonCompile.setEnabled(false);
  713.                 return false;
  714.             }
  715.         } catch (HeadlessException | NoSuchAlgorithmException | IOException e) {
  716.             defaultErrorMsgBox();
  717.             buttonCompile.setEnabled(false);
  718.             return false;
  719.         }
  720.     }
  721.  
  722.     private String getFileChecksum(File file) throws IOException, NoSuchAlgorithmException {
  723.         MessageDigest digest = MessageDigest.getInstance("SHA-256");
  724.         FileInputStream fis = new FileInputStream(file);
  725.         byte[] byteArray = new byte[1024];
  726.         int bytesCount = 0;
  727.         while ((bytesCount = fis.read(byteArray)) != -1) {
  728.             digest.update(byteArray, 0, bytesCount);
  729.         }
  730.         fis.close();
  731.         byte[] bytes = digest.digest();
  732.         StringBuilder sb = new StringBuilder();
  733.         for (int i = 0; i < bytes.length; i++) {
  734.             sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
  735.         }
  736.         return sb.toString();
  737.     }
  738.  
  739.     private boolean downloadAndExtract(String link, File folder, boolean skipFirstFolder) {
  740.         File zip = new File(folder + File.separator + "temp_" + System.nanoTime() + ".zip");
  741.         folder.mkdirs();
  742.         try (InputStream in = new URL(link).openStream()) {
  743.             Files.copy(in, zip.toPath(), StandardCopyOption.REPLACE_EXISTING);
  744.             in.close();
  745.  
  746.             ZipFile zipFile = new ZipFile(zip);
  747.             Enumeration<?> enu = zipFile.entries();
  748.             while (enu.hasMoreElements()) {
  749.                 ZipEntry zipEntry = (ZipEntry) enu.nextElement();
  750.  
  751.                 String name = zipEntry.getName();
  752.                 if (skipFirstFolder) {
  753.                     name = "/" + name.split("/", 2)[1];
  754.                 }
  755.                 File file = new File(folder.getAbsolutePath() + File.separator + name);
  756.                 if (name.endsWith("/")) {
  757.                     file.mkdirs();
  758.                     continue;
  759.                 }
  760.  
  761.                 File parent = file.getParentFile();
  762.                 if (parent != null) {
  763.                     parent.mkdirs();
  764.                 }
  765.  
  766.                 InputStream is = zipFile.getInputStream(zipEntry);
  767.                 FileOutputStream fos = new FileOutputStream(file);
  768.                 byte[] bytes = new byte[1024];
  769.                 int length;
  770.                 while ((length = is.read(bytes)) >= 0) {
  771.                     fos.write(bytes, 0, length);
  772.                 }
  773.                 is.close();
  774.                 fos.close();
  775.  
  776.             }
  777.             zipFile.close();
  778.             Files.delete(zip.toPath());
  779.             return true;
  780.         } catch (Exception e) {
  781.             return false;
  782.         }
  783.     }
  784.  
  785.     private void defaultErrorMsgBox() {
  786.         showMsgBox("An Error occurred!", JOptionPane.ERROR_MESSAGE);
  787.     }
  788.  
  789.     private void showMsgBox(String msg, int icon) {
  790.         JOptionPane.showMessageDialog(null, msg, titleShort, icon);
  791.     }
  792. }
  793.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement