Search in sources :

Example 1 with DownloadException

use of net.technicpack.launchercore.exception.DownloadException in project LauncherV3 by TechnicPack.

the class Installer method internalInstallAndRun.

protected void internalInstallAndRun(final ResourceLoader resources, final ModpackModel pack, final String build, final boolean doFullInstall, final LauncherFrame frame, final DownloadListener listener, final boolean doLaunch) {
    runningThread = new Thread(new Runnable() {

        @Override
        public void run() {
            boolean everythingWorked = false;
            try {
                MojangVersion version = null;
                InstallTasksQueue<MojangVersion> tasksQueue = new InstallTasksQueue<MojangVersion>(listener);
                MojangVersionBuilder versionBuilder = createVersionBuilder(pack, tasksQueue);
                if (!pack.isLocalOnly() && build != null && !build.isEmpty()) {
                    buildTasksQueue(tasksQueue, resources, pack, build, doFullInstall, versionBuilder);
                    version = installer.installPack(tasksQueue, pack, build);
                } else {
                    version = versionBuilder.buildVersionFromKey(null);
                    if (version != null)
                        pack.initDirectories();
                }
                if (doLaunch) {
                    if (version == null) {
                        throw new PackNotAvailableOfflineException(pack.getDisplayName());
                    }
                    boolean usingMojangJava = version.getJavaVersion() != null && settings.shouldUseMojangJava();
                    JavaVersionRepository javaVersions = launcher.getJavaVersions();
                    Memory memoryObj = Memory.getClosestAvailableMemory(Memory.getMemoryFromId(settings.getMemory()), javaVersions.getSelectedVersion().is64Bit());
                    long memory = memoryObj.getMemoryMB();
                    String versionNumber = javaVersions.getSelectedVersion().getVersionNumber();
                    RunData data = pack.getRunData();
                    if (data != null && !data.isRunDataValid(memory, versionNumber, usingMojangJava)) {
                        FixRunDataDialog dialog = new FixRunDataDialog(frame, resources, data, javaVersions, memoryObj, !settings.shouldAutoAcceptModpackRequirements(), usingMojangJava);
                        dialog.setVisible(true);
                        if (dialog.getResult() == FixRunDataDialog.Result.ACCEPT) {
                            memoryObj = dialog.getRecommendedMemory();
                            memory = memoryObj.getMemoryMB();
                            IJavaVersion recommendedJavaVersion = dialog.getRecommendedJavaVersion();
                            javaVersions.selectVersion(recommendedJavaVersion.getVersionNumber(), recommendedJavaVersion.is64Bit());
                            if (dialog.shouldRemember()) {
                                settings.setAutoAcceptModpackRequirements(true);
                            }
                        } else
                            return;
                    }
                    if (!usingMojangJava && RunData.isJavaVersionAtLeast(versionNumber, "1.9")) {
                        int result = JOptionPane.showConfirmDialog(frame, resources.getString("launcher.jverwarning", versionNumber), resources.getString("launcher.jverwarning.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                        if (result != JOptionPane.YES_OPTION)
                            return;
                    }
                    LaunchAction launchAction = settings.getLaunchAction();
                    if (launchAction == null || launchAction == LaunchAction.HIDE) {
                        launcherUnhider = new LauncherUnhider(settings, frame);
                    } else
                        launcherUnhider = null;
                    LaunchOptions options = new LaunchOptions(pack.getDisplayName(), packIconMapper.getImageLocation(pack).getAbsolutePath(), settings);
                    launcher.launch(pack, memory, options, launcherUnhider, version);
                    if (launchAction == null || launchAction == LaunchAction.HIDE) {
                        frame.setVisible(false);
                    } else if (launchAction == LaunchAction.NOTHING) {
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                frame.launchCompleted();
                            }
                        });
                    } else if (launchAction == LaunchAction.CLOSE) {
                        System.exit(0);
                    }
                }
                everythingWorked = true;
            } catch (InterruptedException e) {
                boolean cancelledByUser = false;
                synchronized (cancelLock) {
                    if (isCancelledByUser) {
                        cancelledByUser = true;
                        isCancelledByUser = false;
                    }
                }
                // Canceled by user
                if (!cancelledByUser) {
                    if (e.getCause() != null)
                        Utils.getLogger().info("Cancelled by exception.");
                    else
                        Utils.getLogger().info("Cancelled by code.");
                    e.printStackTrace();
                } else
                    Utils.getLogger().info("Cancelled by user.");
            } catch (PackNotAvailableOfflineException e) {
                JOptionPane.showMessageDialog(frame, e.getMessage(), resources.getString("launcher.installerror.unavailable"), JOptionPane.WARNING_MESSAGE);
            } catch (DownloadException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.download", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (ZipException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.unzip", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (CacheDeleteException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.cache", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (BuildInaccessibleException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(frame, e.getMessage(), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (!everythingWorked || !doLaunch) {
                    EventQueue.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            frame.launchCompleted();
                        }
                    });
                }
            }
        }
    }) {

        // /Interrupt is being called from a mysterious source, so unless this is a user-initiated cancel
        // /Let's print the stack trace of the interruptor.
        @Override
        public void interrupt() {
            boolean userCancelled = false;
            synchronized (cancelLock) {
                if (isCancelledByUser)
                    userCancelled = true;
            }
            if (!userCancelled) {
                Utils.getLogger().info("Mysterious interruption source.");
                try {
                    // I am a charlatan and a hack.
                    throw new Exception("Grabbing stack trace- this isn't necessarily an error.");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            super.interrupt();
        }
    };
    runningThread.start();
}
Also used : Memory(net.technicpack.utilslib.Memory) CacheDeleteException(net.technicpack.launchercore.exception.CacheDeleteException) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) DownloadException(net.technicpack.launchercore.exception.DownloadException) RunData(net.technicpack.launchercore.modpacks.RunData) PackNotAvailableOfflineException(net.technicpack.launchercore.exception.PackNotAvailableOfflineException) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) LaunchAction(net.technicpack.launchercore.util.LaunchAction) MojangVersionBuilder(net.technicpack.minecraftcore.mojang.version.MojangVersionBuilder) BuildInaccessibleException(net.technicpack.launchercore.exception.BuildInaccessibleException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) BuildInaccessibleException(net.technicpack.launchercore.exception.BuildInaccessibleException) DownloadException(net.technicpack.launchercore.exception.DownloadException) ZipException(java.util.zip.ZipException) PackNotAvailableOfflineException(net.technicpack.launchercore.exception.PackNotAvailableOfflineException) CacheDeleteException(net.technicpack.launchercore.exception.CacheDeleteException) IOException(java.io.IOException) IJavaVersion(net.technicpack.launchercore.launch.java.IJavaVersion) FixRunDataDialog(net.technicpack.launcher.ui.components.FixRunDataDialog) LaunchOptions(net.technicpack.minecraftcore.launch.LaunchOptions)

