public DataHandler(out bool bData, Logging log)
        {
            dhLog     = log;
            prmeFiles = (String)Settings.Default["prme_src_files"];
            secFiles  = (String)Settings.Default["sec_src_files"];
            custFiles = (String)Settings.Default["cust_src_files"];

            custItemLoc = (String)Settings.Default["cust_itm_loc"];
            custMobLoc  = (String)Settings.Default["cust_mob_loc"];

            srcFldPath = (String)Settings.Default["src_dir"] + "\\";
            genFldPath = (String)Settings.Default["gen_dir"] + "\\";

            bReIsEnabled     = (bool)Settings.Default["use_re"];
            bSecIsEnabled    = (bool)Settings.Default["use_sec"];
            bCustIsEnabled   = (bool)Settings.Default["use_cust"];
            bShowErrorsInApp = (bool)Settings.Default["rpt_errs_in_app"];

            usedFiles = new List <String>();

            bDataConstraintErrExists  = false;
            bDataConstraintWarnExists = false;

            items = new List <item>();
            mobs  = new List <mob>();

            bData = false;

            fileNames = prmeFiles;

            if (bSecIsEnabled)
            {
                fileNames += "," + secFiles;
            }


            files = fileNames.Split(',');

            foreach (String file in files)
            {
                if (bReIsEnabled)
                {
                    if (file.Contains("re"))
                    {
                        usedFiles.Add(file);
                    }
                }
                else
                {
                    if (!file.Contains("re"))
                    {
                        usedFiles.Add(file);
                    }
                }
            }

            files = custFiles.Split(',');

            if (bCustIsEnabled)
            {
                foreach (String file in files)
                {
                    usedFiles.Add(file);
                }
            }

            foreach (string file in usedFiles)
            {
                String filePath = srcFldPath + file + ".sql";
                if (File.Exists(filePath))
                {
                    if (filePath.Contains("item"))
                    {
                        readData(filePath, "item", file);
                    }
                    else if (filePath.Contains("mob"))
                    {
                        readData(filePath, "mob", file);
                    }
                }
                else
                {
                    if (bShowErrorsInApp)
                    {
                        MessageBox.Show(null, file + " is not located in the designated folder: " + srcFldPath, "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        dhLog.addLogEntry("err", file + " is not located in the designated folder: " + srcFldPath + ".");
                        break;
                    }

                    bData = false;
                    break;
                }
            }

            checkConstraints("item");

            if (bDataConstraintErrExists && !bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more errors occurred while loading in the item source data.  Please refer to the log file(s) for more information.   Item data was not loaded.", "Data Load Error", MessageBoxButtons.OK);
                }
            }
            else if (!bDataConstraintErrExists && bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more warnings occurred while loading in the item source data.  Please refer to the log file(s) for more information.  Item data was loaded.", "Data Load Complete", MessageBoxButtons.OK);
                }
            }
            else if (bDataConstraintErrExists && bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more errors and warnings occurred while loading in the item source data.  Please refer to the log file(s) for more information.  Item data was not loaded.", "Data Load Error", MessageBoxButtons.OK);
                }
            }

            bDataConstraintErrExists  = false;
            bDataConstraintWarnExists = false;

            checkConstraints("mob");

            if (bDataConstraintErrExists && !bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more errors occurred while loading in the mob source data.  Please refer to the log file(s) for more information.   Mob data was not loaded.", "Data Load Error", MessageBoxButtons.OK);
                }
            }
            else if (!bDataConstraintErrExists && bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more warnings occurred while loading in the mob source data.  Please refer to the log file(s) for more information.   Mob data was loaded.", "Data Load Complete", MessageBoxButtons.OK);
                }
            }
            else if (bDataConstraintErrExists && bDataConstraintWarnExists)
            {
                if (!bShowErrorsInApp)
                {
                    MessageBox.Show(null, "One or more errors and warnings occurred while loading in the mob source data.  Please refer to the log file(s) for more information.    Mob data was not loaded.", "Data Load Error", MessageBoxButtons.OK);
                }
            }

            if (!bDataConstraintErrExists)
            {
                bData = true;
            }
            else
            {
                bData = false;
            }
        }
