示例#1
0
        private bool SaveFile(string tableName)
        {
            var tbl = StaticReference.GetTableByFullName(tableName);

            if (tbl == null)
            {
                return(true);
            }

            tbl.Save(); // save
            tbl.Altered = false;
            if (tcMain.SelectedTabPage.Text.Contains("(*)"))
            {
                tcMain.SelectedTabPage.Text = tcMain.SelectedTabPage.Text.Replace("(*)", "");
            }
            var page = GetTabPageByFilename(tableName);
            var view = GetViewFromTabPage(page);

            if (_editedCells.ContainsKey(view))
            {
                _editedCells.Remove(view);
                view.Invalidate();
            }
            ClearNewRowHighlight(view);
            StaticReference.ShowInformation(this, LanguageManager.Get("Message_SaveSuccess"));
            return(true);
        }
示例#2
0
        private void View_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            GridView    view = GetViewFromSelectedTabPage();
            KOTableFile tbl  = StaticReference.GetTableByFullName(view.Tag as string);

            if (e.RowHandle < 0 || e.Column.AbsoluteIndex < 0)
            {
                return;
            }
            if (!(tbl == null))
            {
                /* New row highlight */
                if (NewRowHighlightEnabled(view, tbl.Table.Rows[e.RowHandle]))
                {
                    e.Appearance.BackColor = Color.FromArgb(128, Color.ForestGreen);
                }
            }
            if (_editedCells.ContainsKey(view))
            {
                /* Edited cell highlight */
                foreach (KeyValuePair <int, int> kvp in _editedCells[view])
                {
                    int cIndex = kvp.Value;
                    int rIndex = kvp.Key;
                    if (e.Column.AbsoluteIndex == cIndex && e.RowHandle == rIndex)
                    {
                        e.Appearance.BackColor = Color.FromArgb(128, Color.Gold);
                        break;
                    }
                }
            }
            //throw new NotImplementedException();
        }
示例#3
0
        private void GridViewEvent_ValidateRow(object sender, ValidateRowEventArgs e)
        {
            var gridView = sender as GridView;

            if (gridView == null)
            {
                return;
            }

            var tbl = StaticReference.GetTableByFullName(gridView.Tag as string);

            if (tbl != null)
            {
                // var page = GetTabPageByFilename();
                var page = GetTabPageByFilename(tbl.FullName);
                if (null != page)
                {
                    if (!page.Text.Contains("(*)"))
                    {
                        page.Text += "(*)";
                    }
                }

                tbl.Altered = true;
            }
        }
 public void AddStaticReference(TypeDefinition typeDefinition)
 {
     if (!StaticReference.Contains(typeDefinition))
     {
         StaticReference.Add(typeDefinition);
     }
 }
示例#5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Title           = @"Select path and enter filename";
                sfd.Filter          = @"Knight OnLine data tables |*.tbl";
                sfd.OverwritePrompt = true;
                if (DialogResult.OK == sfd.ShowDialog())
                {
                    var tbl = StaticReference.GetTableByFullName(_tableName);

                    if (tbl == null)
                    {
                        StaticReference.ShowError(this, LanguageManager.Get("Message_FileNotOpen"));
                        Close();
                        return;
                    }

                    foreach (var v in StaticReference.EncryptionMethods.Where(v => string.Compare(v.Name(), cbEncryptionList.Text, StringComparison.Ordinal) == 0))
                    {
                        tbl.SetEncryption(v);
                    }
                    tbl.SaveAs(sfd.FileName);
                    StaticReference.ShowInformation(this, LanguageManager.Get("Message_Done"));
                    Close();
                    // tePath.Text = sfd.FileName;
                }
            }
        }
