【热更工具】添加查看热更文件的界面

dev_chengFeng
gaoxin 2021-06-07 10:39:27 +08:00
parent b95a511dc2
commit 24ebb4cf9e
1 changed files with 212 additions and 78 deletions

View File

@ -12,16 +12,18 @@ using System.Diagnostics;
using ResUpdate; using ResUpdate;
using System.Threading; using System.Threading;
using System.Net; using System.Net;
using System;
namespace GameEditor.FrameTool { namespace GameEditor.FrameTool
{
public static class HotFixTool public static class HotFixTool
{ {
//重新下载外部.unity3d文件 //重新下载外部.unity3d文件
public static void RegetExternalFile(string resUrl, string outPath) public static void RegetExternalFile(string resUrl, string outPath, string fileName)
{ {
//获取下载文件链接 //获取下载文件链接
string url = resUrl + "/files.unity3d"; string url = resUrl + "/" + fileName;
string dlPath = outPath + "/files.unity3d"; string dlPath = outPath + "/" + fileName;
// 文件夹没有就创建 // 文件夹没有就创建
if (!Directory.Exists(outPath)) if (!Directory.Exists(outPath))
{ {
@ -99,7 +101,7 @@ namespace GameEditor.FrameTool {
public static decimal GetDiffSize(List<ResourceFile> diffList) public static decimal GetDiffSize(List<ResourceFile> diffList)
{ {
decimal size = 0; decimal size = 0;
foreach(ResourceFile rf in diffList) foreach (ResourceFile rf in diffList)
{ {
size += rf.size; size += rf.size;
} }
@ -116,6 +118,9 @@ namespace GameEditor.FrameTool {
public List<HotFixSetting> hotFixSettings; public List<HotFixSetting> hotFixSettings;
public string project_files_path;
public string local_files_path;
public decimal project_local_size = 0; public decimal project_local_size = 0;
public List<ResourceFile> project_local_list; public List<ResourceFile> project_local_list;
@ -144,12 +149,12 @@ namespace GameEditor.FrameTool {
UnityEngine.Debug.LogError("热更工程路径为空!"); UnityEngine.Debug.LogError("热更工程路径为空!");
return; return;
} }
// 工程中的位置 // 工程中的位置
string project_files_path = Application.dataPath + "/../BuildABs/" + HotfixWindow.Platform + "/"; project_files_path = Application.dataPath + "/../BuildABs/" + AppConst.PlatformPath + "/";
// GIT位置 // GIT位置
string local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + HotfixWindow.Platform + "/"; local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + AppConst.PlatformPath + "/";
// 计算差异文件 // 计算差异文件
project_local_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(project_files_path), HotFixTool.GetFilesList(local_files_path)); project_local_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(project_files_path), HotFixTool.GetFilesList(local_files_path));
@ -171,7 +176,7 @@ namespace GameEditor.FrameTool {
public bool isCalSize = false; // 判断是否计算过大小了 public bool isCalSize = false; // 判断是否计算过大小了
public bool isChoose = false; // 是否被选中 public bool isChoose = false; // 是否被选中
public decimal local_cdn_size = 0; // git与cdn比较 热更文件的文件大小 public decimal local_cdn_size = 0; // git与cdn比较 热更文件的文件大小
public decimal project_cdn_size = 0; // 工程与cdn比较 热更文件的文件大小 public decimal project_cdn_size = 0; // 工程与cdn比较 热更文件的文件大小
@ -179,6 +184,7 @@ namespace GameEditor.FrameTool {
public List<ResourceFile> project_cdn_list; // 工程与cdn比较 热更文件列表 public List<ResourceFile> project_cdn_list; // 工程与cdn比较 热更文件列表
public VersionTxt local_version; public VersionTxt local_version;
public VersionTxt cdn_version;
public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting) public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting)
{ {
@ -191,7 +197,8 @@ namespace GameEditor.FrameTool {
public void CalHotFixSize() public void CalHotFixSize()
{ {
if(HotfixWindow._HotFixProjectPath.Equals("")){ if (HotfixWindow._HotFixProjectPath.Equals(""))
{
UnityEngine.Debug.LogError("热更工程路径为空!"); UnityEngine.Debug.LogError("热更工程路径为空!");
return; return;
} }
@ -199,16 +206,21 @@ namespace GameEditor.FrameTool {
// cdn上files文件保存的位置 // cdn上files文件保存的位置
string cdn_files_path = path_cdn_setting + "__Download/"; string cdn_files_path = path_cdn_setting + "__Download/";
// 工程中的位置 // 工程中的位置
string project_files_path = Application.dataPath + "/../BuildABs/" + HotfixWindow.Platform + "/"; string project_files_path = Application.dataPath + "/../BuildABs/" + AppConst.PlatformPath + "/";
// GIT位置 // GIT位置
string local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + HotfixWindow.Platform + "/"; string local_files_path = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + AppConst.PlatformPath + "/";
// 读取version文件 // 读取version文件
string json = File.ReadAllText(path_cdn_setting + AppConst.GameVersionFile); string json = File.ReadAllText(path_cdn_setting + AppConst.GameVersionFile);
local_version = JsonUtility.FromJson<VersionTxt>(json); local_version = JsonUtility.FromJson<VersionTxt>(json);
// 下载cdn上的files文件 // 下载cdn上的files文件
HotFixTool.RegetExternalFile(local_version.resUrl + HotfixWindow.Platform, cdn_files_path); 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));
@ -235,15 +247,10 @@ namespace GameEditor.FrameTool {
static Dictionary<string, HotFixConfig> _HotFixConfigDic = new Dictionary<string, HotFixConfig>(); static Dictionary<string, HotFixConfig> _HotFixConfigDic = new Dictionary<string, HotFixConfig>();
static string benchName = ""; static string benchName = "";
public static string _HotFixProjectPath; public static string _HotFixProjectPath;
static string _Password = "tcx123";
static bool _IsUpdateCDN = false;
static bool _IsGitPull = false;
#if UNITY_ANDROID
public static string Platform = "Android";
#elif UNITY_IOS
public static string Platform = "IOS";
#else
public static string Platform = "Android";
#endif
[MenuItem("Build/Hotfix")] [MenuItem("Build/Hotfix")]
static void Init() static void Init()
{ {
@ -251,17 +258,21 @@ namespace GameEditor.FrameTool {
benchName = GitUtil.GetCurBenchName(); benchName = GitUtil.GetCurBenchName();
UnityEngine.Debug.Log("当前分支:" + benchName); UnityEngine.Debug.Log("当前分支:" + benchName);
_HotFixProjectPath = EditorPrefs.GetString("_HotFixProjectPath", ""); _HotFixProjectPath = EditorPrefs.GetString("_HotFixProjectPath", "");
if (!_IsGitPull && _HotFixProjectPath != "")
{
ABGitPull();
}
InitData(); InitData();
InitStyle(); InitStyle();
// Get existing open window or if none, make a new one: // Get existing open window or if none, make a new one:
HotfixWindow window = (HotfixWindow)EditorWindow.GetWindow(typeof(HotfixWindow)); HotfixWindow window = (HotfixWindow)EditorWindow.GetWindow(typeof(HotfixWindow));
window.titleContent = new GUIContent("热更大小"); window.titleContent = new GUIContent("热更");
window.Show(); window.Show();
} }
static void InitData() static void InitData()
{ {
_IsGitPull = false;
_HotFixConfigDic.Clear(); _HotFixConfigDic.Clear();
foreach (string[] sc in _SettingConfig) foreach (string[] sc in _SettingConfig)
{ {
@ -284,22 +295,34 @@ namespace GameEditor.FrameTool {
} }
// 自定义style // 自定义style
static GUIStyle FStyle = new GUIStyle(); static GUIStyle F_B_30 = new GUIStyle();
static GUIStyle SStyle = new GUIStyle(); static GUIStyle F_25 = new GUIStyle();
static GUIStyle L_PL_50 = new GUIStyle();
static void InitStyle() static void InitStyle()
{ {
FStyle.fontSize = 30; F_B_30.fontSize = 30;
FStyle.fontStyle = FontStyle.Bold; F_B_30.fontStyle = FontStyle.Bold;
SStyle.fontSize = 25; F_25.fontSize = 25;
L_PL_50.padding.left = 50;
} }
void OnGUI() void OnGUI()
{ {
if (AppConst.PlatformPath != "Android" && AppConst.PlatformPath != "IOS")
{
EditorGUILayout.LabelField("<color=red>请先切换到Android或者IOS平台</color>", F_B_30);
return;
}
_Password = EditorGUILayout.PasswordField("请输入密码:", _Password);
if (_Password != "tcx123")
{
return;
}
EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical();
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("当前工程GIT分支"+ benchName); EditorGUILayout.LabelField("当前工程GIT分支" + benchName);
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
_HotFixProjectPath = EditorGUILayout.TextField("热更GIT工程地址", _HotFixProjectPath); _HotFixProjectPath = EditorGUILayout.TextField("热更GIT工程地址", _HotFixProjectPath);
@ -309,71 +332,182 @@ namespace GameEditor.FrameTool {
EditorPrefs.SetString("_HotFixProjectPath", _HotFixProjectPath); EditorPrefs.SetString("_HotFixProjectPath", _HotFixProjectPath);
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.Space();
_IsUpdateCDN = EditorGUILayout.ToggleLeft("是否显示CDN更新选项", _IsUpdateCDN);
EditorGUILayout.LabelField("请选择要更新的CDN"); EditorGUILayout.Space();
foreach(string k in _HotFixConfigDic.Keys)// i = 0; i < _CurConfig.Length; i++) EditorGUILayout.Space();
EditorGUILayout.LabelField("请选择要更新的GIT路径");
foreach (string k in _HotFixConfigDic.Keys)// i = 0; i < _CurConfig.Length; i++)
{ {
HotFixConfig _CurConfig = _HotFixConfigDic[k]; HotFixConfig _CurConfig = _HotFixConfigDic[k];
_CurConfig.isChoose = EditorGUILayout.ToggleLeft("<color=yellow>"+_CurConfig.desc+"</color>", _CurConfig.isChoose, FStyle, GUILayout.Height(40)); _CurConfig.isChoose = EditorGUILayout.ToggleLeft("<color=yellow>" + _CurConfig.desc + "</color>", _CurConfig.isChoose, F_B_30, GUILayout.Height(40));
if (_CurConfig.isChoose) if (_CurConfig.isChoose)
{ {
EditorGUILayout.LabelField("工程到Git"+_CurConfig.project_local_size.ToString("0.00") + "M"); EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("工程到Git" + _CurConfig.project_local_size.ToString("0.00") + "M");
if (!_CurConfig.isCalSize) if (!_CurConfig.isCalSize)
{ {
_CurConfig.CalHotFixSize(); _CurConfig.CalHotFixSize();
} }
//EditorGUILayout.LabelField("本地到CDN目录"+_CurConfig[i].local_cdn_size.ToString("0.00") + "M"); if (GUILayout.Button("更新到GIT", GUILayout.Height(20f)))
//EditorGUILayout.LabelField("工程到CDN目录"+_CurConfig[i].project_cdn_size.ToString("0.00") + "M");
//EditorGUILayout.BeginHorizontal();
//if (GUILayout.Button("编辑Config", GUILayout.Height(20f)))
//{
//}
//if (GUILayout.Button("编辑Version", GUILayout.Height(20f)))
//{
//}
//// 自动计算一遍大小
//if (!_CurConfig.isCalSize)
//{
// _CurConfig.CalHotFixSize();
//}
//EditorGUILayout.EndHorizontal();
foreach (HotFixSetting hfs in _CurConfig.hotFixSettings)// i = 0; i < _CurConfig.Length; i++)
{ {
hfs.isChoose = EditorGUILayout.ToggleLeft("<color=green>" + hfs.desc + "</color>", hfs.isChoose, SStyle, GUILayout.Height(30)); HotfixConfimWindow.Create("是否要将工程热更文件同步到GIT " + _CurConfig.desc, _CurConfig.project_local_list, () =>
if (hfs.isChoose)
{ {
EditorGUILayout.BeginHorizontal(); UpdateUnity3dToGit(_CurConfig);
EditorGUILayout.BeginVertical(); });
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();
if (GUILayout.Button("编辑Config", GUILayout.Height(40f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameConfigFile;
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Version", GUILayout.Height(40f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameVersionFile;
ProcessUtil.OpenText(tpath);
}
// 自动计算一遍大小
if (!hfs.isCalSize)
{
hfs.CalHotFixSize();
}
EditorGUILayout.EndHorizontal();
}
} }
EditorGUILayout.EndHorizontal();
if (_IsUpdateCDN)
{
foreach (HotFixSetting hfs in _CurConfig.hotFixSettings)// i = 0; i < _CurConfig.Length; i++)
{
EditorGUILayout.BeginVertical(L_PL_50);
hfs.isChoose = EditorGUILayout.ToggleLeft("<color=green>" + hfs.desc + "</color>", hfs.isChoose, F_25, GUILayout.Height(30));
if (hfs.isChoose)
{
// 自动计算一遍大小
if (!hfs.isCalSize)
{
hfs.CalHotFixSize();
}
EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical();
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("工程到CDN" + hfs.project_cdn_size.ToString("0.00") + "M");
EditorGUILayout.EndVertical();
if (GUILayout.Button("编辑Setting", GUILayout.Height(30f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + "setting.txt";
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Config", GUILayout.Height(30f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameConfigFile;
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Version", GUILayout.Height(30f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameVersionFile;
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("刷新", GUILayout.Height(30f), GUILayout.Width(100f)))
{
hfs.CalHotFixSize();
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
} }
} }
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
} }
// 拉取git工程
private static void ABGitPull()
{
if(!_IsGitPull)
{
ProcessUtil.ProcessCommand(_HotFixProjectPath, "git pull", true);
_IsGitPull = true;
}
}
//同步工程中的热更文件到git
private static void UpdateUnity3dToGit(HotFixConfig hfc)
{
string updateName;
List<ResourceFile> updateList;
List<string> log = new List<string>();
// 初始化数据
updateName = benchName + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
log.Add("热更文件的版本:" + updateName);
updateList = hfc.project_local_list;
if (updateList.Count <= 0)
{
UnityEngine.Debug.Log("未检测到文件改动");
return;
}
// copy unity3d
log.Add("热更文件:");
string fromPath = hfc.project_files_path;
string toPath = hfc.local_files_path;
foreach (ResourceFile rf in updateList)
{
File.Copy(fromPath + rf.fileName, toPath + rf.fileName, true);
log.Add(rf.fileName);
}
// write log
string[] logArray = log.ToArray();
// git commit
}
} }
} //看热更大小
public class HotfixConfimWindow : EditorWindow
{
string content;
List<ResourceFile> diffList;
Action a;
Vector2 _scp = Vector2.zero;
public static void Create(string content, List<ResourceFile> diffList, Action a)
{
HotfixConfimWindow window = (HotfixConfimWindow)EditorWindow.GetWindow(typeof(HotfixConfimWindow), true, "提示", true);
window.SetContent(content, diffList, a);
window.ShowAuxWindow();
}
public void SetContent(string _content, List<ResourceFile> _diffList, Action _a)
{
content = _content;
diffList = _diffList;
a = _a;
}
private void OnGUI()
{
EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField(content);
_scp = EditorGUILayout.BeginScrollView(_scp);
foreach(ResourceFile rf in diffList)
{
EditorGUILayout.LabelField(rf.fileName);
}
EditorGUILayout.EndScrollView();
EditorGUILayout.LabelField("更新大小:" + HotFixTool.GetDiffSize(diffList).ToString("0.00") + "M");
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("取消")){
Close();
}
if (GUILayout.Button("确定"))
{
if (a!= null) a();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
}
}