/// <summary> /// 清理并导出所有文件 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void bClearAndExport_Click(object sender, EventArgs e) { List <TreeNode> nodeList = new List <TreeNode>(); foreach (TreeNode node in MainForm.CurrentMainForm.tree.Nodes["scripts"].Nodes) { if (node.Text == "Map") { foreach (TreeNode sceneNode in node.Nodes) { nodeList.Add(sceneNode); } } else { nodeList.Add(node); } } ProgressForm pForm = new ProgressForm(1, nodeList.Count); pForm.Show(); int index = 1; foreach (TreeNode node in nodeList) { string classification = node.Text; bool sceneScript = (node.Parent.Text == "Map"); pForm.ShowProgress(index, string.Format("导出{0}分类下的LS数据表...", classification)); index++; string tableName = "SCENE_STRING_TABLE"; string fileName = string.Format(@"scripts\Map\{0}\include\scenestrings.ls", classification); if (!sceneScript) { tableName = string.Format("{0}_STRING_TABLE", classification.ToUpper()); fileName = string.Format(@"scripts\{0}\include\strings.ls", classification); } DataRow[] lsRows = GetValidStringDataRow(classification, sceneScript); string content = CodeConvert.ConvertLsFileContent(lsRows, tableName); fileName = Path.Combine(Helper.ClientPath, fileName); Helper.WriteStringToFile(content, fileName); } MessageBox.Show("LS文件导出成功!", "导出所有LS文件", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 输出脚本和ls文件 /// </summary> /// <param name="idList">脚本id链表</param> /// <returns>脚本和ls文件hash表</returns> public Hashtable OutputScriptData(List <string> idList, bool exportCondenseString) { Hashtable fileTable = null; try { if (conn.State == ConnectionState.Closed) // 打开sql连接 { conn.Open(); } if (idList.Count > 0) // 导出文件数大于零 { fileTable = new Hashtable(); // 文件 List <string> classificationList = new List <string>(); // 分类链表 string sqlString = string.Format("SELECT * FROM {0}", "sys_script_lsfile"); DataTable lsTable = GetDataTable(sqlString); // 导出文件 foreach (string id in idList) { sqlString = string.Format("SELECT * FROM {0} WHERE id = {1}", "sys_script_script", id); DataTable scriptTable = GetDataTable(sqlString); if (scriptTable.Rows.Count > 0) { string path = scriptTable.Rows[0]["path"].ToString(); if (scriptTable.Rows[0]["data"] is DBNull) { fileTable[path] = ""; continue; } string data = DecodeScriptData(((byte[])scriptTable.Rows[0]["data"])); string classification = GetClassification(scriptTable.Rows[0]["path"].ToString()); // 导出ls文件 DataRow[] lsRows = lsTable.Select(string.Format("classification = '{0}'", classification)); if (lsRows.Length > 0 && !classificationList.Contains(classification)) { string tableName = "SCENE_STRING_TABLE"; if (!path.StartsWith(@"scripts\Map")) { tableName = string.Format("{0}_STRING_TABLE", classification.ToUpper()); fileTable[string.Format(@"scripts\{0}\include\strings.ls", classification)] = CodeConvert.ConvertLsFileContent(lsRows, tableName); } else { fileTable[string.Format(@"scripts\Map\{0}\include\scenestrings.ls", classification)] = CodeConvert.ConvertLsFileContent(lsRows, tableName); } classificationList.Add(classification); } fileTable[path] = data; } } } } catch (SqlException ex) { MessageBox.Show("在导出脚本文件时产生sql异常: " + ex.ToString()); } finally { if (conn.State == ConnectionState.Open) // 关闭sql连接 { conn.Close(); } } return(fileTable); }