示例#6
0
        private void bgwFindNext_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            while (true && !bgwFindNext.CancellationPending)
            {
                mre.WaitOne();
                mre.Reset();
                IEnumerable <indexColumnPair> resultSet  = findNextMatch(false);
                IEnumerator <indexColumnPair> resultEnum = resultSet.GetEnumerator();
                if (!resultEnum.MoveNext() || resultEnum.Current == null)
                {
                    this.Invoke(new Action(() => { StaticReference.ShowInformation(this, Auxillary.LanguageManager.Get("Message_NoMoreMatches")); }));
                }
                else
                {
                    do
                    {
                        // MessageBox.Show(_gridView.GetRowCellValue(resultEnum.Current.index, resultEnum.Current.m_column).ToString());
                        _parent.Invoke(new Action(() => {
                            _gridView.FocusedRowHandle = resultEnum.Current.index;
                            _gridView.FocusedColumn    = resultEnum.Current.m_column;
                            _gridView.SetRowCellValue(resultEnum.Current.index, resultEnum.Current.m_column, teReplaceValue.Text);
                        }));

                        mre.WaitOne();
                        mre.Reset();
                    }while (resultEnum.MoveNext() && !bgwFindNext.CancellationPending);

                    this.Invoke(new Action(() => { StaticReference.ShowInformation(this, Auxillary.LanguageManager.Get("Message_NoMoreMatches")); }));
                }
            }
        }
示例#7
0
        // NavGroups : ngSearch //
        private void ngSearch_Find_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            GridView view = GetViewFromSelectedTabPage();

            if (view == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst"));
                return;
            }
            view.ShowFindPanel();
        }
示例#8
0
 private void frmExportAsSQL_Load(object sender, System.EventArgs e)
 {
     _tbl = StaticReference.GetTableByFullName(_tableName);
     if (_tbl == null)
     {
         StaticReference.ShowError(this, LanguageManager.Get("Message_NoFileOpen"));
         Close();
         return;
     }
     PopulateColumns();
     // meDescription.Text = StaticReference.GenerateKey(256);
 }
示例#9
0
        protected override void SetBody(TypedIndex type, float speculativeMargin, BodyInertia inertia, Vector3 offset)
        {
            var physicsSystem = GameObject.CurrentScene.GetOrCreateSystem <PhysicsSystem>();

            if (_voxelStatic.Exists)
            {
                physicsSystem.RemoveStatic(_voxelStatic);
            }
            var transformedOffset = Vector3.Transform(offset, GameObject.Transform.WorldOrientation);

            _voxelStatic = physicsSystem.AddStatic(new StaticDescription(GameObject.Transform.WorldPosition + transformedOffset, new CollidableDescription(type, speculativeMargin)), this);
        }
示例#10
0
 public frmLogin()
 {
     InitializeComponent();
     try
     {
         teUsername.Text = StaticReference.Decrypt(RegistrySettings.Username, RegistrySettings._key, RegistrySettings._keySize);
         tePassword.Text = StaticReference.Decrypt(RegistrySettings.Password, RegistrySettings._key, RegistrySettings._keySize);
     } catch { /* ignored */ }
     ceKeepLoggedIn.Checked = RegistrySettings.KeepLoggedIn;
     ceRememberMe.Checked   = RegistrySettings.RememberMe;
     // linkNewMember.url
 }
示例#11
0
        private void ngFile_Save_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            if (SaveFile(fileName))
            {
            }
        }
示例#12
0
        private void ngFile_SaveAs_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            using (frmSaveAs encSelect = new frmSaveAs(fileName))
            {
                encSelect.ShowDialog();
            }
        }
示例#13
0
        private void nbiSqlExport_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            using (frmExportAsSQL export = new frmExportAsSQL(fileName))
            {
                export.ShowDialog();
            }
        }
