void btnOK_Click(object sender, EventArgs e) => this.EventHandlerWithCatch(() =>
 {
     frmRecipeEdit.AssignNewRecipes();
     DatabaseAPI.AssignRecipeSalvageIDs();
     DatabaseAPI.AssignRecipeIDs();
     var serializer = My.MyApplication.GetSerializer();
     DatabaseAPI.SaveRecipes(serializer);
     DatabaseAPI.SaveEnhancementDb(serializer);
     this.Close();
 });
        bool ImportRecipeCSV(string iFName1, string iFName2)
        {
            StreamReader iStream1;
            StreamReader iStream2;

            try
            {
                iStream1 = new StreamReader(iFName1);
                iStream2 = new StreamReader(iFName2);
            }
            catch (Exception ex)
            {
                Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical, "Recipe CSVs Not Opened");
                return(false);
            }
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;

            DatabaseAPI.Database.Recipes = new Recipe[0];
            int num5;

            try
            {
                string iLine1;
                do
                {
                    iLine1 = FileIO.ReadLineUnlimited(iStream1, char.MinValue);
                    if (iLine1 != null && !iLine1.StartsWith("#"))
                    {
                        ++num4;
                        if (num4 >= 18)
                        {
                            this.BusyMsg(Strings.Format(num1, "###,##0") + " Recipes Created.");
                            num4 = 0;
                        }
                        string[] array = CSV.ToArray(iLine1);
                        if (array.Length >= 18)
                        {
                            bool   flag  = false;
                            string iName = array[0];
                            if (iName.Contains("_Memorized"))
                            {
                                iName = iName.Replace("_Memorized", "");
                                flag  = true;
                            }
                            if (iName.LastIndexOf("_", StringComparison.Ordinal) > 0)
                            {
                                iName = iName.Substring(0, iName.LastIndexOf("_", StringComparison.Ordinal));
                            }
                            int    num6    = (int)Math.Round(Conversion.Val(array[10]));
                            Recipe recipe1 = DatabaseAPI.GetRecipeByName(iName);
                            if (recipe1 == null)
                            {
                                recipe1 = new Recipe
                                {
                                    InternalName = iName,
                                    ExternalName = !(array[1] != "") ? iName : array[1],
                                    Rarity       = (Recipe.RecipeRarity)Math.Round(Conversion.Val(array[9]) - 1.0)
                                };
                                DatabaseAPI.Database.Recipes = DatabaseAPI.Database.Recipes.Append(recipe1).ToArray();
                            }
                            int index1 = -1;
                            int num7   = recipe1.Item.Length - 1;
                            for (int index2 = 0; index2 <= num7; ++index2)
                            {
                                if (recipe1.Item[index2].Level == num6 - 1)
                                {
                                    index1 = index2;
                                }
                            }
                            if (index1 < 0)
                            {
                                recipe1.Item = recipe1.Item.Append(new Recipe.RecipeEntry()).ToArray();
                            }
                            recipe1.Item[index1].Level = num6 - 1;
                            if (flag)
                            {
                                recipe1.Item[index1].BuyCostM   = (int)Math.Round(Conversion.Val(array[15]));
                                recipe1.Item[index1].CraftCostM = (int)Math.Round(Conversion.Val(array[11]));
                            }
                            else
                            {
                                recipe1.Item[index1].BuyCost   = (int)Math.Round(Conversion.Val(array[15]));
                                recipe1.Item[index1].CraftCost = (int)Math.Round(Conversion.Val(array[11]));
                            }
                            if (array[7].Length > 0)
                            {
                                int index2 = DatabaseAPI.NidFromUidEnhExtended(array[7]);
                                if (index2 > -1)
                                {
                                    recipe1.Enhancement = DatabaseAPI.Database.Enhancements[index2].UID;
                                    DatabaseAPI.Database.Enhancements[index2].RecipeName = recipe1.InternalName;
                                }
                            }
                            ++num1;
                        }
                    }
                }while (iLine1 != null);
                iStream1.Close();
                num5 = 0;
                string iLine2;
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream2, char.MinValue);
                    if (iLine2 != null && !iLine2.StartsWith("#"))
                    {
                        ++num4;
                        if (num4 >= 18)
                        {
                            this.BusyMsg(Strings.Format(num5, "###,##0") + " Recipes Created.");
                            num4 = 0;
                        }
                        string[] array = CSV.ToArray(iLine2);
                        if (array.Length >= 3)
                        {
                            int    num6  = -1;
                            bool   flag  = false;
                            string iName = array[0];
                            if (iName.Contains("_Memorized"))
                            {
                                iName = iName.Replace("_Memorized", "");
                                flag  = true;
                            }
                            if (iName.LastIndexOf("_", StringComparison.Ordinal) > 0)
                            {
                                num6  = (int)Math.Round(Conversion.Val(iName.Substring(iName.LastIndexOf("_", StringComparison.Ordinal) + 1)));
                                iName = iName.Substring(0, iName.LastIndexOf("_", StringComparison.Ordinal));
                            }
                            if (num6 > -1 & !flag)
                            {
                                Recipe recipeByName = DatabaseAPI.GetRecipeByName(iName);
                                if (recipeByName != null)
                                {
                                    int index1 = -1;
                                    ++num5;
                                    Recipe recipe = recipeByName;
                                    int    num7   = recipe.Item.Length - 1;
                                    for (int index2 = 0; index2 <= num7; ++index2)
                                    {
                                        if (recipe.Item[index2].Level == num6 - 1)
                                        {
                                            index1 = index2;
                                        }
                                    }
                                    if (index1 > -1)
                                    {
                                        int index2 = -1;
                                        int num8   = recipe.Item[index1].Salvage.Length - 1;
                                        for (int index3 = 0; index3 <= num8; ++index3)
                                        {
                                            if (recipe.Item[index1].Salvage[index3] == "")
                                            {
                                                index2 = index3;
                                                break;
                                            }
                                        }
                                        if (index2 > -1)
                                        {
                                            recipe.Item[index1].Salvage[index2]    = array[2];
                                            recipe.Item[index1].Count[index2]      = (int)Math.Round(Conversion.Val(array[1]));
                                            recipe.Item[index1].SalvageIdx[index2] = -1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }while (iLine2 != null);
                DatabaseAPI.AssignRecipeSalvageIDs();
                DatabaseAPI.GuessRecipes();
                DatabaseAPI.AssignRecipeIDs();
                Interaction.MsgBox("Done. Recipe-Enhancement links have been guessed.", MsgBoxStyle.Information, "Import");
            }
            catch (Exception ex)
            {
                Exception exception = ex;
                iStream1.Close();
                iStream2.Close();
                this.BusyHide();
                Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, "CSV Parse Error");
                return(false);
            }
            this.BusyHide();
            iStream2.Close();
            Interaction.MsgBox(("Parse Completed!\r\nTotal Records: " + num5.ToString() + "\r\nGood: " + num2.ToString() + "\r\nRejected: " + num3.ToString()), MsgBoxStyle.Information, "File Parsed");
            var serializer = My.MyApplication.GetSerializer();

            DatabaseAPI.SaveRecipes(serializer);
            DatabaseAPI.SaveEnhancementDb(serializer);
            return(true);
        }
Exemple #3
0
        bool ParseClasses(string iFileName)

        {
            int          num1 = 0;
            StreamReader iStream1;

            try
            {
                iStream1 = new StreamReader(iFileName);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                int num2 = (int)Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical, "IO CSV Not Opened");
                ProjectData.ClearProjectError();
                return(false);
            }
            int    num3 = 0;
            int    num4 = 0;
            int    num5 = 0;
            string iLine1;

            do
            {
                iLine1 = FileIO.ReadLineUnlimited(iStream1, char.MinValue);
                if (iLine1 == null || iLine1.StartsWith("#"))
                {
                    continue;
                }
                ++num5;
                if (num5 >= 11)
                {
                    BusyMsg("Pass 1 of 2: " + Strings.Format(num3, "###,##0") + " records scanned.\r\n" + Strings.Format(num1, "###,##0") + " records matched, " + Strings.Format(num4, "###,##0") + " records discarded.");
                    num5 = 0;
                }
                string[] array = CSV.ToArray(iLine1);
                if (array.Length > 1)
                {
                    int subIndex = 0;
                    int index1   = DatabaseAPI.NidFromUidRecipe(array[0], ref subIndex);
                    if (index1 > -1 & index1 <DatabaseAPI.Database.Recipes.Length& subIndex> -1)
                    {
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage    = new string[7];
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx = new int[7];
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count      = new int[7];
                        int index2 = 0;
                        do
                        {
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage[index2]    = "";
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx[index2] = -1;
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index2]      = 0;
                            ++index2;
                        }while (index2 <= 6);
                        ++num1;
                    }
                    else
                    {
                        ++num4;
                    }
                }
                ++num3;
            }while (iLine1 != null);
            iStream1.Close();
            StreamReader iStream2;

            try
            {
                iStream2 = new StreamReader(iFileName);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                int num2 = (int)Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical, "IO CSV Not Opened");
                ProjectData.ClearProjectError();
                return(false);
            }
            int num6 = 0;
            int num7 = 0;

            try
            {
                string iLine2;
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream2, char.MinValue);
                    if (iLine2 == null || iLine2.StartsWith("#"))
                    {
                        continue;
                    }
                    ++num5;
                    if (num5 >= 11)
                    {
                        BusyMsg("Pass 2 of 2: " + Strings.Format(num3, "###,##0") + " records scanned.\r\n" + Strings.Format(num6, "###,##0") + " records done, " + Strings.Format(num7, "###,##0") + " records discarded.");
                        num5 = 0;
                    }
                    string[] array = CSV.ToArray(iLine2);
                    if (array.Length > 1)
                    {
                        int subIndex = 0;
                        int index1   = DatabaseAPI.NidFromUidRecipe(array[0], ref subIndex);
                        if (index1 > -1 & index1 <DatabaseAPI.Database.Recipes.Length& subIndex> -1)
                        {
                            int index2 = -1;
                            int num2   = DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count.Length - 1;
                            for (int index3 = 0; index3 <= num2; ++index3)
                            {
                                if (DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index3] != 0)
                                {
                                    continue;
                                }
                                index2 = index3;
                                break;
                            }
                            if (index2 > -1)
                            {
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index2]      = (int)Math.Round(Conversion.Val(array[1]));
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage[index2]    = array[2];
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx[index2] = -1;
                            }
                            ++num6;
                        }
                        else
                        {
                            ++num7;
                        }
                    }
                    ++num3;
                }while (iLine2 != null);
                BusyMsg("Reassigning salvage IDs and saving...");
                DatabaseAPI.AssignRecipeSalvageIDs();
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception exception = ex;
                iStream2.Close();
                int num2 = (int)Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, "IO CSV Parse Error");
                ProjectData.ClearProjectError();
                return(false);
            }
            var serializer = MyApplication.GetSerializer();

            DatabaseAPI.SaveRecipes(serializer);
            DisplayInfo();
            int num8 = (int)Interaction.MsgBox(("Parse Completed!\r\nTotal Records: " + Convert.ToString(num3) + "\r\nGood: " + Convert.ToString(num6) + "\r\nRejected: " + Convert.ToString(num7)), MsgBoxStyle.Information, "File Parsed");

            return(true);
        }
        void btnImport_Click(object sender, EventArgs e)
        {
            if (Interaction.MsgBox("Really erase all stored recipes and attempt import?", MsgBoxStyle.YesNo | MsgBoxStyle.Question, "Careful...") != MsgBoxResult.Yes)
            {
                return;
            }
            char[] chArray = new char[1] {
                '\r'
            };
            string[] strArray1 = Clipboard.GetDataObject().GetData("System.String", true).ToString().Split(chArray);
            chArray[0] = '\t';
            DatabaseAPI.Database.Recipes = new Recipe[0];
            int num1 = strArray1.Length - 1;

            for (int index1 = 0; index1 <= num1; ++index1)
            {
                string[] strArray2 = strArray1[index1].Split(chArray);
                if (strArray2.Length > 7)
                {
                    string iName = strArray2[0].Replace("_Memorized", "").LastIndexOf("_", StringComparison.Ordinal) <= 0 ? strArray2[0] : strArray2[0].Substring(0, strArray2[0].Replace("_Memorized", "").LastIndexOf("_", StringComparison.Ordinal));
                    if (!char.IsLetterOrDigit(iName[0]))
                    {
                        iName = iName.Substring(1);
                    }
                    Recipe recipe1 = DatabaseAPI.GetRecipeByName(iName);
                    if (recipe1 == null)
                    {
                        IDatabase database    = DatabaseAPI.Database;
                        Recipe[]  recipeArray = (Recipe[])Utils.CopyArray(database.Recipes, (Array) new Recipe[DatabaseAPI.Database.Recipes.Length + 1]);
                        database.Recipes = recipeArray;
                        DatabaseAPI.Database.Recipes[DatabaseAPI.Database.Recipes.Length - 1] = new Recipe();
                        recipe1 = DatabaseAPI.Database.Recipes[DatabaseAPI.Database.Recipes.Length - 1];
                        Recipe recipe2 = recipe1;
                        recipe2.InternalName = iName;
                        recipe2.ExternalName = !(strArray2[14] == "") ? "" : strArray2[1];
                        recipe2.Rarity       = (Recipe.RecipeRarity)Math.Round(Conversion.Val(strArray2[15]) - 1.0);
                    }
                    int    index2  = -1;
                    Recipe recipe3 = recipe1;
                    int    num2    = recipe3.Item.Length - 1;
                    for (int index3 = 0; index3 <= num2; ++index3)
                    {
                        if ((double)recipe3.Item[index3].Level == Conversion.Val(strArray2[16]) - 1.0)
                        {
                            index2 = index3;
                        }
                    }
                    if (index2 < 0)
                    {
                        recipe3.Item = (Recipe.RecipeEntry[])Utils.CopyArray(recipe3.Item, (Array) new Recipe.RecipeEntry[recipe3.Item.Length + 1]);
                        recipe3.Item[recipe3.Item.Length - 1] = new Recipe.RecipeEntry();
                        index2 = recipe3.Item.Length - 1;
                    }
                    recipe3.Item[index2].Level = (int)Math.Round(Conversion.Val(strArray2[16]) - 1.0);
                    if (strArray2[0].IndexOf("Memorized") > -1)
                    {
                        recipe3.Item[index2].BuyCostM   = (int)Math.Round(Conversion.Val(strArray2[19]) - 1.0);
                        recipe3.Item[index2].CraftCostM = (int)Math.Round(Conversion.Val(strArray2[17]) - 1.0);
                    }
                    else
                    {
                        recipe3.Item[index2].BuyCost   = (int)Math.Round(Conversion.Val(strArray2[19]) - 1.0);
                        recipe3.Item[index2].CraftCost = (int)Math.Round(Conversion.Val(strArray2[17]) - 1.0);
                    }
                    int index4 = 0;
                    do
                    {
                        if (Conversion.Val(strArray2[4 + index4 * 2]) > 0.0)
                        {
                            recipe3.Item[index2].Count[index4]      = (int)Math.Round(Conversion.Val(strArray2[4 + index4 * 2]));
                            recipe3.Item[index2].Salvage[index4]    = strArray2[5 + index4 * 2];
                            recipe3.Item[index2].SalvageIdx[index4] = -1;
                        }
                        ++index4;
                    }while (index4 <= 4);
                }
            }
            DatabaseAPI.AssignRecipeSalvageIDs();
            DatabaseAPI.GuessRecipes();
            DatabaseAPI.AssignRecipeIDs();
            this.FillList();
            int num3 = (int)Interaction.MsgBox("Done. Recipe-Enhancement links have been guessed.", MsgBoxStyle.Information, "Import");
        }
        private bool ParseClasses(string iFileName)

        {
            var          num1 = 0;
            StreamReader iStream1;

            try
            {
                iStream1 = new StreamReader(iFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "IO CSV Not Opened", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            var    num3 = 0;
            var    num4 = 0;
            var    num5 = 0;
            string iLine1;

            do
            {
                iLine1 = FileIO.ReadLineUnlimited(iStream1, char.MinValue);
                if (iLine1 == null || iLine1.StartsWith("#"))
                {
                    continue;
                }
                ++num5;
                if (num5 >= 11)
                {
                    BusyMsg("Pass 1 of 2: " + Strings.Format(num3, "###,##0") + " records scanned.\r\n" +
                            Strings.Format(num1, "###,##0") + " records matched, " + Strings.Format(num4, "###,##0") +
                            " records discarded.");
                    num5 = 0;
                }

                var array = CSV.ToArray(iLine1);
                if (array.Length > 1)
                {
                    var subIndex = 0;
                    var index1   = DatabaseAPI.NidFromUidRecipe(array[0], ref subIndex);
                    if ((index1 > -1) & (index1 < DatabaseAPI.Database.Recipes.Length) & (subIndex > -1))
                    {
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage    = new string[7];
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx = new int[7];
                        DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count      = new int[7];
                        var index2 = 0;
                        do
                        {
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage[index2]    = "";
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx[index2] = -1;
                            DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index2]      = 0;
                            ++index2;
                        } while (index2 <= 6);

                        ++num1;
                    }
                    else
                    {
                        ++num4;
                    }
                }

                ++num3;
            } while (iLine1 != null);

            iStream1.Close();
            StreamReader iStream2;

            try
            {
                iStream2 = new StreamReader(iFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "IO CSV Not Opened", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            var num6 = 0;
            var num7 = 0;

            try
            {
                string iLine2;
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream2, char.MinValue);
                    if (iLine2 == null || iLine2.StartsWith("#"))
                    {
                        continue;
                    }
                    ++num5;
                    if (num5 >= 11)
                    {
                        BusyMsg("Pass 2 of 2: " + Strings.Format(num3, "###,##0") + " records scanned.\r\n" +
                                Strings.Format(num6, "###,##0") + " records done, " + Strings.Format(num7, "###,##0") +
                                " records discarded.");
                        num5 = 0;
                    }

                    var array = CSV.ToArray(iLine2);
                    if (array.Length > 1)
                    {
                        var subIndex = 0;
                        var index1   = DatabaseAPI.NidFromUidRecipe(array[0], ref subIndex);
                        if ((index1 > -1) & (index1 < DatabaseAPI.Database.Recipes.Length) & (subIndex > -1))
                        {
                            var index2 = -1;
                            var num2   = DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count.Length - 1;
                            for (var index3 = 0; index3 <= num2; ++index3)
                            {
                                if (DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index3] != 0)
                                {
                                    continue;
                                }
                                index2 = index3;
                                break;
                            }

                            if (index2 > -1)
                            {
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].Count[index2] =
                                    (int)Math.Round(Conversion.Val(array[1]));
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].Salvage[index2]    = array[2];
                                DatabaseAPI.Database.Recipes[index1].Item[subIndex].SalvageIdx[index2] = -1;
                            }

                            ++num6;
                        }
                        else
                        {
                            ++num7;
                        }
                    }

                    ++num3;
                } while (iLine2 != null);

                BusyMsg("Reassigning salvage IDs and saving...");
                DatabaseAPI.AssignRecipeSalvageIDs();
            }
            catch (Exception ex)
            {
                iStream2.Close();
                MessageBox.Show(ex.Message, "IO CSV Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            var serializer = MyApplication.GetSerializer();

            DatabaseAPI.SaveRecipes(serializer);
            DisplayInfo();
            MessageBox.Show($"Parse Completed!\r\nTotal Records: {num3}\r\nGood: {num6}\r\nRejected: {num7}",
                            "File Parsed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }
        bool ParseClasses(string iFileName)
        {
            int          num6 = 0;
            StreamReader iStream2;

            try
            {
                iStream2 = new StreamReader(iFileName);
            }
            catch (Exception ex)
            {
                Exception ex4 = ex;
                Interaction.MsgBox(ex4.Message, MsgBoxStyle.Critical, "IO CSV Not Opened");
                return(false);
            }
            int    num7 = 0;
            int    num8 = 0;
            int    num9 = 0;
            string iLine2;

            do
            {
                iLine2 = FileIO.ReadLineUnlimited(iStream2, '\0');
                if (iLine2 != null && !iLine2.StartsWith("#"))
                {
                    num9++;
                    if (num9 >= 11)
                    {
                        this.BusyMsg(string.Concat(new string[]
                        {
                            "Pass 1 of 2: ",
                            Strings.Format(num7, "###,##0"),
                            " records scanned.\r\n",
                            Strings.Format(num6, "###,##0"),
                            " records matched, ",
                            Strings.Format(num8, "###,##0"),
                            " records discarded."
                        }));
                        num9 = 0;
                    }
                    string[] array = CSV.ToArray(iLine2);
                    if (array.Length > 1)
                    {
                        int subIndex = 0;
                        int index    = DatabaseAPI.NidFromUidRecipe(array[0], ref subIndex);
                        if (index > -1 & index <DatabaseAPI.Database.Recipes.Length& subIndex> -1)
                        {
                            DatabaseAPI.Database.Recipes[index].Item[subIndex].Salvage    = new string[7];
                            DatabaseAPI.Database.Recipes[index].Item[subIndex].SalvageIdx = new int[7];
                            DatabaseAPI.Database.Recipes[index].Item[subIndex].Count      = new int[7];
                            int index2 = 0;
                            do
                            {
                                DatabaseAPI.Database.Recipes[index].Item[subIndex].Salvage[index2]    = "";
                                DatabaseAPI.Database.Recipes[index].Item[subIndex].SalvageIdx[index2] = -1;
                                DatabaseAPI.Database.Recipes[index].Item[subIndex].Count[index2]      = 0;
                                index2++;
                            }while (index2 <= 6);
                            num6++;
                        }
                        else
                        {
                            num8++;
                        }
                    }
                    num7++;
                }
            }while (iLine2 != null);
            iStream2.Close();
            try
            {
                iStream2 = new StreamReader(iFileName);
            }
            catch (Exception ex2)
            {
                Exception ex5 = ex2;
                Interaction.MsgBox(ex5.Message, MsgBoxStyle.Critical, "IO CSV Not Opened");
                return(false);
            }
            num6 = 0;
            num8 = 0;
            try
            {
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream2, '\0');
                    if (iLine2 != null && !iLine2.StartsWith("#"))
                    {
                        num9++;
                        if (num9 >= 11)
                        {
                            this.BusyMsg(string.Concat(new string[]
                            {
                                "Pass 2 of 2: ",
                                Strings.Format(num7, "###,##0"),
                                " records scanned.\r\n",
                                Strings.Format(num6, "###,##0"),
                                " records done, ",
                                Strings.Format(num8, "###,##0"),
                                " records discarded."
                            }));
                            num9 = 0;
                        }
                        string[] array2 = CSV.ToArray(iLine2);
                        if (array2.Length > 1)
                        {
                            int subIndex2 = 0;
                            int index3    = DatabaseAPI.NidFromUidRecipe(array2[0], ref subIndex2);
                            if (index3 > -1 & index3 <DatabaseAPI.Database.Recipes.Length& subIndex2> -1)
                            {
                                int index4 = -1;
                                int num10  = DatabaseAPI.Database.Recipes[index3].Item[subIndex2].Count.Length - 1;
                                for (int index2 = 0; index2 <= num10; index2++)
                                {
                                    if (DatabaseAPI.Database.Recipes[index3].Item[subIndex2].Count[index2] == 0)
                                    {
                                        index4 = index2;
                                        break;
                                    }
                                }
                                if (index4 > -1)
                                {
                                    DatabaseAPI.Database.Recipes[index3].Item[subIndex2].Count[index4]      = (int)Math.Round(Conversion.Val(array2[1]));
                                    DatabaseAPI.Database.Recipes[index3].Item[subIndex2].Salvage[index4]    = array2[2];
                                    DatabaseAPI.Database.Recipes[index3].Item[subIndex2].SalvageIdx[index4] = -1;
                                }
                                num6++;
                            }
                            else
                            {
                                num8++;
                            }
                        }
                        num7++;
                    }
                }while (iLine2 != null);
                this.BusyMsg("Reassigning salvage IDs and saving...");
                DatabaseAPI.AssignRecipeSalvageIDs();
            }
            catch (Exception ex3)
            {
                Exception exception = ex3;
                iStream2.Close();
                Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, "IO CSV Parse Error");
                return(false);
            }
            DatabaseAPI.SaveRecipes();
            this.DisplayInfo();
            Interaction.MsgBox(string.Concat(new string[]
            {
                "Parse Completed!\r\nTotal Records: ",
                Conversions.ToString(num7),
                "\r\nGood: ",
                Conversions.ToString(num6),
                "\r\nRejected: ",
                Conversions.ToString(num8)
            }), MsgBoxStyle.Information, "File Parsed");
            return(true);
        }
