コード例 #1
0
ファイル: EditForm.cs プロジェクト: weimingtom/pap2
        /// <summary>
        /// 脚本内容改变
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void luaEdit1_OnChange(object sender, EventArgs e)
        {
            string scriptName = m_filename;

            if (scriptName.IndexOf('\\') != -1)
            {
                scriptName = scriptName.Substring(scriptName.LastIndexOf('\\') + 1);
            }

            if (scriptType == "localFile") // 本地文件跳过加锁机制
            {
                this.Text = scriptName + "*";
                return;
            }

            if (isLocked) // 已经锁了,没人会再改掉服务器端了,忽略检查吧
            {
                return;
            }

            if (IsChanged) // 真的改了
            {
                DataBaseManager databaseManager  = DataBaseManager.GetDataBaseManager();
                string          strServerContent = databaseManager.GetScriptData(this.m_id);

                if (strServerContent == null)
                {
                    MessageBox.Show("校验服务器端文件失败,可能服务器端文件已删除。", "锁定脚本",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.luaEditBox.Text = "";
                    this.luaEditBox.Text = this.ScriptCode;

                    return;
                }

                if (strServerContent != this.ScriptCode)
                {
                    MessageBox.Show("服务器端的文件已被修改过,要重新加载最新内容!", "锁定脚本", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.ScriptCode = strServerContent;
                }

                // 加锁前先解锁 如果是自己加锁后程序崩溃了,再次启动编辑可以解自己以前加的锁。前提是自己不能unlock别人的锁(待考证)
                databaseManager.UnLockScript(this.ID);

                // 正式加锁
                bool bret = databaseManager.LockScript(this.m_id);

                if (bret)
                {
                    // 锁定成功,那么置修改标志于文件名后
                    this.Text     = scriptName + "*";
                    this.isLocked = true;
                }
                else
                {
                    //锁定失败,说明被别人锁了(由于LockScript中包含报错界面,故我就不重复报错了再)
                    this.luaEditBox.Text = this.ScriptCode;
                }
            }
        }
コード例 #2
0
ファイル: EditForm.cs プロジェクト: weimingtom/pap2
        public void Reload()
        {
            if (IsChanged)
            {
                throw (new Exception("文件改变后reload无效"));
            }
            DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
            string          strServerContent = dbm.GetScriptData(this.m_id);

            if (strServerContent != null)
            {
                this.ScriptCode = strServerContent;
            }
        }
コード例 #3
0
ファイル: ClearLSForm.cs プロジェクト: weimingtom/pap2
        /// <summary>
        /// 获取指定分类里所有没有使用过的LS字符串
        /// </summary>
        /// <param name="classification">分类</param>
        /// <returns>LS字符串</returns>
        private List <string> GetUnuseStringList(string classification)
        {
            List <string> unuseStringList = new List <string>();
            string        content;
            List <string> scriptList = new List <string>(); // 脚本链表

            string condition = string.Format(@"path LIKE 'scripts\Map\{0}\%'", classification);

            if (!checkBoxX1.Checked) // 非场景分类下的字符串
            {
                condition = string.Format(@"path LIKE 'scripts\{0}%'", classification);
            }

            DataRow[] scriptRows = scriptTable.Select(condition);

            foreach (DataRow r in scriptRows)
            {
                string id = r["id"].ToString();
                content = dataBaseManager.GetScriptData(id);
                List <string> list = CodeConvert.GetStringList(content);

                foreach (string s in list)
                {
                    if (!scriptList.Contains(s))
                    {
                        scriptList.Add(s);
                    }
                }
            }

            DataRow[] lsRows = lsTable.Select(string.Format("classification = '{0}'", classification));

            foreach (DataRow r in lsRows)
            {
                content = r["content"].ToString();

                if (!scriptList.Contains(content))
                {
                    unuseStringList.Add(content);
                }
            }

            return(unuseStringList);
        }
コード例 #4
0
ファイル: StringReplaceForm.cs プロジェクト: weimingtom/pap2
        private void btnReplace_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("替换结果将不直接写入数据库,而且不能恢复,确认继续操作?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
            {
                return;
            }

            SetControlsEnabled(false);
            if (treePreview.Nodes.Count == 0)
            {
                MessageBox.Show("请先搜索出文件,再针对文件进行替换!");
                SetControlsEnabled(true);
                return;
            }

            DataBaseManager dbm = DataBaseManager.GetDataBaseManager();

            //第1步 检查锁
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (dbm.IsScriptLocked(strID))
                {
                    //文件锁了
                    MessageBox.Show("失败:文件[" + tn_file.Text + "]被正在被人编辑,无法启动替换。");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第2步 检查在选择过程中,选中项的服务器端数据变过没有
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file        = tn_file.Tag as Hashtable;
                string    strFileContent = ht_file["strFileContent"].ToString();
                string    strID          = ht_file["id"].ToString();
                if (strFileContent != dbm.GetScriptData(strID))
                {
                    //服务器端变过了
                    MessageBox.Show("失败:查找之后,替换之前,文件内容已变更,所以无法替换,请重新启动替换程序!");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第3步 锁定选择项
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (!dbm.LockScript(strID))
                {
                    MessageBox.Show("失败:检查一致性的过程中有人锁定了脚本,请迅速保存所有文件后重新运行脚本编辑器再次替换。");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第4步 替换选择项
            string strResult  = "";
            string strFind    = findTextBox.Text;
            string strReplace = replaceTextBox.Text;

            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file    = tn_file.Tag as Hashtable;
                string    strContent = "";
                foreach (TreeNode tnz in tn_file.Nodes)
                {
                    Hashtable ht_nodez = tnz.Tag as Hashtable;
                    strContent += ht_nodez["line_before"].ToString();
                    if (!tnz.Checked)
                    {
                        strContent += strFind;
                    }
                    else
                    {
                        strContent += strReplace;
                    }
                }
                strContent += ht_file["line_last"].ToString();
                string strView = "";
                bool   ret     = dbm.SaveScriptData(tn_file.Text, strContent, out strView);
                strResult += tn_file.Text + (ret ? "...OK\n" : "...NG\n");
            }

            //第5步 解锁选择项
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (!dbm.UnLockScript(strID))
                {
                    MessageBox.Show(strResult + "成功:替换完成后解锁失败,原因不明,请联系管理员");
                    SetControlsEnabled(true);
                    return;
                }
            }

            MessageBox.Show("替换完成!");//\n" + strResult);
            treePreview.Nodes.Clear();
            wbPriview.DocumentText = "";
            SetControlsEnabled(true);
        }