Search in sources :

Example 6 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class GUIMain method checkForUpdates.

protected static void checkForUpdates(String title, Icon icon, String localPluginVersion) throws URISyntaxException, IOException {
    JSONObject response = (JSONObject) HTTPRequestUtils.getJSONResponse("https://api.loohpjames.com/spigot/data").get("InteractiveChat-DiscordSRV-Addon");
    String spigotPluginVersion = (String) ((JSONObject) response.get("latestversion")).get("release");
    String devBuildVersion = (String) ((JSONObject) response.get("latestversion")).get("devbuild");
    int spigotPluginId = (int) (long) ((JSONObject) response.get("spigotmc")).get("pluginid");
    int posOfThirdDot = localPluginVersion.indexOf(".", localPluginVersion.indexOf(".", localPluginVersion.indexOf(".") + 1) + 1);
    Version currentDevBuild = new Version(localPluginVersion);
    Version currentRelease = new Version(localPluginVersion.substring(0, posOfThirdDot >= 0 ? posOfThirdDot : localPluginVersion.length()));
    Version spigotmc = new Version(spigotPluginVersion);
    Version devBuild = new Version(devBuildVersion);
    int input;
    if (currentRelease.compareTo(spigotmc) < 0) {
        // update
        input = JOptionPane.showOptionDialog(null, createLabel("There is a new version available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion, 15), title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, new Object[] { "OK", "Download Link" }, null);
    } else if (currentDevBuild.compareTo(devBuild) < 0) {
        // dev build update
        input = JOptionPane.showOptionDialog(null, createLabel("There is a new DEV build available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion, 15), title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, new Object[] { "OK", "Download Link" }, null);
    } else {
        // latest
        JOptionPane.showMessageDialog(null, createLabel("You are already running the latest version! (" + localPluginVersion + ")", 15), title, JOptionPane.INFORMATION_MESSAGE, icon);
        input = 0;
    }
    if (input == 1) {
        if (Desktop.isDesktopSupported()) {
            Desktop dt = Desktop.getDesktop();
            dt.browse(new URI("https://ci.loohpjames.com/job/InteractiveChat-DiscordSRV-Addon/"));
        }
    }
}
Also used : JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) Desktop(java.awt.Desktop) Version(com.loohp.interactivechat.updater.Version) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) URI(java.net.URI)

Example 7 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class GUIMain method downloadAssets.

protected static void downloadAssets(String title, BufferedImage image, Icon icon) {
    File defaultAssetsFolder = new File("InteractiveChatDiscordSrvAddon/built-in", "Default");
    defaultAssetsFolder.mkdirs();
    File libsFolder = new File("InteractiveChatDiscordSrvAddon", "libs");
    libsFolder.mkdirs();
    JPanel panel = new JPanel();
    panel.add(GUIMain.createLabel("Select Minecraft Version: ", 13));
    JComboBox<String> options = new JComboBox<>();
    for (String version : ResourceDownloadManager.getMinecraftVersions()) {
        options.addItem(version);
    }
    panel.add(options);
    int result = JOptionPane.showOptionDialog(null, panel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, null, null);
    if (result < 0) {
        return;
    }
    ResourceDownloadManager resourceDownloadManager = new ResourceDownloadManager((String) options.getSelectedItem(), defaultAssetsFolder);
    LibraryDownloadManager libraryDownloadManager = new LibraryDownloadManager(libsFolder);
    JFrame frame = new JFrame(title);
    frame.setIconImage(image);
    frame.setSize(800, 175);
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
    panel.setLayout(new GridLayout(0, 1));
    JLabel label = GUIMain.createLabel("<html>Downloading Assets:<html/>", 13);
    label.setSize(800, 125);
    panel.add(label);
    JProgressBar progressBar = new JProgressBar(0, 10000);
    panel.add(progressBar);
    frame.add(panel, BorderLayout.CENTER);
    frame.setResizable(false);
    frame.setVisible(true);
    CompletableFuture<Void> future = new CompletableFuture<>();
    new Thread(() -> {
        resourceDownloadManager.downloadResources((type, fileName, percentage) -> {
            switch(type) {
                case CLIENT_DOWNLOAD:
                    label.setText("<html>Downloading Assets:<br>Downloading client jar<html/>");
                    break;
                case EXTRACT:
                    label.setText("<html>Downloading Assets:<br>Extracting " + fileName + "<html/>");
                    break;
                case DOWNLOAD:
                    label.setText("<html>Downloading Assets:<br>Downloading " + fileName + "<html/>");
                    progressBar.setValue(Math.min(9999, (int) (percentage * 100)));
                    break;
                case DONE:
                    label.setText("<html>Done!<html/>");
                    break;
            }
        });
        libraryDownloadManager.downloadLibraries((downloadResult, jarName) -> {
            if (downloadResult) {
                label.setText("<html>Downloaded library \"" + jarName + "\"<html/>");
            }
        });
        future.complete(null);
    }).start();
    future.join();
    progressBar.setValue(9999);
    JOptionPane.showMessageDialog(null, createLabel("Assets saved at: " + defaultAssetsFolder.getAbsolutePath(), 15), title, JOptionPane.INFORMATION_MESSAGE, icon);
    frame.setVisible(false);
    frame.dispose();
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) Version(com.loohp.interactivechat.updater.Version) Enumeration(java.util.Enumeration) URL(java.net.URL) Registry(com.loohp.interactivechat.registry.Registry) URISyntaxException(java.net.URISyntaxException) RenderingHints(java.awt.RenderingHints) CompletableFuture(java.util.concurrent.CompletableFuture) SwingConstants(javax.swing.SwingConstants) FileUtils(com.loohp.interactivechat.utils.FileUtils) GridLayout(java.awt.GridLayout) LinkedHashMap(java.util.LinkedHashMap) ResourceDownloadManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager) Graphics2D(java.awt.Graphics2D) Map(java.util.Map) InteractiveChatRegistry(com.loohp.interactivechatdiscordsrvaddon.registry.InteractiveChatRegistry) ImageIO(javax.imageio.ImageIO) ImageIcon(javax.swing.ImageIcon) URI(java.net.URI) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) BorderLayout(java.awt.BorderLayout) LinkedList(java.util.LinkedList) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) JProgressBar(javax.swing.JProgressBar) PrintWriter(java.io.PrintWriter) Desktop(java.awt.Desktop) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) StringWriter(java.io.StringWriter) DecimalFormat(java.text.DecimalFormat) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JOptionPane(javax.swing.JOptionPane) File(java.io.File) List(java.util.List) HTTPRequestUtils(com.loohp.interactivechat.utils.HTTPRequestUtils) JLabel(javax.swing.JLabel) LibraryDownloadManager(com.loohp.interactivechatdiscordsrvaddon.libs.LibraryDownloadManager) Entry(java.util.Map.Entry) ConfigurationSection(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.ConfigurationSection) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) Toolkit(java.awt.Toolkit) JPanel(javax.swing.JPanel) LibraryDownloadManager(com.loohp.interactivechatdiscordsrvaddon.libs.LibraryDownloadManager) JComboBox(javax.swing.JComboBox) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) GridLayout(java.awt.GridLayout) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceDownloadManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager) JFrame(javax.swing.JFrame) File(java.io.File)

Aggregations

Version (com.loohp.interactivechat.updater.Version)7 JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)4 Desktop (java.awt.Desktop)3 File (java.io.File)3 URI (java.net.URI)3 ConfigurationSection (com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.ConfigurationSection)2 YamlConfiguration (com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration)2 Registry (com.loohp.interactivechat.registry.Registry)2 FileUtils (com.loohp.interactivechat.utils.FileUtils)2 HTTPRequestUtils (com.loohp.interactivechat.utils.HTTPRequestUtils)2 InteractiveChatRegistry (com.loohp.interactivechatdiscordsrvaddon.registry.InteractiveChatRegistry)2 ResourceDownloadManager (com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2