Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
new: added mod info and author info in mod browser
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Aug 8, 2020
1 parent a1e3796 commit e36e87c
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fabric Mod Manager
version = 0.0.6-SNAPSHOT+build-20200807
version = 0.0.7-RC1
group = me.flashyreese

# Dependencies
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/me/flashyreese/fabricmm/api/RepositoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public RepositoryManager(File repositoryCache, String repositoryUrl) throws Exce
this.repositoryCache = repositoryCache;
this.repositoryUrl = repositoryUrl;
this.users = new ArrayList<>();
loadLocalRepositories();
loadLocalRepositories(false);
}

private void loadLocalRepositories() throws Exception {
private void loadLocalRepositories(boolean force) throws Exception {
Moshi moshi = new Moshi.Builder().build();
Type type = Types.newParameterizedType(List.class, User.class);
JsonAdapter<List<User>> adapter = moshi.adapter(type);
Expand All @@ -49,7 +49,7 @@ private void loadLocalRepositories() throws Exception {
for (Project project: user.getProjects()){
if(project.getCurseForgeProject() != -1){
File projectJsonFile = getProjectFile(project.getCurseForgeProject());
if (projectJsonFile != null){
if (projectJsonFile != null && !force){
Type newType = Types.newParameterizedType(List.class, MinecraftVersion.class);
JsonAdapter<List<MinecraftVersion>> jsonAdapter = moshi.adapter(newType);
FileReader fileReader = new FileReader(projectJsonFile);
Expand All @@ -59,6 +59,7 @@ private void loadLocalRepositories() throws Exception {
fileReader.close();
List<MinecraftVersion> minecraftVersions = jsonAdapter.fromJson(projectJson);
project.setMinecraftVersions(minecraftVersions);
loadProjectInfo(project);
}else{
Future<?> future = executor.submit(() -> {
try {
Expand Down Expand Up @@ -95,10 +96,11 @@ private File getProjectFile(int curseForgeId) throws Exception {
}

private void downloadProjectFile(Project project) throws Exception {
CurseAddon curseAddon = getCurseAddonFromProjectID(project.getCurseForgeProject());
CurseAddon curseAddon = getCurseAddonFromProjectID(project.getCurseForgeProject(), true);
if (curseAddon.getDefaultCurseAttachment() != null && curseAddon.getDefaultCurseAttachment().getThumbnailUrl() != null){
project.setIconUrl(curseAddon.getDefaultCurseAttachment().getThumbnailUrl());
}
project.setProjectUrl(curseAddon.getWebsiteUrl());
List<MinecraftVersion> minecraftVersions = convertCurseAddonToMinecraftFiles(curseAddon);
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<List<MinecraftVersion>> jsonAdapter = moshi.adapter(Types.newParameterizedType(List.class, MinecraftVersion.class));
Expand All @@ -110,15 +112,22 @@ private void downloadProjectFile(Project project) throws Exception {
project.setMinecraftVersions(minecraftVersions);
}

private void loadProjectInfo(Project project) throws Exception {
CurseAddon curseAddon = getCurseAddonFromProjectID(project.getCurseForgeProject(), false);
project.setProjectUrl(curseAddon.getWebsiteUrl());
}

public List<MinecraftVersion> convertCurseAddonToMinecraftFiles(CurseAddon curseAddon) throws Exception {
return convertCurseFilesToMinecraftVersions(curseAddon.getFiles());
}

private CurseAddon getCurseAddon(String json) throws Exception {
private CurseAddon getCurseAddon(String json, boolean includesFiles) throws Exception {
Moshi moshi = new Moshi.Builder().build();
CurseAddon curseAddon = moshi.adapter(CurseAddon.class).fromJson(json);
assert curseAddon != null;
processCurseFiles(curseAddon);
if(includesFiles){
processCurseFiles(curseAddon);
}
return curseAddon;
}

Expand All @@ -144,12 +153,12 @@ private void processCurseFiles(CurseAddon curseAddon) throws Exception {
}
}

private CurseAddon getCurseAddonFromProjectID(long id) throws Exception {
private CurseAddon getCurseAddonFromProjectID(long id, boolean includeFiles) throws Exception {
URL url = new URL(String.format("https://addons-ecs.forgesvc.net/api/v2/addon/%s", id));
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String addonJson = in.lines().collect(Collectors.joining());
in.close();
return getCurseAddon(addonJson);
return getCurseAddon(addonJson, includeFiles);
}

private List<MinecraftVersion> convertCurseFilesToMinecraftVersions(List<CurseFile> curseFiles) throws Exception {
Expand Down Expand Up @@ -182,6 +191,11 @@ private List<MinecraftVersion> convertCurseFilesToMinecraftVersions(List<CurseFi
return project.getMinecraftVersions();
}


public void updateLocalRepository() throws Exception {
loadLocalRepositories(true);
}

public List<User> getUsers() {
return users;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Project {
private String sourcesUrl;
private int curseForgeProject;

private String projectUrl;
private List<MinecraftVersion> minecraftVersions;//Curse will parse to this

private User user;

public String getId() {
Expand All @@ -38,6 +38,14 @@ public int getCurseForgeProject() {
return curseForgeProject;
}

public String getProjectUrl() {
return projectUrl;
}

public void setProjectUrl(String projectUrl) {
this.projectUrl = projectUrl;
}

public List<MinecraftVersion> getMinecraftVersions() {
return minecraftVersions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

public class FabricModManagerUI extends JFrame {

private final int SCALE = 65;

private I18nManager i18nManager;
private RepositoryManager repositoryManager;
private JTabbedPane contentPane;
Expand All @@ -40,7 +42,7 @@ public FabricModManagerUI() throws Exception {

private void initComponents() throws Exception {
i18nManager = new I18nManager("assets/lang");
i18nManager.setLocale(Locale.US);
i18nManager.setLocale(Locale.US);//Todo: addLoadFromConfig

tray = SystemTray.getSystemTray();
trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemClassLoader().getResource("icon.png")), new TranslatableText("fmm.title").toString());
Expand All @@ -49,7 +51,7 @@ private void initComponents() throws Exception {
contentPane = new JTabbedPane();
//Fixme: Jank
contentPane.setLocation(0, 0);
contentPane.setPreferredSize(new Dimension(1280, 720));
contentPane.setPreferredSize(new Dimension(16* SCALE, 9* SCALE));

library = new LibraryManagerUI(contentPane);
modBrowser = new ModRepositoryBrowserUI(contentPane, repositoryManager, trayIcon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FabricModManagerMenuBar extends JMenuBar {
private JMenu languageMenu;
private JMenu helpMenu;
private JMenuItem openMinecraftLauncher;
private JMenuItem updateLocalRepositories;
private JMenuItem updateLocalRepository;
private JMenuItem checkForUpdates;
private JMenuItem about;

Expand All @@ -46,7 +46,7 @@ private void initComponents(){
languageMenu = new JMenu();
helpMenu = new JMenu();
openMinecraftLauncher = new JMenuItem();
updateLocalRepositories = new JMenuItem();
updateLocalRepository = new JMenuItem();
checkForUpdates = new JMenuItem();
about = new JMenuItem();
}
Expand All @@ -63,15 +63,13 @@ private void setupComponents(FabricModManagerUI fabricModManagerUI, RepositoryMa
}
});

updateLocalRepositories.addActionListener(e -> new Thread(() -> {
/*for(Repository repository: repositoryManager.getRepositories()){
try {
repositoryManager.updateLocalRepository(repository);
} catch (IOException ioException) {
ioException.printStackTrace();
}
updateLocalRepository.addActionListener(e -> new Thread(() -> {
try {
repositoryManager.updateLocalRepository();
} catch (Exception exception) {
exception.printStackTrace();
}
modRepositoryBrowserUI.updateModList(repositoryManager);*/
modRepositoryBrowserUI.updateModList(repositoryManager);
}).start());

checkForUpdates.addActionListener(e -> new Thread(() -> {
Expand Down Expand Up @@ -104,7 +102,7 @@ private void setupComponents(FabricModManagerUI fabricModManagerUI, RepositoryMa

private void loadComponents(){
quickToolsMenu.add(openMinecraftLauncher);
repositoryMenu.add(updateLocalRepositories);
repositoryMenu.add(updateLocalRepository);
helpMenu.add(checkForUpdates);
helpMenu.add(about);
this.add(quickToolsMenu);
Expand All @@ -117,7 +115,7 @@ public void updateComponentsText(){
quickToolsMenu.setText(new TranslatableText("fmm.menubar.quick_tools").toString());
openMinecraftLauncher.setText(new TranslatableText("fmm.menubar.quick_tools.open_minecraft_launcher").toString());
repositoryMenu.setText(new TranslatableText("fmm.menubar.repository").toString());
updateLocalRepositories.setText(new TranslatableText("fmm.menubar.repository.update_local_repositories").toString());
updateLocalRepository.setText(new TranslatableText("fmm.menubar.repository.update_local_repository").toString());
languageMenu.setText(new TranslatableText("fmm.menubar.language").toString());
helpMenu.setText(new TranslatableText("fmm.menubar.help").toString());
checkForUpdates.setText(new TranslatableText("fmm.menubar.help.check_for_updates").toString());
Expand Down
Loading

0 comments on commit e36e87c

Please sign in to comment.