Exemple #7
0
        void btnImport_Click(object sender, EventArgs e) => this.EventHandlerWithCatch(() =>
        {
            if (Interaction.MsgBox("Really erase all stored recipes and attempt import?", MsgBoxStyle.YesNo | MsgBoxStyle.Question, "Careful...") != MsgBoxResult.Yes)
            {
                return;
            }
            char[] delimiter             = { '\r' };
            string[] strArray1           = Clipboard.GetDataObject()?.GetData("System.String", true).ToString().Split(delimiter);
            delimiter[0]                 = '\t';
            DatabaseAPI.Database.Recipes = new Recipe[0];
            int num1 = strArray1.Length - 1;
            for (int index1 = 0; index1 <= num1; ++index1)
            {
                string[] strArray2 = strArray1[index1].Split(delimiter);
                if (strArray2.Length <= 7)
                {
                    continue;
                }
                string iName = strArray2[0].Replace("_Memorized", "").LastIndexOf("_", StringComparison.Ordinal) <= 0 ? strArray2[0] : strArray2[0].Substring(0, strArray2[0].Replace("_Memorized", "").LastIndexOf("_", StringComparison.Ordinal));
                if (!char.IsLetterOrDigit(iName[0]))
                {
                    iName = iName.Substring(1);
                }
                Recipe recipe1 = DatabaseAPI.GetRecipeByName(iName);
                if (recipe1 == null)
                {
                    recipe1 =
                        new Recipe
                    {
                        InternalName = iName,
                        ExternalName = strArray2[14] != "" ? "" : strArray2[1],
                        Rarity       = (Recipe.RecipeRarity)Math.Round(Conversion.Val(strArray2[15]) - 1.0)
                    };
                    DatabaseAPI.Database.Recipes = DatabaseAPI.Database.Recipes.Append(recipe1).ToArray();
                }

                int index2 = -1;
                int num2   = recipe1.Item.Length - 1;
                for (int index3 = 0; index3 <= num2; ++index3)
                {
                    if (Math.Abs(recipe1.Item[index3].Level - (Conversion.Val(strArray2[16]) - 1.0)) < float.Epsilon)
                    {
                        index2 = index3;
                    }
                }
                if (index2 < 0)
                {
                    recipe1.Item = (Recipe.RecipeEntry[])Utils.CopyArray(recipe1.Item, new Recipe.RecipeEntry[recipe1.Item.Length + 1]);
                    recipe1.Item[recipe1.Item.Length - 1] = new Recipe.RecipeEntry();
                    index2 = recipe1.Item.Length - 1;
                }
                recipe1.Item[index2].Level = (int)Math.Round(Conversion.Val(strArray2[16]) - 1.0);
                if (strArray2[0].IndexOf("Memorized", StringComparison.Ordinal) > -1)
                {
                    recipe1.Item[index2].BuyCostM   = (int)Math.Round(Conversion.Val(strArray2[19]) - 1.0);
                    recipe1.Item[index2].CraftCostM = (int)Math.Round(Conversion.Val(strArray2[17]) - 1.0);
                }
                else
                {
                    recipe1.Item[index2].BuyCost   = (int)Math.Round(Conversion.Val(strArray2[19]) - 1.0);
                    recipe1.Item[index2].CraftCost = (int)Math.Round(Conversion.Val(strArray2[17]) - 1.0);
                }
                int index4 = 0;
                do
                {
                    if (Conversion.Val(strArray2[4 + index4 * 2]) > 0.0)
                    {
                        recipe1.Item[index2].Count[index4]      = (int)Math.Round(Conversion.Val(strArray2[4 + index4 * 2]));
                        recipe1.Item[index2].Salvage[index4]    = strArray2[5 + index4 * 2];
                        recipe1.Item[index2].SalvageIdx[index4] = -1;
                    }
                    ++index4;
                }while (index4 <= 4);
            }
            DatabaseAPI.AssignRecipeSalvageIDs();
            DatabaseAPI.GuessRecipes();
            DatabaseAPI.AssignRecipeIDs();
            FillList();
            Interaction.MsgBox("Done. Recipe-Enhancement links have been guessed.", MsgBoxStyle.Information, "Import");
        });
        bool ImportRecipeCSV(string iFName1, string iFName2)
        {
            StreamReader iStream;
            StreamReader iStream2;

            try
            {
                iStream  = new StreamReader(iFName1);
                iStream2 = new StreamReader(iFName2);
            }
            catch (Exception ex)
            {
                Exception ex3 = ex;
                Interaction.MsgBox(ex3.Message, MsgBoxStyle.Critical, "Recipe CSVs Not Opened");
                return(false);
            }
            int num5 = 0;
            int num6 = 0;
            int num7 = 0;
            int num8 = 0;

            Recipe[] recipeArray = new Recipe[0];
            DatabaseAPI.Database.Recipes = recipeArray;
            try
            {
                string iLine2;
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream, '\0');
                    if (iLine2 != null && !iLine2.StartsWith("#"))
                    {
                        num8++;
                        if (num8 >= 18)
                        {
                            this.BusyMsg(Strings.Format(num5, "###,##0") + " Recipes Created.");
                            num8 = 0;
                        }
                        string[] array = CSV.ToArray(iLine2);
                        if (array.Length >= 18)
                        {
                            bool   flag  = false;
                            string iName = array[0];
                            if (iName.Contains("_Memorized"))
                            {
                                iName = iName.Replace("_Memorized", "");
                                flag  = true;
                            }
                            if (iName.LastIndexOf("_", StringComparison.Ordinal) > 0)
                            {
                                iName = iName.Substring(0, iName.LastIndexOf("_", StringComparison.Ordinal));
                            }
                            int    num9   = (int)Math.Round(Conversion.Val(array[10]));
                            Recipe recipe = DatabaseAPI.GetRecipeByName(iName);
                            if (recipe == null)
                            {
                                IDatabase database = DatabaseAPI.Database;
                                recipeArray      = (Recipe[])Utils.CopyArray(database.Recipes, new Recipe[DatabaseAPI.Database.Recipes.Length + 1]);
                                database.Recipes = recipeArray;
                                DatabaseAPI.Database.Recipes[DatabaseAPI.Database.Recipes.Length - 1] = new Recipe();
                                recipe = DatabaseAPI.Database.Recipes[DatabaseAPI.Database.Recipes.Length - 1];
                                Recipe recipe2 = recipe;
                                recipe2.InternalName = iName;
                                if (array[1] != "")
                                {
                                    recipe2.ExternalName = array[1];
                                }
                                else
                                {
                                    recipe2.ExternalName = iName;
                                }
                                recipe2.Rarity = (Recipe.RecipeRarity)Math.Round(Conversion.Val(array[9]) - 1.0);
                            }
                            int    index   = -1;
                            Recipe recipe3 = recipe;
                            int    num10   = recipe3.Item.Length - 1;
                            for (int index2 = 0; index2 <= num10; index2++)
                            {
                                if (recipe3.Item[index2].Level == num9 - 1)
                                {
                                    index = index2;
                                }
                            }
                            if (index < 0)
                            {
                                index               = recipe3.Item.Length;
                                recipe3.Item        = (Recipe.RecipeEntry[])Utils.CopyArray(recipe3.Item, new Recipe.RecipeEntry[index + 1]);
                                recipe3.Item[index] = new Recipe.RecipeEntry();
                            }
                            recipe3.Item[index].Level = num9 - 1;
                            if (flag)
                            {
                                recipe3.Item[index].BuyCostM   = (int)Math.Round(Conversion.Val(array[15]));
                                recipe3.Item[index].CraftCostM = (int)Math.Round(Conversion.Val(array[11]));
                            }
                            else
                            {
                                recipe3.Item[index].BuyCost   = (int)Math.Round(Conversion.Val(array[15]));
                                recipe3.Item[index].CraftCost = (int)Math.Round(Conversion.Val(array[11]));
                            }
                            if (array[7].Length > 0)
                            {
                                int index3 = DatabaseAPI.NidFromUidEnhExtended(array[7]);
                                if (index3 > -1)
                                {
                                    recipe3.Enhancement = DatabaseAPI.Database.Enhancements[index3].UID;
                                    DatabaseAPI.Database.Enhancements[index3].RecipeName = recipe3.InternalName;
                                }
                            }
                            num5++;
                        }
                    }
                }while (iLine2 != null);
                iStream.Close();
                num5 = 0;
                do
                {
                    iLine2 = FileIO.ReadLineUnlimited(iStream2, '\0');
                    if (iLine2 != null && !iLine2.StartsWith("#"))
                    {
                        num8++;
                        if (num8 >= 18)
                        {
                            this.BusyMsg(Strings.Format(num5, "###,##0") + " Recipes Created.");
                            num8 = 0;
                        }
                        string[] array2 = CSV.ToArray(iLine2);
                        if (array2.Length >= 3)
                        {
                            int    num11  = -1;
                            bool   flag2  = false;
                            string iName2 = array2[0];
                            if (iName2.Contains("_Memorized"))
                            {
                                iName2 = iName2.Replace("_Memorized", "");
                                flag2  = true;
                            }
                            if (iName2.LastIndexOf("_", StringComparison.Ordinal) > 0)
                            {
                                num11  = (int)Math.Round(Conversion.Val(iName2.Substring(iName2.LastIndexOf("_", StringComparison.Ordinal) + 1)));
                                iName2 = iName2.Substring(0, iName2.LastIndexOf("_", StringComparison.Ordinal));
                            }
                            if (num11 > -1 & !flag2)
                            {
                                Recipe recipeByName = DatabaseAPI.GetRecipeByName(iName2);
                                if (recipeByName != null)
                                {
                                    int index4 = -1;
                                    num5++;
                                    Recipe recipe4 = recipeByName;
                                    int    num12   = recipe4.Item.Length - 1;
                                    for (int index5 = 0; index5 <= num12; index5++)
                                    {
                                        if (recipe4.Item[index5].Level == num11 - 1)
                                        {
                                            index4 = index5;
                                        }
                                    }
                                    if (index4 > -1)
                                    {
                                        int index6 = -1;
                                        int num13  = recipe4.Item[index4].Salvage.Length - 1;
                                        for (int index7 = 0; index7 <= num13; index7++)
                                        {
                                            if (recipe4.Item[index4].Salvage[index7] == "")
                                            {
                                                index6 = index7;
                                                break;
                                            }
                                        }
                                        if (index6 > -1)
                                        {
                                            recipe4.Item[index4].Salvage[index6]    = array2[2];
                                            recipe4.Item[index4].Count[index6]      = (int)Math.Round(Conversion.Val(array2[1]));
                                            recipe4.Item[index4].SalvageIdx[index6] = -1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }while (iLine2 != null);
                DatabaseAPI.AssignRecipeSalvageIDs();
                DatabaseAPI.GuessRecipes();
                DatabaseAPI.AssignRecipeIDs();
                Interaction.MsgBox("Done. Recipe-Enhancement links have been guessed.", MsgBoxStyle.Information, "Import");
            }
            catch (Exception ex2)
            {
                Exception exception = ex2;
                iStream.Close();
                iStream2.Close();
                this.BusyHide();
                Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, "CSV Parse Error");
                return(false);
            }
            this.BusyHide();
            iStream2.Close();
            Interaction.MsgBox(string.Concat(new string[]
            {
                "Parse Completed!\r\nTotal Records: ",
                Conversions.ToString(num5),
                "\r\nGood: ",
                Conversions.ToString(num6),
                "\r\nRejected: ",
                Conversions.ToString(num7)
            }), MsgBoxStyle.Information, "File Parsed");
            DatabaseAPI.SaveRecipes();
            DatabaseAPI.SaveEnhancementDb();
            return(true);
        }