Apoc
Well-Known Member
- Joined
- Jan 16, 2010
- Messages
- 2,790
- Reaction score
- 94
Just a simple exe file to convert Pirox's .ini profile format, to HB's XML format.
Please keep in mind; this does NOT support vendors, as pirox profiles don't hold enough information to create the vendor tags with. (And I'm not going to write a WoWHead parser to pull the required info)
It will insert some default tags. If you want to change the sell/mail behaviors, edit the XML it spits out.
Instructions:
Drop the Pirox .ini profile on the exe, and... thats it. A file with a .xml extension will be created (with the same name as the .ini version).
EXE is attached below for those not wanting to play with code.
Actual code is as follows;
Please keep in mind; this does NOT support vendors, as pirox profiles don't hold enough information to create the vendor tags with. (And I'm not going to write a WoWHead parser to pull the required info)
It will insert some default tags. If you want to change the sell/mail behaviors, edit the XML it spits out.
Instructions:
Drop the Pirox .ini profile on the exe, and... thats it. A file with a .xml extension will be created (with the same name as the .ini version).
EXE is attached below for those not wanting to play with code.
Actual code is as follows;
Code:
using System;using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
namespace PiroxToHonorbuddy
{
internal class Program
{
private static void Main(string[] args)
{
try
{
if (args.Length == 0)
{
Console.WriteLine("Please specify a Pirox profile.");
return;
}
if (!File.Exists(args[0]))
{
Console.WriteLine("File does not exist.");
return;
}
// Quick wrapper to make reading easier. Win32 API is annoying...
var file = new IniFile(args[0]);
// TODO: Sanit-check these for "0" values
string minLevel = file.Read("Profile", "MinLevel");
string maxLevel = file.Read("Profile", "MaxLevel");
// Just use the filename as the name. Don't bother parsing the name in the profile
string name = Path.GetFileNameWithoutExtension(args[0]);
// Pirox profiles continue the "z#" count throughout ini sections. So we need to store the "i" counter globally
// to ensure we can read in the next sections on the profile properly.
int i;
// Get WPs
var pts = new List<Point>();
// 10k just to make sure we get everything. This is seriously overkill, but pirox profiles really have no "count" type variable
// to optimize reading. Then again, .ini format for profiles in general is terrible
for (i = 1; i < 10000; i++)
{
string tmp = file.Read("GoTo", "z" + i);
if (tmp == null)
{
continue;
}
if (!tmp.StartsWith("WPX"))
{
continue;
}
// Remove Pirox's call stuff
tmp = tmp.Replace("WPX", "").Replace("(", "").Replace(")", "").Trim();
// Split it. X, Y, Z
string[] split = tmp.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// Parse it to a "Point"
var p = new Point(
float.Parse(split[0], CultureInfo.InvariantCulture),
float.Parse(split[1], CultureInfo.InvariantCulture),
float.Parse(split[2], CultureInfo.InvariantCulture));
pts.Add(p);
}
// TODO: Add vendor shit.
var root = new XElement(
"HBProfile",
new XElement("Name", name),
// Defaults
new XElement("MinDurability", "0.4"),
new XElement("MinFreeBagSlots", "1"),
new XElement("MailGrey", false),
new XElement("MailWhite", true),
new XElement("MailGreen", true),
new XElement("MailBlue", true),
new XElement("MailPurple", true),
new XElement("SellGrey", false),
new XElement("SellWhite", false),
new XElement("SellGreen", false),
new XElement("SellBlue", false),
new XElement("SellPurple", false),
// From profile
new XElement("MinLevel", minLevel),
new XElement("MaxLevel", maxLevel),
// [GoTo] points
new XElement(
"Hotspots",
pts.Select(p => p.ToXml()).ToArray()));
File.WriteAllText(Path.ChangeExtension(args[0], ".xml"), root.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
#region Nested type: IniFile
public class IniFile
{
private readonly string _path;
public IniFile(string iniPath)
{
_path = iniPath;
}
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public string Read(string section, string key)
{
var temp = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", temp, 255, _path);
if (i == 0)
{
return null;
}
return temp.ToString();
}
}
#endregion
#region Nested type: Point
private struct Point
{
public float X, Y, Z;
public Point(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
public XElement ToXml()
{
return new XElement(
"Hotspot",
new XAttribute("X", X),
new XAttribute("Y", Y),
new XAttribute("Z", Z));
}
}
#endregion
}
}
Attachments
Last edited: