private void OnConnectedCompleted(object sender, SocketAsyncEventArgs e) { if (e.SocketError != SocketError.Success) { return; } Socket socket = sender as Socket; OnLogEvent("服务器连接成功。。。"); //开启新的接受消息异步操作事件 var receiveSaea = new SocketAsyncEventArgs(); var receiveBuffer = new byte[1024 * 4]; receiveSaea.SetBuffer(receiveBuffer, 0, receiveBuffer.Length); //设置消息的缓冲区大小 receiveSaea.Completed += OnReceiveCompleted; //绑定回调事件 receiveSaea.RemoteEndPoint = _endPoint; _socket.ReceiveAsync(receiveSaea); string timestamp = MD5Utils.ConvertDateTimeInt(DateTime.Now) + ""; string uuid = Guid.NewGuid().ToString().Replace("-", "").ToUpper(); string vk = MD5Utils.GetMD5(timestamp + "7oE9nPEG9xXV69phU31FYCLUagKeYtsF" + uuid); SendMsg(Request.gid(rid, uuid, timestamp, vk)); }
static void AddBundleInfo(string bundleName, ref FileList filelist) { if (string.IsNullOrEmpty(bundleName)) { return; } string bundlePath = string.Format("{0}/{1}", PackAssetBundle.bundleBuildFolder, bundleName); uint crc = 0; if (!BuildPipeline.GetCRCForAssetBundle(bundlePath, out crc)) { return; } FileInfo fileInfo = new FileInfo(bundlePath); UInt32 size = (UInt32)fileInfo.Length; string md5 = ""; if (string.Equals(bundleName, ResourceConst.PkgBundleFolder)) { md5 = MD5Utils.GetMD5(bundlePath); } else { md5 = FileDepencies.GetBundleMD5(bundlePath); } filelist.AddBundleInfo(bundleName, crc, size, md5); }
private static string _getConfigFieldMD5(object obj) { if (obj == null) { return(MD5Utils.GetMD5("null")); } Type t = obj.GetType(); string md5 = ""; if (t.IsArray || (t.IsGenericType && typeof(IEnumerable).IsAssignableFrom(t))) { IEnumerable arr = (IEnumerable)obj; StringBuilder sb = new StringBuilder(); foreach (object o in arr) { sb.Append(_getConfigFieldMD5(o)); } md5 = MD5Utils.GetMD5(sb.ToString()); } else if (t.IsSubclassOf(typeof(Config))) { md5 = ((Config)obj)._getMD5(); } else { md5 = MD5Utils.GetMD5(obj.ToString()); } return(md5); }
static void AddConfInfo(FileList filelist) { if (filelist == null) { return; } string confFolder = string.Format("{0}/{1}", PackAssetBundle.bundleBuildFolder, ResourceConst.ConfFolder); string[] files = Directory.GetFiles(confFolder); foreach (string file in files) { string fileName = Path.GetFileName(file); string bundleName = string.Format("{0}/{1}", ResourceConst.ConfFolder, fileName); uint crc = FileToCRC32.GetFileCRC32Int(file); FileInfo fileInfo = new FileInfo(file); UInt32 size = (UInt32)fileInfo.Length; string md5 = MD5Utils.GetMD5(file); filelist.AddBundleInfo(bundleName, crc, size, md5); } }
private static void SaveFilesText(BuildTarget target) { string streamingPath = bundlePath + "StreamingAssets"; AssetBundle asset = AssetBundle.LoadFromFile(streamingPath); AssetBundleManifest bundleManifest = asset.LoadAsset("AssetBundleManifest") as AssetBundleManifest; asset.Unload(false); Hashtable bundleDatas = new Hashtable(); string[] bundleList = bundleManifest.GetAllAssetBundles(); foreach (string bundleName in bundleList) { ArrayList fileInfo = new ArrayList(); string abPath = bundlePath + bundleName; // TODO 查找依赖 // SortList<string> deps = GetBundleDependencies(obj); // byte[] buffer = GetFilesBuffer(deps); byte[] fileBytes = FileUtils.ReadBytes(abPath); long fileSize = fileBytes.Length; string fileMD5 = MD5Utils.GetMD5(fileBytes); fileInfo.Add(fileSize); fileInfo.Add(fileMD5); bundleDatas.Add(bundleName, fileInfo); } // 保存到 files.txt string tmpPath = "Assets/tmp/"; // 一定要写绝对的路径 string filePath = tmpPath + "files.txt"; string jsonStr = MiniJSON.jsonEncode(bundleDatas); byte[] bytes = Encoding.UTF8.GetBytes(jsonStr); FileUtils.WriteBytes(filePath, bytes); AssetDatabase.Refresh(); // 生成 assetbundle AssetBundleBuild[] buildMap = new AssetBundleBuild[1]; string[] assetNames = new string[1]; BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression; //LZ4压缩 assetNames[0] = filePath; buildMap[0].assetNames = assetNames; buildMap[0].assetBundleName = "files"; BuildPipeline.BuildAssetBundles(tmpPath, buildMap, options, target); // copy FileUtils.CopyFile(tmpPath + "files", bundlePath + "files"); FileUtils.CopyFile(filePath, bundlePath + "files.txt"); Directory.Delete(tmpPath, true); AssetDatabase.Refresh(); }
public static FileListCompareAll Compare(string newPath, string oldPath) { if (string.IsNullOrEmpty(newPath) || string.IsNullOrEmpty(oldPath)) { return(null); } if (!File.Exists(newPath) || !File.Exists(oldPath)) { return(null); } FileList newFileList = ReadFileList(newPath); FileList oldFileList = ReadFileList(oldPath); //FileList newFileList = BuildCommon.ReadJsonFromFile<FileList>(newPath); //FileList oldFileList = BuildCommon.ReadJsonFromFile<FileList>(oldPath); if (newFileList == null) { Debug.LogErrorFormat("{0} Load Failed!", newPath); return(null); } if (oldFileList == null) { Debug.LogErrorFormat("{0} Load Failed!", oldPath); return(null); } FileListCompareAll compareall = new FileListCompareAll(); compareall.time = System.DateTime.Now.ToString(); compareall.newFileList = string.Format("{0} : {1}", newPath, MD5Utils.GetMD5(newPath)); compareall.oldFileList = string.Format("{0} : {1}", oldPath, MD5Utils.GetMD5(oldPath)); for (int i = 1; i < (int)BundleUpdateMode.Update_End; i++) { BundleUpdateMode mode = (BundleUpdateMode)i; FileListCompareData comData = FileList.Compare(newFileList, oldFileList, true, mode); if (comData == null) { continue; } FileListCompareInfo info = new FileListCompareInfo(); info.mode = mode.ToString(); info.data = comData; compareall.infoList.Add(info); } return(compareall); }
/// <summary> /// 获取文件MD5 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static string GetFileMD5(string filePath) { try { FileInfo fileTmp = new FileInfo(filePath); if (fileTmp.Exists) { FileStream fs = new FileStream(filePath, FileMode.Open); int len = (int)fs.Length; byte[] data = new byte[len]; fs.Close(); return(MD5Utils.GetMD5(data)); } return(""); } catch (FileNotFoundException e) { Console.WriteLine(e.Message); return(""); } }
private string _getMD5() { FieldInfo[] fieldInfos = GetType().GetFields(); fieldInfos.BubbleSort((f1, f2) => { return(f1.Name.GetHashCode().CompareTo(f2.Name.GetHashCode())); }); StringBuilder sb = new StringBuilder(); for (int i = 0; i < fieldInfos.Length; i++) { FieldInfo field = fieldInfos[i]; Attribute[] attributes = Attribute.GetCustomAttributes(field, typeof(NonSerializedAttribute)); if (attributes.Length != 0) { continue; } object value = field.GetValue(this); sb.Append(_getConfigFieldMD5(value)); } return(MD5Utils.GetMD5(sb.ToString())); }
/// <summary> /// 随机生成Noncestr /// </summary> /// <returns></returns> public static string GetNoncestr() { Random random = new Random(); return(MD5Utils.GetMD5(random.Next(1000).ToString(), "GBK")); }
public override string FileName(TaskEntity taskEntity) { if (!string.IsNullOrEmpty(fileName)) { return(fileName); } if (taskEntity.FileInfo == null || string.IsNullOrEmpty(taskEntity.FileInfo.NormalFilePath)) { throw new ArgumentNullException("生成压缩文件时,一般文件地址为空,无法生成压缩文件"); } if (!File.Exists(taskEntity.FileInfo.NormalFilePath)) { throw new Exception(string.Format("生成压缩文件时,一般文件[{0}]指定路径下不存在,无法生成压缩文件", taskEntity.FileInfo.NormalFilePath)); } string compressPath = FileHelper.GetDirectoryName(taskEntity.FileInfo.NormalFilePath); string compressFileName = FileHelper.GetFileName(taskEntity.FileInfo.NormalFilePath); string compressFileNameWithoutExt = FileHelper.GetFileNameWithoutExtension(taskEntity.FileInfo.NormalFilePath); if (!normalFileValidateReg.IsMatch(compressFileName)) { throw new Exception(string.Format("生成压缩文件时,一般文件名[{0}]格式不符合要求", compressFileName)); } string encryptKey = Common.GetEncryptKey(); if (string.IsNullOrEmpty(encryptKey)) { throw new Exception("生成压缩文件时,配置中未读取密钥串"); } string fileMd5 = MD5Utils.GetMD5HashFromFile(taskEntity.FileInfo.NormalFilePath); string fileAndKeyMd5 = MD5Utils.GetMD5(fileMd5 + encryptKey); //文件校验位 按照规则前三个字符和后三个字符拼接组成6个字符作为校验码 string fileDataCode = fileAndKeyMd5.PreNChar(3) + fileAndKeyMd5.AfterNChar(3); if (string.IsNullOrEmpty(fileDataCode) || fileDataCode.Length != 6) { throw new Exception("生成压缩文件时,计算文件校验位时出现异常"); } compressFileNameWithoutExt += "_" + fileDataCode; string fileNameMd5 = MD5Utils.GetMD5(compressFileNameWithoutExt + "_" + encryptKey); //生成文件校验位 按照规则取后2个字符和前4个字符拼接成6个字符为校验位 string fileNameCode = fileNameMd5.AfterNChar(2) + fileNameMd5.PreNChar(4); if (string.IsNullOrEmpty(fileNameCode) || fileNameCode.Length != 6) { throw new Exception("生成压缩文件时,计算文件名校验位时出现异常"); } fileName = compressFileNameWithoutExt + "_" + fileNameCode + ".jl" + ".zip"; return(fileName); }