Skip to content

Commit

Permalink
Added world and texture pack support, moved files to releases
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Mar 21, 2015
1 parent 03858b5 commit 2d610b6
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 302 deletions.
Binary file removed CurseGraph.jar
Binary file not shown.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CurseGraph

This small application creates a background process in SystemTray (On Windows, its the small icon bar on bottom right) and tracks and records your mods total downloads every 15 minutes. By default, my mods are added, but you can press "Remove" to remove them and "Add a Mod" in main menu to add a new mod. Files are saved in C:/Users/username/LatMod/CurseGraph/, formatted in Json
This small application creates a background process in SystemTray (On Windows, its the small icon bar on bottom right) and tracks and records your projects total downloads every 15 minutes. By default, "LatCoreMC", "Tinker's Construct" and "Mine & Blade: Battlegear 2" are added, but you can press "Remove" to remove them and "Add" in main menu to add a new project. Files are saved in C:/Users/username/LatMod/CurseGraph/, formatted in Json

Valid ModIDs are "224778-latcoremc" or "tinkers-construct" (the ending of your Curse project's link). Older projects dont have the number.
Valid ProjectIDs are "224778-latcoremc" or "tinkers-construct" (the ending of your Curse project's link). Older projects don't have the number. (It's still a mystery, maybe someone can explain this to me)

This is still WIP for MacOSX, you can still doubleclick to open Graph selector, but you have to edit ModIDs in /user home/CurseGraph/mods.json
This is still WIP for MacOSX, you can still doubleclick to open Graph selector, but you have to edit ProjectIDs in /user home/CurseGraph/projects.json

Get latest version here: https://github.com/LatvianModder/CurseGraph/releases
98 changes: 98 additions & 0 deletions src/latmod/cursegraph/Curse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package latmod.cursegraph;

import java.util.Map;

import com.google.gson.annotations.Expose;

public class Curse
{
public static enum Type
{
MOD("mc-mods", "Mod"),
TEX_PACK("texture-packs", "Texture Pack"),
WORLD("worlds", "World");

public static final Type[] VALUES = values();
public final String ID;
public final String name;

Type(String s, String s1)
{ ID = s; name = s1; }

public static Type get(String s)
{
for(Type t : VALUES)
if(s.equals(t.ID)) return t;
return null;
}

public String toString()
{ return ID; }
}

public static class Project
{
public String modID;

@Expose public Integer typeID;
@Expose public String title;
@Expose public String game;
@Expose public String category;
@Expose public String url;
@Expose public String thumbnail;
@Expose public String[] authors;
@Expose public Map<String, Integer> downloads;
@Expose public Integer favorites;
@Expose public Integer likes;
@Expose public String updated_at;
@Expose public String created_at;
@Expose public String project_url;
@Expose public String release_type;
@Expose public String license;
@Expose public Version download;
@Expose public Map<String, Version[]> versions;

public String toString()
{ return modID; }

public int hashCode()
{ return toString().hashCode(); }

public boolean equals(Object o)
{ return o.toString().equals(toString()); }

public int getTotalDownloads()
{
int i = downloads.get("total") + 0;

if(i == -1) return 0;

if(i == 0)
{
for(String s : versions.keySet())
{
for(Version v : versions.get(s))
i += v.downloads.intValue();
}

if(i == 0) { i = -1; return 0; }
}

return i;
}

public Type getType()
{ return Type.VALUES[typeID]; }
}

public static class Version
{
@Expose public Integer id;
@Expose public String url;
@Expose public String name;
@Expose public String type;
@Expose public String version;
@Expose public Integer downloads;
@Expose public String created_at;
}
}
100 changes: 66 additions & 34 deletions src/latmod/cursegraph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,84 @@

import javax.swing.*;

import latmod.cursegraph.Main.Mod;

import com.google.gson.annotations.Expose;

public class Graph
{
public static long checkMillis = 900000L;

public static File dataFile;
public static GraphData graphData;
public static BufferedImage image_graph;
public static Checker checker;

public static void init() throws Exception
{
dataFile = new File(Main.folder, "data.json");
graphData = Utils.fromJsonFile(dataFile, GraphData.class);

graphData = null;
if(!dataFile.exists()) dataFile.createNewFile();

if(dataFile.exists())
if(graphData == null)
{
try
{
FileInputStream fis = new FileInputStream(dataFile);
String graphDataS = Utils.toString(fis);
fis.close();

if(graphDataS != null && !graphDataS.isEmpty())
graphData = Utils.fromJson(graphDataS, GraphData.class);
}
catch(Exception e) { e.printStackTrace(); }
graphData = new GraphData();
checkNull();
}

image_graph = Main.loadImage("graph_background.png");

new Checker().start();
checker = new Checker();
checker.start();
}

public static void checkNull()
{
if(graphData.projects == null) graphData.projects = new HashMap<String, Map<Long, Integer>>();
if(graphData.lastCheck == null) graphData.lastCheck = -1L;
}

public static void logData() throws Exception
{
if(graphData == null)
{
graphData = new GraphData();
graphData.graph = new HashMap<String, Map<Long, Integer>>();
}
if(graphData == null) graphData = new GraphData();

long ms = System.currentTimeMillis();

for(int i = 0; i < Main.loadedMods.size(); i++)
//System.out.println("Data logged with ID " + ms + "!");

checkNull();

if(Projects.hasProjects()) for(Curse.Project p : Projects.list)
{
Mod m = Main.loadedMods.get(i);
Map<Long, Integer> map = graphData.projects.get(p.modID);

Map<Long, Integer> map = graphData.graph.get(m.modID);
if(map == null)
{
map = new HashMap<Long, Integer>();
graphData.graph.put(m.modID, map);
graphData.projects.put(p.modID, map);
}

map.put(ms, m.getTotalDownloads());
int d = p.getTotalDownloads();

if(graphData.lastCheck == -1L)
map.put(ms, d);
else
{
Integer i = map.get(graphData.lastCheck);
if(i != null && i.longValue() != d)
map.put(ms, d);
}
}

checkNull();
graphData.lastCheck = ms;

String s = Utils.toJson(graphData, true);
FileOutputStream fos = new FileOutputStream(dataFile);
fos.write(s.getBytes()); fos.close();
}

public static class GraphData
{
@Expose public Map<String, Map<Long, Integer>> graph;
@Expose public Map<String, Map<Long, Integer>> projects;
@Expose public Long lastCheck;
}

public static class Checker implements Runnable
Expand All @@ -85,9 +94,24 @@ public static class Checker implements Runnable

public void start()
{
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
if(thread != null) stop();

if(thread == null)
{
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
}
}

@SuppressWarnings("deprecation")
public void stop()
{
if(thread != null)
{
thread.stop();
thread = null;
}
}

public void run()
Expand All @@ -97,15 +121,19 @@ public void run()
while(true)
{
logData();
Thread.sleep(checkMillis);

if(Main.config.refreshMinutes <= 0)
{ Main.config.refreshMinutes = 15; Main.config.save(); }

Thread.sleep(Main.config.refreshMinutes * 60L * 1000L);
}
}
catch(Exception e)
{ e.printStackTrace(); thread = null; }
}
}

public static void displayGraph(final Mod mod)
public static void displayGraph(final Curse.Project mod)
{
final JLabel picLabel = new JLabel(new ImageIcon(image_graph))
{
Expand All @@ -115,10 +143,14 @@ public void paint(Graphics g)
{
super.paint(g);

Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

int w = getWidth();
int h = getHeight();

Map<Long, Integer> map = graphData.graph.get(mod.modID);
Map<Long, Integer> map = graphData.projects.get(mod.modID);

TimedValue values[] = new TimedValue[map.size()];

Expand Down
Loading

0 comments on commit 2d610b6

Please sign in to comment.