/// <summary> /// 处理沙盒被污染 /// 注意:在覆盖安装的时候,会保留沙盒目录里的文件,所以需要强制清空。 /// </summary> private void ProcessSandboxDirty() { string appVersion = PatchManager.Instance.GetAPPVersion(); string filePath = PatchHelper.GetSandboxStaticFilePath(); // 如果是首次打开,记录APP版本信息 if (PatchHelper.CheckSandboxStaticFileExist() == false) { MotionLog.Log($"Create sandbox static file : {filePath}"); FileUtility.CreateFile(filePath, appVersion); return; } // 每次启动时比对APP版本号是否一致 string recordVersion = FileUtility.ReadFile(filePath); // 如果记录的版本号不一致 if (recordVersion != appVersion) { MotionLog.Warning($"Sandbox is dirty, Record version is {recordVersion}, APP version is {appVersion}"); MotionLog.Warning("Clear all sandbox files."); PatchHelper.ClearSandbox(); // 重新写入最新的APP版本信息 MotionLog.Log($"Recreate sandbox static file : {filePath}"); FileUtility.CreateFile(filePath, appVersion); } }
void IFsmNode.OnEnter() { PatchEventDispatcher.SendPatchStatesChangeMsg(EPatchStates.CheckSandboxDirty); string appVersion = PatchManager.Instance.GetAPPVersion(); string filePath = PatchHelper.GetSandboxStaticFilePath(); // 记录APP版本信息到静态文件 if (PatchHelper.CheckSandboxStaticFileExist() == false) { PatchHelper.Log(ELogLevel.Log, $"Create sandbox static file : {filePath}"); FileUtility.CreateFile(filePath, appVersion); _patcher.SwitchNext(); return; } // 每次启动时比对APP版本号是否一致 string recordVersion = FileUtility.ReadFile(filePath); // 如果记录的版本号不一致 if (recordVersion != appVersion) { PatchHelper.Log(ELogLevel.Warning, $"Sandbox is dirty, Record version is {recordVersion}, APP version is {appVersion}"); PatchHelper.Log(ELogLevel.Warning, "Clear all sandbox files."); PatchHelper.ClearSandbox(); _patcher.SwitchLast(); } else { _patcher.SwitchNext(); } }