【打包工具】修复拷贝提示错误

dev_chengFeng
JieLing 2021-05-31 21:54:13 +08:00
parent 10deef53cf
commit 3e12b64118
2 changed files with 17 additions and 11 deletions

View File

@ -248,13 +248,17 @@ public class AutoPack : EditorWindow
string to = toPath + dir; string to = toPath + dir;
if (Directory.Exists(to)) Directory.Delete(to, true); if (Directory.Exists(to)) Directory.Delete(to, true);
Directory.CreateDirectory(to); Directory.CreateDirectory(to);
GameCore.FileUtils.CopyDir(fromPath + dir, to); GameCore.FileUtils.CopyDir(fromPath + dir, to, (string dirName, string fileName, float progress)=>
{
EditorUtility.DisplayProgressBar("正在复制:"+ dirName, fileName, progress);
});
EditorUtility.ClearProgressBar();
} }
Debug.Log(PackConfig[index][0] + ":母包工程资源替换完成"); Debug.Log(PackConfig[index][0] + ":母包工程资源替换完成");
// 替换build-id // 替换build-id
EditorUtility.DisplayProgressBar("重写AndroidManifest", "", 1f); EditorUtility.DisplayProgressBar("重写AndroidManifest", "", 0.5f);
RewriteManifest(fromPath + "/src/main/AndroidManifest.xml", toPath + "/src/main/AndroidManifest.xml"); RewriteManifest(fromPath + "/src/main/AndroidManifest.xml", toPath + "/src/main/AndroidManifest.xml");
Debug.Log(PackConfig[index][0] + "母包Manifest修改完成"); Debug.Log(PackConfig[index][0] + "母包Manifest修改完成");
EditorUtility.ClearProgressBar(); EditorUtility.ClearProgressBar();
@ -306,14 +310,18 @@ public class AutoPack : EditorWindow
string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android"; string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android";
if (Directory.Exists(toPath)) Directory.Delete(toPath, true); if (Directory.Exists(toPath)) Directory.Delete(toPath, true);
Directory.CreateDirectory(toPath); Directory.CreateDirectory(toPath);
GameCore.FileUtils.CopyDir(ABPath, toPath); GameCore.FileUtils.CopyDir(ABPath, toPath, (string dirName, string fileName, float progress) =>
{
EditorUtility.DisplayProgressBar("正在复制:" + dirName, fileName, progress);
});
EditorUtility.ClearProgressBar();
Debug.Log(PackConfig[index][0] + "替换AB包完成"); Debug.Log(PackConfig[index][0] + "替换AB包完成");
} }
// 替换配置文件 // 替换配置文件
private static void ReplaceConfigAndVersion(int index) private static void ReplaceConfigAndVersion(int index)
{ {
EditorUtility.DisplayProgressBar("替换配置文件", "", 1f); EditorUtility.DisplayProgressBar("替换配置文件", "", 0.5f);
string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android/"; string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android/";
string fromPath = _MomPackPath + PackConfig[index][2] + "/Config/"; string fromPath = _MomPackPath + PackConfig[index][2] + "/Config/";
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true); File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
@ -325,7 +333,7 @@ public class AutoPack : EditorWindow
// 开始生成apk // 开始生成apk
private static void StartGradleBuild(int index) private static void StartGradleBuild(int index)
{ {
EditorUtility.DisplayProgressBar("正在生成APK", "", 1f); EditorUtility.DisplayProgressBar("正在生成APK", "", 0.5f);
string apkPath = _MomPackPath + PackConfig[index][2] + "/APK/"; string apkPath = _MomPackPath + PackConfig[index][2] + "/APK/";
if (!Directory.Exists(apkPath)) if (!Directory.Exists(apkPath))
{ {
@ -338,7 +346,7 @@ public class AutoPack : EditorWindow
} }
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "gradlew assembleRelease>" + apkPath + time +"/_log.txt"); GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "gradlew assembleRelease>" + apkPath + time +"/_log.txt");
EditorUtility.DisplayProgressBar("正在导出APK", "", 1f); EditorUtility.DisplayProgressBar("正在导出APK", "", 0.5f);
string apkFilePath = _MomPackPath + PackConfig[index][2] + "/build/outputs/apk/release/" + PackConfig[index][2] + "-release.apk"; string apkFilePath = _MomPackPath + PackConfig[index][2] + "/build/outputs/apk/release/" + PackConfig[index][2] + "-release.apk";
if (File.Exists(apkFilePath)) if (File.Exists(apkFilePath))
{ {

View File

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using UnityEditor;
namespace GameCore { namespace GameCore {
/// <summary> /// <summary>
@ -81,7 +80,7 @@ namespace GameCore {
/// </summary> /// </summary>
/// <param name="fromDir"></param> /// <param name="fromDir"></param>
/// <param name="toDir"></param> /// <param name="toDir"></param>
public static void CopyDir(string fromDir, string toDir) public static void CopyDir(string fromDir, string toDir, Action<string, string, float> callBack = null)
{ {
if (!Directory.Exists(fromDir)) if (!Directory.Exists(fromDir))
return; return;
@ -97,15 +96,14 @@ namespace GameCore {
string fileName = Path.GetFileName(formFileName); string fileName = Path.GetFileName(formFileName);
string toFileName = Path.Combine(toDir, fileName); string toFileName = Path.Combine(toDir, fileName);
File.Copy(formFileName, toFileName); File.Copy(formFileName, toFileName);
EditorUtility.DisplayProgressBar("复制文件夹:"+fromDir, formFileName, (float)(++i / files.Length)); if (callBack != null) callBack(fromDir, fileName, (float)++i/files.Length);
} }
EditorUtility.ClearProgressBar();
string[] fromDirs = Directory.GetDirectories(fromDir); string[] fromDirs = Directory.GetDirectories(fromDir);
foreach (string fromDirName in fromDirs) foreach (string fromDirName in fromDirs)
{ {
string dirName = Path.GetFileName(fromDirName); string dirName = Path.GetFileName(fromDirName);
string toDirName = Path.Combine(toDir, dirName); string toDirName = Path.Combine(toDir, dirName);
CopyDir(fromDirName, toDirName); CopyDir(fromDirName, toDirName, callBack);
} }
} }