Skip to content

Instantly share code, notes, and snippets.

@dkrusky
Created July 30, 2018 16:04
Show Gist options
  • Save dkrusky/74afb1dce818224fe9e1e3deec568421 to your computer and use it in GitHub Desktop.
Save dkrusky/74afb1dce818224fe9e1e3deec568421 to your computer and use it in GitHub Desktop.
ZygorGuides Fixer (Console C#) - Removes references to files and guides that dont exist as well as Trial references, and removes languages that aren't in your current Locale.
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ZygorFixer {
class Program {
// property to store world of warcraft install path
public static string InstallPath { get; private set; }
// property to stor world of warcraft locale
public static string Locale { get; private set; }
static void Main( string[] args )
{
GetWarcraftInstallPath();
GetWarcraftLocale();
if(Locale.Length > 0 && InstallPath.Length > 0)
{
Fix();
}
}
private static void Fix()
{
bool WriteLine = false;
string file = "";
List<string> new_data = new List<string>();
// loader fix
file = System.IO.Path.Combine(InstallPath, "interface", "addons", "ZygorGuidesViewer", "files.xml");
if (System.IO.File.Exists(file))
{
new_data = new List<string>();
string[] data = System.IO.File.ReadAllLines(file);
foreach (string s in data)
{
MatchCollection mc = Regex.Matches(s, "file=\"(.*)\"");
if (mc.Count > 0)
{
try
{
string lua = "";
foreach (Match match in mc)
{
lua = System.IO.Path.Combine(InstallPath, "interface", "addons", "ZygorGuidesViewer", match.Groups[1].Value);
if (System.IO.File.Exists(lua))
{
new_data.Add(s);
}
}
} catch (Exception e)
{
new_data.Add(s);
}
} else
{
new_data.Add(s);
}
}
}
System.IO.File.Copy(file, file + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", false);
System.IO.File.WriteAllLines(file, new_data);
// localization fix
file = System.IO.Path.Combine(InstallPath, "interface", "addons", "ZygorGuidesViewer", "Localization", "Localization.xml");
if (System.IO.File.Exists(file))
{
new_data = new List<string>();
string[] data = System.IO.File.ReadAllLines(file);
foreach (string s in data)
{
WriteLine = true;
MatchCollection mc = Regex.Matches(s, "<Script file=\"(.*)_(.*).lua\"/>");
if (mc.Count > 0)
{
foreach (Match match in mc)
{
if (match.Groups[2].Value != Locale)
{
WriteLine = false;
}
}
}
if (WriteLine == true)
{
new_data.Add(s);
}
}
}
System.IO.File.Copy(file, file + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", false);
System.IO.File.WriteAllLines(file, new_data);
// guide fix
file = System.IO.Path.Combine(InstallPath, "interface", "addons", "ZygorGuidesViewer", "Guides", "Autoload.xml");
if (System.IO.File.Exists(file))
{
new_data = new List<string>();
string[] data = System.IO.File.ReadAllLines(file);
foreach (string s in data)
{
WriteLine = true;
// remove master entries
MatchCollection mc = Regex.Matches(s, "file=\"(.*)_(.*).lua\"");
if (mc.Count > 0)
{
foreach (Match match in mc)
{
if (String.Equals(match.Groups[2].Value, "MASTER", StringComparison.OrdinalIgnoreCase))
{
WriteLine = false;
}
}
}
// remove trial entries
mc = Regex.Matches(s, "file=\"(.*)Trial.lua\"");
if (mc.Count > 0)
{
WriteLine = false;
}
if (WriteLine == true)
{
// remove files that don't exist
mc = Regex.Matches(s, "file=\"(.*)\"");
if (mc.Count > 0)
{
try
{
string lua = "";
foreach (Match match in mc)
{
lua = System.IO.Path.Combine(InstallPath, "interface", "addons", "ZygorGuidesViewer", "Guides", match.Groups[1].Value);
if (System.IO.File.Exists(lua))
{
new_data.Add(s);
}
}
} catch (Exception e)
{
new_data.Add(s);
}
} else
{
new_data.Add(s);
}
}
}
}
System.IO.File.Copy(file, file + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", false);
System.IO.File.WriteAllLines(file, new_data);
}
public static T GetValue<T>( string registryKeyPath, string value, T defaultValue = default(T) )
{
T retVal = default(T);
retVal = (T)Registry.GetValue(registryKeyPath, value, defaultValue);
return retVal;
}
private static void GetWarcraftLocale()
{
string locale = "";
locale = GetValue<string>(@"HKEY_CURRENT_USER\Software\Blizzard Entertainment\Battle.net\Launch Options\WoW", "LOCALE", "");
if (locale.Length > 0)
{
Locale = locale;
return;
}
}
private static void GetWarcraftInstallPath()
{
string path = "";
// 64 bit install path
path = GetValue<string>(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Blizzard Entertainment\World of Warcraft", "InstallPath", "");
if (path.Length > 0)
{
InstallPath = path;
return;
}
// 32 bit install path
path = GetValue<string>(@"HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft", "InstallPath", "");
if (path.Length > 0)
{
InstallPath = path;
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment