public InstalledPack getOffsetPack(int offset) { int index = mPackStore.getSelectedIndex(); index += offset; int size = mPackStore.getPackNames().size(); while (index < 0) { index += size; } while (index >= size) { index -= size; } return mPackStore.getInstalledPacks().get(mPackStore.getPackNames().get(index)); }
public void setPack(InstalledPack pack) { int index = mPackStore.getPackNames().indexOf(pack.getName()); if (index >= 0) { mPackStore.setSelectedIndex(index); mPackStore.save(); } }
public void reloadAllPacks(User user) { final User threadUser = user; final AvailablePackList packList = this; for (final String packName : mPackStore.getPackNames()) { final InstalledPack pack = mPackStore.getInstalledPacks().get(packName); if (pack.isPlatform()) { Thread thread = new Thread(pack.getName() + " Info Loading Thread") { @Override public void run() { try { String name = pack.getName(); PlatformPackInfo platformPackInfo = PlatformPackInfo.getPlatformPackInfo(name); PackInfo info = platformPackInfo; if (platformPackInfo.hasSolder()) { info = SolderPackInfo.getSolderPackInfo( platformPackInfo.getSolder(), name, threadUser); } info.getLogo(); info.getIcon(); info.getBackground(); pack.setInfo(info); pack.setRefreshListener(packList); } catch (RestfulAPIException e) { Utils.getLogger() .log(Level.WARNING, "Unable to load platform pack " + pack.getName(), e); pack.setLocalOnly(); pack.setRefreshListener(packList); } EventQueue.invokeLater( new Runnable() { @Override public void run() { packList.triggerUpdateListeners(pack); } }); } }; thread.start(); } } Thread thread = new Thread("TitansCraft Solder Defaults") { @Override public void run() { int index = 0; try { FullModpacks technic = RestObject.getRestObject( FullModpacks.class, SolderConstants.getFullSolderUrl( SolderConstants.TECHNIC, threadUser.getProfile().getName())); Solder solder = new Solder(SolderConstants.TECHNIC, technic.getMirrorUrl()); for (SolderPackInfo info : technic.getModpacks().values()) { String name = info.getName(); info.setSolder(solder); InstalledPack pack = null; if (mPackStore.getInstalledPacks().containsKey(name)) { pack = mPackStore.getInstalledPacks().get(info.getName()); pack.setRefreshListener(packList); pack.setInfo(info); final InstalledPack deferredPack = pack; final int deferredIndex = index; EventQueue.invokeLater( new Runnable() { @Override public void run() { packList.triggerUpdateListeners(deferredPack); mPackStore.reorder(deferredIndex, deferredPack.getName()); } }); } else { pack = new InstalledPack(mirrorStore, name, false); pack.setRefreshListener(packList); pack.setInfo(info); final InstalledPack deferredPack = pack; final int deferredIndex = index; EventQueue.invokeLater( new Runnable() { @Override public void run() { mPackStore.add(deferredPack); packList.triggerUpdateListeners(deferredPack); mPackStore.reorder(deferredIndex, deferredPack.getName()); } }); } index++; } } catch (RestfulAPIException e) { Utils.getLogger() .log(Level.WARNING, "Não foi possível carregar modpacks do TitansCraft", e); for (String packName : mPackStore.getPackNames()) { InstalledPack pack = mPackStore.getInstalledPacks().get(packName); if (!pack.isPlatform() && pack.getInfo() == null && pack.getName() != null) pack.setLocalOnly(); } } } }; thread.start(); thread = new Thread("Forced Solder Thread") { @Override public void run() { for (String solder : mForcedSolderPacks) { try { SolderPackInfo info = SolderPackInfo.getSolderPackInfo(solder); if (info == null) { throw new RestfulAPIException(); } info.getLogo(); info.getIcon(); info.getBackground(); InstalledPack pack = null; if (mPackStore.getInstalledPacks().containsKey(info.getName())) { pack = mPackStore.getInstalledPacks().get(info.getName()); pack.setInfo(info); final InstalledPack deferredPack = pack; EventQueue.invokeLater( new Runnable() { @Override public void run() { packList.triggerUpdateListeners(deferredPack); } }); } else { pack = new InstalledPack(mirrorStore, info.getName(), true); pack.setRefreshListener(packList); pack.setInfo(info); final InstalledPack deferredPack = pack; EventQueue.invokeLater( new Runnable() { @Override public void run() { mPackStore.add(deferredPack); packList.triggerUpdateListeners(deferredPack); } }); } } catch (RestfulAPIException e) { Utils.getLogger() .log(Level.WARNING, "Unable to load forced solder pack " + solder, e); } } } }; thread.start(); }