diff --git a/installer/Installer.java b/installer/Installer.java index 42cd81d..c749f6b 100644 --- a/installer/Installer.java +++ b/installer/Installer.java @@ -196,521 +196,6 @@ public Installer(File target) entryPanel.setLayout(new BoxLayout(entryPanel,BoxLayout.X_AXIS)); entryPanel.setAlignmentX(LEFT_ALIGNMENT); entryPanel.setAlignmentY(TOP_ALIGNMENT); - // Extract new lib - File lib_dir = new File(targetDir,"libraries/com/mtbs3d/minecrift/"+version); - lib_dir.mkdirs(); - File ver_file = new File (lib_dir, "minecrift-"+version+".jar"); - FileOutputStream ver_jar = new FileOutputStream(ver_file); - while ((d = version_jar.read(data)) != -1) { - ver_jar.write(data,0,d); - } - ver_jar.close(); - - return ver_json_file.exists() && ver_file.exists(); - } catch (Exception e) { - finalMessage += " Error: "+e.getLocalizedMessage(); - } - - } - return false; - } - - private boolean EnableHRTF() // Implementation by Zach Jaggi - { - // Find the correct location to stick alsoftrc - File alsoftrc; - - //I honestly have no clue where Mac stores this, so I'm assuming the same as Linux. - if (isWindows && appDataDir != null) - { - alsoftrc = new File(appDataDir, "alsoft.ini"); - } - else - { - alsoftrc = new File(userHomeDir, ".alsoftrc"); - } - try - { - //Overwrite the current file. - alsoftrc.createNewFile(); - PrintWriter writer = new PrintWriter(alsoftrc); - writer.write("hrtf = true\n"); - writer.write("frequency = 44100\n"); - writer.close(); - return true; - } - catch (Exception e) - { - finalMessage += " Error: "+e.getLocalizedMessage(); - } - - return false; - } - - // VIVE START - install openVR dlls - private boolean InstallOpenVR() { - //nope. - return true; - } - - private boolean installFile(String osFolder, String resource){ - File win32_dir = new File (targetDir, osFolder); - win32_dir.mkdirs(); - InputStream openvrdll = Installer.class.getResourceAsStream(resource); - File dll_out = new File (targetDir, resource); - if (!copyInputStreamToFile(openvrdll, dll_out)){ - return false; - } - - return true; - } - - // VIVE END - install openVR dll - - private void sleep(int millis) - { - try { - Thread.sleep(millis); - } catch (InterruptedException e) {} - } - - /* - * Main task. Executed in background thread. - */ - public String finalMessage; - @Override - public Void doInBackground() - { - StringBuilder sbErrors = new StringBuilder(); - String minecriftVersionName = "vivecraft-" + version + mod; - boolean checkedRedists = false; - boolean redistSuccess = true; - boolean downloadedForge = false; - boolean installedForge = false; - - monitor.setProgress(0); - - try { - // Set progress dialog size (using reflection - hacky) - Field progressdialog = monitor.getClass().getDeclaredField("dialog"); - if (progressdialog != null) { - progressdialog.setAccessible(true); - Dialog dlg = (Dialog) progressdialog.get(monitor); - if (dlg != null) { - dlg.setSize(550, 200); - dlg.setLocationRelativeTo(null); - } - } - } - catch (NoSuchFieldException e) {} - catch (IllegalAccessException e) {} - - - finalMessage = "Failed: Couldn't download C++ redistributables. "; - monitor.setNote("Checking for required libraries..."); - monitor.setProgress(5); - - if (System.getProperty("os.name").contains("Windows")) - { - // Windows C++ redists (ah the joys of c native code) - - checkedRedists = true; - - - - // Determine if we have a Win 64bit OS. - boolean is64bitOS = (System.getenv("ProgramFiles(x86)") != null); - - File redist2012_64 = new File(tempDir + "/vcredist_x64_2012.exe"); - File redist2012_32 = new File(tempDir + "/vcredist_x86_2012.exe"); - File redist2010_64 = new File(tempDir + "/vcredist_x64_2010.exe"); - File redist2010_32 = new File(tempDir + "/vcredist_x86_2010.exe"); - - boolean neededRedist2012_64 = false; - boolean neededRedist2012_32 = false; - boolean neededRedist2010_64 = false; - boolean neededRedist2010_32 = false; - - // Download VS 2012 64bit - if (NEEDS_2012_REDIST && redistSuccess && is64bitOS) { - if (!redist2012_64.exists()) { - neededRedist2012_64 = true; - monitor.setNote("Downloading VC 2012 C++ 64bit redist..."); - monitor.setProgress(10); - if (!downloadFile(winredist2012_64url, redist2012_64)) { - redist2012_64.deleteOnExit(); - redistSuccess = false; - } - } - } - - // Download VS 2010 64bit - if (NEEDS_2010_REDIST && redistSuccess && is64bitOS) { - if (!redist2010_64.exists()) { - neededRedist2010_64 = true; - monitor.setNote("Downloading VC 2010 C++ 64bit redist..."); - monitor.setProgress(15); - if (!downloadFile(winredist2010_64url, redist2010_64)) { - redist2010_64.deleteOnExit(); - redistSuccess = false; - } - } - } - - // Download VS 2012 32bit - if (NEEDS_2012_REDIST && redistSuccess && !redist2012_32.exists()) { - neededRedist2012_32 = true; - monitor.setNote("Downloading VC 2012 C++ 32bit redist..."); - monitor.setProgress(20); - if (!downloadFile(winredist2012_32url, redist2012_32)) { - redist2012_32.deleteOnExit(); - redistSuccess = false; - } - } - - // Download VS 2010 32bit - if (NEEDS_2010_REDIST && redistSuccess && !redist2010_32.exists()) { - neededRedist2010_32 = true; - monitor.setNote("Downloading VC 2010 C++ 32bit redist..."); - monitor.setProgress(25); - if (!downloadFile(winredist2010_32url, redist2010_32)) { - redist2010_32.deleteOnExit(); - redistSuccess = false; - } - } - - // Install VS2012 64bit - if (NEEDS_2012_REDIST && redistSuccess && is64bitOS && neededRedist2012_64) { - monitor.setNote("Installing VC 2012 C++ 32bit redist..."); - monitor.setProgress(30); - try { - Process process = new ProcessBuilder(redist2012_64.getAbsolutePath(), "/quiet", "/norestart").start(); - process.waitFor(); - } catch (Exception e) { - e.printStackTrace(); - redist2012_64.deleteOnExit(); - redistSuccess = false; - } - } - - // Install VS2010 64bit - if (NEEDS_2010_REDIST && redistSuccess && is64bitOS && neededRedist2010_64) { - monitor.setNote("Installing VC 2010 C++ 64bit redist..."); - monitor.setProgress(33); - try { - Process process = new ProcessBuilder(redist2010_64.getAbsolutePath(), "/quiet", "/norestart").start(); - process.waitFor(); - } catch (Exception e) { - e.printStackTrace(); - redist2010_64.deleteOnExit(); - redistSuccess = false; - } - } - - // Install VS2012 32bit - if (NEEDS_2012_REDIST && redistSuccess && neededRedist2012_32) { - monitor.setNote("Installing VC 2012 C++ 32bit redist..."); - monitor.setProgress(36); - try { - Process process = new ProcessBuilder(redist2012_32.getAbsolutePath(), "/quiet", "/norestart").start(); - process.waitFor(); - } catch (Exception e) { - e.printStackTrace(); - redist2012_32.deleteOnExit(); - redistSuccess = false; - } - } - - // Install VS2010 32bit - if (NEEDS_2010_REDIST && redistSuccess && neededRedist2010_32) { - monitor.setNote("Installing VC 2010 C++ 32bit redist..."); - monitor.setProgress(39); - try { - Process process = new ProcessBuilder(redist2010_32.getAbsolutePath(), "/quiet", "/norestart").start(); - process.waitFor(); - } catch (Exception e) { - e.printStackTrace(); - redist2010_32.deleteOnExit(); - redistSuccess = false; - } - } - } - - if (checkedRedists && !redistSuccess) { - JOptionPane.showMessageDialog(null, "Could not download VC++ Redist. Game might not work.", "Warning", JOptionPane.INFORMATION_MESSAGE); - } - - finalMessage = "Failed: Couldn't download Optifine. "; - monitor.setNote("Checking Optifine... Please donate to them!"); - monitor.setProgress(42); - // Attempt optifine download... - boolean downloadedOptifine = false; - monitor.setNote("Downloading Optifine... Please donate to them!"); - - for (int i = 1; i <= 3; i++) - { - if (DownloadOptiFine()) - { - // Got it! - downloadedOptifine = true; - break; - } - - // Failed. Sleep a bit and retry... - if (i < 3) { - monitor.setNote("Downloading Optifine... waiting..."); - try { - Thread.sleep(i * 1000); - } - catch (InterruptedException e) { - } - monitor.setNote("Downloading Optifine...retrying..."); - } - } - - if(useShadersMod.isSelected()){ - finalMessage = "Failed: Couldn't download ShadersMod. "; - monitor.setNote("Checking ShadersModCore"); - monitor.setProgress(42); - boolean downloadedSMC = false; - monitor.setNote("Downloading ShadersModCore"); - - for (int i = 1; i <= 3; i++) - { - if (downloadSMC(useForge.isSelected())) - { - // Got it! - downloadedSMC = true; - break; - } - - // Failed. Sleep a bit and retry... - if (i < 3) { - monitor.setNote("Downloading ShadersModCore... waiting..."); - try { - Thread.sleep(i * 1000); - } - catch (InterruptedException e) { - } - monitor.setNote("Downloading ShadersModCore...retrying..."); - } - } - } - - monitor.setProgress(50); - monitor.setNote("Checking for base game..."); - - - if(!SetupMinecraftAsLibrary()) - { - JOptionPane.showMessageDialog(null, - "Could not locate or download base game. The Mincraft Launcher will attempt to download it.", - "Warning!",JOptionPane.WARNING_MESSAGE); - } - // VIVE START - install openVR - monitor.setProgress(52); - monitor.setNote("Installing OpenVR..."); - finalMessage = "Failed: Couldn't extract openvr_api.dll to .minecraft folder."; - if(!InstallOpenVR()) - { - monitor.close(); - return null; - } - // VIVE END - install openVR - - // Setup forge if necessary - if (useForge.isSelected() && !forgeVersionInstalled) { - monitor.setProgress(55); - monitor.setNote("Downloading Forge " + FULL_FORGE_VERSION + "..."); - downloadedForge = downloadFile(forge_url, forgeInstaller); - if(!downloadedForge) - JOptionPane.showMessageDialog(null, "Could not download Forge. Please exit this installer and download it manually", "Forge Installation", JOptionPane.WARNING_MESSAGE); - } - if (downloadedForge && useForge.isSelected() && !forgeVersionInstalled) { - monitor.setProgress(65); - monitor.setNote("Installing Forge " + FULL_FORGE_VERSION + "..."); - installedForge = installForge(forgeInstaller); - } - monitor.setProgress(75); - monitor.setNote("Extracting correct Minecrift version..."); - finalMessage = "Failed: Couldn't extract Minecrift. Try redownloading this installer."; - if(!ExtractVersion()) - { - monitor.close(); - return null; - } - if(useHrtf.isSelected()) - { - monitor.setProgress(85); - monitor.setNote("Configuring HRTF audio..."); - if(!EnableHRTF()) - { - sbErrors.append("Failed to set up HRTF! Vivecraft will still work but audio won't be binaural.\n"); - } - } - boolean profileCreated = false; - finalMessage = "Failed: Couldn't setup profile!"; - if (createProfile.isSelected()) - { - monitor.setProgress(95); - monitor.setNote("Creating Vivecraft profile..."); - if (!updateLauncherJson(targetDir, minecriftVersionName)) - sbErrors.append("Failed to set up 'Vivecraft' profile (you can still manually select Edit Profile->Use Version " + minecriftVersionName + " in the Minecraft launcher)\n"); - else - profileCreated = true; - } - - String profileName = getMinecraftProfileName(useForge.isSelected(), useShadersMod.isSelected()); - if(chkCustomProfileName.isSelected() && txtCustomProfileName.getText().trim() != ""){ - profileName = txtCustomProfileName.getText(); - } - - if (!downloadedOptifine) { - finalMessage = "Installed (but failed to download OptiFine). Restart Minecraft" + - (profileCreated == false ? " and Edit Profile->Use Version " + minecriftVersionName : " and select the '" + profileName + "' profile.") + - "\nPlease download and install Optifine " + OF_FILE_NAME + " from https://optifine.net/downloads before attempting to play."; - } - else { - finalMessage = "Installed successfully! Restart Minecraft" + - (profileCreated == false ? " and Edit Profile->Use Version " + minecriftVersionName : " and select the '" + profileName + "' profile."); - } - - monitor.setProgress(100); - monitor.close(); - return null; - } - - /* - * Executed in event dispatching thread - */ - @Override - public void done() { - setCursor(null); // turn off the wait cursor - JOptionPane.showMessageDialog(null, finalMessage, "Complete", JOptionPane.INFORMATION_MESSAGE); - dialog.dispose(); - emptyFrame.dispose(); - } - - } - @Override - public void propertyChange(PropertyChangeEvent evt) { - if ("progress" == evt.getPropertyName()) { - int progress = (Integer) evt.getNewValue(); - System.out.println(progress); - } - } - - public void run() - { - JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new String[]{"Install", "Cancel"}); - - emptyFrame = new Frame("Vivecraft Installer"); - emptyFrame.setUndecorated(true); - emptyFrame.setVisible(true); - emptyFrame.setLocationRelativeTo(null); - dialog = optionPane.createDialog(emptyFrame, "Vivecraft Installer"); - dialog.setResizable(true); - dialog.setSize(620,748); - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - dialog.setVisible(true); - String str = ((String)optionPane.getValue()); - if (str !=null && ((String)optionPane.getValue()).equalsIgnoreCase("Install")) - { - int option = JOptionPane.showOptionDialog( - null, - "Please ensure you have closed the Minecraft launcher before proceeding.\n" - //"Also, if installing with Forge please ensure you have installed Forge " + FORGE_VERSION + " first.", - ,"Important!", - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE, null, null, null); - - if (option == JOptionPane.OK_OPTION) { - monitor = new ProgressMonitor(null, "Installing Vivecraft...", "", 0, 100); - monitor.setMillisToDecideToPopup(0); - monitor.setMillisToPopup(0); - - task = new InstallTask(); - task.addPropertyChangeListener(this); - task.execute(); - } - else{ - dialog.dispose(); - emptyFrame.dispose(); - } - } - else{ - dialog.dispose(); - emptyFrame.dispose(); - } - } - - private static void createAndShowGUI() { - String userHomeDir = System.getProperty("user.home", "."); - String osType = System.getProperty("os.name").toLowerCase(); - String mcDir = ".minecraft"; - File minecraftDir; - - if (osType.contains("win") && System.getenv("APPDATA") != null) - { - minecraftDir = new File(System.getenv("APPDATA"), mcDir); - } - else if (osType.contains("mac")) - { - minecraftDir = new File(new File(new File(userHomeDir, "Library"),"Application Support"),"minecraft"); - } - else - { - minecraftDir = new File(userHomeDir, mcDir); - releaseNotePathAddition = "/"; - } - - Installer panel = new Installer(minecraftDir); - panel.run(); - } - - private boolean updateLauncherJson(File mcBaseDirFile, String minecriftVer) - { - boolean result = false; - - try { - int jsonIndentSpaces = 2; - String profileName = getMinecraftProfileName(useForge.isSelected(), useShadersMod.isSelected()); - if(chkCustomProfileName.isSelected() && txtCustomProfileName.getText().trim() != ""){ - profileName = txtCustomProfileName.getText(); - } - File fileJson = new File(mcBaseDirFile, "launcher_profiles.json"); - String json = readAsciiFile(fileJson); - JSONObject root = new JSONObject(json); - //System.out.println(root.toString(jsonIndentSpaces)); - - JSONObject profiles = (JSONObject)root.get("profiles"); - JSONObject prof = null; - try { - prof = (JSONObject) profiles.get(profileName); - } - catch (Exception e) { - //this is normal if doesnt exist. - } - java.text.DateFormat dateFormat=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - if (prof == null) { - prof = new JSONObject(); - prof.put("name", profileName); - prof.put("useHopperCrashService", false); - prof.put("launcherVisibilityOnGameClose", "keep the launcher open"); - prof.put("created", dateFormat.format(new java.util.Date())); - profiles.put(profileName, prof); - } - - prof.put("lastVersionId", minecriftVer + mod); - prof.put("javaArgs", "-Xmx" + ramAllocation.getSelectedItem() + "G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn256M -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true"); - root.put("selectedProfile", profileName); - prof.put("lastUsed", dateFormat.format(new java.util.Date())); - if(chkCustomGameDir.isSelected() && txtCustomGameDir.getText().trim() != ""){ - prof.put("gameDir", txtCustomGameDir.getText()); - } else { - prof.remove("gameDir"); - } - selectedDirText = new JTextField(); selectedDirText.setEditable(false); @@ -909,7 +394,6 @@ private boolean updateLauncherJson(File mcBaseDirFile, String minecriftVer) "If checked, install the drivers needed for KATVR Treadmill
" + "DO NOT select this unless you have the KATVR runtime installed."); katvr.setAlignmentX(LEFT_ALIGNMENT); - if (!isWindows) katvr.setEnabled(false); kiosk = new JCheckBox("Kiosk Mode", false); @@ -2164,4 +1648,4 @@ private boolean copyInputStreamToFile( InputStream in, File file ) return success; } -} +} \ No newline at end of file