예제 #1
0
    public static void WriteTbl(JsonData jsonData, string filename, string version)
    {
        JsonData      memberData   = jsonData["member"];
        List <byte>   byteData     = new List <byte>();
        string        typeString   = "";
        string        memberString = "";
        List <string> keyString    = jsonData["key"].ToString().Split('+').ToList <string>();
        string        splitChar    = jsonData["dataSplitChar"].ToString();

        for (int i = 0; i < memberData.Count; i++)
        {
            typeString   += memberData[i]["titleType"].ToString() + "|";
            memberString += memberData[i]["memberName"].ToString() + "|";
        }
        typeString   = typeString.Substring(0, typeString.Length - 1);
        memberString = memberString.Substring(0, memberString.Length - 1);
        byteData     = (ByteUtility.Write(version, byteData.ToArray <byte>()).ToList <byte>());
        byteData     = (ByteUtility.Write(splitChar, byteData.ToArray <byte>()).ToList <byte>());
        byteData     = (ByteUtility.Write(typeString, byteData.ToArray <byte>()).ToList <byte>());
        byteData     = (ByteUtility.Write(memberString, byteData.ToArray <byte>()).ToList <byte>());

        string xlsPath  = Application.dataPath + "/GameRes/Config/xls/" + filename.Split('.')[0] + ".csv";
        string filePath = Application.dataPath + "/GameRes/Config/tbl/" + filename.Split('.')[0].ToLower() + ".tbl";



        //FileStream fs2 = new FileStream(xlsPath, FileMode.Open, FileAccess.Read, FileShare.None);
        //StreamReader sr2 = new StreamReader(fs2, System.Text.Encoding.ASCII);
        //string copyStr = "";

        //List<string> utfFileStr = new List<string>();
        //while ((copyStr = sr2.ReadLine()) != null)
        //{
        //    utfFileStr.Add(copyStr);
        //}
        //sr2.Close();
        //fs2.Dispose();

        //File.Delete(xlsPath);

        //FileStream fs1 = new FileStream(xlsPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
        //StreamWriter wr1 = new StreamWriter(fs1, System.Text.Encoding.UTF8);
        //for (int i = 0; i < utfFileStr.Count; i++)
        //{
        //    wr1.WriteLine(utfFileStr[i]);
        //}
        //wr1.Flush();
        //wr1.Close();
        //fs1.Dispose();

        FileStream   fs    = new FileStream(xlsPath, FileMode.Open, FileAccess.Read, FileShare.None);
        StreamReader sr    = new StreamReader(fs, System.Text.Encoding.GetEncoding("GB2312"));
        string       str   = "";
        int          index = 0;

        byte[] outByteData = new byte[0];
        while ((str = sr.ReadLine()) != null)
        {
            if (xlsPath.Contains("Upgrade"))
            {
                Util.LogForSkill(str);
            }
            if (index != 0)
            {
                string[] paramArray      = str.Split(',');
                byte[]   keyByteData     = new byte[0];
                byte[]   propetyByteData = new byte[0];
                string   key             = "";
                for (int j = 0; j < paramArray.Length; j++)
                {
                    if (keyString.Contains(memberData[j]["titleName"].ToString()))
                    {
                        key += paramArray[j];
                    }
                    //Util.LogForSkill(memberData[j]["titleType"].ToString());
                    //Util.LogForSkill(paramArray[j]);
                    switch (memberData[j]["titleType"].ToString())
                    {
                    //case "uint":
                    //    propetyByteData = ByteUtility.Write(uint.Parse(paramArray[j]), propetyByteData);
                    //    break;
                    case "short":
                        propetyByteData = ByteUtility.Write(short.Parse(paramArray[j]), propetyByteData);
                        break;

                    case "string":
                        propetyByteData = ByteUtility.Write(paramArray[j], propetyByteData);
                        break;

                    case "float":
                        propetyByteData = ByteUtility.Write(float.Parse(paramArray[j]), propetyByteData);
                        break;

                    case "int":
                        propetyByteData = ByteUtility.Write(int.Parse(paramArray[j]), propetyByteData);
                        break;

                    case "List<string>":
                        propetyByteData = ByteUtility.WriteListString(paramArray[j], propetyByteData);
                        break;

                    case "List<int>":
                        propetyByteData = ByteUtility.WriteListInt(paramArray[j], propetyByteData);
                        break;
                    }
                }
                keyByteData = ByteUtility.Write(key, keyByteData);
                byte[] tmp = outByteData;
                outByteData = new byte[keyByteData.Length + tmp.Length + propetyByteData.Length];
                keyByteData.CopyTo(outByteData, 0);
                propetyByteData.CopyTo(outByteData, keyByteData.Length);
                tmp.CopyTo(outByteData, keyByteData.Length + propetyByteData.Length);
            }
            index++;
        }
        fs.Close();
        sr.Close();
        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }
        byteData.AddRange(outByteData.ToList <byte>());
        byte[] byteoutputData = byteData.ToArray <byte>();
        File.WriteAllBytes(filePath, byteoutputData);
        Util.Log("{0} is generated success", filePath);
    }