示例#14
0
        private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            var      tbl  = StaticReference.GetTableByFullName(fileName);
            GridView view = GetViewFromSelectedTabPage();

            if (view == null || tbl == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst"));
                return;
            }

            if (view.SelectedRowsCount == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoRowsSelected"));
                return;
            }
            if (StaticReference.ShowQuestion(this, string.Format(LanguageManager.Get("Message_DeleteConfirm"), view.SelectedRowsCount)) == DialogResult.Yes)
            {
                List <DataRow> selectedRows = new List <DataRow>();

                for (int i = 0; i < view.SelectedRowsCount; i++)
                {
                    selectedRows.Add(tbl.Table.Rows[view.GetSelectedRows()[i]]);
                }

                if (_editedCells.ContainsKey(view))
                {
                    foreach (var q in view.GetSelectedRows())
                    {
                        _editedCells[view].RemoveAll(i => i.Key == q);
                    }
                    view.Invalidate();
                }
                foreach (var t in selectedRows)
                {
                    tbl.Table.Rows.Remove(t);
                    RemoveNewRowHighlight(view, t);
                }
                view.ClearSelection();
                StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_DeleteSuccess"), selectedRows.Count));
            }
        }
示例#15
0
        private void btnDebug_Click(object sender, EventArgs e)
        {
            SHA256 mySHA256 = SHA256Managed.Create();
            var    key      = mySHA256.ComputeHash(Encoding.ASCII.GetBytes("Q3QgesV4wMug5ZtS7DenWAw3"));

            StaticReference.ShowWarning(this, BitConverter.ToString(key));
            var iv = new byte[16] {
                0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
            };
            var result = KODevLoginManager.EncryptString("wowowowowharam", key, iv);

            StaticReference.ShowError(this, result);
            //RegistrySettings.Load();
            // RegistrySettings.Save();
        }
示例#16
0
        private void ngSearch_FindAndReplace_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            GridView view = GetViewFromSelectedTabPage();

            if (view == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst"));
                return;
            }

            using (frmFindAndReplace far = new frmFindAndReplace(this, view))
            {
                far.ShowDialog();
            }
        }
示例#17
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var loginResult = KODevLoginManager.Login(teUsername.Text, tePassword.Text);

            switch (loginResult.Result.Substring(0, 29))
            {
            //LOGINSTATUS_KEY_3 (TOKEN METHODU İÇİN)  Token mevcut, fakat süresi dolmuş. Yeniden ID şifre ile token almak gerekli.
            case "LS003F5esRwzAPt33psnJdEt7eJkT":
            //LOGINSTATUS_KEY_4 (TOKEN METHODU İÇİN) Token mevcut, geçerli fakat kullanıcının gönderdiği değer yanlış!
            case "LS004GUcuNEM67D2P5PbUXqTLPHTt":
            //LOGINSTATUS_KEY_5 (PAROLA METHODU İÇİN) Hesap şuan kullanımda (token başkasında.)
            case "LS004rPrCHnnYLHUREjrh2fUggjQJ":
            //LOGINSTATUS_KEY_1 (PAROLA METHODU İÇİN) ID veya Parola yanlış.
            case "LS001Gs84DmanHUWmrWwLgDKysrFk":
                StaticReference.ShowError(this, loginResult.Message);
                break;

            //LOGINSTATUS_KEY_2 (TOKEN METHODU İÇİN)  Token mevcut, geçerli ve doğru.
            case "LS002RvkzvsDWeLdGDGCKHDKx8SuP":
            //LOGINSTATUS_KEY_T (PAROLA METHODU İÇİN) ID ve Parola doğru, token değeri JSON içerisinde token kısmına eklenir.
            case "LS00TF5esRwzAPt33psnJdEt7eJkT":
            {
                RegistrySettings.LoggedIn     = true;
                RegistrySettings.KeepLoggedIn = ceKeepLoggedIn.Checked;
                RegistrySettings.RememberMe   = ceRememberMe.Checked;

                RegistrySettings.Username = StaticReference.Encrypt(teUsername.Text, RegistrySettings._key, RegistrySettings._keySize);
                if (RegistrySettings.RememberMe)
                {
                    RegistrySettings.Password = StaticReference.Encrypt(tePassword.Text, RegistrySettings._key, RegistrySettings._keySize);
                }
                else
                {
                    RegistrySettings.Password = "******";
                }

                RegistrySettings.Save();
                Close();
            }
            break;

            //LOGINSTATUS_KEY_E
            case "LS00Ef9TV4vPbmGh9tytn7HdTMZp2":
                StaticReference.ShowError(this, loginResult.Message);
                break;
            }
        }
