forked from Legacy-Fabric/fabric-installer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
368 additions
and
1,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
node { | ||
stage 'Checkout' | ||
|
||
checkout scm | ||
|
||
stage 'Build' | ||
|
||
sh "rm -rf build/libs/" | ||
sh "chmod +x gradlew" | ||
sh "./gradlew build uploadArchives --refresh-dependencies --stacktrace" | ||
|
||
stage "Archive artifacts" | ||
|
||
archive 'build/libs/*' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
group = net.fabricmc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.installer; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.fabricmc.installer.util.*; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class ClientInstaller { | ||
|
||
public static void install(File mcDir, String mappingsVersion, String loaderVersion, IInstallerProgress progress) throws IOException { | ||
System.out.println("Installing " + mappingsVersion + " with fabric " + loaderVersion); | ||
String[] split = mappingsVersion.split("\\."); | ||
|
||
String profileName = String.format("%s-%s-%s", Reference.LOADER_NAME, loaderVersion, mappingsVersion); | ||
|
||
String url = String.format("%s/%s/%s/%s/%3$s-%4$s.json", Reference.MAVEN_SERVER_URL, Reference.PACKAGE, Reference.LOADER_NAME, loaderVersion); | ||
String fabricInstallMeta = IOUtils.toString(new URL(url), "UTF-8"); | ||
JsonObject installMeta = Utils.GSON.fromJson(fabricInstallMeta, JsonObject.class); | ||
|
||
MinecraftLaunchJson launchJson = new MinecraftLaunchJson(installMeta); | ||
launchJson.id = profileName; | ||
launchJson.inheritsFrom = split[0]; | ||
|
||
//Adds loader and the mappings | ||
launchJson.libraries.add(new MinecraftLaunchJson.Library(Reference.PACKAGE.replaceAll("/", ".") + ":" + Reference.MAPPINGS_NAME + ":" + mappingsVersion, Reference.MAVEN_SERVER_URL)); | ||
launchJson.libraries.add(new MinecraftLaunchJson.Library(Reference.PACKAGE.replaceAll("/", ".") + ":" + Reference.LOADER_NAME + ":" + loaderVersion, Reference.MAVEN_SERVER_URL)); | ||
|
||
File versionsDir = new File(mcDir, "versions"); | ||
File profileDir = new File(versionsDir, profileName); | ||
File profileJson = new File(profileDir, profileName + ".json"); | ||
|
||
if (!profileDir.exists()) { | ||
profileDir.mkdirs(); | ||
} | ||
|
||
/* | ||
This is a fun meme | ||
The vanilla launcher assumes the profile name is the same name as a maven artifact, how ever our profile name is a combination of 2 | ||
(mappings and loader). The launcher will also accept any jar with the same name as the profile, it doesnt care if its empty | ||
*/ | ||
File dummyJar = new File(profileDir, profileName + ".jar"); | ||
FileUtils.touch(dummyJar); | ||
|
||
FileUtils.writeStringToFile(profileJson, Utils.GSON.toJson(launchJson), StandardCharsets.UTF_8); | ||
|
||
progress.updateProgress(Translator.getString("install.success"), 100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.installer; | ||
|
||
import net.fabricmc.installer.util.*; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.EmptyBorder; | ||
import java.awt.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.function.Consumer; | ||
|
||
public class InstallerGui extends JFrame implements IInstallerProgress { | ||
private JPanel contentPane; | ||
private JButton buttonInstall; | ||
private JComboBox<String> mappingVersionComboBox; | ||
private JComboBox<String> loaderVersionComboBox; | ||
private JTextField installLocation; | ||
private JButton selectFolderButton; | ||
private JProgressBar progressBar; | ||
private JLabel statusLabel; | ||
|
||
public InstallerGui() throws XmlPullParserException, IOException { | ||
initComponents(); | ||
setContentPane(contentPane); | ||
setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); | ||
|
||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
setIconImage(Toolkit.getDefaultToolkit().getImage(classLoader.getResource("icon.png"))); | ||
|
||
MavenHandler loaderMaven = new MavenHandler(); | ||
loaderMaven.load(Reference.MAVEN_SERVER_URL, Reference.PACKAGE, Reference.LOADER_NAME); | ||
for (String str : loaderMaven.versions) { | ||
loaderVersionComboBox.addItem(str); | ||
} | ||
loaderVersionComboBox.setSelectedIndex(0); | ||
|
||
MavenHandler mappingMaven = new MavenHandler(); | ||
mappingMaven.load(Reference.MAVEN_SERVER_URL, Reference.PACKAGE, Reference.MAPPINGS_NAME); | ||
for (String str : mappingMaven.versions) { | ||
mappingVersionComboBox.addItem(str); | ||
} | ||
mappingVersionComboBox.setSelectedIndex(0); | ||
} | ||
|
||
public void install() { | ||
String mappingsVersion = (String) mappingVersionComboBox.getSelectedItem(); | ||
String loaderVersion = (String) loaderVersionComboBox.getSelectedItem(); | ||
System.out.println(Translator.getString("gui.installing")); | ||
new Thread(() -> { | ||
try { | ||
updateProgress(Translator.getString("gui.installing") + ": " + loaderVersion, 0); | ||
File mcPath = new File(installLocation.getText()); | ||
if (!mcPath.exists()) { | ||
throw new RuntimeException(Translator.getString("install.client.error.noLauncher")); | ||
} | ||
ClientInstaller.install(mcPath, mappingsVersion, loaderVersion, this); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
error(e.getLocalizedMessage()); | ||
} | ||
}).start(); | ||
} | ||
|
||
public void selectInstallLocation() { | ||
JFileChooser chooser = new JFileChooser(); | ||
chooser.setCurrentDirectory(new File(installLocation.getText())); | ||
chooser.setDialogTitle(Translator.getString("gui.selectInstallLocation")); | ||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | ||
chooser.setAcceptAllFileFilterUsed(false); | ||
|
||
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { | ||
installLocation.setText(chooser.getSelectedFile().getAbsolutePath()); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateProgress(String text, int percentage) { | ||
statusLabel.setText(text); | ||
statusLabel.setForeground(Color.BLACK); | ||
progressBar.setValue(percentage); | ||
} | ||
|
||
@Override | ||
public void error(String error) { | ||
statusLabel.setText(error); | ||
statusLabel.setForeground(Color.RED); | ||
} | ||
|
||
public static void start() | ||
throws XmlPullParserException, IOException, ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, | ||
IllegalAccessException { | ||
//This will make people happy | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
InstallerGui dialog = new InstallerGui(); | ||
dialog.pack(); | ||
dialog.setTitle(Translator.getString("fabric.installer.name")); | ||
dialog.setLocationRelativeTo(null); | ||
dialog.setVisible(true); | ||
} | ||
|
||
private void initComponents() { | ||
contentPane = new JPanel(); | ||
contentPane.setBorder(new EmptyBorder(5, 10, 5, 10)); | ||
|
||
addRow(jPanel -> { | ||
jPanel.add(new JLabel(Translator.getString("gui.version.mappings"))); | ||
jPanel.add(mappingVersionComboBox = new JComboBox<>()); | ||
}); | ||
|
||
addRow(jPanel -> { | ||
jPanel.add(new JLabel("gui.version.loader")); | ||
jPanel.add(loaderVersionComboBox = new JComboBox<>()); | ||
}); | ||
|
||
addRow(jPanel -> { | ||
jPanel.add(new JLabel(Translator.getString("gui.selectInstallLocation"))); | ||
jPanel.add(installLocation = new JTextField()); | ||
jPanel.add(selectFolderButton = new JButton()); | ||
|
||
selectFolderButton.setText("..."); | ||
selectFolderButton.addActionListener(e -> selectInstallLocation()); | ||
installLocation.setText(Utils.findDefaultInstallDir().getAbsolutePath()); | ||
}); | ||
|
||
addRow(jPanel -> { | ||
jPanel.add(statusLabel = new JLabel()); | ||
jPanel.add(progressBar = new JProgressBar()); | ||
progressBar.setMaximum(100); | ||
|
||
//Forces the progress bar to expand to fit the width | ||
jPanel.setLayout(new GridLayout(0, 1)); | ||
}); | ||
|
||
addRow(jPanel -> { | ||
jPanel.add(buttonInstall = new JButton(Translator.getString("gui.install"))); | ||
buttonInstall.addActionListener(e -> install()); | ||
getRootPane().setDefaultButton(buttonInstall); | ||
}); | ||
|
||
} | ||
|
||
private void addRow(Consumer<JPanel> consumer) { | ||
JPanel panel = new JPanel(new FlowLayout()); | ||
consumer.accept(panel); | ||
contentPane.add(panel, BorderLayout.CENTER); | ||
} | ||
|
||
} |
Oops, something went wrong.