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

深圳网站建设加q5299丶14602推广番禺论坛网站建设

深圳网站建设加q5299丶14602推广,番禺论坛网站建设,物联网公司排名国内,做系统之前的网站打包出来的热更文件,如果每次都要全部上传到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/790320/

相关文章:

  • dede模板蓝色大气简洁企业网站模板wordpress安装在windows上
  • 上海虹桥站什么网站允许搭建
  • 搭建一个企业网站快速网站建设推荐
  • 昌宁网站建设企业网站维护报价
  • 重庆网站制作珠海公司惠州企业网站设计
  • 黑链 对网站的影响wordpress建网店
  • 淘宝电商运营培训长沙网站seo源头厂家
  • 网站建设技能考试试题三免费的推广网站
  • 购物网站发展规划与建设进度游戏推广引流软件
  • 网站整体框架甘肃做高端网站的公司
  • 网站建设服务是什么意思网站通常用什么编程做
  • 北京做手机网站外国人爱做视频网站吗
  • 北京网站建设培训机构个人装修接活app
  • 暗红色网站个人备案能做企业网站吗
  • 网站关键词整体方案建设网站技术公司简介
  • 邯郸网站建设的企业昆山网站备案
  • 浏览器怎么打开网站服务器自己做卖东西网站
  • 一家公司为什么要建官方网站电脑中安装wordpress
  • 用什么软件写网站郑州防控升级
  • 哪里有免费建设网站大学生html网页设计个人博客模板
  • 门户网站的区别服装公司网站多少钱
  • 网站开发 自学快闪视频制作软件app
  • 网站建设方法:新产品招区域总代理
  • 在线直播网站开发西安公司排名
  • 辽宁住房和城乡建设部网站雍熙网站建设
  • 外贸网站建设和优化哪些网站用天平做logo
  • 网站建设公司 校园网站网站建站网站的
  • 江门网站建设费用教做发绳的网站
  • 武威做网站的公司公众号服务平台
  • 图床网站怎么做阳江网上问政平台