示例#18
0
        private void frmColumnEditor_Load(object sender, EventArgs e)
        {
            _tbl = StaticReference.GetTableByFullName(_tableName);
            if (_tbl == null)
            {
                StaticReference.ShowError(this, LanguageManager.Get("Message_NoFileOpen"));
                Close();
                return;
            }
            PopulateColumns();

            foreach (var v in _dataTypeList)
            {
                cbColumnDataType_Add.Properties.Items.Add(v);
                cbColumnDataType_Update.Properties.Items.Add(v);
            }
        }
示例#19
0
        void tcMain_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            var er = e as TabPageChangedEventArgs;

            if (er != null)
            {
                if (er.Page == null)
                {
                    return;
                }
                //Text = LanguageManager.Get("mainFrm_Menu_About_Program") + $" - {er.Page.Tag as string}";
                lblOpenFile.Caption = er.Page.Tag as string;
                KOTableFile tbl = StaticReference.GetTableByFullName(er.Page.Tag as string);
                RedrawFileInformation(tbl);
                //ngFile.Caption = $"File ({tbl.Name})";
            }
        }
示例#20
0
        private void btnRepAll_Click(object sender, EventArgs e)
        {
            int replacementCount = 0;

            foreach (var v in findNextMatch(true))
            {
                _parent.Invoke(new Action(() => {
                    _gridView.FocusedRowHandle = v.index;
                    _gridView.FocusedColumn    = v.m_column;
                    string rowCellValue        = Convert.ToString(_gridView.GetRowCellValue(v.index, v.m_column));
                    rowCellValue = rowCellValue.Replace(teFindValue.Text, teReplaceValue.Text);
                    _gridView.SetRowCellValue(v.index, v.m_column, rowCellValue);
                }));
                replacementCount++;
            }

            this.Invoke(new Action(() => { StaticReference.ShowInformation(this, string.Format(Auxillary.LanguageManager.Get("Message_NMatchesReplaced"), replacementCount)); }));
        }
示例#21
0
        private bool CloseFile(string tableName)
        {
            var tbl = StaticReference.GetTableByFullName(tableName);

            if (tbl == null)
            {
                return(true);
            }

            if (tbl.Altered)
            {
                string q = string.Format(LanguageManager.Get("Message_SaveConfirmChanges"), tableName);

                switch (StaticReference.ShowQuestion(this, q))
                {
                case DialogResult.Yes:
                    tbl.Save();     // save
                    break;

                case DialogResult.Cancel:
                    return(false);
                }
            }

            try
            {
                /* Clear edited cell value if exist */
                var page = GetTabPageByFilename(tableName);
                var view = GetViewFromTabPage(page);
                if (_editedCells.ContainsKey(view))
                {
                    _editedCells.Remove(view);
                    view.Invalidate();
                }
                ClearNewRowHighlight(view);
                StaticReference.RemoveTableByFullName(tableName);
            }
            catch
            {
                // ignored
            }

            return(true);
        }
示例#22
0
        private void btnRemoveChecked_Click(object sender, EventArgs e)
        {
            if (clbColumns.CheckedItems.Count == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems"));
                return;
            }

            foreach (CheckedListBoxItem v in clbColumns.CheckedItems)
            {
                string[] zzz = Convert.ToString(v.Value).Split(',');
                int      ind = Convert.ToInt32(zzz[0]);
                _tbl.Table.Columns.RemoveAt(ind);

                //  v
                // Columnindex = 0;
            }
            PopulateColumns();
        }
