当前位置: 首页 > news >正文

天津河北做网站的公司额尔古纳网站建设价格

天津河北做网站的公司,额尔古纳网站建设价格,政务网站建设信息,wordpress+php版本太低打包出来的热更文件,如果每次都要全部上传到CDN文件服务器,不进耗费时间长,还浪费流量。 所以让AI写了个简单的文件比较工具类,然后修改了一下可用。记录一下。 路径可自行更改。校验算法这里使用的是MD5,如果使用SH…

打包出来的热更文件,如果每次都要全部上传到CDN文件服务器,不进耗费时间长,还浪费流量。

所以让AI写了个简单的文件比较工具类,然后修改了一下可用。记录一下。

路径可自行更改。校验算法这里使用的是MD5,如果使用SHA256校验,时间会长达1分钟,MD5只有5秒左右。一般用MD5即可。同步拷贝的写法时间太长,改为异步拷贝的写法,时间减半,只需30秒和3秒。(项目的热更文件67个,总大小在700M左右)

代码如下,放到Assets/Editor/路径下即可。
 

using System;
using System.IO;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEditor;/// <summary>
/// 比较热更文件的差异 拷贝到另一个文件夹
/// </summary>
public class HotfixComparerAsync
{
#if UNITY_ANDROIDstatic string SourceFolder = Application.dataPath + "/../ServerData/Android"; // 源文件夹路径static string TargetFolder = Application.dataPath + "/../ServerData/Android_server"; // 目标文件夹路径static string OutputFolder = Application.dataPath + "/../ServerData/Android_hotfix"; // 输出文件夹路径,存放复制的文件
#endif
#if UNITY_IOSstatic string SourceFolder = Application.dataPath + "/../ServerData/iOS"; // 源文件夹路径static string TargetFolder = Application.dataPath + "/../ServerData/iOS_server"; // 目标文件夹路径static string OutputFolder = Application.dataPath + "/../ServerData/iOS_hotfix"; // 输出文件夹路径,存放复制的文件
#endif
#if UNITY_STANDALONE_WINstatic string SourceFolder = Application.dataPath + "/../ServerData/StandaloneWindows64"; // 源文件夹路径static string TargetFolder = Application.dataPath + "/../ServerData/StandaloneWindows64_server"; // 目标文件夹路径static string OutputFolder = Application.dataPath + "/../ServerData/StandaloneWindows64_hotfix"; // 输出文件夹路径,存放复制的文件
#endif[MenuItem("Tools/比较并拷贝热更文件Async")]public static void CompareAndCopyFiles(){DateTime startTime = DateTime.Now;if (!Directory.Exists(OutputFolder)){Directory.CreateDirectory(OutputFolder);}var sourceFiles = new HashSet<string>(Directory.GetFiles(SourceFolder, "*.*", SearchOption.AllDirectories));var targetFilesHashes = new Dictionary<string, string>();foreach (var file in Directory.GetFiles(TargetFolder, "*.*", SearchOption.AllDirectories)){string relativePath = MakeRelativePath(file, TargetFolder);targetFilesHashes[relativePath] = FileHash(file);}var tasks = new List<Task>();foreach (var sourceFile in sourceFiles){string relativePath = MakeRelativePath(sourceFile, SourceFolder);tasks.Add(Task.Run(() => ProcessFile(sourceFile, relativePath, targetFilesHashes)));}Task.WhenAll(tasks.ToArray()).Wait();TimeSpan diff = DateTime.Now - startTime;Debug.Log($"比较完成耗费:{diff.Minutes}分{diff.Seconds}秒");}private static void ProcessFile(string sourceFile, string relativePath, Dictionary<string, string> targetFilesHashes){if (targetFilesHashes.ContainsKey(relativePath)){string hash = FileHash(sourceFile);if (targetFilesHashes[relativePath] != hash){CopyFile(sourceFile, Path.Combine(OutputFolder, relativePath));}}else{CopyFile(sourceFile, Path.Combine(OutputFolder, relativePath));}}private static string MakeRelativePath(string path, string rootDirectory){return path.Substring(rootDirectory.Length + 1);}private static string FileHash(string file){using (var stream = File.OpenRead(file)){using (var hash = MD5.Create()){byte[] hashBytes = hash.ComputeHash(stream);return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();}}}private static void CopyFile(string sourceFile, string targetFile){//File.Copy(sourceFile, targetFile, true);// 获取目标文件的目录路径string targetDirectory = Path.GetDirectoryName(targetFile);// 如果目标目录不存在,则创建它if (!Directory.Exists(targetDirectory)){Directory.CreateDirectory(targetDirectory);}try{// 尝试复制文件File.Copy(sourceFile, targetFile, true);}catch (Exception e){// 处理可能的异常Debug.LogError($"Failed to copy file from {sourceFile} to {targetFile}. Error: {e.Message}");}}
}

http://www.yayakq.cn/news/326581/

相关文章:

  • 石家庄网站建设就找企行家泰安人才市场官网
  • 中小型企业网站优化价格o2o系统软件
  • 机场建设相关网站网站开发后端怎么开发
  • 制作网站需要注意的细节必应搜索引擎入口官网
  • 昆山网站建设怎么样黄骅市天气预报最新
  • 泰州住房城乡建设网站哪家网络公司做网站
  • vs2015做网站的后端兰州市政建设集团网站
  • WordPress文章 溢出网络优化的基本流程
  • 怎么做网站后端小程序制作材料
  • 企业门户网站需求分析wordpress 数据库连接错误
  • 赣榆网站建设wordpress 重装界面
  • 花钱让别人做的网站版权是谁的百度上怎么免费开店
  • php外贸网站建设科技类网站设计
  • 上海网站排名优化公司网站下载端口建设
  • logo灵感网站创建网站哪个好
  • 企业网站策划方案模板大型做网站公司
  • 网站维护的工作内容步骤什么网站可以做海报赚钱
  • 网站内容创造wordpress英文站群
  • 河南移动官网网站建设如何建网站保定
  • 做易经网站东莞常平电镀工业园
  • 建设一个网站的工作方案网络托管运营
  • 湖南至诚建设机械有限公司网站苏州园区建设网站首页
  • html5网站图标广西seo公司有哪些
  • 影视网站建设源码wordpress自定义文章类型分类获取
  • 网站备案相机为网站网站做宣传
  • 衡阳网站建设公司地址广州建设网站制作
  • 网站做管理后台需要知道什么建设教育网站的国内外研究现状
  • 杭州网站推广排名怎样做一个简单的网站
  • 北京 工业网站建设公司排名名师工作室建设名师网站
  • 国外开源网站系统深圳市外贸网站建设多少钱