示例#2
0
        private int checkValidity(String iptStr, int caseVal, String data, String id)
        {
            int rtnVal = 0;

            switch (caseVal)
            {
            case 0:
                if (!Int32.TryParse(iptStr, out rtnVal))
                {
                    if (bShowErrorsInApp)
                    {
                        MessageBox.Show(null, "Item " + id + "'s ID value failed to parse correctly.  Please check your " + itemLocale + " source file.  Invalid row:\r\r " + data, "Integer Parsing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        itmLog.addLogEntry("err", "Item " + id + "'s ID value failed to parse correctly.  Please check your " + itemLocale + " source file.");
                    }

                    bCritFailure = true;
                }
                break;

            case 3:
                if (!Int32.TryParse(iptStr, out rtnVal))
                {
                    if (bShowErrorsInApp)
                    {
                        MessageBox.Show(null, "Item " + id + "'s type value failed to parse correctly.  Please check your " + itemLocale + " source file.  Invalid row:\r\r " + data, "Integer Parsing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        itmLog.addLogEntry("warn", "Item " + id + "'s type value failed to parse correctly.  Please check your " + itemLocale + " source file.");
                    }

                    bWarningsOccurred = true;
                }
                break;
            }

            return(rtnVal);
        }
        private void checkConstraints(String type)
        {
            if (type == "item")
            {
                for (int i1 = 0; i1 < items.Count(); i1++)
                {
                    if (i1 != items.Count() - 1)
                    {
                        for (int j1 = i1 + 1; j1 < items.Count(); j1++)
                        {
                            if ((items[i1].iEngName == items[j1].iEngName && items[i1].itemLocale == items[j1].itemLocale))
                            {
                                if (bShowErrorsInApp)
                                {
                                    MessageBox.Show(null, "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constraint error.  Name_english value is already used.  Please check your " + items[i1].itemLocale + " source file.", "Data Constraint Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    dhLog.addLogEntry("err", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constraint error.  Name_english value is already used.  Please check your " + items[i1].itemLocale + " source file.");
                                }
                                bDataConstraintErrExists = true;
                                break;
                            }
                            else if (items[i1].iID == items[j1].iID)
                            {
                                if (bShowErrorsInApp)
                                {
                                    MessageBox.Show(null, "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constraint error.  ID value is already used.  Please check your " + items[i1].itemLocale + " source file.", "Data Constraint Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    dhLog.addLogEntry("err", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constraint error.  ID value is already used.  Please check your " + items[i1].itemLocale + " source file.");
                                }
                                bDataConstraintErrExists = true;
                                break;
                            }
                            else
                            {
                                bDataConstraintErrExists = false;
                            }
                        }

                        if (items[i1].iType < 0 || items[i1].iType == 1 || items[i1].iType == 9 || (items[i1].iType >= 13 && items[i1].iType <= 17) || items[i1].iType > 18)
                        {
                            dhLog.addLogEntry("warn", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constrained warning.  Item type is not valid, defaulting to Etc item (3).  Please check your " + items[i1].itemLocale + " source file.");
                            items[i1].iType           = 3;
                            bDataConstraintWarnExists = true;
                        }
                        else if (items[i1].iBPrice < items[i1].iSPrice)
                        {
                            dhLog.addLogEntry("warn", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constrained warning.  Item buy price is lower than its sell price.  Zeny exploit possible.  Please check your " + items[i1].itemLocale + " source file.");
                            bDataConstraintWarnExists = true;
                        }
                        else if (items[i1].iSlots > 4)
                        {
                            dhLog.addLogEntry("warn", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constrained warning.  Item indicates more than 4 card slots, but server only supports 4.  Defaulting to 4.  Please check your " + items[i1].itemLocale + " source file.");
                            items[i1].iSlots          = 4;
                            bDataConstraintWarnExists = true;
                        }
                        else if ((items[i1].iType == 4 || items[i1].iType == 5 || items[i1].iType == 6 || items[i1].iType == 10 || items[i1].iType == 12) && (items[i1].iEqpLocals <= 0 || (getMasks(items[i1].iEqpLocals)).Count == 0))
                        {
                            dhLog.addLogEntry("warn", "Item " + items[i1].iID.ToString() + " " + items[i1].iEngName + " has a constrained warning.  Item indicates more than 4 card slots, but server only supports 4.  Defaulting to 4.  Please check your " + items[i1].itemLocale + " source file.");
                            items[i1].iSlots          = 4;
                            bDataConstraintWarnExists = true;
                        }
                    }

                    if (bDataConstraintErrExists)
                    {
                        break;
                    }
                }
            }
            else if (type == "mob")
            {
                for (int i1 = 0; i1 < mobs.Count(); i1++)
                {
                    if (i1 != mobs.Count() - 1)
                    {
                        for (int j1 = i1 + 1; j1 < mobs.Count(); j1++)
                        {
                            if (mobs[i1].mID == mobs[j1].mID)
                            {
                                if (bShowErrorsInApp)
                                {
                                    MessageBox.Show(null, "Mob " + mobs[i1].mID.ToString() + " " + mobs[i1].mEngName + " has a constraint error.  The ID value is already used.  Please check your " + mobs[i1].mobLocale + " source file.", "Data Constraint Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    dhLog.addLogEntry("err", "Mob " + mobs[i1].mID.ToString() + " " + mobs[i1].mEngName + " has a constraint error.  The ID value is already used.  Please check your " + items[i1].itemLocale + " source file.");
                                }
                                bDataConstraintErrExists = true;
                                break;
                            }
                            else
                            {
                                bDataConstraintErrExists = false;
                            }
                        }
                    }

                    if (bDataConstraintErrExists)
                    {
                        break;
                    }
                }
            }
        }