diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-02 21:26:57 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-02 21:26:57 +0000 |
commit | 19e15c87a1fc74f71fd6f9a743201a24ac582997 (patch) | |
tree | a615525476ef6bad8a2af4d8b90c8aea935f9109 /tools | |
parent | 29f07d2f98b82674708f1185f26ed3c482992b04 (diff) | |
download | mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.gz mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.bz2 mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.xz mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.zip |
Merged trunk changes from revision 2716 to 2756 into the 0.1.0 branch.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Purger.java | 159 | ||||
-rw-r--r-- | tools/Reorganize.java | 29 |
2 files changed, 179 insertions, 9 deletions
diff --git a/tools/Purger.java b/tools/Purger.java new file mode 100644 index 00000000..1751c8de --- /dev/null +++ b/tools/Purger.java @@ -0,0 +1,159 @@ +/*
+ * Purger (c) 2006 Eugenio Favalli
+ * License: GPL, v2 or later
+ */
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+
+ public class Purger {
+
+ public static void main(String[] args) {
+ if (args.length != 2) {
+ System.out.println(
+ "Usage: java Purger <folder> <date>\n" +
+ " - folder: is the path to account.txt and athena.txt files.\n" +
+ " - date: accounts created before this date will be purged (dd/mm/yy).");
+ return;
+ }
+
+ int accounts = 0;
+ int characters = 0;
+ int deletedCharacters = 0;
+ Vector activeAccounts = new Vector();
+
+ File oldAccount = new File(args[0] + "account.txt");
+ File oldAthena = new File(args[0] + "athena.txt");
+ File newAccount = new File(args[0] + "account.txt.new");
+ File newAthena = new File(args[0] + "athena.txt.new");
+
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
+ Date purgeDate;
+ try {
+ purgeDate = dateFormat.parse(args[1]);
+ }
+ catch (ParseException e) {
+ System.out.println("ERROR: Wrong date format.");
+ return;
+ }
+
+ String line;
+ try {
+ FileInputStream fin = new FileInputStream(oldAccount);
+ BufferedReader input = new BufferedReader(
+ new InputStreamReader(fin));
+ FileOutputStream fout = new FileOutputStream(newAccount);
+ PrintStream output = new PrintStream(fout);
+
+ while ((line = input.readLine()) != null) {
+ boolean copy = false;
+ String[] fields = line.split("\t");
+ // Check if we're reading a comment or the last line
+ if (line.substring(0, 2).equals("//") || fields[1].charAt(0) == '%') {
+ copy = true;
+ }
+ else {
+ // Server accounts should not be purged
+ if (!fields[4].equals("S")) {
+ accounts++;
+ dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ try {
+ Date date = dateFormat.parse(fields[3]);
+ if (date.after(purgeDate)) {
+ activeAccounts.add(fields[0]);
+ copy = true;
+ }
+ }
+ catch (ParseException e) {
+ System.out.println(
+ "ERROR: Wrong date format in account.txt. ("
+ + accounts + ": " + line + ")");
+ //return;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+ else {
+ copy = true;
+ }
+ }
+ if (copy) {
+ try {
+ output.println(line);
+ }
+ catch (Exception e) {
+ System.err.println("ERROR: Unable to write file.");
+ }
+ }
+ }
+ }
+ catch (FileNotFoundException e ) {
+ System.out.println(
+ "ERROR: file " + oldAccount.getAbsolutePath() + " not found.");
+ return;
+ }
+ catch (Exception e) {
+ System.out.println("ERROR: unable to process account.txt");
+ e.printStackTrace();
+ return;
+ }
+
+ input.close();
+ output.close();
+
+ try {
+ FileInputStream fin = new FileInputStream(oldAthena);
+ BufferedReader input = new BufferedReader(
+ new InputStreamReader(fin));
+ FileOutputStream fout = new FileOutputStream(newAthena);
+ PrintStream output = new PrintStream(fout);
+
+ while ((line = input.readLine()) != null) {
+ boolean copy = false;
+ String[] fields = line.split("\t");
+ // Check if we're reading a comment or the last line
+ if (line.substring(0, 2).equals("//")
+ || fields[1].charAt(0) == '%') {
+ copy = true;
+ }
+ else {
+ characters++;
+ String id = fields[1].substring(0, fields[1].indexOf(','));
+ if (activeAccounts.contains(id)) {
+ copy = true;
+ }
+ else {
+ deletedCharacters++;
+ }
+ }
+ if (copy) {
+ output.println(line);
+ }
+ }
+ }
+ catch (FileNotFoundException e ) {
+ System.out.println(
+ "ERROR: file " + oldAthena.getAbsolutePath() + " not found.");
+ return;
+ }
+ catch (Exception e) {
+ System.out.println("ERROR: unable to process athena.txt");
+ e.printStackTrace();
+ return;
+ }
+
+ input.close();
+ output.close();
+
+ System.out.println(
+ "Removed " + (accounts - activeAccounts.size()) + "/" +
+ accounts + " accounts.");
+ System.out.println(
+ "Removed " + deletedCharacters + "/"
+ + characters + " characters.");
+ }
+
+}
\ No newline at end of file diff --git a/tools/Reorganize.java b/tools/Reorganize.java index 22f42604..0b9c8606 100644 --- a/tools/Reorganize.java +++ b/tools/Reorganize.java @@ -12,7 +12,7 @@ import java.io.File; import javax.imageio.ImageIO; /** - * Tool to reorganize the hair spritesets. + * Tool to reorganize the headgears. */ public class Reorganize { @@ -47,7 +47,7 @@ public class Reorganize // Read the existing frames into a vector Vector<BufferedImage> spriteSet = gridCut(source, HAIR_SPRITE_WIDTH, HAIR_SPRITE_HEIGHT, - HAIR_FRAMES, HAIR_COLORS); + HAIR_FRAMES, 1); // Determine minimal rectangle that can still contain the contents of // any frame @@ -60,21 +60,16 @@ public class Reorganize System.exit(1); } - // Make crop rect one pixel larger (since we want an inclusive rect) - cropRect.add( - cropRect.x + cropRect.width + 1, - cropRect.y + cropRect.height + 1); - System.out.println(arg[0] + ": width=\"" + cropRect.width + "\" height=\"" + cropRect.height + "\""); */ - filterHairstyle(spriteSet); + filterHeadgear(spriteSet); BufferedImage target = gridDraw( spriteSet, new Rectangle(0, 0, HAIR_SPRITE_WIDTH, HAIR_SPRITE_HEIGHT), - HAIR_FRAMES - 4, HAIR_COLORS); + HAIR_FRAMES - 4, 1); // Save the target image try { @@ -149,6 +144,13 @@ public class Reorganize } } + // Make crop rect one pixel larger (since we want an inclusive rect) + if (cropRect != null) { + cropRect.add( + cropRect.x + cropRect.width + 1, + cropRect.y + cropRect.height + 1); + } + return cropRect; } @@ -184,4 +186,13 @@ public class Reorganize spriteSet.remove(i * HAIR_FRAMES + 1); } } + + private static void filterHeadgear(Vector<BufferedImage> spriteSet) + { + // Remove frame 1, 2, 6 and 7 + spriteSet.remove(7); + spriteSet.remove(6); + spriteSet.remove(2); + spriteSet.remove(1); + } } |