use of net.technicpack.launcher.settings.TechnicSettings 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();
}
}
use of net.technicpack.launcher.settings.TechnicSettings 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