public static string GetBranchClientLuaPath(string excelPath, int branchId) { string clientLuaPath = ExcelParserFileHelper.GetTempLuaPath(excelPath, false); clientLuaPath = clientLuaPath.Replace("/tmp/", LuaTablePaths[branchId].Substring(2)); return(clientLuaPath); }
public static string GetLocalClientLuaPath(string excelPath) { string clientLuaPath = ExcelParserFileHelper.GetTempLuaPath(excelPath, false); clientLuaPath = clientLuaPath.Replace("/tmp/", LuaLocalPath.Substring(2)); return(clientLuaPath); }
public static bool ReGenLuaTable(string exlPath) { Excel exl = GlobalCfg.Instance.GetParsedExcel(exlPath, true); if (exl == null) { return(false); } string md5 = ExcelParserFileHelper.GetMD5HashFromFile(exlPath); if (md5 == null) { return(false); } string md5str = "--md5:" + md5 + "\n"; #region 生成服务器配置 string serverContents = md5str + exl.ToString(true); FileUtil.WriteTextFile(serverContents, GlobalCfg.GetLocalServerLuaPath(exl.tableName)); #endregion #region 生成客户端配置 if (!exl.isServerTable) { string clientContents = md5str + exl.ToString(false); FileUtil.WriteTextFile(clientContents, GlobalCfg.GetLocalClientLuaPath(exlPath)); } #endregion return(true); }
public static void ReGenLuaTable(string xlsxPath) { Excel excel = GlobalCfg.Instance.GetParsedExcel(xlsxPath); string fname = excel.tableName + ".txt"; string md5 = ExcelParserFileHelper.GetMD5HashFromFile(xlsxPath); string contents = "--md5:" + md5 + "\n"; contents += excel.ToString(); FileUtil.WriteTextFile(contents, Path.Combine(GlobalCfg.SourcePath, GlobalCfg.LocalTmpTablePath, fname)); }
private void MatchExcelFile(string path, string relativeDir, string fileNameContainExt) { string excelmd5 = ExcelParserFileHelper.GetMD5HashFromFile(path); string tarPath = ExcelParserFileHelper.GetTargetLuaPath(path, true); string tempPath = ExcelParserFileHelper.GetTempLuaPath(path, true); //#region 生成一份服务器的配置 //if (!ExcelParserFileHelper.IsSameFileMD5(tarPath, excelmd5)) //{ // Excel excel = Excel.Parse(latestExlPath, true); // if (excel != null && excel.success) // GenServerVersion(excel, tempPath, excelmd5); //} //#endregion #region 客户端的Excel生成一份客户端的配置 if (path.IndexOf("serverexcel") < 0) { //tarPath = ExcelParserFileHelper.GetTargetLuaPath(path, false); //if (aimPath == null) //{ // tempPath = ExcelParserFileHelper.GetTempLuaPath(path, false); //} //else //{ // //这里暂时这么处理 // tempPath = aimPath; //} //if (!ExcelParserFileHelper.IsSameFileMD5(tempPath, excelmd5)) //{ // Excel excel = Excel.Parse(latestExlPath, false); // if (excel != null && excel.success) // GenClientVersion(excel, tempPath, excelmd5); //} Excel excel = Excel.Parse(path, false); if (excel != null && excel.success) { GenClientVersion(excel, tempPath, excelmd5); } if (NeedAutoImport(path)) { _NeedImportClient.Add(Path.GetFileNameWithoutExtension(tempPath)); } } if (NeedAutoImport(path)) { _NeedImportServer.Add(Path.GetFileNameWithoutExtension(tempPath)); } #endregion }
public static Excel Parse(string file) { ISheet sheet = GetMainSheet(file); if (sheet != null) { Excel excel = new Excel(sheet); excel.path = file; excel.isServerTable = ExcelParserFileHelper.IsServer(file); excel.SetTableName(file); excel.ParsePropertyInfos(); excel.ParseExcelContents(); return(excel); } return(null); }
private LuaTableData InitLuaTableData(string excelpath) { if (!_lTableDataDic.ContainsKey(excelpath)) { _lTableDataDic[excelpath] = new LuaTableData { tables = new List <table>(), tableDiffs = new List <tablediff>() }; } //对比md5,看是否需要重新生成LocalLuaTable llt string tablename = string.Format("Table_{0}", Path.GetFileNameWithoutExtension(excelpath)); string lltpath = Path.Combine(SourcePath, LocalTmpTablePath, tablename + ".txt"); string md5 = ExcelParserFileHelper.GetMD5HashFromFile(excelpath); LuaTableData ltd = _lTableDataDic[excelpath]; if (!File.Exists(lltpath) || md5 != ReadTableMD5(lltpath)) { ExcelParser.ReGenLuaTable(excelpath); } if (!ltd.IsInitTable(0)) { ltd.ModifiedTables(0, parse(lltpath)); } TmpTableRealPaths = GenTmpPath(tablename); for (int i = 1; i < TmpTableRealPaths.Count + 1; i++) { if (File.Exists(TmpTableRealPaths[i - 1])) { if (!ltd.IsInitTable(i)) { ltd.ModifiedTables(i, parse(TmpTableRealPaths[i - 1])); } } else { if (!ltd.IsInitTable(i)) { ltd.ModifiedTables(i, null); } } } return(ltd); }
private LuaTableData InitLuaTableData(string excelpath) { if (!_lTableDataDic.ContainsKey(excelpath)) { LuaTableData ltd = new LuaTableData { tableDiffs = new List <tablediff>() }; #region 对比md5,看是否需要重新生成LocalLuaTable llt string tablename = string.Format("Table_{0}", Path.GetFileNameWithoutExtension(excelpath)); string slltpath = GetLocalServerLuaPath(tablename); string clltpath = GetLocalClientLuaPath(excelpath); string md5 = ExcelParserFileHelper.GetMD5HashFromFile(excelpath); bool isServer = ExcelParserFileHelper.IsServer(excelpath); if (md5 == null) { return(null); } if (!File.Exists(slltpath) || md5 != ReadTableMD5(slltpath) || (!isServer && (!File.Exists(clltpath) || md5 != ReadTableMD5(clltpath)))) { if (!ExcelParser.ReGenLuaTable(excelpath)) { return(null); } } #endregion try { ltd.tables[0] = parse(slltpath, excelpath); } catch (LuaTableException ex) /*可能会有重复ID的错误 和 Lua table 语法错误*/ { System.Windows.Forms.MessageBoxButtons button = System.Windows.Forms.MessageBoxButtons.OK; System.Windows.Forms.DialogResult errorDr = System.Windows.Forms.MessageBox.Show(ex.Message, "错误", button); if (errorDr == System.Windows.Forms.DialogResult.OK) { return(null); } } for (int i = 1; i < BranchCount + 1; i++) { string serverLuaPath = GetBranchServerLuaPath(tablename, i - 1); if (File.Exists(serverLuaPath)) { try { ltd.tables[i] = parse(serverLuaPath, excelpath); } catch (LuaTableException ex) { System.Windows.Forms.MessageBoxButtons button = System.Windows.Forms.MessageBoxButtons.OK; System.Windows.Forms.DialogResult errorDr = System.Windows.Forms.MessageBox.Show(serverLuaPath + "\n" + ex.Message, "错误", button); if (errorDr == System.Windows.Forms.DialogResult.OK) { return(null); } } } else { string excelName = Path.GetFileNameWithoutExtension(excelpath); ltd.tables[i] = new table(ReadTableMD5(slltpath), string.Format("Table_{0}", excelName), excelpath); } } _lTableDataDic[excelpath] = ltd; } return(_lTableDataDic[excelpath]); }
static void WriteTableImportFile(string contents, bool isServer = true) { string path = ExcelParserFileHelper.GetTempLuaPath(_TableImportPath, isServer); FileUtil.WriteTextFile(contents, path); }