tomrus88 / dbcviewer

World of Warcraft Client Database files viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code change for definition name case mismatches

BearSleepy opened this issue · comments

I had this issue last year, just sharing my changes. There are probably regular people that never realize why.

Also there are issues running from other programs. Like DascView which uses the windows associated app mechanism, effectively launches with working directory of system32, like "c:\Windows\System32" which is less than ideal for lots of reasons.

In MainForm.cs

        var definitions = m_definitions.Tables.Where(t => (t.Name.Equals(m_dbcName, StringComparison.OrdinalIgnoreCase)));
        //var definitions = m_definitions.Tables.Where(t => t.Name == m_dbcName);

        if (!definitions.Any())
        {
            definitions = m_definitions.Tables.Where(t => t.Name.Equals(Path.GetFileName(m_dbcFile), StringComparison.OrdinalIgnoreCase));
            //definitions = m_definitions.Tables.Where(t => t.Name == Path.GetFileName(m_dbcFile));
        }

In Program.cs

internal static class Program
{
	internal static string OrignalWorkingDirectory { get; set; }
	internal static string ApplicationDirectory { get; set; }
    
	/// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
	{
		OrignalWorkingDirectory = Directory.GetCurrentDirectory();
		ApplicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		// Allow callers to not need to specify our app directory as starting directory.
		// CascView for example will not set this and will cause DBCViewer to fail to find definitions.
		Directory.SetCurrentDirectory(ApplicationDirectory);

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }
}

You can have this too. It allows a generic Lua output. You know where this file is I'm sure ;)

using PluginInterface;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.Composition;
 using System.Data;
 using System.IO;
 using System.Text;
 using System.Text.RegularExpressions;

 namespace ExportFileDataAsLuaTable
 {
    [Export(typeof(IPlugin))]
    public class FileDataLuaExporter : IPlugin
    {
        [Import("PluginFinished")]
        public Action<int> Finished { get; set; }
        [Import("ClearDataTable")]
        public Action ClearDataTable { get; set; }

        public void Run(DataTable table)
        {
            if (table.TableName == "SoundKit.db2")
            {
                using (var sw1 = new StreamWriter("SoundKitData.lua"))
                {
                    sw1.WriteLine("local SOUNDDATA = {");

                    foreach (DataRow row in table.Rows)
                    {
                        sw1.WriteLine("[{0}] = \"{1}\"", row[16], row[0]);
                    }

                    sw1.WriteLine("}");
                }

                return;
            }

			if (table.TableName == "ManifestInterfaceData.db2")
			{
				using (var sw = new StreamWriter("ManifestInterfaceData.txt"))
				{
					foreach (DataRow row in table.Rows)
					{
						sw.WriteLine("{0}{1}", row[1], row[2]);
					}
				}
			}

			var fileName = Path.GetFileNameWithoutExtension(table.TableName) + ".lua";
			using (var sw = new StreamWriter(fileName))
			{
				RunGeneric(table, sw);
			}
        }

		string FilterToLuaText(string s)
		{
			if (s.IndexOf('\n') != -1 || s.IndexOf('\r') != -1)
				s = Regex.Replace(s, @"\r\n?|\n", "\\n");

			if (s.IndexOf('\"') != -1)	// assume caller will use double quotes if enclosing
				s = Regex.Replace(s, "\\\"", "\\\"");

			return s;
		}

		public void RunGeneric(DataTable table, StreamWriter sw)
		{
			var tableName = Path.GetFileNameWithoutExtension(table.TableName);

			sw.WriteLine("-- " + tableName);
			sw.WriteLine("");

			sw.WriteLine(@"db_tablecols = db_tablecols or {}; db_tablecols['" + tableName + "'] = {");
			foreach (DataColumn col in table.Columns)
			{
				sw.Write("\"" + FilterToLuaText(col.Caption) + "\", ");
			}
			sw.WriteLine("}");
			sw.WriteLine("");

			sw.WriteLine(@"db_tables = db_tables or {}; db_tables['" + tableName + "'] = {");
            foreach (DataRow row in table.Rows)
            {
				sw.Write("{");
				foreach (var item in row.ItemArray)
				{
					var s = item as String;
					if ((object)s != null)
						s = "\"" + FilterToLuaText(s) + "\", ";
					else if ((object)item != null)
						s = item.ToString() + ", ";
					else
						s = " , ";
					sw.Write(s);
				}
				sw.WriteLine("},");
            }
			sw.WriteLine("}");
			sw.WriteLine("");
        }