Search in sources :

Example 1 with SearchResultPackSource

use of net.technicpack.platform.packsources.SearchResultPackSource in project LauncherV3 by TechnicPack.

the class ModpackSelector method loadNewJob.

private void loadNewJob(final String searchText) {
    setTintActive(true);
    defaultPacks.removePassthroughContainer(this);
    currentSearchTimer = new Timer(500, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String localSearchTag = searchText.trim();
            String localSearchUrl = searchText.trim();
            if (!localSearchUrl.startsWith("http://") && !localSearchUrl.startsWith("https://"))
                localSearchUrl = "https://" + localSearchTag;
            try {
                URI uri = new URI(localSearchUrl);
                String host = uri.getHost();
                String scheme = uri.getScheme();
                if (host != null && scheme != null && (scheme.equals("http") || scheme.equals("https")) && (host.equals("www.technicpack.net") || host.equals("technicpack.net") || host.equals("api.technicpack.net"))) {
                    String path = uri.getPath();
                    if (path.startsWith("/"))
                        path = path.substring(1);
                    if (path.endsWith("/"))
                        path = path.substring(0, path.length() - 1);
                    String[] fragments = path.split("/");
                    if ((fragments.length == 2 && fragments[0].equals("modpack")) || (fragments.length == 3 && fragments[0].equals("api") && fragments[1].equals("modpack"))) {
                        String slug = fragments[fragments.length - 1];
                        Matcher siteMatcher = siteRegex.matcher(slug);
                        if (siteMatcher.find()) {
                            slug = siteMatcher.group(1);
                        }
                        Matcher slugMatcher = slugRegex.matcher(slug);
                        if (slugMatcher.find()) {
                            findMoreUrl = localSearchUrl;
                            findMoreWidget.setWidgetData(resources.getString("launcher.packselector.api"));
                            ArrayList<IPackSource> source = new ArrayList<IPackSource>(1);
                            source.add(new SinglePlatformSource(platformApi, solderApi, slug));
                            currentLoadJob = packLoader.createRepositoryLoadJob(ModpackSelector.this, source, null, false);
                            return;
                        }
                    }
                }
            } catch (URISyntaxException ex) {
            // It wasn't a valid URI which is actually fine.
            }
            String encodedSearch = filterContents.getText();
            try {
                encodedSearch = URLEncoder.encode(encodedSearch, "UTF-8");
            } catch (UnsupportedEncodingException ex) {
            }
            findMoreUrl = "https://www.technicpack.net/modpacks?q=" + encodedSearch;
            findMoreWidget.setWidgetData(resources.getString("launcher.packselector.more"));
            ArrayList<IPackSource> sources = new ArrayList<IPackSource>(2);
            sources.add(new NameFilterPackSource(defaultPacks, localSearchTag));
            sources.add(new SearchResultPackSource(platformSearchApi, localSearchTag));
            currentLoadJob = packLoader.createRepositoryLoadJob(ModpackSelector.this, sources, null, false);
        }
    });
    currentSearchTimer.setRepeats(false);
    currentSearchTimer.start();
}
Also used : IPackSource(net.technicpack.launchercore.modpacks.sources.IPackSource) SearchResultPackSource(net.technicpack.platform.packsources.SearchResultPackSource) SinglePlatformSource(net.technicpack.platform.packsources.SinglePlatformSource) Matcher(java.util.regex.Matcher) ActionEvent(java.awt.event.ActionEvent) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NameFilterPackSource(net.technicpack.launchercore.modpacks.sources.NameFilterPackSource) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Matcher (java.util.regex.Matcher)1 Timer (javax.swing.Timer)1 IPackSource (net.technicpack.launchercore.modpacks.sources.IPackSource)1 NameFilterPackSource (net.technicpack.launchercore.modpacks.sources.NameFilterPackSource)1 SearchResultPackSource (net.technicpack.platform.packsources.SearchResultPackSource)1 SinglePlatformSource (net.technicpack.platform.packsources.SinglePlatformSource)1