Exemple #1
0
        public System.Collections.ArrayList JoinElements(eList newList, int listID, bool addNew, bool backupNew, bool replaceChanged, bool backupChanged, bool removeMissing, bool backupMissing, string dirBackupNew, string dirBackupChanged, string dirBackupMissing)
        {
            object[][] newElementValues         = newList.elementValues;
            string[]   newElementTypes          = newList.elementTypes;
            System.Collections.ArrayList report = new System.Collections.ArrayList();
            bool exists;

            for (int n = 0; n < elementValues.Length; n++)
            {
                Application.DoEvents();
                exists = false;
                for (int e = 0; e < newElementValues.Length; e++)
                {
                    if (this.GetValue(n, 0) == newList.GetValue(e, 0))
                    {
                        exists = true;
                    }
                }
                if (exists)
                {
                    if (dirBackupMissing != null && System.IO.Directory.Exists(dirBackupMissing))
                    {
                        ExportItem(dirBackupMissing + "\\List_" + listID.ToString() + "_Item_" + this.GetValue(n, 0) + ".txt", n);
                    }
                    if (removeMissing)
                    {
                        report.Add("- MISSING ITEM (*removed): " + ((int)elementValues[n][0]).ToString());
                        RemoveItem(n);
                        n--;
                    }
                    else
                    {
                        report.Add("- MISSING ITEM (*not removed): " + ((int)elementValues[n][0]).ToString());
                    }
                }
            }

            for (int e = 0; e < newElementValues.Length; e++)
            {
                Application.DoEvents();
                exists = false;
                for (int n = 0; n < elementValues.Length; n++)
                {
                    if (this.GetValue(n, 0) == newList.GetValue(e, 0))
                    {
                        exists = true;
                        if (this.elementValues[n].Length != newList.elementValues[e].Length)
                        {
                            report.Add("<> DIFFERENT ITEM (*not replaced, invalid amount of values): " + this.GetValue(n, 0));
                        }
                        else
                        {
                            for (int i = 0; i < this.elementValues[n].Length; i++)
                            {
                                if (this.GetValue(n, i) != newList.GetValue(e, i))
                                {
                                    if (backupChanged && System.IO.Directory.Exists(dirBackupChanged))
                                    {
                                        ExportItem(dirBackupChanged + "\\List_" + listID.ToString() + "_Item_" + this.GetValue(n, 0) + ".txt", n);
                                    }
                                    if (replaceChanged)
                                    {
                                        report.Add("<> DIFFERENT ITEM (*replaced): " + this.GetValue(n, 0));
                                        elementValues[n] = newList.elementValues[e];
                                    }
                                    else
                                    {
                                        report.Add("<> DIFFERENT ITEM (*not replaced): " + this.GetValue(n, 0));
                                    }
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                if (exists)
                {
                    if (backupNew && System.IO.Directory.Exists(dirBackupNew))
                    {
                        newList.ExportItem(dirBackupNew + "\\List_" + listID.ToString() + "_Item_" + newList.GetValue(e, 0) + ".txt", e);
                    }
                    if (addNew)
                    {
                        AddItem(newElementValues[e]);
                        report.Add("+ NEW ITEM (*added): " + this.GetValue(elementValues.Length - 1, 0));
                    }
                    else
                    {
                        report.Add("+ NEW ITEM (*not added): " + this.GetValue(elementValues.Length - 1, 0));
                    }
                }
            }

            return(report);
        }
Exemple #2
0
        public eList[] Load(string elFile)
        {
            eList[]      Li = new eList[0];
            FileStream   fs = File.OpenRead(elFile);
            BinaryReader br = new BinaryReader(fs);

            Version   = br.ReadInt16();
            Signature = br.ReadInt16();

            string[] configFiles = Directory.GetFiles(Application.StartupPath + "\\configs", "PW_*_v" + Version + ".cfg");
            if (configFiles.Length > 0)
            {
                ConfigFile            = configFiles[0];
                Li                    = loadConfiguration(ConfigFile);
                form.Progress.Visible = true;
                form.Progress.Maximum = Li.Length;
                for (int l = 0; l < Li.Length; l++)
                {
                    ++form.Progress.Value;
                    if (Li[l].listOffset != null)
                    {
                        if (Li[l].listOffset.Length > 0)
                        {
                            Li[l].listOffset = br.ReadBytes(Li[l].listOffset.Length);
                        }
                    }
                    else
                    {
                        if (l == 20)
                        {
                            byte[] head  = br.ReadBytes(4);
                            byte[] count = br.ReadBytes(4);
                            byte[] body  = br.ReadBytes(BitConverter.ToInt32(count, 0));
                            byte[] tail  = br.ReadBytes(4);
                            Li[l].listOffset = new byte[head.Length + count.Length + body.Length + tail.Length];
                            Array.Copy(head, 0, Li[l].listOffset, 0, head.Length);
                            Array.Copy(count, 0, Li[l].listOffset, 4, count.Length);
                            Array.Copy(body, 0, Li[l].listOffset, 8, body.Length);
                            Array.Copy(tail, 0, Li[l].listOffset, 8 + body.Length, tail.Length);
                        }
                        if (l == 100)
                        {
                            byte[] head  = br.ReadBytes(4);
                            byte[] count = br.ReadBytes(4);
                            byte[] body  = br.ReadBytes(BitConverter.ToInt32(count, 0));
                            Li[l].listOffset = new byte[head.Length + count.Length + body.Length];
                            Array.Copy(head, 0, Li[l].listOffset, 0, head.Length);
                            Array.Copy(count, 0, Li[l].listOffset, 4, count.Length);
                            Array.Copy(body, 0, Li[l].listOffset, 8, body.Length);
                        }
                    }
                    if (l == ConversationListIndex)
                    {
                        if (Li[l].elementTypes[0].Contains("AUTO"))
                        {
                            byte[] pattern        = (Encoding.GetEncoding("GBK")).GetBytes("facedata\\");
                            long   sourcePosition = br.BaseStream.Position;
                            int    listLength     = -72 - pattern.Length;
                            bool   run            = true;
                            while (run)
                            {
                                run = false;
                                for (int i = 0; i < pattern.Length; i++)
                                {
                                    listLength++;
                                    if (br.ReadByte() != pattern[i])
                                    {
                                        run = true;
                                        break;
                                    }
                                }
                            }
                            br.BaseStream.Position = sourcePosition;
                            Li[l].elementTypes[0]  = "byte:" + listLength;
                        }

                        Li[l].elementValues       = new object[1][];
                        Li[l].elementValues[0]    = new object[Li[l].elementTypes.Length];
                        Li[l].elementValues[0][0] = readValue(br, Li[l].elementTypes[0]);
                    }
                    else
                    {
                        Li[l].elementValues = new object[br.ReadInt32()][];
                        for (int e = 0; e < Li[l].elementValues.Length; e++)
                        {
                            Application.DoEvents();
                            Li[l].elementValues[e] = new object[Li[l].elementTypes.Length];
                            for (int f = 0; f < Li[l].elementValues[e].Length; f++)
                            {
                                Li[l].elementValues[e][f] = readValue(br, Li[l].elementTypes[f]);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Файл конфигурации версии не найден!\nВерсия: " + Version + "\nПуть: " + "configs\\PW_*_v" + Version + ".cfg");
            }
            form.Progress.Value   = 0;
            form.Progress.Visible = false;
            br.Close();
            fs.Close();

            return(Li);
        }