Example 2 with DownloadException

use of net.technicpack.launchercore.exception.DownloadException in project LauncherV3 by TechnicPack.

the class LauncherMain method main.

public static void main(String[] argv) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
    }
    ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
    StartupParameters params = new StartupParameters(argv);
    try {
        JCommander.newBuilder().addObject(params).build().parse(argv);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    TechnicSettings settings = null;
    try {
        settings = SettingsFactory.buildSettingsObject(Relauncher.getRunningPath(LauncherMain.class), params.isMover());
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
    }
    if (settings == null) {
        ResourceLoader installerResources = new ResourceLoader(null, "net", "technicpack", "launcher", "resources");
        installerResources.setSupportedLanguages(supportedLanguages);
        installerResources.setLocale(ResourceLoader.DEFAULT_LOCALE);
        InstallerFrame dialog = new InstallerFrame(installerResources, params);
        dialog.setVisible(true);
        return;
    }
    LauncherDirectories directories = new TechnicLauncherDirectories(settings.getTechnicRoot());
    ResourceLoader resources = new ResourceLoader(directories, "net", "technicpack", "launcher", "resources");
    resources.setSupportedLanguages(supportedLanguages);
    resources.setLocale(settings.getLanguageCode());
    // Sanity check
    checkIfRunningInsideOneDrive(directories.getLauncherDirectory());
    if (params.getBuildNumber() != null && !params.getBuildNumber().isEmpty())
        buildNumber = new CommandLineBuildNumber(params);
    else
        buildNumber = new VersionFileBuildNumber(resources);
    TechnicConstants.setBuildNumber(buildNumber);
    setupLogging(directories, resources);
    String launcherBuild = buildNumber.getBuildNumber();
    int build = -1;
    try {
        build = Integer.parseInt((new VersionFileBuildNumber(resources)).getBuildNumber());
    } catch (NumberFormatException ex) {
    // This is probably a debug build or something, build number is invalid
    }
    // These 2 need to happen *before* the launcher or the updater run so we have valuable debug information and so
    // we can properly use websites that use Let's Encrypt (and other current certs not supported by old Java versions)
    runStartupDebug();
    injectNewRootCerts();
    Relauncher launcher = new TechnicRelauncher(new HttpUpdateStream("https://api.technicpack.net/launcher/"), settings.getBuildStream() + "4", build, directories, resources, params);
    try {
        if (launcher.runAutoUpdater())
            startLauncher(settings, params, directories, resources);
    } catch (InterruptedException e) {
    // Canceled by user
    } catch (DownloadException e) {
    // JOptionPane.showMessageDialog(null, resources.getString("launcher.updateerror.download", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) ResourceLoader(net.technicpack.ui.lang.ResourceLoader) LauncherDirectories(net.technicpack.launchercore.install.LauncherDirectories) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DownloadException(net.technicpack.launchercore.exception.DownloadException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) HttpUpdateStream(net.technicpack.autoupdate.http.HttpUpdateStream) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) DownloadException(net.technicpack.launchercore.exception.DownloadException) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) TechnicSettings(net.technicpack.launcher.settings.TechnicSettings) InstallerFrame(net.technicpack.launcher.ui.InstallerFrame) StartupParameters(net.technicpack.launcher.settings.StartupParameters) CommandLineBuildNumber(net.technicpack.launcher.autoupdate.CommandLineBuildNumber)

Example 3 with DownloadException

use of net.technicpack.launchercore.exception.DownloadException in project LauncherV3 by TechnicPack.

the class Download method run.

@Override
@SuppressWarnings("unused")
public void run() {
    try {
        HttpURLConnection conn = Utils.openHttpConnection(url);
        int response = conn.getResponseCode();
        int responseFamily = response / 100;
        if (responseFamily == 3) {
            String redirUrlText = conn.getHeaderField("Location");
            if (redirUrlText != null && !redirUrlText.isEmpty()) {
                URL redirectUrl = null;
                try {
                    redirectUrl = new URL(redirUrlText);
                } catch (MalformedURLException ex) {
                    throw new DownloadException("Invalid Redirect URL: " + url, ex);
                }
                conn = Utils.openHttpConnection(redirectUrl);
                response = conn.getResponseCode();
                responseFamily = response / 100;
            }
        }
        if (responseFamily != 2) {
            throw new DownloadException("The server issued a " + response + " response code.");
        }
        InputStream in = getConnectionInputStream(conn);
        size = conn.getContentLengthLong();
        outFile = new File(outPath);
        outFile.delete();
        try (ReadableByteChannel rbc = Channels.newChannel(in);
            FileOutputStream fos = new FileOutputStream(outFile)) {
            fos.getChannel().lock();
            stateChanged();
            Thread progress = new MonitorThread(Thread.currentThread(), rbc);
            progress.start();
            fos.getChannel().transferFrom(rbc, 0, size > 0 ? size : Integer.MAX_VALUE);
            in.close();
            rbc.close();
            progress.interrupt();
            synchronized (timeoutLock) {
                if (isTimedOut) {
                    return;
                }
            }
            if (size > 0) {
                long fileLength = outFile.length();
                if (size == fileLength) {
                    result = Result.SUCCESS;
                } else {
                    throw new DownloadException("File size doesn't match. Expected " + size + ", got " + fileLength);
                }
            } else {
                result = Result.SUCCESS;
            }
        }
    } catch (ClosedByInterruptException ex) {
        result = Result.FAILURE;
        return;
    } catch (PermissionDeniedException e) {
        exception = e;
        result = Result.PERMISSION_DENIED;
    } catch (OverlappingFileLockException e) {
        exception = e;
        result = Result.LOCK_FAILED;
    } catch (DownloadException e) {
        exception = e;
        result = Result.FAILURE;
    } catch (Exception e) {
        exception = e;
        e.printStackTrace();
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) PermissionDeniedException(net.technicpack.launchercore.exception.PermissionDeniedException) DownloadException(net.technicpack.launchercore.exception.DownloadException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) DownloadException(net.technicpack.launchercore.exception.DownloadException) PermissionDeniedException(net.technicpack.launchercore.exception.PermissionDeniedException) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException)

Example 4 with DownloadException

use of net.technicpack.launchercore.exception.DownloadException in project LauncherV3 by TechnicPack.

the class EnsureJavaRuntimeManifestTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
    JavaVersion wantedRuntime = version.getJavaVersion();
    if (wantedRuntime == null) {
        // Nothing to do here, this version doesn't have a Mojang JRE
        return;
    }
    final String runtimeName = wantedRuntime.getComponent();
    JavaRuntimes availableRuntimes = MojangUtils.getJavaRuntimes();
    if (availableRuntimes == null) {
        throw new DownloadException("Failed to get Mojang JRE information");
    }
    JavaRuntime runtime = availableRuntimes.getRuntimeForCurrentOS(runtimeName);
    Download manifest = runtime.getManifest();
    File output = new File(runtimesDirectory + File.separator + "manifests", runtimeName + ".json");
    (new File(output.getParent())).mkdirs();
    IFileVerifier fileVerifier = new SHA1FileVerifier(manifest.getSha1());
    if (!output.exists() || !fileVerifier.isFileValid(output)) {
        examineJavaQueue.addTask(new DownloadFileTask(manifest.getUrl(), output, fileVerifier));
    }
    examineJavaQueue.addTask(new InstallJavaRuntimeTask(modpack, runtimesDirectory, output, runtimeName, examineJavaQueue, downloadJavaQueue));
}
Also used : JavaRuntime(net.technicpack.minecraftcore.mojang.java.JavaRuntime) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) JavaVersion(net.technicpack.minecraftcore.mojang.version.io.JavaVersion) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) JavaRuntimes(net.technicpack.minecraftcore.mojang.java.JavaRuntimes) DownloadException(net.technicpack.launchercore.exception.DownloadException) Download(net.technicpack.minecraftcore.mojang.version.io.Download) File(java.io.File) DownloadFileTask(net.technicpack.launchercore.install.tasks.DownloadFileTask)

