using System.IO; using System.Threading; using Thousandto.Update.Log; using ZipFileUtils = UnityEngine.Gonbest.MagicCube.ZipFileUtils; namespace Thousandto.Update.Trans { /// /// 启动时,转移安卓资源 /// public class TransAndroidResource : TransResource { private static string[] _firstUnzipList = new string[] { "Assets/GameAssets/Resources/References", "Assets/GameAssets/Resources/Config", "Assets/GameAssets/Resources/SceneConfig", "Assets/GameAssets/Resources/MapInfo", }; public static bool ForTest = false; public override void BeginTransRes() { //先转移指定列表的资源 _success = UpzipApk(_firstUnzipList, true); if(_success) CallInternalCallback(); UpdateLog.DEBUG_LOG(string.Format("转移资源结束 {0}/{1}", nWriteCount, nReadCount)); UpdateLog.DEBUG_LOG("转移资源结束: " + _success); //RunThread(() => //{ // //然后开一个线程转移剩余的资源 // if(UpzipApk(_firstUnzipList, false)) // { // CallInternalCallback(); // } //}); } //优先释放流程 private bool UpzipApk(string[] targetList, bool useContain) { var apkPath = FixApkPath(_resourcePath); return ZipFileUtils.UnzipTargetList(apkPath, IsUnZipObb ? null : targetList, _outPath, useContain, ref nReadCount, ref nWriteCount, IsUnZipObb); } private void Rename(string sourcePath, string targetPath) { if (File.Exists(targetPath)) File.Delete(targetPath); File.Move(sourcePath, targetPath); } private string FixApkPath(string source) { var apkPath = source; apkPath = apkPath.Replace("!/assets", ""); apkPath = apkPath.Replace("jar:file://", ""); return apkPath; } private void RunThread(ThreadStart action) { Thread t = new Thread(action); t.Priority = ThreadPriority.Lowest; t.Start(); } private void OccurDiskFull() { //try { int index = 0; string tempPath = _outPath + "/Temp"; while (File.Exists(tempPath)) { tempPath += (++index); } int buffer = 512 * 1024 * 1024; using (var tempStream = File.Create(tempPath)) { //tempStream.SetLength(buffer); tempStream.Write(new byte[buffer], 0, buffer); tempStream.Flush(); tempStream.Close(); //File.Delete(tempPath); ++nWriteCount; } //return; } //catch (Exception ex) //{ // UpdateLog.ERROR_LOG("Exception:" + ex.Message); // _success = false; // UpdateLog.DEBUG_LOG(string.Format("转移结束 {0}/{1}", nWriteCount, nReadCount)); // return; //} } } }