Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.sm64pcrtx;
- import java.awt.Desktop;
- import java.awt.EventQueue;
- import java.awt.HeadlessException;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.filechooser.FileNameExtensionFilter;
- import javax.imageio.ImageIO;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.nio.file.Files;
- import java.nio.file.StandardCopyOption;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Enumeration;
- import java.util.Scanner;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipFile;
- import java.awt.event.ActionEvent;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import javax.swing.JCheckBox;
- public class Installer extends JFrame {
- private static final long serialVersionUID = 1L;
- private String version = "v3.0.4";
- private String title = "Super Mario 64 Render96 & RayTracing Installer " + version;
- private String titleShort = "SM64 R96 & RT Installer " + version;
- private String notSelected = "None";
- private JPanel contentPane;
- private JButton buttonCompile;
- private File msys2 = null;
- private JLabel labelMsys2;
- private JButton buttonMsys2;
- private JButton buttonMsys2Download;
- private JButton buttonMsys2Help;
- private String selectedMsys2Prefix = "MSYS2-Path: ";
- private File rom = null;
- private JLabel labelRom;
- private JButton buttonRom;
- private JButton buttonRomHelp;
- private String selectedRomPrefix = "Base-ROM: ";
- private File path = null;
- private JLabel labelPath;
- private JButton buttonPath;
- private JButton buttonPathHelp;
- private String selectedPathPrefix = "Target-Path: ";
- private JCheckBox checkBoxRaytracing;
- private JCheckBox checkBoxRender96Models;
- private JCheckBox checkBoxRender96Textures;
- private JCheckBox checkBoxHQMusic;
- private JCheckBox checkBoxSavegameFileA;
- private JCheckBox checkBoxSavegameFileB;
- private JCheckBox checkBoxSavegameFileC;
- private JCheckBox checkBoxSavegameFileD;
- private String linkMediafireTos = "https://www.mediafire.com/policies/terms_of_service.php";
- private String linkBuilder = "https://sm64pc.info/sm64pcbuilder2/";
- private String linkMsys = "https://www.msys2.org/";
- private String linkRender96 = "https://linktr.ee/Render96";
- private String linkDiscordPcPort = "https://discord.gg/ZezK78p";
- private String linkDiscordHqMusic = "https://discord.gg/fjkzzteKCe";
- private String linkGithubRender96 = "https://github.com/Render96/Render96ex/archive/refs/heads/alpha.zip";
- private String linkGithubRender96Raytracing = "https://github.com/Render96/Render96ex/archive/refs/heads/tester_rt64alpha.zip";
- private String linkGithubDxilDll = "https://github.com/DarioSamo/sm64rt/raw/master/lib/rt64/dxil.dll";
- private String linkGithubRt64libDll = "https://github.com/DarioSamo/sm64rt/raw/master/lib/rt64/rt64lib.dll";
- private String linkMediafireModels = "https://www.mediafire.com/file/apywibprrjfjz9u/models.zip/file";
- private String linkMediafireTextures = "https://www.mediafire.com/file/d22kbfjsguvo57p/textures.zip/file";
- private String linkMediafireMusic = "https://www.mediafire.com/file/l0gfz5b2t7k3o16/hqmusic.zip/file";
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Installer frame = new Installer();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Installer() throws IOException {
- setResizable(false);
- File currentFolder = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath());
- setTitle(title);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 1300, 403);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- setIconImage(ImageIO.read(this.getClass().getResourceAsStream("icon.png")));
- setLocationRelativeTo(null);
- labelMsys2 = new JLabel(selectedMsys2Prefix + notSelected);
- labelMsys2.setBounds(240, 15, 624, 14);
- contentPane.add(labelMsys2);
- buttonMsys2 = new JButton("Select MSYS2-Path");
- buttonMsys2.setBounds(10, 11, 220, 23);
- File defaultMsys2Path = new File("C:\\msys64");
- if (defaultMsys2Path.exists() && new File(defaultMsys2Path + File.separator + "msys2_shell.cmd").exists() && new File(defaultMsys2Path + File.separator + "mingw64.exe").exists()) {
- msys2 = defaultMsys2Path;
- labelMsys2.setText(selectedMsys2Prefix + defaultMsys2Path.getAbsolutePath());
- }
- buttonMsys2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser chooserMsys = new JFileChooser();
- chooserMsys.setCurrentDirectory(currentFolder);
- chooserMsys.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- int returnVal = chooserMsys.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- msys2 = chooserMsys.getSelectedFile();
- labelMsys2.setText(selectedMsys2Prefix + msys2.getAbsolutePath());
- checkValid();
- }
- }
- });
- contentPane.add(buttonMsys2);
- labelRom = new JLabel(selectedRomPrefix + notSelected);
- labelRom.setBounds(240, 49, 624, 14);
- contentPane.add(labelRom);
- buttonRom = new JButton("Select Base-ROM (US, z64)");
- buttonRom.setBounds(10, 45, 220, 23);
- buttonRom.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser chooserRom = new JFileChooser();
- chooserRom.setCurrentDirectory(currentFolder);
- chooserRom.setFileSelectionMode(JFileChooser.FILES_ONLY);
- chooserRom.setFileFilter(new FileNameExtensionFilter("*.z64 Files", "z64"));
- int returnVal = chooserRom.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- rom = chooserRom.getSelectedFile();
- labelRom.setText(selectedRomPrefix + rom.getAbsolutePath());
- checkValid();
- }
- }
- });
- contentPane.add(buttonRom);
- labelPath = new JLabel(selectedPathPrefix + notSelected);
- labelPath.setBounds(240, 83, 624, 14);
- contentPane.add(labelPath);
- buttonPath = new JButton("Select Target-Path");
- buttonPath.setBounds(10, 79, 220, 23);
- buttonPath.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser chooserPath = new JFileChooser();
- chooserPath.setCurrentDirectory(currentFolder);
- chooserPath.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- int returnVal = chooserPath.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- path = traceCompilingFolder(chooserPath.getSelectedFile());
- labelPath.setText(selectedPathPrefix + path.getAbsolutePath());
- checkValid();
- }
- }
- });
- contentPane.add(buttonPath);
- buttonCompile = new JButton("Compile the Game!");
- buttonCompile.setFont(new Font("Tahoma", Font.BOLD, 18));
- buttonCompile.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- compile(checkBoxRaytracing.isSelected(), checkBoxRender96Models.isSelected(), checkBoxRender96Textures.isSelected(), checkBoxHQMusic.isSelected(), checkBoxSavegameFileA.isSelected(),
- checkBoxSavegameFileB.isSelected(), checkBoxSavegameFileC.isSelected(), checkBoxSavegameFileD.isSelected());
- }
- });
- buttonCompile.setEnabled(false);
- buttonCompile.setBounds(10, 308, 1264, 46);
- contentPane.add(buttonCompile);
- checkBoxRaytracing = new JCheckBox("Install Raytracing");
- checkBoxRaytracing.setSelected(true);
- checkBoxRaytracing.setBounds(10, 119, 1164, 23);
- contentPane.add(checkBoxRaytracing);
- checkBoxRender96Models = new JCheckBox("Install Render96 Models");
- checkBoxRender96Models.setSelected(true);
- checkBoxRender96Models.setBounds(10, 145, 1164, 23);
- contentPane.add(checkBoxRender96Models);
- checkBoxRender96Textures = new JCheckBox("Install Render96 Textures");
- checkBoxRender96Textures.setSelected(true);
- checkBoxRender96Textures.setBounds(10, 171, 1164, 23);
- contentPane.add(checkBoxRender96Textures);
- checkBoxHQMusic = new JCheckBox("Install HQ Music");
- checkBoxHQMusic.setSelected(true);
- checkBoxHQMusic.setBounds(10, 197, 1164, 23);
- contentPane.add(checkBoxHQMusic);
- checkBoxSavegameFileA = new JCheckBox("100% Savegame [FILE A]");
- checkBoxSavegameFileA.setBounds(10, 232, 200, 23);
- contentPane.add(checkBoxSavegameFileA);
- checkBoxSavegameFileB = new JCheckBox("100% Savegame [FILE B]");
- checkBoxSavegameFileB.setBounds(230, 232, 200, 23);
- contentPane.add(checkBoxSavegameFileB);
- checkBoxSavegameFileC = new JCheckBox("100% Savegame [FILE C]");
- checkBoxSavegameFileC.setBounds(10, 258, 200, 23);
- contentPane.add(checkBoxSavegameFileC);
- checkBoxSavegameFileD = new JCheckBox("100% Savegame [FILE D]");
- checkBoxSavegameFileD.setSelected(true);
- checkBoxSavegameFileD.setBounds(230, 258, 200, 23);
- contentPane.add(checkBoxSavegameFileD);
- buttonMsys2Download = new JButton("Download MSYS2");
- buttonMsys2Download.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkMsys).toURI());
- } catch (Exception e1) {
- }
- }
- });
- buttonMsys2Download.setBounds(974, 11, 190, 23);
- contentPane.add(buttonMsys2Download);
- buttonRomHelp = new JButton("What is the Base-ROM?");
- buttonRomHelp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- showMsgBox(
- "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.",
- JOptionPane.INFORMATION_MESSAGE);
- }
- });
- buttonRomHelp.setBounds(974, 45, 300, 23);
- contentPane.add(buttonRomHelp);
- buttonPathHelp = new JButton("What is the Target-Path?");
- buttonPathHelp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- showMsgBox("A new subfolder will be automatically created inside the Target-Path.\nThe project will be installed inside the new automatically created subfolder.",
- JOptionPane.INFORMATION_MESSAGE);
- }
- });
- buttonPathHelp.setBounds(974, 79, 300, 23);
- contentPane.add(buttonPathHelp);
- buttonMsys2Help = new JButton("Help");
- buttonMsys2Help.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- showMsgBox("Please select the Installation-Path of your MSYS2 installation (Default Installation-Path: \"C:\\msys64\")!", JOptionPane.INFORMATION_MESSAGE);
- }
- });
- buttonMsys2Help.setBounds(1174, 11, 100, 23);
- contentPane.add(buttonMsys2Help);
- checkValid();
- String msgMediafire = "Mediafire will record how many times the HD-Textures, the HD-Models and the HQ Music will be downloaded, etc.!"
- + "\nIf you are living in the european union you have to agree to Mediafire's ToS before continuing!\n\n";
- JButton jbt_mediafire_dontagree = new JButton("I DO NOT AGREE TO MEDIAFIRE'S ToS");
- jbt_mediafire_dontagree.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- System.exit(0);
- } catch (Exception e1) {
- }
- }
- });
- Font buttonFont = new Font(jbt_mediafire_dontagree.getFont().getName(), Font.ITALIC, jbt_mediafire_dontagree.getFont().getSize());
- JButton jbt_mediafire_tos = new JButton("Mediafire's ToS");
- jbt_mediafire_tos.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkMediafireTos).toURI());
- } catch (Exception e1) {
- }
- }
- });
- jbt_mediafire_tos.setFont(buttonFont);
- Object[] optionsMediafire = { "I AGREE TO MEDIAFIRE'S ToS / I DO NOT LIVE IN THE EUROPEAN UNION", jbt_mediafire_dontagree, jbt_mediafire_tos};
- int check_closed = JOptionPane.showOptionDialog(null, msgMediafire, titleShort, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, optionsMediafire, optionsMediafire[1]);
- if (check_closed == JOptionPane.CLOSED_OPTION) {
- System.exit(0);
- }
- JButton jbt_builder = new JButton("sm64pcBuilder2 Website");
- jbt_builder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkBuilder).toURI());
- } catch (Exception e1) {
- }
- }
- });
- JButton jbt_render96 = new JButton("Render96 Website");
- jbt_render96.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkRender96).toURI());
- } catch (Exception e1) {
- }
- }
- });
- JButton jbt_discord_central = new JButton("SM64 PC Port Central Discord");
- jbt_discord_central.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkDiscordPcPort).toURI());
- } catch (Exception e1) {
- }
- }
- });
- JButton jbt_discord_music = new JButton("SM64 HQ Music Discord");
- jbt_discord_music.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(new URL(linkDiscordHqMusic).toURI());
- } catch (Exception e1) {
- }
- }
- });
- jbt_builder.setFont(buttonFont);
- jbt_discord_central.setFont(buttonFont);
- jbt_discord_music.setFont(buttonFont);
- jbt_render96.setFont(buttonFont);
- Object[] options = { "CONTINUE THE INSTALLER", jbt_builder, jbt_render96, jbt_discord_central, jbt_discord_music };
- String msg = "This installer currently only works on windows operating systems!"
- + "\n\nThis installer This installer will build a playable technical preview version of Super Mario 64 Render96 & Raytracing."
- + "\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."
- + "\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!"
- + "\nPlease check out the Discords, the sm64pcBuilder2 and the Render96 Project and down below.\n\n";
- JOptionPane.showOptionDialog(null, msg, titleShort, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
- }
- private File traceCompilingFolder(File rootPath) {
- String pathDefault = rootPath.getAbsolutePath() + File.separator + "SM64_R96_RT_" + System.currentTimeMillis();
- String pathString = pathDefault;
- long number = 1;
- while (new File(pathString).exists()) {
- pathString = pathDefault + "_" + number;
- number++;
- }
- return new File(pathString);
- }
- private void compile(boolean raytracing, boolean installModels, boolean installTextures, boolean installHQMusic, boolean savegameA, boolean savegameB, boolean savegameC, boolean savegameD) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- if (checkValid()) {
- disableInput();
- int step = 1;
- int maxSteps = 7;
- String description = "";
- if (installModels) {
- maxSteps++;
- }
- if (installTextures) {
- maxSteps++;
- }
- if (installHQMusic) {
- maxSteps++;
- }
- if (savegameA || savegameB || savegameC || savegameD) {
- maxSteps++;
- }
- String gitRepo = "";
- if (raytracing) {
- gitRepo = linkGithubRender96Raytracing;
- } else {
- gitRepo = linkGithubRender96;
- }
- description = "Downloading GitHub Repository (~400MB)...";
- setInstallationProgress(step, maxSteps, description);
- if (downloadAndExtract(gitRepo, path, true)) {
- step++;
- description = "Copying Base-ROM...";
- setInstallationProgress(step, maxSteps, description);
- try {
- Files.copy(rom.toPath(), new File(path.getAbsolutePath() + File.separator + "baserom.us.z64").toPath(), StandardCopyOption.REPLACE_EXISTING);
- step++;
- description = "Downloading \"dxil.dll\"...";
- setInstallationProgress(step, maxSteps, description);
- try (InputStream in = new URL(linkGithubDxilDll).openStream()) {
- File buildFolder = new File(path.getAbsolutePath() + File.separator + "build" + File.separator + "us_pc");
- buildFolder.mkdirs();
- Files.copy(in, new File(buildFolder.getAbsolutePath() + File.separator + "dxil.dll").toPath(), StandardCopyOption.REPLACE_EXISTING);
- step++;
- description = "Downloading \"rt64lib.dll\"...";
- setInstallationProgress(step, maxSteps, description);
- try (InputStream in2 = new URL(linkGithubRt64libDll).openStream()) {
- Files.copy(in2, new File(buildFolder.getAbsolutePath() + File.separator + "rt64lib.dll").toPath(), StandardCopyOption.REPLACE_EXISTING);
- in2.close();
- 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);
- boolean msysClosed = false;
- Process process = Runtime.getRuntime().exec("tasklist.exe /FI \"IMAGENAME EQ mintty.exe\"");
- Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
- while (scanner.hasNext()) {
- String line = scanner.nextLine();
- if (line.contains(":")) {
- msysClosed = true;
- break;
- }
- }
- if (msysClosed) {
- showMsgBox(
- "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!",
- JOptionPane.INFORMATION_MESSAGE);
- step++;
- description = "Updating MSYS2-Package \"pacman\"...";
- setInstallationProgress(step, maxSteps, description);
- Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -c \"pacman -Syuu --noconfirm\"");
- waitForMysy();
- step++;
- description = "Installing missing MSYS2-Dependencies...";
- setInstallationProgress(step, maxSteps, description);
- Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator
- + "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\"");
- waitForMysy();
- step++;
- description = "Compiling the Project...";
- setInstallationProgress(step, maxSteps, description);
- if (raytracing) {
- Runtime.getRuntime().exec(msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -where \"" + path.getAbsolutePath()
- + "\" -c \"make RENDER_API=RT64 EXTERNAL_DATA=1 -j16\"");
- } else {
- Runtime.getRuntime().exec(
- msys2.getAbsolutePath() + File.separator + "msys2_shell.cmd -mingw64 -where \"" + path.getAbsolutePath() + "\" -c \"make EXTERNAL_DATA=1 -j16\"");
- }
- waitForMysy();
- if (installModels) {
- step++;
- description = "Downloading and Installing Render96 Models (~120MB)...";
- setInstallationProgress(step, maxSteps, description);
- downloadAndExtract(getDirectDownloadLink(linkMediafireModels, "models.zip"), buildFolder, false);
- }
- if (installTextures) {
- step++;
- description = "Downloading and Installing Render96 Textures (~540MB)...";
- setInstallationProgress(step, maxSteps, description);
- downloadAndExtract(getDirectDownloadLink(linkMediafireTextures, "textures.zip"), buildFolder, false);
- }
- if (installHQMusic) {
- step++;
- description = "Downloading and Installing HQ Music (~700MB)...";
- setInstallationProgress(step, maxSteps, description);
- downloadAndExtract(getDirectDownloadLink(linkMediafireMusic, "hqmusic.zip"), buildFolder, false);
- }
- if (savegameA || savegameB || savegameC || savegameD) {
- step++;
- description = "Installing Savegame(s)...";
- setInstallationProgress(step, maxSteps, description);
- String dataFolderPath = System.getenv("APPDATA") + File.separator + "sm64ex";
- File dataFolder = new File(dataFolderPath);
- if (!dataFolder.exists()) {
- dataFolder.mkdirs();
- }
- if (savegameA) {
- InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
- try {
- Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_0.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (Exception e) {
- }
- is.close();
- }
- if (savegameB) {
- InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
- try {
- Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_1.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (Exception e) {
- }
- is.close();
- }
- if (savegameC) {
- InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
- try {
- Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_2.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (Exception e) {
- }
- is.close();
- }
- if (savegameD) {
- InputStream is = this.getClass().getResourceAsStream("savegame_100percent.sav");
- try {
- Files.copy(is, new File(dataFolderPath + File.separator + "render96_save_file_3.sav").toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (Exception e) {
- }
- is.close();
- }
- }
- showMsgBox("INSTALLATION COMPLETE!" + "\n\nYou can find the game inside the folder \"<Installation-Folder>\\build\\us_pc\\\""
- + "\nYou only need the content inside the \"us_pc\" folder for the game. You can delete everything else."
- + "\n\nYou have to manually enable the Render96 ModelPack ingame to see the Render96 models and textures"
- + "\n(Pause the game, go to DynOS, go to Model Pack, enable Render96 2.2)"
- + "\nAfter enabling the ModelPack you have to restart your game to see the reflective water."
- + "\n\nTo use a Gamecontroller, connect the controller to your PC before starting the game."
- + "\n\nTo play around with the raytracing settings open the menu for that with the F1-Key ingame.", JOptionPane.INFORMATION_MESSAGE);
- Desktop.getDesktop().open(buildFolder);
- for (File f : buildFolder.listFiles()) {
- if (f.getName().toLowerCase().startsWith("sm64") && f.getName().toLowerCase().endsWith(".exe")) {
- Desktop.getDesktop().open(f);
- break;
- }
- }
- System.exit(0);
- } else {
- showMsgBox("MSYS2 is currently running!\nPlease close all MSYS2 programs and try installing it again!", JOptionPane.ERROR_MESSAGE);
- enableInput();
- }
- } catch (Exception e) {
- defaultErrorMsgBox();
- enableInput();
- }
- in.close();
- } catch (Exception e) {
- defaultErrorMsgBox();
- enableInput();
- }
- } catch (Exception e) {
- defaultErrorMsgBox();
- enableInput();
- }
- } else {
- defaultErrorMsgBox();
- enableInput();
- }
- } else {
- buttonCompile.setEnabled(false);
- showMsgBox("Please select the MSYS2-Folder, the ROM and the Target-Path before compiling!", JOptionPane.ERROR_MESSAGE);
- }
- }
- }).start();
- }
- private String getDirectDownloadLink(String url, String filename) throws Exception {
- BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- String input = inputLine.replace(" ", "");
- if (input.startsWith("href=") && input.endsWith("/" + filename + "\"")) {
- in.close();
- return input.split("\"")[1];
- }
- }
- in.close();
- throw new Exception();
- }
- private void disableInput() {
- buttonCompile.setEnabled(false);
- buttonMsys2.setEnabled(false);
- buttonPath.setEnabled(false);
- buttonRom.setEnabled(false);
- buttonMsys2Download.setEnabled(false);
- buttonMsys2Help.setEnabled(false);
- buttonRomHelp.setEnabled(false);
- buttonPathHelp.setEnabled(false);
- labelMsys2.setEnabled(false);
- labelPath.setEnabled(false);
- labelRom.setEnabled(false);
- checkBoxRaytracing.setEnabled(false);
- checkBoxRender96Models.setEnabled(false);
- checkBoxRender96Textures.setEnabled(false);
- checkBoxHQMusic.setEnabled(false);
- checkBoxSavegameFileA.setEnabled(false);
- checkBoxSavegameFileB.setEnabled(false);
- checkBoxSavegameFileC.setEnabled(false);
- checkBoxSavegameFileD.setEnabled(false);
- buttonCompile.setText("Installing... (Do not close this window!)");
- }
- private void enableInput() {
- buttonCompile.setEnabled(true);
- buttonMsys2.setEnabled(true);
- buttonPath.setEnabled(true);
- buttonRom.setEnabled(true);
- buttonMsys2Download.setEnabled(true);
- buttonMsys2Help.setEnabled(true);
- buttonRomHelp.setEnabled(true);
- buttonPathHelp.setEnabled(true);
- labelMsys2.setEnabled(true);
- labelPath.setEnabled(true);
- labelRom.setEnabled(true);
- checkBoxRaytracing.setEnabled(true);
- checkBoxRender96Models.setEnabled(true);
- checkBoxRender96Textures.setEnabled(true);
- checkBoxHQMusic.setEnabled(true);
- checkBoxSavegameFileA.setEnabled(true);
- checkBoxSavegameFileB.setEnabled(true);
- checkBoxSavegameFileC.setEnabled(true);
- checkBoxSavegameFileD.setEnabled(true);
- buttonCompile.setText("Compile the game!");
- }
- private void setInstallationProgress(int step, int maxStep, String description) {
- buttonCompile.setText("Installation Progress: " + description + " (" + step + "/" + maxStep + ")");
- }
- private void waitForMysy() throws Exception {
- Thread.sleep(10000);
- boolean running = true;
- while (running) {
- Process process = Runtime.getRuntime().exec("tasklist.exe /FI \"IMAGENAME EQ mintty.exe\"");
- Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
- while (scanner.hasNext()) {
- String line = scanner.nextLine();
- if (line.contains(":")) {
- running = false;
- break;
- }
- }
- scanner.close();
- Thread.sleep(500);
- }
- Thread.sleep(500);
- }
- private boolean checkValid() {
- try {
- int amountOkay = 0;
- if (msys2 == null) {
- labelMsys2.setText(selectedMsys2Prefix + notSelected);
- } else if (new File(msys2 + File.separator + "msys2_shell.cmd").exists() && new File(msys2 + File.separator + "mingw64.exe").exists()) {
- amountOkay++;
- } else {
- msys2 = null;
- labelMsys2.setText(selectedMsys2Prefix + notSelected);
- showMsgBox("Selected MSYS2 Installation is invalid!", JOptionPane.ERROR_MESSAGE);
- }
- if (rom == null) {
- labelRom.setText(selectedRomPrefix + notSelected);
- } else if (getFileChecksum(rom).toLowerCase().equals("17ce077343c6133f8c9f2d6d6d9a4ab62c8cd2aa57c40aea1f490b4c8bb21d91")) {
- labelRom.setText(selectedRomPrefix + rom.getAbsolutePath());
- amountOkay++;
- } else {
- rom = null;
- labelRom.setText(selectedRomPrefix + notSelected);
- showMsgBox("Selected ROM is invalid!", JOptionPane.ERROR_MESSAGE);
- }
- if (path == null) {
- labelPath.setText(selectedPathPrefix + notSelected);
- } else {
- if (path.exists()) {
- path = traceCompilingFolder(new File(path.getParent()));
- labelPath.setText(selectedPathPrefix + path.getAbsolutePath());
- }
- amountOkay++;
- }
- if (amountOkay == 3) {
- buttonCompile.setEnabled(true);
- return true;
- } else {
- buttonCompile.setEnabled(false);
- return false;
- }
- } catch (HeadlessException | NoSuchAlgorithmException | IOException e) {
- defaultErrorMsgBox();
- buttonCompile.setEnabled(false);
- return false;
- }
- }
- private String getFileChecksum(File file) throws IOException, NoSuchAlgorithmException {
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- FileInputStream fis = new FileInputStream(file);
- byte[] byteArray = new byte[1024];
- int bytesCount = 0;
- while ((bytesCount = fis.read(byteArray)) != -1) {
- digest.update(byteArray, 0, bytesCount);
- }
- fis.close();
- byte[] bytes = digest.digest();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < bytes.length; i++) {
- sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- private boolean downloadAndExtract(String link, File folder, boolean skipFirstFolder) {
- File zip = new File(folder + File.separator + "temp_" + System.nanoTime() + ".zip");
- folder.mkdirs();
- try (InputStream in = new URL(link).openStream()) {
- Files.copy(in, zip.toPath(), StandardCopyOption.REPLACE_EXISTING);
- in.close();
- ZipFile zipFile = new ZipFile(zip);
- Enumeration<?> enu = zipFile.entries();
- while (enu.hasMoreElements()) {
- ZipEntry zipEntry = (ZipEntry) enu.nextElement();
- String name = zipEntry.getName();
- if (skipFirstFolder) {
- name = "/" + name.split("/", 2)[1];
- }
- File file = new File(folder.getAbsolutePath() + File.separator + name);
- if (name.endsWith("/")) {
- file.mkdirs();
- continue;
- }
- File parent = file.getParentFile();
- if (parent != null) {
- parent.mkdirs();
- }
- InputStream is = zipFile.getInputStream(zipEntry);
- FileOutputStream fos = new FileOutputStream(file);
- byte[] bytes = new byte[1024];
- int length;
- while ((length = is.read(bytes)) >= 0) {
- fos.write(bytes, 0, length);
- }
- is.close();
- fos.close();
- }
- zipFile.close();
- Files.delete(zip.toPath());
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- private void defaultErrorMsgBox() {
- showMsgBox("An Error occurred!", JOptionPane.ERROR_MESSAGE);
- }
- private void showMsgBox(String msg, int icon) {
- JOptionPane.showMessageDialog(null, msg, titleShort, icon);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement