【热更】脚本优化,添加自动打tag的功能

dev_chengFeng
gaoxin 2021-06-18 16:03:27 +08:00
parent 11934333fc
commit e88dcb7863
1 changed files with 152 additions and 25 deletions

View File

@ -108,6 +108,24 @@ namespace GameEditor.FrameTool
} }
return size / 1048576; return size / 1048576;
} }
public static void WriteLog(string path, string name, string[] contents)
{
UnityEngine.Debug.Log("创建log文件");
UnityEngine.Debug.Log(path);
UnityEngine.Debug.Log(name);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string filePath = Path.Combine(path, name) + ".log";
//if (!File.Exists(filePath))
//{
// File.Create(filePath).Close();
//}
File.WriteAllLines(filePath, contents);
}
} }
class HotFixConfig class HotFixConfig
@ -183,13 +201,11 @@ namespace GameEditor.FrameTool
public string local_files_path = ""; public string local_files_path = "";
public decimal local_cdn_size = 0; // git与cdn比较 热更文件的文件大小 public decimal local_cdn_size = 0; // git与cdn比较 热更文件的文件大小
public decimal project_cdn_size = 0; // 工程与cdn比较 热更文件的文件大小
public List<ResourceFile> local_cdn_list; // git与cdn比较 热更文件列表 public List<ResourceFile> local_cdn_list; // git与cdn比较 热更文件列表
public List<ResourceFile> project_cdn_list; // 工程与cdn比较 热更文件列表
public VersionTxt local_version; public VersionTxt local_version;
public VersionTxt cdn_version; public VersionTxt cdn_version;
public Hashtable cdn_setting;
public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting) public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting)
{ {
@ -215,29 +231,130 @@ namespace GameEditor.FrameTool
// GIT位置 // GIT位置
local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + AppConst.PlatformPath + "/"; local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + AppConst.PlatformPath + "/";
// 读取version文件 LoadSetting();
string json = File.ReadAllText(path_cdn_setting + AppConst.GameVersionFile); LoadLocalVersion();
local_version = JsonUtility.FromJson<VersionTxt>(json); LoadCDN();
// 下载cdn上的files文件
HotFixTool.RegetExternalFile(local_version.resUrl + AppConst.PlatformPath, cdn_files_path, "files.unity3d");
// 读取version文件
HotFixTool.RegetExternalFile(local_version.resUrl + AppConst.PlatformPath, cdn_files_path, AppConst.GameVersionFile);
cdn_version = JsonUtility.FromJson<VersionTxt>(File.ReadAllText(cdn_files_path + AppConst.GameVersionFile));
// 计算差异文件 // 计算差异文件
local_cdn_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(local_files_path), HotFixTool.GetFilesList(cdn_files_path)); local_cdn_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(local_files_path), HotFixTool.GetFilesList(cdn_files_path));
project_cdn_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(project_files_path), HotFixTool.GetFilesList(cdn_files_path));
// 计算大小 // 计算大小
local_cdn_size = HotFixTool.GetDiffSize(local_cdn_list); local_cdn_size = HotFixTool.GetDiffSize(local_cdn_list);
project_cdn_size = HotFixTool.GetDiffSize(project_cdn_list);
// //
isCalSize = true; isCalSize = true;
} }
public void LoadSetting()
{
string setting = File.ReadAllText(path_cdn_setting + "Setting.txt", System.Text.Encoding.UTF8);
cdn_setting = MiniJSON.jsonDecode(setting) as Hashtable;
}
public string GetSettingConfig(string key)
{
if (cdn_setting == null || !cdn_setting.ContainsKey(key))
{
return null;
}
return cdn_setting[key] as string;
}
public void LoadLocalVersion()
{
// 读取version文件
string json = File.ReadAllText(path_cdn_setting + AppConst.GameVersionFile);
local_version = JsonUtility.FromJson<VersionTxt>(json);
}
public void LoadCDN()
{
if(local_version == null)
{
UnityEngine.Debug.LogError("请先加载本地version文件");
return;
}
// 下载cdn上的files文件
HotFixTool.RegetExternalFile(local_version.resUrl + AppConst.PlatformPath, cdn_files_path, "files.unity3d");
// 下载version文件
HotFixTool.RegetExternalFile(local_version.resUrl + AppConst.PlatformPath, cdn_files_path, AppConst.GameVersionFile);
// 读取version
string json = File.ReadAllText(cdn_files_path + AppConst.GameVersionFile);
cdn_version = JsonUtility.FromJson<VersionTxt>(json);
}
public void DOUpload()
{
string logName;
string updateName;
string changeFileName;
string logPath = path_cdn_setting + "/__HotFixLog/";
string tagName;
List<string> log = new List<string>();
//if (local_cdn_list.Count <= 0)
//{
// UnityEngine.Debug.Log("未检测到文件改动");
// return;
//}
// 初始化数据
updateName = dir_name + "_" + dir_cdn_setting + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
changeFileName = updateName.Replace("/", "$");
logName = changeFileName + "_UpLoad";
tagName = "hotfix/" + dir_name + "/" + dir_cdn_setting + "/" + local_version.version;
EditorUtility.DisplayProgressBar("正在获取数据:", updateName, 0f);
log.Add("热更文件版本:" + updateName);
log.Add("热更版本号:" + local_version.version);
log.Add("热更大小:" + local_cdn_size);
// copy unity3d
log.Add("热更文件:");
List<string> changeFile = new List<string>();
foreach (ResourceFile rf in local_cdn_list)
{
changeFile.Add(rf.fileName);
log.Add(rf.fileName);
}
changeFile.Add(UpdateConfigs.FILES);
log.Add(UpdateConfigs.FILES);
// write ChangeList
EditorUtility.DisplayProgressBar("正在生成文件变化列表", changeFileName, 1f);
HotFixTool.WriteLog(logPath, changeFileName, changeFile.ToArray());
// upload to cdn
EditorUtility.DisplayProgressBar("正在上传热更文件", changeFileName, 1f);
string cdnType = GetSettingConfig("cdn_type");
if (cdnType == null)
{
UnityEngine.Debug.LogError("CDN配置错误");
EditorUtility.ClearProgressBar();
return;
}
log.Add("CDN TYPE: " + cdnType);
string toolsDir = HotfixWindow._HotFixProjectPath + "/Tools/" + cdnType;
log.Add("TOOLS DIR: " + toolsDir);
string command = string.Format("python UpLoad.py {0} {1} {2}>>{3}", HotfixWindow._HotFixProjectPath + "/Root/" + dir_name, dir_cdn_setting, changeFileName, logPath + logName + ".log");
log.Add("UPLOAD COMMAND: " + command);
ProcessUtil.ProcessCommand(toolsDir, command);
string flushCommand = string.Format("python Flush.py {0}>>{1}", cdn_version.resUrl, logPath + logName + ".log");
log.Add("Flush COMMAND: " + flushCommand);
ProcessUtil.ProcessCommand(toolsDir, flushCommand);
// write log
EditorUtility.DisplayProgressBar("正在生成Log文件", logName, 1f);
HotFixTool.WriteLog(logPath, logName, log.ToArray());
// git commit
string commitName = desc + "更新:" + updateName;
EditorUtility.DisplayProgressBar("正在提交到GIT", commitName, 1f);
ProcessUtil.ProcessCommand(path_cdn_setting, "git add .");
ProcessUtil.ProcessCommand(path_cdn_setting, "git commit -m " + commitName);
ProcessUtil.ProcessCommand(path_cdn_setting, "git push");
// git tag
string dir = Application.dataPath.Replace("/Assets", "");
ProcessUtil.ProcessCommand(dir, string.Format("git tag -a {0} -m {1}", tagName, commitName));
ProcessUtil.ProcessCommand(dir, "git push origin --tags");
UnityEngine.Debug.Log("更新完成,游戏工程标签为:" + tagName + ",热更工程提交:" + commitName);
EditorUtility.ClearProgressBar();
}
} }
//看热更大小 //看热更大小
@ -374,7 +491,9 @@ namespace GameEditor.FrameTool
} }
if (GUILayout.Button("更新到GIT", GUILayout.Height(20f))) if (GUILayout.Button("更新到GIT", GUILayout.Height(20f)))
{ {
HotfixConfimWindow.Create("是否要将工程热更文件同步到GIT " + _CurConfig.desc, _CurConfig.project_local_list, () => string title = "是否要将工程热更文件同步到GIT " + _CurConfig.desc;
string content = string.Format("更新大小:{0}", HotFixTool.GetDiffSize(_CurConfig.project_local_list).ToString("0.00") + "M");
HotfixConfimWindow.Create(title, content, _CurConfig.project_local_list, () =>
{ {
UpdateUnity3dToGit(_CurConfig); UpdateUnity3dToGit(_CurConfig);
}); });
@ -398,7 +517,6 @@ namespace GameEditor.FrameTool
EditorGUILayout.LabelField("CDN当前版本号" + (hfs.cdn_version == null ? "" : hfs.cdn_version.version)); EditorGUILayout.LabelField("CDN当前版本号" + (hfs.cdn_version == null ? "" : hfs.cdn_version.version));
EditorGUILayout.LabelField("GIT到CDN" + hfs.local_cdn_size.ToString("0.00") + "M"); EditorGUILayout.LabelField("GIT到CDN" + hfs.local_cdn_size.ToString("0.00") + "M");
//EditorGUILayout.LabelField("工程到CDN" + hfs.project_cdn_size.ToString("0.00") + "M");
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
if (GUILayout.Button("编辑Setting", GUILayout.Height(30f), GUILayout.Width(100f))) if (GUILayout.Button("编辑Setting", GUILayout.Height(30f), GUILayout.Width(100f)))
@ -422,9 +540,13 @@ namespace GameEditor.FrameTool
} }
if (GUILayout.Button("更新", GUILayout.Height(30f), GUILayout.Width(100f))) if (GUILayout.Button("更新", GUILayout.Height(30f), GUILayout.Width(100f)))
{ {
HotfixConfimWindow.Create("是否要热更: " + hfs.desc, hfs.local_cdn_list, () => //重新加载本地version
hfs.LoadLocalVersion();
string title = "是否要热更: " + hfs.desc;
string content = string.Format("更新大小:{0}CDN当前版本{1},更新后版本{2}", HotFixTool.GetDiffSize(hfs.local_cdn_list).ToString("0.00") + "M", hfs.cdn_version.version, hfs.local_version.version);
HotfixConfimWindow.Create(title, content, hfs.local_cdn_list, () =>
{ {
UpdateUnity3dToCDN(hfs); hfs.DOUpload();
}); });
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
@ -596,20 +718,22 @@ namespace GameEditor.FrameTool
//看热更大小 //看热更大小
public class HotfixConfimWindow : EditorWindow public class HotfixConfimWindow : EditorWindow
{ {
string title;
string content; string content;
List<ResourceFile> diffList; List<ResourceFile> diffList;
Action a; Action a;
Vector2 _scp = Vector2.zero; Vector2 _scp = Vector2.zero;
public static void Create(string content, List<ResourceFile> diffList, Action a) public static void Create(string title, string content, List<ResourceFile> diffList, Action a)
{ {
HotfixConfimWindow window = (HotfixConfimWindow)EditorWindow.GetWindow(typeof(HotfixConfimWindow), true, "提示", true); HotfixConfimWindow window = (HotfixConfimWindow)EditorWindow.GetWindow(typeof(HotfixConfimWindow), true, "提示", true);
window.SetContent(content, diffList, a); window.SetContent(title, content, diffList, a);
window.ShowAuxWindow(); window.ShowAuxWindow();
} }
public void SetContent(string _content, List<ResourceFile> _diffList, Action _a) public void SetContent(string _title, string _content, List<ResourceFile> _diffList, Action _a)
{ {
title = _title;
content = _content; content = _content;
diffList = _diffList; diffList = _diffList;
a = _a; a = _a;
@ -618,14 +742,17 @@ namespace GameEditor.FrameTool
private void OnGUI() private void OnGUI()
{ {
EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField(content); EditorGUILayout.LabelField(title);
_scp = EditorGUILayout.BeginScrollView(_scp); _scp = EditorGUILayout.BeginScrollView(_scp);
foreach(ResourceFile rf in diffList) foreach(ResourceFile rf in diffList)
{ {
EditorGUILayout.LabelField(rf.fileName); EditorGUILayout.LabelField(rf.fileName);
} }
EditorGUILayout.LabelField("files.unity3d");
EditorGUILayout.LabelField(AppConst.GameConfigFile);
EditorGUILayout.LabelField(AppConst.GameVersionFile);
EditorGUILayout.EndScrollView(); EditorGUILayout.EndScrollView();
EditorGUILayout.LabelField("更新大小:" + HotFixTool.GetDiffSize(diffList).ToString("0.00") + "M"); EditorGUILayout.LabelField(content);//"更新大小:" + HotFixTool.GetDiffSize(diffList).ToString("0.00") + "M");
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("取消")){ if (GUILayout.Button("取消")){
Close(); Close();