Ejemplo n.º 1
0
        protected bool SaveToFile(string file_name, ByteBuffer write_buff, string ext_path)
        {
            string file_name_str = file_name;
            string file_path_str = (ext_path == "" || ext_path == null) ? m_cookie_path : ext_path;

            string write_path = AppConfig.DataPath;

            write_path = write_path + file_path_str;
            string full_path = write_path + file_name_str + ".cfg";

            full_path = full_path.Replace("\\", "/");
            //DataEncrypt.EncryptHashTableData(out write_buff, (uint)write_buff.size(), DefineConstantsCookieHandler.CFGFILE_SEED);

            if (File.Exists(full_path))
            {
                File.Delete(full_path);
            }

            //添加一个#作为标识,这里需要优化
            string str = Convert.ToBase64String(write_buff.ToBytes());

            str = str.Insert(str.Length, "#");
            bool ret = Pathtool.SaveDataToFile(full_path, Encoding.UTF8.GetBytes(str));

            // Debug.Log("Write Cookie Path :" + full_path + " str:"+str+" ret:"+ret.ToString());
            write_buff.Close();
            return(ret);
        }
Ejemplo n.º 2
0
        protected bool ReadCookie(string table_name, string ext_info)
        {
            string file_name_str = table_name;
            string file_path     = (ext_info == "" || ext_info == null) ? m_cookie_path : ext_info;

            string write_path = AppConfig.DataPath;

            file_name_str = file_path + file_name_str + ".cfg";
            file_name_str = file_name_str.Replace("\\", "/");

            write_path = write_path + file_name_str;
            // Debug.Log("Read Cookie Path :" +  file_name_str+ " write_path:"+write_path);

            byte[] file_data = new byte[1024 * 100];
            Pathtool.GetDataToFile(write_path, out file_data);
            if (file_data == null || file_data.Length == 0)
            {
                Debug.Log("Read Cookie Failed! : " + file_name_str);
                return(false);
            }

            //DataEncrypt.DecryptHashTableData(out file_data, (uint)file_data.Length, DefineConstantsCookieHandler.CFGFILE_SEED);
            //int rlt = Ogre.CCLuaEngine.defaultEngine().executeString((string)file_data.contents(), (uint)file_data.Length, file_name_str);

            //[修改] 解密后使用DoString执行lua代码
            //加密过的文件最后字符为#,删除#再进行解密
            if (file_data[file_data.Length - 1] == 35)
            {
                string str       = Encoding.UTF8.GetString(file_data);
                byte[] byteArray = Convert.FromBase64String(str.Substring(0, str.Length - 1));
                string show_str  = System.Text.Encoding.Default.GetString(byteArray);
                // Debug.Log("read cookie str : "+show_str);
                XLuaManager.Instance.SafeDoString(Encoding.UTF8.GetString(byteArray), write_path);
            }
            else
            {
                // Debug.Log("load outside file : "+write_path);
                XLuaManager.Instance.LoadOutsideFile(write_path);
            }

            return(true);
        }