Java gamelist splitter

Feel free to talk about anything and everything in this board.
Post Reply
alpenjodler
Newbie
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 2:34 pm

Hi,

I just started playing around with mGalaxy since it's the only one I like that runs on my XP machine.

With all frontends before, I was lacking a way to filter by game age. I really want to be able to run all my games but when I just browse games, I just want to see some wow titles with huge sprites.
So I made small .java program that parses the enriched xmlout.xml from mgalaxy and outputs 3 .xml files with selected games.

You just need to create 3 systems by copying the mame system (C:\Program Files (x86)\mGalaxy\Data\UserSystems) changing the keys in the folders and the UserSystems.xml (I did Multi-system [MAME]-I2zbZe7o,  80 Multi-system [MAME]-I2zbZe8o, 70 Multi-system [MAME]-I2zbZe9o) and replacing the games in the xmlout.xml with the corresponding output file, leaving the header and dbase elements as they are so make this

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<dbase name="Multi-system [MAME]" version="0.200 (mame0200)" update="8/18/2018" comment="">

</dbase>
and post the games from the files replacing the blank line. You need a good editor for that, the first one I tried messed up the 90s file since it was just so big. Sublime Text worked for me (but also crashed once :-D)



My Java program - feel free to use and change as you wish.
One word of advice though:
All my systems use the same video and snapshot directories now but each uses only a part of it. I'm afraid to update the lists now because I'm afraid each part-system will delete the files of the other systems -.-
I think I should improve it so it also divides the files of the asset directories into 3 asset directories

Now if anyone finds a way to put different icons and texts to my 3 different mames, that would be awesome ^^

Code: Select all

package mGalaxyListSplitter;

