Search in sources :

Example 1 with Installer

use of net.technicpack.launcher.launch.Installer in project LauncherV3 by TechnicPack.

the class LauncherMain method startLauncher.

private static void startLauncher(final TechnicSettings settings, StartupParameters startupParameters, final LauncherDirectories directories, ResourceLoader resources, IBuildNumber buildNumber) {
    UIManager.put("ComboBox.disabledBackground", LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    UIManager.put("ComboBox.disabledForeground", LauncherFrame.COLOR_GREY_TEXT);
    System.setProperty("xr.load.xml-reader", "org.ccil.cowan.tagsoup.Parser");
    // Remove all log files older than a week
    new Thread(new Runnable() {

        @Override
        public void run() {
            Iterator<File> files = FileUtils.iterateFiles(new File(directories.getLauncherDirectory(), "logs"), new String[] { "log" }, false);
            while (files.hasNext()) {
                File logFile = files.next();
                if (logFile.exists() && (new DateTime(logFile.lastModified())).isBefore(DateTime.now().minusWeeks(1))) {
                    logFile.delete();
                }
            }
        }
    }).start();
    Utils.getLogger().info("OS: " + System.getProperty("os.name").toLowerCase(Locale.ENGLISH));
    Utils.getLogger().info("Identified as " + OperatingSystem.getOperatingSystem().getName());
    final SplashScreen splash = new SplashScreen(resources.getImage("launch_splash.png"), 0);
    Color bg = LauncherFrame.COLOR_FORMELEMENT_INTERNAL;
    splash.getContentPane().setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), 255));
    splash.pack();
    splash.setLocationRelativeTo(null);
    splash.setVisible(true);
    boolean loadedAether = false;
    try {
        if (Class.forName("org.apache.maven.repository.internal.MavenRepositorySystemUtils", false, ClassLoader.getSystemClassLoader()) != null) {
            loadedAether = true;
        }
    } catch (ClassNotFoundException ex) {
    // Aether is not loaded
    }
    if (!loadedAether) {
        File launcherAssets = new File(directories.getAssetsDirectory(), "launcher");
        File aether = new File(launcherAssets, "aether-dep.jar");
        try {
            Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            m.setAccessible(true);
            m.invoke(ClassLoader.getSystemClassLoader(), aether.toURI().toURL());
        } catch (NoSuchMethodException ex) {
            ex.printStackTrace();
        } catch (InvocationTargetException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
    }
    JavaVersionRepository javaVersions = new JavaVersionRepository();
    (new InstalledJavaSource()).enumerateVersions(javaVersions);
    FileJavaSource javaVersionFile = FileJavaSource.load(new File(settings.getTechnicRoot(), "javaVersions.json"));
    javaVersionFile.enumerateVersions(javaVersions);
    javaVersions.selectVersion(settings.getJavaVersion(), settings.getJavaBitness());
    IUserStore<MojangUser> users = TechnicUserStore.load(new File(directories.getLauncherDirectory(), "users.json"));
    UserModel userModel = new UserModel(users, new AuthenticationService());
    MirrorStore mirrorStore = new MirrorStore(userModel);
    mirrorStore.addSecureMirror("mirror.technicpack.net", new JsonWebSecureMirror("http://mirror.technicpack.net/", "mirror.technicpack.net"));
    IModpackResourceType iconType = new IconResourceType();
    IModpackResourceType logoType = new LogoResourceType();
    IModpackResourceType backgroundType = new BackgroundResourceType();
    PackResourceMapper iconMapper = new PackResourceMapper(directories, resources.getImage("icon.png"), iconType);
    ImageRepository<ModpackModel> iconRepo = new ImageRepository<ModpackModel>(iconMapper, new PackImageStore(iconType, mirrorStore, userModel));
    ImageRepository<ModpackModel> logoRepo = new ImageRepository<ModpackModel>(new PackResourceMapper(directories, resources.getImage("modpack/ModImageFiller.png"), logoType), new PackImageStore(logoType, mirrorStore, userModel));
    ImageRepository<ModpackModel> backgroundRepo = new ImageRepository<ModpackModel>(new PackResourceMapper(directories, null, backgroundType), new PackImageStore(backgroundType, mirrorStore, userModel));
    ImageRepository<IUserType> skinRepo = new ImageRepository<IUserType>(new TechnicFaceMapper(directories, resources), new CrafatarFaceImageStore("http://crafatar.com/", mirrorStore));
    ImageRepository<AuthorshipInfo> avatarRepo = new ImageRepository<AuthorshipInfo>(new TechnicAvatarMapper(directories, resources), new WebAvatarImageStore(mirrorStore));
    HttpSolderApi httpSolder = new HttpSolderApi(settings.getClientId(), userModel);
    ISolderApi solder = new CachedSolderApi(directories, httpSolder, 60 * 60);
    HttpPlatformApi httpPlatform = new HttpPlatformApi("http://api.technicpack.net/", mirrorStore, buildNumber.getBuildNumber());
    IPlatformApi platform = new ModpackCachePlatformApi(httpPlatform, 60 * 60, directories);
    IPlatformSearchApi platformSearch = new HttpPlatformSearchApi("http://api.technicpack.net/", buildNumber.getBuildNumber());
    IInstalledPackRepository packStore = TechnicInstalledPackStore.load(new File(directories.getLauncherDirectory(), "installedPacks"));
    IAuthoritativePackSource packInfoRepository = new PlatformPackInfoRepository(platform, solder);
    ArrayList<IMigrator> migrators = new ArrayList<IMigrator>(1);
    migrators.add(new InitialV3Migrator(platform));
    SettingsFactory.migrateSettings(settings, packStore, directories, users, migrators);
    PackLoader packList = new PackLoader(directories, packStore, packInfoRepository);
    ModpackSelector selector = new ModpackSelector(resources, packList, new SolderPackSource("http://solder.technicpack.net/api/", solder), solder, platform, platformSearch, iconRepo);
    selector.setBorder(BorderFactory.createEmptyBorder());
    userModel.addAuthListener(selector);
    resources.registerResource(selector);
    DiscoverInfoPanel discoverInfoPanel = new DiscoverInfoPanel(resources, startupParameters.getDiscoverUrl(), platform, directories, selector);
    MinecraftLauncher launcher = new MinecraftLauncher(platform, directories, userModel, javaVersions);
    ModpackInstaller modpackInstaller = new ModpackInstaller(platform, settings.getClientId());
    Installer installer = new Installer(startupParameters, mirrorStore, directories, modpackInstaller, launcher, settings, iconMapper);
    IDiscordApi discordApi = new HttpDiscordApi("https://discordapp.com/api/");
    discordApi = new CacheDiscordApi(discordApi, 600, 60);
    final LauncherFrame frame = new LauncherFrame(resources, skinRepo, userModel, settings, selector, iconRepo, logoRepo, backgroundRepo, installer, avatarRepo, platform, directories, packStore, startupParameters, discoverInfoPanel, javaVersions, javaVersionFile, buildNumber, discordApi);
    userModel.addAuthListener(frame);
    ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            splash.dispose();
            if (settings.getLaunchToModpacks())
                frame.selectTab("modpacks");
        }
    };
    discoverInfoPanel.setLoadListener(listener);
    LoginFrame login = new LoginFrame(resources, settings, userModel, skinRepo);
    userModel.addAuthListener(login);
    userModel.addAuthListener(new IAuthListener() {

        @Override
        public void userChanged(Object user) {
            if (user == null)
                splash.dispose();
        }
    });
    userModel.initAuth();
    Utils.sendTracking("runLauncher", "run", buildNumber.getBuildNumber(), settings.getClientId());
}
Also used : MalformedURLException(java.net.MalformedURLException) DiscoverInfoPanel(net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel) PackLoader(net.technicpack.launchercore.modpacks.PackLoader) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) HttpPlatformApi(net.technicpack.platform.http.HttpPlatformApi) LogoResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.LogoResourceType) DateTime(org.joda.time.DateTime) MirrorStore(net.technicpack.launchercore.mirror.MirrorStore) IAuthoritativePackSource(net.technicpack.launchercore.modpacks.sources.IAuthoritativePackSource) ImageRepository(net.technicpack.launchercore.image.ImageRepository) MojangUser(net.technicpack.minecraftcore.mojang.auth.MojangUser) BackgroundResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.BackgroundResourceType) PackResourceMapper(net.technicpack.launchercore.modpacks.resources.PackResourceMapper) AuthorshipInfo(net.technicpack.platform.io.AuthorshipInfo) IInstalledPackRepository(net.technicpack.launchercore.modpacks.sources.IInstalledPackRepository) CachedSolderApi(net.technicpack.solder.cache.CachedSolderApi) IMigrator(net.technicpack.launcher.settings.migration.IMigrator) LauncherFrame(net.technicpack.launcher.ui.LauncherFrame) Method(java.lang.reflect.Method) MinecraftLauncher(net.technicpack.minecraftcore.launch.MinecraftLauncher) FileJavaSource(net.technicpack.launchercore.launch.java.source.FileJavaSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) IPlatformApi(net.technicpack.platform.IPlatformApi) IDiscordApi(net.technicpack.discord.IDiscordApi) WebAvatarImageStore(net.technicpack.launchercore.image.face.WebAvatarImageStore) ActionListener(java.awt.event.ActionListener) JsonWebSecureMirror(net.technicpack.launchercore.mirror.secure.rest.JsonWebSecureMirror) PackImageStore(net.technicpack.launchercore.modpacks.resources.PackImageStore) ModpackCachePlatformApi(net.technicpack.platform.cache.ModpackCachePlatformApi) File(java.io.File) HttpPlatformSearchApi(net.technicpack.platform.http.HttpPlatformSearchApi) PlatformPackInfoRepository(net.technicpack.platform.PlatformPackInfoRepository) Installer(net.technicpack.launcher.launch.Installer) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) IAuthListener(net.technicpack.launchercore.auth.IAuthListener) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) UserModel(net.technicpack.launchercore.auth.UserModel) SolderPackSource(net.technicpack.solder.SolderPackSource) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) CrafatarFaceImageStore(net.technicpack.launchercore.image.face.CrafatarFaceImageStore) SplashScreen(net.technicpack.ui.controls.installation.SplashScreen) ISolderApi(net.technicpack.solder.ISolderApi) LoginFrame(net.technicpack.launcher.ui.LoginFrame) ModpackSelector(net.technicpack.launcher.ui.components.modpacks.ModpackSelector) HttpSolderApi(net.technicpack.solder.http.HttpSolderApi) IconResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IconResourceType) InitialV3Migrator(net.technicpack.launcher.settings.migration.InitialV3Migrator) InstalledJavaSource(net.technicpack.launchercore.launch.java.source.InstalledJavaSource) IUserType(net.technicpack.launchercore.auth.IUserType) IPlatformSearchApi(net.technicpack.platform.IPlatformSearchApi) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) HttpDiscordApi(net.technicpack.discord.HttpDiscordApi) CacheDiscordApi(net.technicpack.discord.CacheDiscordApi) IModpackResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IModpackResourceType) AuthenticationService(net.technicpack.minecraftcore.mojang.auth.AuthenticationService)

