Search in sources :

Example 1 with IPackSource

use of net.technicpack.launchercore.modpacks.sources.IPackSource in project LauncherV3 by TechnicPack.

the class PackLoadJob method run.

@Override
public void run() {
    int threadCount = 0;
    if (doLoadRepository)
        threadCount++;
    if (packSources != null)
        threadCount += packSources.size();
    Collection<Thread> threads = new ArrayList<Thread>(threadCount);
    if (doLoadRepository) {
        for (final String packName : packRepository.getPackNames()) {
            InstalledPack pack = packRepository.getInstalledPacks().get(packName);
            addPackThreadSafe(pack, null, -1);
        }
    }
    if (packSources != null) {
        for (final IPackSource packSource : packSources) {
            Thread packSourceThread = new Thread(packSource.getSourceName() + " Loading Thread") {

                @Override
                public void run() {
                    for (PackInfo info : packSource.getPublicPacks()) {
                        addPackThreadSafe(null, info, packSource.getPriority(info));
                    }
                }
            };
            threads.add(packSourceThread);
            packSourceThread.start();
        }
    }
    for (Thread thread : threads) {
        try {
            thread.join();
        } catch (InterruptedException ex) {
        }
    }
    refreshCompleteThreadSafe();
}
Also used : IPackSource(net.technicpack.launchercore.modpacks.sources.IPackSource) PackInfo(net.technicpack.rest.io.PackInfo) ArrayList(java.util.ArrayList)

Example 2 with IPackSource

use of net.technicpack.launchercore.modpacks.sources.IPackSource 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

IPackSource (net.technicpack.launchercore.modpacks.sources.IPackSource)2 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 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Timer (javax.swing.Timer)1 NameFilterPackSource (net.technicpack.launchercore.modpacks.sources.NameFilterPackSource)1 SearchResultPackSource (net.technicpack.platform.packsources.SearchResultPackSource)1 SinglePlatformSource (net.technicpack.platform.packsources.SinglePlatformSource)1 PackInfo (net.technicpack.rest.io.PackInfo)1