コード例 #1
0
ファイル: CraftBuddy.cs プロジェクト: Daxda/CraftBuddy
        internal void generateProfile(Recipe recipe, ProfileTemplate pt)
        {
            // Read the contents of the base profile.
            string profileContent;
            using(StreamReader sr = new StreamReader(pt.Path))
            {
                profileContent = sr.ReadToEnd();
            }

            // Give feedback if the profile content was empty (we can't recover from this error).
            if(string.IsNullOrEmpty(profileContent))
            {
                Logger.Write(LoggerType.Error, "Base Template was empty!");
                Logger.Write(LoggerType.Error, string.Format("Template path: {0}", pt.Path));
                return;
            }

            // Replace the recipe id in the profile with the currently selected recipe in the craftbuddy window.
            string replacedContent = Regex.Replace(profileContent, "RecipeId=\".*?\"", string.Format("RecipeId=\"{0}\"", recipe.Id));
            if(string.IsNullOrEmpty(replacedContent))
            {
                Logger.Write(LoggerType.Error, "Failed to generate new profile!");
                return;
            }

            // Write the changed content of the base profile back to file.
            using(StreamWriter sw = new StreamWriter(pt.Path))
            {
                sw.WriteLine(replacedContent.Trim());
                Logger.Write("Profile has been created!");
            }

            // TODO: Move to seperate function (maybe SwapProfile())
            Logger.Write("Switching to generated crafting profile.");
            NeoProfileManager.Load(pt.Path);

            if(TreeRoot.Current.ToString() != "Order Bot")
            {
                Logger.Write(LoggerType.Warning,
                    "Current botbase not set to Order Bot. Switch to Order Bot to start crafting!");
            }
        }
コード例 #2
0
ファイル: CraftBuddy.cs プロジェクト: Daxda/CraftBuddy
        public void ReloadTemplates()
        {
            // Generate ProfileTemplate objects
            ProfileTemplates = new List<ProfileTemplate>();
            foreach(string templatePath in Directory.GetFiles(TemplatesPath))
            {
                if(!templatePath.ToLower().EndsWith(".xml"))
                    continue;

                string filename = Path.GetFileNameWithoutExtension(templatePath);
                if(string.IsNullOrEmpty(filename))
                {
                    continue;
                }
                ProfileTemplate pt = new ProfileTemplate(filename, templatePath);
                ProfileTemplates.Add(pt);
            }
        }