示例#23
0
        private void ngEdit_NewRow_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string      fileName = tcMain.SelectedTabPage.Tag as string;
            KOTableFile tbl      = StaticReference.GetTableByFullName(fileName);
            var         view     = GetViewFromSelectedTabPage();
            var         row      = tbl.Table.NewRow();

            tbl.Table.Rows.Add(row);
            AddNewRowHighlight(view, row);
            view.FocusedRowHandle = view.RowCount - 1;
            view.TopRowIndex      = view.RowCount - 1;
            view.RefreshData();
            view.Invalidate();
        }
示例#24
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (_loadedTables.Count == 0)
            {
                StaticReference.ShowWarning(this, "There are no loaded tables to convert.");
                return;
            }
            if (string.IsNullOrEmpty(_destinationFolder))
            {
                StaticReference.ShowWarning(this, "Destination folder is not set.");
                return;
            }
            if (!Directory.Exists(_destinationFolder))
            {
                try
                {
                    Directory.CreateDirectory(_destinationFolder);
                }
                catch (Exception ex)
                {
                    StaticReference.ShowWarning(this, $"An exception occured while creating destination directory.\nException : {ex.Message}");
                    return;
                }
            }

            var encMethod = StaticReference.EncryptionMethods.FirstOrDefault(v => string.Compare(v.Name(), cbEncryption.Text, StringComparison.Ordinal) == 0);

            if (encMethod == null)
            {
                StaticReference.ShowWarning(this, $"Encryption load error.");
                return;
            }
            foreach (var tbl in _loadedTables)
            {
                meLog.Text += $"Saving {_destinationFolder}\\{tbl.Value.Name}" + Environment.NewLine;
                tbl.Value.SetEncryption(encMethod);
                tbl.Value.SaveAs($"{_destinationFolder}\\{tbl.Value.Name}");
            }

            StaticReference.ShowInformation(this, "Done.");
        }
示例#25
0
        private void btnUpdateColumn_Click(object sender, EventArgs e)
        {
            if (clbColumns.CheckedItems.Count == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems"));
                return;
            }
            Type      tp       = _dataTypeList[cbColumnDataType_Update.SelectedIndex];
            DataTable dtCloned = _tbl.Table.Clone();

            dtCloned.Columns[0].DataType = typeof(Int32);

            foreach (CheckedListBoxItem v in clbColumns.CheckedItems)
            {
                string[] zzz = Convert.ToString(v.Value).Split(',');
                int      ind = Convert.ToInt32(zzz[0]);

                if (_tbl.Table.Columns.GetType() == tp)
                {
                    /* same type */
                }
                else
                {
                    dtCloned.Columns[ind].DataType = tp;
                }
                //_tbl.Table.Columns.RemoveAt(ind);

                //  v
                // Columnindex = 0;
            }

            foreach (DataRow row in _tbl.Table.Rows)
            {
                dtCloned.ImportRow(row);
            }
            _tbl.Table = dtCloned;

            PopulateColumns();
        }
示例#26
0
        private void copyRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            var      tbl  = StaticReference.GetTableByFullName(fileName);
            GridView view = GetViewFromSelectedTabPage();

            if (view == null || tbl == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst"));
                return;
            }


            // MessageBox.Show("ctrlc");
            if (view.SelectedRowsCount == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoRowsSelected"));
                return;
            }
            List <DataRow> drList = new List <DataRow>();

            for (int i = 0; i < view.SelectedRowsCount; i++)
            {
                drList.Add(tbl.Table.Rows[view.GetSelectedRows()[i]]);
                //view.GetSelectedRows().cl
            }
            /* Copy the content of selected rows to the internal clipboard. */
            InternalClipboard.Copy(ref drList);
            view.ClearSelection();
            StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_NRowsCopied"), InternalClipboard.GetSize()));
        }
示例#27
0
        private void ngEdit_NewColumn_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string fileName = tcMain.SelectedTabPage.Tag as string;

            using (frmColumnEditor columnEditor = new frmColumnEditor(fileName))
            {
                columnEditor.ShowDialog();
            }

            var grid     = GetTabPageGrid(fileName);
            var newTable = StaticReference.GetTableByFullName(fileName);
            // TODO : Refresh datagrid

            /*     grid.DataSource = null;
             *   grid.DataSource = newTable;
             *   grid.ResetBindings();
             *   grid.RefreshDataSource();*/
            //   GetViewFromSelectedTabPage().SynchronizeData();
        }