import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Splitter {
	public static void writeXml(Node n, OutputStream os) throws TransformerException {
		TransformerFactory tf = TransformerFactory.newInstance();
		// identity
		Transformer t = tf.newTransformer();
		t.setOutputProperty(OutputKeys.INDENT, "yes");
		t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		t.transform(new DOMSource(n), new StreamResult(os));
	}

	public static void main(String[] args) throws Throwable {

		List<Node> rom70 = new ArrayList<Node>();
		List<Node> rom80 = new ArrayList<Node>();
		List<Node> rom90 = new ArrayList<Node>();

		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse(new File(
				"C:\\Program Files (x86)\\mGalaxy\\Data - Kopie\\UserSystems\\Multi-system [MAME]-I2zbZe7o\\xmlout.xml"));
		Element root = document.getDocumentElement();

		for (int i = 0; i < root.getChildNodes().getLength(); i++) {
			Node node = root.getChildNodes().item(i);

			if (node.getAttributes() == null) {
				continue;
			}
			Element elt = (Element) node;
			String yearString = elt.getElementsByTagName("release").item(0).getTextContent();

			int year = Integer.parseInt(yearString.replaceAll("\\?", "0").replaceAll("X", "0"));
			if (year < 1981) {
				rom70.add(node);
			} else if (year < 1988) {
				rom80.add(node);
			} else {
				rom90.add(node);
			}

		}

		FileOutputStream stream = new FileOutputStream("70.xml");

		for (Node node : rom70) {
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();

		stream = new FileOutputStream("80.xml");

		for (Node node : rom80) {
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();

		stream = new FileOutputStream("90.xml");

		for (Node node : rom90) {
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();
	}
}

alpenjodler
Newbie
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 2:34 pm

update:

this version also moves the assets into 3 different directories if you create the directories first.
I also learned I was worried for no reason since some unreferenced files were left over in the directories so mgalaxy doesn't seem to be too eager to delete files after all

Code: Select all


package mGalaxyListSplitter;

import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class Splitter {
	public static void writeXml(Node n, OutputStream os) throws TransformerException {
		TransformerFactory tf = TransformerFactory.newInstance();
		// identity
		Transformer t = tf.newTransformer();
		t.setOutputProperty(OutputKeys.INDENT, "yes");
		t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		t.transform(new DOMSource(n), new StreamResult(os));
	}

	public static void main(String[] args) throws Throwable {

		List<Node> rom70 = new ArrayList<Node>();
		List<Node> rom80 = new ArrayList<Node>();
		List<Node> rom90 = new ArrayList<Node>();

		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse(new File(
				"C:\\Program Files (x86)\\mGalaxy\\Data - Kopie\\UserSystems\\Multi-system [MAME]-I2zbZe7o\\xmlout.xml"));
		Element root = document.getDocumentElement();

		for (int i = 0; i < root.getChildNodes().getLength(); i++) {
			Node node = root.getChildNodes().item(i);

			if (node.getAttributes() == null) {
				continue;
			}
			Element elt = (Element) node;
			String yearString = elt.getElementsByTagName("release").item(0).getTextContent();

			int year = Integer.parseInt(yearString.replaceAll("\\?", "0").replaceAll("X", "0"));
			if (year < 1981) {
				rom70.add(node);
			} else if (year < 1988) {
				rom80.add(node);
			} else {
				rom90.add(node);
			}

		}

		FileOutputStream stream = new FileOutputStream("70.xml");

		for (Node node : rom70) {
			Element elt = (Element) node;

			moveAssets(elt, 7);
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();

		stream = new FileOutputStream("80.xml");

		for (Node node : rom80) {
			Element elt = (Element) node;
			moveAssets(elt, 8);
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();

		stream = new FileOutputStream("90.xml");

		for (Node node : rom90) {
			Element elt = (Element) node;
			moveAssets(elt, 9);
			writeXml(node, stream);

		}
		stream.flush();
		stream.close();
	}

	private static void moveAssets(Element elt, int year) {
		String name = elt.getAttributes().getNamedItem("name").getNodeValue();

		Path temp;
		try {
			temp = Files.move(Paths.get("H:\\mgalaxy\\logos\\" + name + ".png"),
					Paths.get("H:\\mgalaxy\\logos" + year + "\\" + name + ".png"));
		} catch(NoSuchFileException a){}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		

		try {
			temp = Files.move(Paths.get("H:\\mgalaxy\\screenshots\\" + name + ".png"),
					Paths.get("H:\\mgalaxy\\screenshots" + year + "\\" + name + ".png"));
		} catch(NoSuchFileException a){}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			temp = Files.move(Paths.get("H:\\mgalaxy\\covers\\" + name + ".png"),
					Paths.get("H:\\mgalaxy\\covers" + year + "\\" + name + ".png"));
		} catch(NoSuchFileException a){}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			temp = Files.move(Paths.get("H:\\mgalaxy\\videos\\" + name + ".mp4"),
					Paths.get("H:\\mgalaxy\\videos" + year + "\\" + name + ".mp4"));
		} catch(NoSuchFileException a){}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			temp = Files.move(Paths.get("H:\\mgalaxy\\arts\\" + name + ".png"),
					Paths.get("H:\\mgalaxy\\arts" + year + "\\" + name + ".png"));
		} 
		catch(NoSuchFileException a){}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
User avatar
mgalaxy
Administrator
Administrator
Posts: 1192
Joined: Tue Dec 05, 2006 7:46 pm

That's a great idea! Thanks so much for sharing the application with the community!
alpenjodler
Newbie
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 2:34 pm

You're welcome, glad you like it. Thanks for the awesome frontend. I just love tinkering with it :-D Is there any way to turn on logging?

Next I'll figure out how to  make the filters for the genres I don't need disappear.
I didn't use all my mame roms but made a selection with some tool but I guess the catver.ini still lists the mature and educational stuff so the genre filters in the shift menu are quite cluttered.
I guess I just delete those lines from the catver.ini, reload it and see what happens :-D
alpenjodler
Newbie
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 2:34 pm

It works! I just had to reuse my first script since the first step of db update that reads the Catver.ini enters every game into the xmlout.xml.

Now I have 3 mame lists and the filters only list stuff that I actually have :-D

I think I'll also upload my catver.ini and my 3 xmlout.xml files somewhere since they're quite huge bug might be useful for someone who doesn't want to fiddle around with my code :-D

Code: Select all


package mGalaxyListSplitter;

import java.io.FileReader;
import java.io.FileWriter;

public class Catver {
	public static void main(String[] args) throws Throwable {
		FileReader reader = new FileReader("C:\\mame\\_Catver.ini");
		char[] buffer = new char[1024];
		
		StringBuffer filebuffer = new StringBuffer();
		
		int lines = 1024;
		while (lines==1024){
			
			lines = reader.read(buffer);
			filebuffer.append(buffer, 0, lines);
		}
		reader.close();
		FileWriter writer = new FileWriter("c:\\mame\\Catver.ini");
		
		String[] filecontents = filebuffer.toString().split("\n");
		for (String line : filecontents){
			if (line.contains("ature") 
					|| line.contains("Home Videogame") 
					|| line.contains("Device") 
					|| line.contains("Electromechanical") 
					|| line.contains("Compilation") 
					|| line.contains("Casino ") 
					|| line.contains("Slot Machine") 
					|| line.contains("Cards") 
					|| line.contains("Quiz ") 
					|| line.contains("Utilities") 
					|| line.contains("System ") 
					|| line.contains("Tabletop") 
					|| line.contains("Mahjong") 
					|| line.contains("Training Board") 
					|| line.contains("Computer ") 
					|| line.contains("Calculator ")
					|| line.contains("MultiGame ")
					|| line.contains("Game Console")
				    || line.contains("Telephone ") 
				    || line.contains("Board Game ") 
				    || line.contains("Misc. ") 
				    || line.contains("Whac-A-Mole ") 
				    || line.contains("Casino ") 
				    || line.contains("Music ")){
			}else{
				writer.write(line+"\n");
			}
		}
		writer.flush();
		writer.close();
		
	}
}


alpenjodler
Newbie
Newbie
Posts: 9
Joined: Fri Aug 17, 2018 2:34 pm

70
http://www.filedropper.com/xmlout

80
http://www.filedropper.com/xmlout_1

90
http://www.filedropper.com/xmlout_2

Catver.ini
http://www.filedropper.com/catver

Have fun :-D If you're feeling grateful, please take another look at the preview video thread ( http://www.mgalaxy.com/forum/index.php?topic=940.0 ) on xp, mine are still not playing despite trying various codec packs and the videos playing just fine in Windows Media Player (In this case the weird XP one where there are tons of menus sticking out of the little video window)

edit: Ahh, I got it working by updating Windows Media Player :-D
Last edited by alpenjodler on Mon Aug 20, 2018 7:42 pm, edited 1 time in total.
Post Reply