Example 5 with DownloadException

use of net.technicpack.launchercore.exception.DownloadException in project LauncherV3 by TechnicPack.

the class InstallMinecraftAssetsTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    String json = FileUtils.readFileToString(assetsIndex, StandardCharsets.UTF_8);
    JsonObject obj = MojangUtils.getGson().fromJson(json, JsonObject.class);
    if (obj == null) {
        throw new DownloadException("The assets json file was invalid.");
    }
    boolean isVirtual = false;
    if (obj.get(virtualField) != null)
        isVirtual = obj.get(virtualField).getAsBoolean();
    boolean mapToResources = false;
    if (obj.get(mapToResourcesField) != null)
        mapToResources = obj.get(mapToResourcesField).getAsBoolean();
    ((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAreAssetsVirtual(isVirtual);
    ((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAssetsMapToResources(mapToResources);
    JsonObject allObjects = obj.get(objectsField).getAsJsonObject();
    if (allObjects == null) {
        throw new DownloadException("The assets json file was invalid.");
    }
    String assetsKey = ((InstallTasksQueue<MojangVersion>) queue).getMetadata().getAssetsKey();
    if (assetsKey == null || assetsKey.isEmpty())
        assetsKey = "legacy";
    for (Map.Entry<String, JsonElement> field : allObjects.entrySet()) {
        String friendlyName = field.getKey();
        JsonObject file = field.getValue().getAsJsonObject();
        String hash = file.get(hashField).getAsString();
        long size = file.get(sizeField).getAsLong();
        File location = new File(assetsDirectory + "/objects/" + hash.substring(0, 2), hash);
        String url = MojangUtils.getResourceUrl(hash);
        (new File(location.getParent())).mkdirs();
        File target = null;
        if (isVirtual)
            target = new File(assetsDirectory + "/virtual/" + assetsKey + '/' + friendlyName);
        else if (mapToResources)
            target = new File(modpack.getResourcesDir(), friendlyName);
        checkAssetsQueue.addTask(new EnsureFileTask(location, new FileSizeVerifier(size), null, url, hash, downloadAssetsQueue, copyAssetsQueue));
        if (target != null && !target.exists()) {
            (new File(target.getParent())).mkdirs();
            copyAssetsQueue.addTask(new CopyFileTask(location, target));
        }
    }
}
Also used : EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) JsonObject(com.google.gson.JsonObject) CopyFileTask(net.technicpack.launchercore.install.tasks.CopyFileTask) JsonElement(com.google.gson.JsonElement) DownloadException(net.technicpack.launchercore.exception.DownloadException) FileSizeVerifier(net.technicpack.launchercore.install.verifiers.FileSizeVerifier) Map(java.util.Map) File(java.io.File)

Aggregations

DownloadException (net.technicpack.launchercore.exception.DownloadException)11 File (java.io.File)5 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)4 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)3 InstallTasksQueue (net.technicpack.launchercore.install.InstallTasksQueue)2 DownloadFileTask (net.technicpack.launchercore.install.tasks.DownloadFileTask)2 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)2 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 OverlappingFileLockException (java.nio.channels.OverlappingFileLockException)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1