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();
}
Aggregations