示例#28
0
 public object GetStaticContext(StaticReference reference) => GetStaticContext(reference.Handle);
示例#29
0
 public void RemoveStatic(StaticReference reference)
 {
     Simulation.Statics.Remove(reference.Handle);
     _staticContexts.Remove(reference.Handle);
 }
示例#30
0
 private void ParseFileForCells(BinaryReader br, string PluginName, Dictionary<string, bool> IgnoreList, Dictionary<string, bool> CellList) {
     List<string> Masters = new List<string>() { PluginName.ToLower(Statics.Culture) };
     if (DEBUG) allWarnings.Add("PLUGIN=" + Masters[0]);
     int DEBUG_cells = 0;
     int DEBUG_refs = 0;
     int DEBUG_added = 0;
     int DEBUG_moved = 0;
     int DEBUG_deleted = 0;
     while (br.BaseStream.Position < br.BaseStream.Length) {
         string s = ReadString(br);
         int size = br.ReadInt32();
         br.BaseStream.Position += 8;
         switch (s) {
             case "TES3":
                 int read = 0;
                 while (read < size) {
                     s = ReadString(br);
                     int size2 = br.ReadInt32();
                     read += size2 + 8;
                     long pos = br.BaseStream.Position;
                     switch (s) {
                         case "MAST":
                             Masters.Add(ReadCString(br, size2).ToLower(Statics.Culture));
                             if (DEBUG) allWarnings.Add("MASTER[" + (Masters.Count - 1) + "]=" + Masters[Masters.Count-1]);
                             break;
                     }
                     br.BaseStream.Position = pos + size2;
                 }
                 break;
             case "CELL":
                 if (DEBUG) DEBUG_cells++;
                 string CellName = "";
                 bool IsValidCell = false;
                 bool InReference = false;
                 bool ReferenceHasScale = false;
                 bool ReferenceDeleted = false;
                 bool ReadData = false;
                 bool Interior = false;
                 uint RefID = 0;
                 int MastID = 0;
                 int CellX = 0;
                 int CellY = 0;
                 StaticReference sr = new StaticReference();
                 read = 0;
                 while (read < size) {
                     s = ReadString(br);
                     int size2 = br.ReadInt32();
                     read += size2 + 8;
                     long pos = br.BaseStream.Position;
                     switch (s) {
                         case "DATA":
                             if (!InReference) {
                                 if (ReadData) break;
                                 uint flags = br.ReadUInt32();
                                 if ((flags & 0x01) == 0 || (cbStatIntExt.Checked && (flags & 0x81) == 0x81) || (cbStatIntWater.Checked && (flags & 0x83) == 0x03)) IsValidCell = true;
                                 if ((flags & 0x01) != 0) {
                                     Interior = true;
                                     if (CellList.ContainsKey(CellName.ToLower(Statics.Culture))) IsValidCell = CellList[CellName.ToLower(Statics.Culture)];
                                 }
                                 else Interior = false;
                                 CellX = br.ReadInt32();
                                 CellY = br.ReadInt32();
                                 ReadData = true;
                             } else {
                                 sr.x = br.ReadSingle();
                                 sr.y = br.ReadSingle();
                                 sr.z = br.ReadSingle();
                                 sr.yaw = br.ReadSingle();
                                 sr.pitch = br.ReadSingle();
                                 sr.roll = br.ReadSingle();
                             }
                             break;
                         case "FRMR":
                             if (DEBUG) DEBUG_refs++;
                             if (!IsValidCell) break;
                             if (InReference) {
                                 if (!ReferenceHasScale) sr.scale = 1;
                                 if (StaticsList.ContainsKey(sr.name) && (!IgnoreList.ContainsKey(sr.name) || !IgnoreList[sr.name])) {
                                     sr.SetID(StaticsList, StaticMap);
                                     string Worldspace = Interior ? CellName : "";
                                     string Reference = Masters[MastID] + "\u0001" + (Interior ? "" : CellX + "\u0002" + CellY + "\u0001") + RefID;
                                     if (ReferenceDeleted) {
                                         if (UsedStaticsList.ContainsKey(Worldspace) && UsedStaticsList[Worldspace].ContainsKey(Reference)) UsedStaticsList[Worldspace].Remove(Reference);
                                     }
                                     else {
                                         if (!UsedStaticsList.ContainsKey(Worldspace)) UsedStaticsList.Add(Worldspace, new Dictionary<string, StaticReference>());
                                         UsedStaticsList[Worldspace][Reference] = sr;
                                     }
                                     if (DEBUG) {
                                         if (ReferenceDeleted) ++DEBUG_deleted;
                                         else if (MastID > 0) ++DEBUG_moved;
                                         else ++DEBUG_added;
                                     }
                                 }
                             }
                             RefID = br.ReadUInt32();
                             MastID = (int)(RefID >> 24);
                             RefID &= 0x00FFFFFF;
                             sr = new StaticReference();
                             InReference = true;
                             ReferenceHasScale = false;
                             ReferenceDeleted = false;
                             break;
                         case "DELE":
                             ReferenceDeleted = true;
                             break;
                         case "NAME":
                             if (InReference) sr.name = ReadCString(br, size2).ToLower(Statics.Culture);
                             else CellName = ReadCString(br, size2);
                             break;
                         case "XSCL":
                             if (!InReference) break;
                             sr.scale = br.ReadSingle();
                             ReferenceHasScale = true;
                             break;
                     }
                     br.BaseStream.Position = pos + size2;
                 }
                 if (InReference) {
                     if (!ReferenceHasScale) sr.scale = 1;
                     if (StaticsList.ContainsKey(sr.name) && (!IgnoreList.ContainsKey(sr.name) || !IgnoreList[sr.name])) {
                         sr.SetID(StaticsList, StaticMap);
                         string Worldspace = Interior ? CellName : "";
                         string Reference = Masters[MastID] + "\u0001" + (Interior ? "" : CellX + "\u0002" + CellY + "\u0001") + RefID;
                         if (ReferenceDeleted) {
                             if (UsedStaticsList.ContainsKey(Worldspace) && UsedStaticsList[Worldspace].ContainsKey(Reference)) UsedStaticsList[Worldspace].Remove(Reference);
                         }
                         else {
                             if (!UsedStaticsList.ContainsKey(Worldspace)) UsedStaticsList.Add(Worldspace, new Dictionary<string, StaticReference>());
                             UsedStaticsList[Worldspace][Reference] = sr;
                         }
                         if (DEBUG) {
                             if (ReferenceDeleted) ++DEBUG_deleted;
                             else if (MastID > 0) ++DEBUG_moved;
                             else ++DEBUG_added;
                         }
                     }
                 }
                 break;
             default:
                 br.BaseStream.Position += size;
                 break;
         }
     }
     if (DEBUG) allWarnings.Add("Scanning summary for: " + PluginName + " : " + DEBUG_cells + " cells : " + DEBUG_refs + " refs : " + DEBUG_added + " added : " + DEBUG_moved + " moved : " + DEBUG_deleted + " deleted");
 }
