Exemplo n.º 1
0
        private bool CompareItems()
        {
            OtbReader reader1 = new OtbReader();
            if (!reader1.Read(this.file1Text.Text))
            {
                MessageBox.Show("Could not open {0}.", this.file1Text.Text);
                return false;
            }

            OtbReader reader2 = new OtbReader();
            if (!reader2.Read(this.file2Text.Text))
            {
                MessageBox.Show("Could not open {0}.", this.file2Text.Text);
                return false;
            }

            IEnumerator<ServerItem> enumerator1 = reader1.Items.GetEnumerator();
            IEnumerator<ServerItem> enumerator2 = reader2.Items.GetEnumerator();

            if (reader1.Count != reader2.Count)
            {
                resultTextBox.AppendText(string.Format("Item count:  [ {0} / {1} ]" + Environment.NewLine, reader1.Count, reader2.Count));
            }

            while (enumerator1.MoveNext())
            {
                if (!enumerator2.MoveNext())
                {
                    return false;
                }

                ServerItem item1 = enumerator1.Current;
                ServerItem item2 = enumerator2.Current;

                if (item1.ClientId != item2.ClientId)
                {
                    resultTextBox.AppendText(string.Format("ID: {0}  -  Sprite changed  -  [ {1} / {2} ]" + Environment.NewLine, item1.ID, item1.ClientId, item2.ClientId));
                    continue;
                }

                if (item1.SpriteHash != null && item2.SpriteHash != null && !Utils.ByteArrayCompare(item1.SpriteHash, item2.SpriteHash))
                {
                    resultTextBox.AppendText(string.Format("ID: {0}  -  Sprite updated." + Environment.NewLine, item1.ID));
                }

                foreach (PropertyInfo property in item1.GetType().GetProperties())
                {
                    if (property.Name != "SpriteHash" && property.Name != "ClientId")
                    {
                        object value1 = property.GetValue(item1, null);
                        object value2 = item2.GetType().GetProperty(property.Name).GetValue(item2, null);

                        if (!value1.Equals(value2))
                        {
                            resultTextBox.AppendText(string.Format("ID: {0}  -  {1}  -  [ {2} / {3} ]{4}", item1.ID, property.Name, value1, value2, Environment.NewLine));
                        }
                    }
                }
            }

            if (resultTextBox.Text.Length == 0)
            {
                MessageBox.Show("No differences found!");
            }

            return true;
        }
Exemplo n.º 2
0
        public void Open(string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                FileDialog dialog = new OpenFileDialog();
                dialog.Filter = "OTB files (*.otb)|*.otb";
                dialog.Title = "Open OTB File";

                if (dialog.ShowDialog() != DialogResult.OK || dialog.FileName.Length == 0)
                {
                    return;
                }

                path = dialog.FileName;
                this.IsTemporary = false;
                this.Saved = true;
            }

            if (this.Loaded)
            {
                this.Clear();
            }

            OtbReader reader = new OtbReader();
            if (reader.Read(path))
            {
                this.serverItems = reader.Items;
                this.CurrentOtbFullPath = path;
                this.CurrentOtbVersion = this.serverItems.MinorVersion;

                // try find a plugin that can handle this version of otb
                this.CurrentPlugin = Program.plugins.AvailablePlugins.Find(this.CurrentOtbVersion);
                if (this.CurrentPlugin == null)
                {
                    this.serverItems.Clear();
                    MessageBox.Show(string.Format("Could not find a plugin that could handle client version {0}", this.CurrentOtbVersion));
                    return;
                }

                if (!this.LoadClient(this.CurrentPlugin, this.CurrentOtbVersion))
                {
                    this.Clear(false);
                    return;
                }

                this.fileSaveAsMenuItem.Enabled = true;
                this.fileSaveMenuItem.Enabled = true;
                this.editCreateItemMenuItem.Enabled = true;
                this.editFindItemMenuItem.Enabled = true;
                this.viewShowOnlyMismatchedMenuItem.Enabled = true;
                this.viewShowDecaptedItemsMenuItem.Enabled = true;
                this.viewUpdateItemsListMenuItem.Enabled = true;
                this.toolsUpdateVersionMenuItem.Enabled = true;
                this.toolsReloadItemAttributesMenuItem.Enabled = true;
                this.toolStripSaveButton.Enabled = true;
                this.toolStripSaveAsButton.Enabled = true;
                this.toolStripFindItemButton.Enabled = true;
                this.serverItemListBox.Plugin = this.CurrentPlugin.Instance;
                this.serverItemListBox.Enabled = true;
                this.newItemButton.Enabled = true;
                this.duplicateItemButton.Enabled = true;
                this.reloadItemButton.Enabled = true;
                this.findItemButton.Enabled = true;
                this.Loaded = true;
                this.BuildItemsListBox();
            }
        }