Beispiel #1
0
        public static void Extract(string FilePath)
        {
            foundFolder       = false;
            Form1.AddingStart = true;
            Form1.AddingEnd   = false;
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += new DoWorkEventHandler(
                delegate(object o, DoWorkEventArgs args) {
                try {
                    string AddonName;
                    Console.WriteLine(FilePath);
                    AddonName            = Path.GetFileNameWithoutExtension(FilePath);
                    AddonName            = AddonName.Replace("_", " ");
                    AddonName            = Regex.Replace(AddonName, "(?<=[a-z])([A-Z])", " $1");
                    string extensionName = Path.GetExtension(FilePath);
                    Console.WriteLine("Compressed addon is " + extensionName);
                    Console.WriteLine("Adding Addon " + AddonName);
                    Directory.CreateDirectory(managerDir + AddonName);
                    if (extensionName == ".7z")
                    {
                        Console.WriteLine("Using 7za.exe");
                        string zPath = @"Resources\7za.exe";// change the path and give yours
                        try {
                            ProcessStartInfo pro = new ProcessStartInfo();
                            pro.WindowStyle      = ProcessWindowStyle.Hidden;
                            pro.FileName         = zPath;
                            pro.Arguments        = "x \"" + FilePath + "\" -o" + "\"" + managerDir + AddonName + "\"";
                            Process x            = Process.Start(pro);
                            x.WaitForExit();
                        }
                        catch (System.Exception Ex) {
                            Console.WriteLine("Error in .7z extraction " + Ex);
                            //DO logic here
                        }
                        DirCheckLister(AddonName);
                    }
                    else
                    {
                        if (extensionName == ".bsp" || extensionName == ".py")
                        {
                            Console.WriteLine("Since file is " + extensionName + " There is no extracting to be done, skipping to next task.");
                            CreateList(managerDir + AddonName, AddonName);
                        }
                        else
                        {
                            using (ArchiveFile archiveFile = new ArchiveFile(FilePath)) {
                                archiveFile.Extract(managerDir + AddonName); // extract all
                            }

                            DirCheckLister(AddonName);
                        }
                    }
                    if (FilePath.Contains("Download"))
                    {
                        File.Delete(FilePath);
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine("An error occured in Extract: " + ex.Message);
                }
            });
            bw.RunWorkerAsync();
        }
Beispiel #2
0
        public static bool GenerateLUAFile(bool reloadUI = true)
        {
            try
            {
                if (!Directory.Exists(AddonPath))
                {
                    Directory.CreateDirectory(AddonPath);
                }

                Log.Write($"Creating Addon from SpellBook, AddonName will be [{AddonName}]...");

                Log.Write($"Creating file: [{AddonName}.toc]", Color.Gray);

                using (var sr = new StreamWriter($"{AddonPath}\\{AddonName}.toc"))
                {
                    //  ## Author: WiNiFiX
                    //  ## Interface: 60200
                    //  ## Title: DoIt
                    //  ## Version: 1.0.0
                    //  ## SavedVariablesPerCharacter: DoItOptions
                    //  DoItBase.lua

                    sr.WriteLine($"## Author: {AddonAuthor.Replace("\r", "").Replace("\n", "")}");

                    if (InterfaceVersion.Contains("-"))
                    {
                        sr.WriteLine($"## Interface: {InterfaceVersion.Split('-')[1].Trim()}");
                    }
                    else
                    {
                        sr.WriteLine($"## Interface: {InterfaceVersion}");
                    }
                    sr.WriteLine($"## Title: {AddonName.Replace("\r", "").Replace("\n", "")}");
                    sr.WriteLine($"## Version: {Application.ProductVersion}");
                    sr.WriteLine($"## SavedVariablesPerCharacter: {AddonName.Replace("\r", "").Replace("\n", "")}_settings");
                    sr.WriteLine($"{AddonName.Replace("\r", "").Replace("\n", "")}.lua");
                    sr.Close();
                }

                Log.Write($"Creating file: [{AddonName}.lua]", Color.Gray);

                using (var sr = new StreamWriter($"{AddonPath}\\{AddonName}.lua"))
                {
                    //local cooldowns = { --These should be spellIDs for the spell you want to track for cooldowns
                    //    56641,    -- Steadyshot
                    //    3044,     -- Arcane Shot
                    //    34026     -- Kill Command
                    //}

                    var cooldowns = "local cooldowns = { --These should be spellIDs for the spell you want to track for cooldowns" + Environment.NewLine;

                    foreach (var spell in Spells)
                    {
                        if (spell.InternalSpellNo == Spells.Count)  // We are adding the last spell, dont include the comma
                        {
                            cooldowns += $"    {spell.SpellId} \t -- {spell.SpellName}" + Environment.NewLine;
                        }
                        else
                        {
                            cooldowns += $"    {spell.SpellId},\t -- {spell.SpellName}" + Environment.NewLine;
                        }
                    }

                    cooldowns += "}" + Environment.NewLine;

                    sr.Write(cooldowns);

                    var auras = "local buffs = { --These should be auraIDs for the spell you want to track " + Environment.NewLine;

                    foreach (var aura in Auras)
                    {
                        if (aura.InternalAuraNo == Auras.Count)  // We are adding the last aura, dont include the comma
                        {
                            auras += $"    {aura.AuraId} \t -- {aura.AuraName}" + Environment.NewLine;
                        }
                        else
                        {
                            auras += $"    {aura.AuraId},\t -- {aura.AuraName}" + Environment.NewLine;
                        }
                    }

                    auras += "}" + Environment.NewLine;

                    sr.Write(auras);

                    var debuffs = "local debuffs = { --These should be auraIDs for the spell you want to track " + Environment.NewLine;

                    foreach (var aura in Auras)
                    {
                        if (aura.InternalAuraNo == Auras.Count)  // We are adding the last aura, dont include the comma
                        {
                            debuffs += $"    {aura.AuraId} \t -- {aura.AuraName}" + Environment.NewLine;
                        }
                        else
                        {
                            debuffs += $"    {aura.AuraId},\t -- {aura.AuraName}" + Environment.NewLine;
                        }
                    }

                    debuffs += "}" + Environment.NewLine;

                    sr.Write(debuffs);

                    var luaContents = Addon.LuaContents;

                    luaContents = luaContents.Replace("DoIt", AddonName);

                    string AddonInterfaceVersion = InterfaceVersion;
                    if (InterfaceVersion.Contains("-"))
                    {
                        AddonInterfaceVersion = InterfaceVersion.Split('-')[1].Trim();
                    }

                    if (AddonInterfaceVersion == "70000") // Legion changes as per http://www.wowinterface.com/forums/showthread.php?t=53248
                    {
                        luaContents = luaContents.Replace("SetTexture", "SetColorTexture");

                        // For now the below are disabled till further testing is done
                        // luaContents = luaContents.Replace(@"UnitPower(""player"");", @"UnitPower(""player"", UnitPowerType(""player""))");
                        // luaContents = luaContents.Replace(@"UnitPowerMax(""player"");", @"UnitPowerMax(""player"", UnitPowerType(""player""))");
                    }

                    sr.WriteLine(luaContents);
                    sr.Close();
                }

                Log.Write("Addon file generated.", Color.Green);
                Log.Write($"Make sure that the addon: [{AddonName}] is enabled in your list of WoW Addons or the rotation bot will fail to work", Color.Black);

                if (reloadUI)
                {
                    WoW.SendMacro("/console scriptErrors 1"); // Show wow Lua errors
                    WoW.SendMacro("/reload");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Write("Failed to generate addon file:", Color.Red);
                Log.Write(ex.Message, Color.Red);

                return(false);
            }
        }