Example 2 with Installer

use of net.technicpack.launcher.launch.Installer in project LauncherV3 by TechnicPack.

the class LauncherMain method startLauncher.

private static void startLauncher(final TechnicSettings settings, StartupParameters startupParameters, final LauncherDirectories directories, ResourceLoader resources) {
    UIManager.put("ComboBox.disabledBackground", LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    UIManager.put("ComboBox.disabledForeground", LauncherFrame.COLOR_GREY_TEXT);
    System.setProperty("xr.load.xml-reader", "org.ccil.cowan.tagsoup.Parser");
    // Remove all log files older than a week
    new Thread(() -> {
        Iterator<File> files = FileUtils.iterateFiles(new File(directories.getLauncherDirectory(), "logs"), new String[] { "log" }, false);
        while (files.hasNext()) {
            File logFile = files.next();
            if (logFile.exists() && (new DateTime(logFile.lastModified())).isBefore(DateTime.now().minusWeeks(1))) {
                logFile.delete();
            }
        }
    }).start();
    final SplashScreen splash = new SplashScreen(resources.getImage("launch_splash.png"), 0);
    Color bg = LauncherFrame.COLOR_FORMELEMENT_INTERNAL;
    splash.getContentPane().setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), 255));
    splash.pack();
    splash.setLocationRelativeTo(null);
    splash.setVisible(true);
    JavaVersionRepository javaVersions = new JavaVersionRepository();
    (new InstalledJavaSource()).enumerateVersions(javaVersions);
    FileJavaSource javaVersionFile = FileJavaSource.load(new File(settings.getTechnicRoot(), "javaVersions.json"));
    javaVersionFile.enumerateVersions(javaVersions);
    javaVersions.selectVersion(settings.getJavaVersion(), settings.getJavaBitness());
    TechnicUserStore users = TechnicUserStore.load(new File(directories.getLauncherDirectory(), "users.json"));
    MicrosoftAuthenticator microsoftAuthenticator = new MicrosoftAuthenticator(new File(directories.getLauncherDirectory(), "oauth"));
    MojangAuthenticator mojangAuthenticator = new MojangAuthenticator(users.getClientToken());
    UserModel userModel = new UserModel(users, mojangAuthenticator, microsoftAuthenticator);
    IModpackResourceType iconType = new IconResourceType();
    IModpackResourceType logoType = new LogoResourceType();
    IModpackResourceType backgroundType = new BackgroundResourceType();
    PackResourceMapper iconMapper = new PackResourceMapper(directories, resources.getImage("icon.png"), iconType);
    ImageRepository<ModpackModel> iconRepo = new ImageRepository<>(iconMapper, new PackImageStore(iconType));
    ImageRepository<ModpackModel> logoRepo = new ImageRepository<>(new PackResourceMapper(directories, resources.getImage("modpack/ModImageFiller.png"), logoType), new PackImageStore(logoType));
    ImageRepository<ModpackModel> backgroundRepo = new ImageRepository<>(new PackResourceMapper(directories, null, backgroundType), new PackImageStore(backgroundType));
    ImageRepository<IUserType> skinRepo = new ImageRepository<>(new TechnicFaceMapper(directories, resources), new MinotarFaceImageStore("https://minotar.net/"));
    ImageRepository<AuthorshipInfo> avatarRepo = new ImageRepository<>(new TechnicAvatarMapper(directories, resources), new WebAvatarImageStore());
    HttpSolderApi httpSolder = new HttpSolderApi(settings.getClientId());
    ISolderApi solder = new CachedSolderApi(directories, httpSolder, 60 * 60);
    HttpPlatformApi httpPlatform = new HttpPlatformApi("https://api.technicpack.net/", buildNumber.getBuildNumber());
    IPlatformApi platform = new ModpackCachePlatformApi(httpPlatform, 60 * 60, directories);
    IPlatformSearchApi platformSearch = new HttpPlatformSearchApi("https://api.technicpack.net/", buildNumber.getBuildNumber());
    IInstalledPackRepository packStore = TechnicInstalledPackStore.load(new File(directories.getLauncherDirectory(), "installedPacks"));
    IAuthoritativePackSource packInfoRepository = new PlatformPackInfoRepository(platform, solder);
    ArrayList<IMigrator> migrators = new ArrayList<IMigrator>(1);
    migrators.add(new InitialV3Migrator(platform));
    migrators.add(new ResetJvmArgsIfDefaultString());
    SettingsFactory.migrateSettings(settings, packStore, directories, users, migrators);
    PackLoader packList = new PackLoader(directories, packStore, packInfoRepository);
    ModpackSelector selector = new ModpackSelector(resources, packList, new SolderPackSource("https://solder.technicpack.net/api/", solder), solder, platform, platformSearch, iconRepo);
    selector.setBorder(BorderFactory.createEmptyBorder());
    userModel.addAuthListener(selector);
    resources.registerResource(selector);
    DiscoverInfoPanel discoverInfoPanel = new DiscoverInfoPanel(resources, startupParameters.getDiscoverUrl(), platform, directories, selector);
    MinecraftLauncher launcher = new MinecraftLauncher(platform, directories, userModel, javaVersions, buildNumber);
    ModpackInstaller modpackInstaller = new ModpackInstaller(platform, settings.getClientId());
    Installer installer = new Installer(startupParameters, directories, modpackInstaller, launcher, settings, iconMapper);
    IDiscordApi discordApi = new HttpDiscordApi("https://discord.com/api/");
    discordApi = new CacheDiscordApi(discordApi, 600, 60);
    final LauncherFrame frame = new LauncherFrame(resources, skinRepo, userModel, settings, selector, iconRepo, logoRepo, backgroundRepo, installer, avatarRepo, platform, directories, packStore, startupParameters, discoverInfoPanel, javaVersions, javaVersionFile, buildNumber, discordApi);
    userModel.addAuthListener(frame);
    ActionListener listener = e -> {
        splash.dispose();
        if (settings.getLaunchToModpacks())
            frame.selectTab("modpacks");
    };
    discoverInfoPanel.setLoadListener(listener);
    LoginFrame login = new LoginFrame(resources, settings, userModel, skinRepo);
    userModel.addAuthListener(login);
    userModel.addAuthListener(user -> {
        if (user == null)
            splash.dispose();
    });
    userModel.startupAuth();
    Utils.sendTracking("runLauncher", "run", buildNumber.getBuildNumber(), settings.getClientId());
}
Also used : PackImageStore(net.technicpack.launchercore.modpacks.resources.PackImageStore) CommandLineBuildNumber(net.technicpack.launcher.autoupdate.CommandLineBuildNumber) IModpackResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IModpackResourceType) Utils(net.technicpack.utilslib.Utils) SSLContext(javax.net.ssl.SSLContext) IPlatformApi(net.technicpack.platform.IPlatformApi) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) IconResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IconResourceType) LoggerOutputStream(net.technicpack.ui.components.LoggerOutputStream) JavaUtils(net.technicpack.utilslib.JavaUtils) HttpPlatformApi(net.technicpack.platform.http.HttpPlatformApi) KeyStoreException(java.security.KeyStoreException) MinecraftLauncher(net.technicpack.minecraftcore.launch.MinecraftLauncher) IInstalledPackRepository(net.technicpack.launchercore.modpacks.sources.IInstalledPackRepository) InetAddress(java.net.InetAddress) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) IDiscordApi(net.technicpack.discord.IDiscordApi) HttpPlatformSearchApi(net.technicpack.platform.http.HttpPlatformSearchApi) WebAvatarImageStore(net.technicpack.launchercore.image.face.WebAvatarImageStore) InstallerFrame(net.technicpack.launcher.ui.InstallerFrame) ConsoleFrame(net.technicpack.ui.components.ConsoleFrame) Path(java.nio.file.Path) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) PackResourceMapper(net.technicpack.launchercore.modpacks.resources.PackResourceMapper) SettingsFactory(net.technicpack.launcher.settings.SettingsFactory) ISolderApi(net.technicpack.solder.ISolderApi) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) CacheDiscordApi(net.technicpack.discord.CacheDiscordApi) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler) KeyStore(java.security.KeyStore) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicSettings(net.technicpack.launcher.settings.TechnicSettings) InitialV3Migrator(net.technicpack.launcher.settings.migration.InitialV3Migrator) HttpSolderApi(net.technicpack.solder.http.HttpSolderApi) KeyManagementException(java.security.KeyManagementException) Logger(java.util.logging.Logger) BuildLogFormatter(net.technicpack.launchercore.logging.BuildLogFormatter) Collectors(java.util.stream.Collectors) BackgroundResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.BackgroundResourceType) Certificate(java.security.cert.Certificate) IMigrator(net.technicpack.launcher.settings.migration.IMigrator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Installer(net.technicpack.launcher.launch.Installer) SplashScreen(net.technicpack.ui.controls.installation.SplashScreen) FileJavaSource(net.technicpack.launchercore.launch.java.source.FileJavaSource) Handler(java.util.logging.Handler) HttpDiscordApi(net.technicpack.discord.HttpDiscordApi) ModpackSelector(net.technicpack.launcher.ui.components.modpacks.ModpackSelector) UserModel(net.technicpack.launchercore.auth.UserModel) IAuthoritativePackSource(net.technicpack.launchercore.modpacks.sources.IAuthoritativePackSource) MinotarFaceImageStore(net.technicpack.launchercore.image.face.MinotarFaceImageStore) java.util(java.util) ActionListener(java.awt.event.ActionListener) MicrosoftAuthenticator(net.technicpack.minecraftcore.microsoft.auth.MicrosoftAuthenticator) ResourceLoader(net.technicpack.ui.lang.ResourceLoader) StartupParameters(net.technicpack.launcher.settings.StartupParameters) Level(java.util.logging.Level) IUserStore(net.technicpack.launchercore.auth.IUserStore) LauncherFrame(net.technicpack.launcher.ui.LauncherFrame) DownloadException(net.technicpack.launchercore.exception.DownloadException) IPlatformSearchApi(net.technicpack.platform.IPlatformSearchApi) HttpUpdateStream(net.technicpack.autoupdate.http.HttpUpdateStream) IUserType(net.technicpack.launchercore.auth.IUserType) DiscoverInfoPanel(net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel) ModpackCachePlatformApi(net.technicpack.platform.cache.ModpackCachePlatformApi) PackLoader(net.technicpack.launchercore.modpacks.PackLoader) AuthorshipInfo(net.technicpack.platform.io.AuthorshipInfo) net.technicpack.launcher.io(net.technicpack.launcher.io) LogoResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.LogoResourceType) Console(net.technicpack.ui.components.Console) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) CachedSolderApi(net.technicpack.solder.cache.CachedSolderApi) InstalledJavaSource(net.technicpack.launchercore.launch.java.source.InstalledJavaSource) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) Files(java.nio.file.Files) IBuildNumber(net.technicpack.autoupdate.IBuildNumber) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) JCommander(com.beust.jcommander.JCommander) DateTime(org.joda.time.DateTime) PlatformPackInfoRepository(net.technicpack.platform.PlatformPackInfoRepository) FileUtils(org.apache.commons.io.FileUtils) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) MojangAuthenticator(net.technicpack.minecraftcore.mojang.auth.MojangAuthenticator) java.awt(java.awt) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) LoginFrame(net.technicpack.launcher.ui.LoginFrame) java.io(java.io) Paths(java.nio.file.Paths) ImageRepository(net.technicpack.launchercore.image.ImageRepository) LauncherDirectories(net.technicpack.launchercore.install.LauncherDirectories) SolderPackSource(net.technicpack.solder.SolderPackSource) TechnicConstants(net.technicpack.launchercore.TechnicConstants) OperatingSystem(net.technicpack.utilslib.OperatingSystem) javax.swing(javax.swing) DiscoverInfoPanel(net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel) MinotarFaceImageStore(net.technicpack.launchercore.image.face.MinotarFaceImageStore) PackLoader(net.technicpack.launchercore.modpacks.PackLoader) HttpPlatformApi(net.technicpack.platform.http.HttpPlatformApi) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) LogoResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.LogoResourceType) DateTime(org.joda.time.DateTime) IAuthoritativePackSource(net.technicpack.launchercore.modpacks.sources.IAuthoritativePackSource) ImageRepository(net.technicpack.launchercore.image.ImageRepository) BackgroundResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.BackgroundResourceType) PackResourceMapper(net.technicpack.launchercore.modpacks.resources.PackResourceMapper) AuthorshipInfo(net.technicpack.platform.io.AuthorshipInfo) IInstalledPackRepository(net.technicpack.launchercore.modpacks.sources.IInstalledPackRepository) CachedSolderApi(net.technicpack.solder.cache.CachedSolderApi) IMigrator(net.technicpack.launcher.settings.migration.IMigrator) LauncherFrame(net.technicpack.launcher.ui.LauncherFrame) MinecraftLauncher(net.technicpack.minecraftcore.launch.MinecraftLauncher) FileJavaSource(net.technicpack.launchercore.launch.java.source.FileJavaSource) IPlatformApi(net.technicpack.platform.IPlatformApi) IDiscordApi(net.technicpack.discord.IDiscordApi) WebAvatarImageStore(net.technicpack.launchercore.image.face.WebAvatarImageStore) ActionListener(java.awt.event.ActionListener) MicrosoftAuthenticator(net.technicpack.minecraftcore.microsoft.auth.MicrosoftAuthenticator) PackImageStore(net.technicpack.launchercore.modpacks.resources.PackImageStore) ModpackCachePlatformApi(net.technicpack.platform.cache.ModpackCachePlatformApi) HttpPlatformSearchApi(net.technicpack.platform.http.HttpPlatformSearchApi) PlatformPackInfoRepository(net.technicpack.platform.PlatformPackInfoRepository) Installer(net.technicpack.launcher.launch.Installer) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) MojangAuthenticator(net.technicpack.minecraftcore.mojang.auth.MojangAuthenticator) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) UserModel(net.technicpack.launchercore.auth.UserModel) SolderPackSource(net.technicpack.solder.SolderPackSource) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) SplashScreen(net.technicpack.ui.controls.installation.SplashScreen) ISolderApi(net.technicpack.solder.ISolderApi) LoginFrame(net.technicpack.launcher.ui.LoginFrame) ModpackSelector(net.technicpack.launcher.ui.components.modpacks.ModpackSelector) HttpSolderApi(net.technicpack.solder.http.HttpSolderApi) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) IconResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IconResourceType) InitialV3Migrator(net.technicpack.launcher.settings.migration.InitialV3Migrator) InstalledJavaSource(net.technicpack.launchercore.launch.java.source.InstalledJavaSource) IUserType(net.technicpack.launchercore.auth.IUserType) IPlatformSearchApi(net.technicpack.platform.IPlatformSearchApi) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) HttpDiscordApi(net.technicpack.discord.HttpDiscordApi) CacheDiscordApi(net.technicpack.discord.CacheDiscordApi) IModpackResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IModpackResourceType)