示例#31
0
        private void simpleButton1_Click(object sender, System.EventArgs e)
        {
            if (clbColumns.CheckedItems.Count == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems"));
                return;
            }
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Filter = LanguageManager.Get("frmExportAsSQL_Filter");
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    /* Let's begin */
                    StringBuilder insertQuery = new StringBuilder();

                    StringBuilder createQuery = new StringBuilder();
                    int           batch       = 0;
                    if (ceDropTable.Checked)
                    {
                        createQuery.Append($"DROP TABLE {teTableName.Text};\n");
                    }
                    createQuery.Append($"CREATE TABLE {teTableName.Text}(");
                    if (ceTruncateTable.Checked)
                    {
                        insertQuery.Append($"TRUNCATE TABLE {teTableName.Text};\n");
                    }
                    insertQuery.Append($"INSERT INTO {teTableName.Text} VALUES \n");

                    foreach (CheckedListBoxItem clbi in clbColumns.CheckedItems)
                    {
                        string[] zzz = Convert.ToString(clbi.Value).Split(',');
                        int      ind = Convert.ToInt32(zzz[0]);
                        TextEdit te  = _columnNames[ind];
                        createQuery.Append(te.Text);
                        switch (_tbl.Table.Columns[ind].DataType.FullName)
                        {
                        case "System.UInt64":
                        case "System.Int64":
                            createQuery.Append($" bigint,\n");
                            break;

                        case "System.Double":
                        case "System.Single":
                            createQuery.Append($" real,\n");
                            break;

                        case "System.UInt32":
                        case "System.Int32":
                            createQuery.Append($" int,\n");
                            break;

                        case "System.UInt16":
                        case "System.Int16":
                            createQuery.Append($" smallint,\n");
                            break;

                        case "System.SByte":
                        case "System.Byte":
                            createQuery.Append($" tinyint,\n");
                            break;

                        case "System.String":
                            createQuery.Append($" varchar(MAX),\n");
                            break;

                        default:
                            createQuery.Append($" unknown(MAX),\n");
                            break;
                        } /* EOF cell type switch */
                    }
                    int insertedRows = 0;

                    foreach (DataRow v in _tbl.Table.Rows)
                    {
                        insertQuery.Append("(");
                        foreach (CheckedListBoxItem clbi in clbColumns.CheckedItems)
                        {
                            string[]   zzz  = Convert.ToString(clbi.Value).Split(',');
                            int        ind  = Convert.ToInt32(zzz[0]);
                            DataColumn clmn = _tbl.Table.Columns[ind];
                            if (clmn.DataType.FullName == "System.String")
                            {
                                insertQuery.Append(("'" + v[clmn].ToString().Replace('\'', '’').Replace("\\", "\\\\") + "',"));
                            }
                            else if (clmn.DataType.FullName == "System.Single" || clmn.DataType.FullName == "System.Double")
                            {
                                /* Convert float notation from ',' to '.' */
                                insertQuery.Append(Convert.ToString(Convert.ToDouble(v[clmn].ToString())).Replace(",", ".") + ",");
                            }
                            else
                            {
                                insertQuery.Append(v[clmn] + ",");
                            }
                        }
                        insertQuery.Remove(insertQuery.Length - 1, 1);
                        insertQuery.Append("),\n");
                        if (++insertedRows == 999)
                        {
                            /* We need to break it to several parts. */
                            insertQuery.Remove(insertQuery.Length - 2, 2);
                            insertQuery.Append(";");
                            File.WriteAllText(sfd.FileName.Replace(".sql", "") + "_data" + (batch++) + ".sql", insertQuery.ToString());
                            insertQuery.Clear();
                            /* prepare for next batch */
                            insertQuery.Append($"INSERT INTO {teTableName.Text} VALUES \n");
                            insertedRows = 0;
                        }
                    }
                    insertQuery.Remove(insertQuery.Length - 2, 2);
                    insertQuery.Append(";");
                    createQuery.Remove(createQuery.Length - 2, 2);
                    createQuery.Append(");\n\n");
                    if (ceCreateTable.Checked)
                    {
                        File.WriteAllText(sfd.FileName.Replace(".sql", "") + "_ddl" + ".sql", createQuery.ToString());
                    }
                    File.AppendAllText(sfd.FileName.Replace(".sql", "") + "_data" + (batch++) + ".sql", insertQuery.ToString());
                }
            }
            StaticReference.ShowInformation(this, LanguageManager.Get("Message_ExportComplete"));
        }