use of net.technicpack.launchercore.launch.java.JavaVersionRepository 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();
}
use of net.technicpack.launchercore.launch.java.JavaVersionRepository 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());
}
use of net.technicpack.launchercore.launch.java.JavaVersionRepository 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());
}
Aggregations