Example 3 with Installer

use of net.technicpack.launcher.launch.Installer in project LauncherV3 by TechnicPack.

the class LauncherMain method injectNewRootCerts.

private static void injectNewRootCerts() {
    // Adapted from Forge installer
    final String javaVersion = System.getProperty("java.version");
    if (javaVersion == null || !javaVersion.startsWith("1.8.0_")) {
        Utils.getLogger().log(Level.INFO, "Don't need to inject new root certificates: Java is newer than 8 (" + javaVersion + ")");
        return;
    }
    try {
        if (Integer.parseInt(javaVersion.substring("1.8.0_".length())) >= 101) {
            Utils.getLogger().log(Level.INFO, "Don't need to inject new root certificates: Java 8 is 101+ (" + javaVersion + ")");
            return;
        }
    } catch (final NumberFormatException e) {
        Utils.getLogger().log(Level.WARNING, "Couldn't parse Java version, can't inject new root certs", e);
        return;
    }
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        final Path ksPath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts");
        keyStore.load(Files.newInputStream(ksPath), "changeit".toCharArray());
        Map<String, Certificate> jdkTrustStore = Collections.list(keyStore.aliases()).stream().collect(Collectors.toMap(a -> a, (String alias) -> {
            try {
                return keyStore.getCertificate(alias);
            } catch (KeyStoreException e) {
                Utils.getLogger().log(Level.WARNING, "Failed to get certificate", e);
                return null;
            }
        }));
        KeyStore leKS = KeyStore.getInstance(KeyStore.getDefaultType());
        InputStream leKSFile = LauncherMain.class.getResourceAsStream("/net/technicpack/launcher/resources/technickeystore.jks");
        leKS.load(leKSFile, "technicrootca".toCharArray());
        Map<String, Certificate> leTrustStore = Collections.list(leKS.aliases()).stream().collect(Collectors.toMap(a -> a, (String alias) -> {
            try {
                return leKS.getCertificate(alias);
            } catch (KeyStoreException e) {
                Utils.getLogger().log(Level.WARNING, "Failed to get certificate", e);
                return null;
            }
        }));
        KeyStore mergedTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        mergedTrustStore.load(null, new char[0]);
        for (final Map.Entry<String, Certificate> entry : jdkTrustStore.entrySet()) {
            mergedTrustStore.setCertificateEntry(entry.getKey(), entry.getValue());
        }
        for (final Map.Entry<String, Certificate> entry : leTrustStore.entrySet()) {
            mergedTrustStore.setCertificateEntry(entry.getKey(), entry.getValue());
        }
        TrustManagerFactory instance = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        instance.init(mergedTrustStore);
        SSLContext tls = SSLContext.getInstance("TLS");
        tls.init(null, instance.getTrustManagers(), null);
        HttpsURLConnection.setDefaultSSLSocketFactory(tls.getSocketFactory());
        Utils.getLogger().log(Level.INFO, "Injected new root certificates");
    } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
        Utils.getLogger().log(Level.WARNING, "Failed to inject new root certificates. Problems might happen");
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) PackImageStore(net.technicpack.launchercore.modpacks.resources.PackImageStore) CommandLineBuildNumber(net.technicpack.launcher.autoupdate.CommandLineBuildNumber) IModpackResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IModpackResourceType) Utils(net.technicpack.utilslib.Utils) SSLContext(javax.net.ssl.SSLContext) IPlatformApi(net.technicpack.platform.IPlatformApi) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) IconResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IconResourceType) LoggerOutputStream(net.technicpack.ui.components.LoggerOutputStream) JavaUtils(net.technicpack.utilslib.JavaUtils) HttpPlatformApi(net.technicpack.platform.http.HttpPlatformApi) KeyStoreException(java.security.KeyStoreException) MinecraftLauncher(net.technicpack.minecraftcore.launch.MinecraftLauncher) IInstalledPackRepository(net.technicpack.launchercore.modpacks.sources.IInstalledPackRepository) InetAddress(java.net.InetAddress) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) IDiscordApi(net.technicpack.discord.IDiscordApi) HttpPlatformSearchApi(net.technicpack.platform.http.HttpPlatformSearchApi) WebAvatarImageStore(net.technicpack.launchercore.image.face.WebAvatarImageStore) InstallerFrame(net.technicpack.launcher.ui.InstallerFrame) ConsoleFrame(net.technicpack.ui.components.ConsoleFrame) Path(java.nio.file.Path) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) PackResourceMapper(net.technicpack.launchercore.modpacks.resources.PackResourceMapper) SettingsFactory(net.technicpack.launcher.settings.SettingsFactory) ISolderApi(net.technicpack.solder.ISolderApi) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) CacheDiscordApi(net.technicpack.discord.CacheDiscordApi) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler) KeyStore(java.security.KeyStore) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicSettings(net.technicpack.launcher.settings.TechnicSettings) InitialV3Migrator(net.technicpack.launcher.settings.migration.InitialV3Migrator) HttpSolderApi(net.technicpack.solder.http.HttpSolderApi) KeyManagementException(java.security.KeyManagementException) Logger(java.util.logging.Logger) BuildLogFormatter(net.technicpack.launchercore.logging.BuildLogFormatter) Collectors(java.util.stream.Collectors) BackgroundResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.BackgroundResourceType) Certificate(java.security.cert.Certificate) IMigrator(net.technicpack.launcher.settings.migration.IMigrator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Installer(net.technicpack.launcher.launch.Installer) SplashScreen(net.technicpack.ui.controls.installation.SplashScreen) FileJavaSource(net.technicpack.launchercore.launch.java.source.FileJavaSource) Handler(java.util.logging.Handler) HttpDiscordApi(net.technicpack.discord.HttpDiscordApi) ModpackSelector(net.technicpack.launcher.ui.components.modpacks.ModpackSelector) UserModel(net.technicpack.launchercore.auth.UserModel) IAuthoritativePackSource(net.technicpack.launchercore.modpacks.sources.IAuthoritativePackSource) MinotarFaceImageStore(net.technicpack.launchercore.image.face.MinotarFaceImageStore) java.util(java.util) ActionListener(java.awt.event.ActionListener) MicrosoftAuthenticator(net.technicpack.minecraftcore.microsoft.auth.MicrosoftAuthenticator) ResourceLoader(net.technicpack.ui.lang.ResourceLoader) StartupParameters(net.technicpack.launcher.settings.StartupParameters) Level(java.util.logging.Level) IUserStore(net.technicpack.launchercore.auth.IUserStore) LauncherFrame(net.technicpack.launcher.ui.LauncherFrame) DownloadException(net.technicpack.launchercore.exception.DownloadException) IPlatformSearchApi(net.technicpack.platform.IPlatformSearchApi) HttpUpdateStream(net.technicpack.autoupdate.http.HttpUpdateStream) IUserType(net.technicpack.launchercore.auth.IUserType) DiscoverInfoPanel(net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel) ModpackCachePlatformApi(net.technicpack.platform.cache.ModpackCachePlatformApi) PackLoader(net.technicpack.launchercore.modpacks.PackLoader) AuthorshipInfo(net.technicpack.platform.io.AuthorshipInfo) net.technicpack.launcher.io(net.technicpack.launcher.io) LogoResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.LogoResourceType) Console(net.technicpack.ui.components.Console) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) CachedSolderApi(net.technicpack.solder.cache.CachedSolderApi) InstalledJavaSource(net.technicpack.launchercore.launch.java.source.InstalledJavaSource) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) Files(java.nio.file.Files) IBuildNumber(net.technicpack.autoupdate.IBuildNumber) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) JCommander(com.beust.jcommander.JCommander) DateTime(org.joda.time.DateTime) PlatformPackInfoRepository(net.technicpack.platform.PlatformPackInfoRepository) FileUtils(org.apache.commons.io.FileUtils) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) MojangAuthenticator(net.technicpack.minecraftcore.mojang.auth.MojangAuthenticator) java.awt(java.awt) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) LoginFrame(net.technicpack.launcher.ui.LoginFrame) java.io(java.io) Paths(java.nio.file.Paths) ImageRepository(net.technicpack.launchercore.image.ImageRepository) LauncherDirectories(net.technicpack.launchercore.install.LauncherDirectories) SolderPackSource(net.technicpack.solder.SolderPackSource) TechnicConstants(net.technicpack.launchercore.TechnicConstants) OperatingSystem(net.technicpack.utilslib.OperatingSystem) javax.swing(javax.swing) CertificateException(java.security.cert.CertificateException) ResetJvmArgsIfDefaultString(net.technicpack.launcher.settings.migration.ResetJvmArgsIfDefaultString) KeyStoreException(java.security.KeyStoreException) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) KeyManagementException(java.security.KeyManagementException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Certificate(java.security.cert.Certificate)

Aggregations

ActionListener (java.awt.event.ActionListener)3 CacheDiscordApi (net.technicpack.discord.CacheDiscordApi)3 HttpDiscordApi (net.technicpack.discord.HttpDiscordApi)3 IDiscordApi (net.technicpack.discord.IDiscordApi)3 Installer (net.technicpack.launcher.launch.Installer)3 IMigrator (net.technicpack.launcher.settings.migration.IMigrator)3 InitialV3Migrator (net.technicpack.launcher.settings.migration.InitialV3Migrator)3 LauncherFrame (net.technicpack.launcher.ui.LauncherFrame)3 LoginFrame (net.technicpack.launcher.ui.LoginFrame)3 DiscoverInfoPanel (net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel)3 ModpackSelector (net.technicpack.launcher.ui.components.modpacks.ModpackSelector)3 IUserType (net.technicpack.launchercore.auth.IUserType)3 UserModel (net.technicpack.launchercore.auth.UserModel)3 ImageRepository (net.technicpack.launchercore.image.ImageRepository)3 WebAvatarImageStore (net.technicpack.launchercore.image.face.WebAvatarImageStore)3 ModpackInstaller (net.technicpack.launchercore.install.ModpackInstaller)3 JavaVersionRepository (net.technicpack.launchercore.launch.java.JavaVersionRepository)3 FileJavaSource (net.technicpack.launchercore.launch.java.source.FileJavaSource)3 InstalledJavaSource (net.technicpack.launchercore.launch.java.source.InstalledJavaSource)3 ModpackModel (net.technicpack.launchercore.modpacks.ModpackModel)3