// 加载指定版本信息 public static bool LoadVersionInfo(VersionNum version) { VersionInfo versionInfo = null; LocalVersionList.TryGetValue(version.Id3rd, out versionInfo); if (null == versionInfo) { versionInfo = new VersionInfo(version); if (versionInfo.IsValid) { LocalVersionList.Add(version.Id3rd, versionInfo); return(true); } } else if (versionInfo.IsValid) { return(true); } else { LocalVersionList.Remove(version.Id3rd); return(false); } return(false); }
public VersionInfo(VersionNum versionId, bool isNativeVersion = false) { VersionId = versionId; IsNativeVersion = isNativeVersion; if (isNativeVersion) { VersionFolderPath = ABHelper.AppNativeVersionPath; VersionFilePath = string.Format("{0}/{1}", VersionFolderPath, ABHelper.VersionFileName); NativeFilePath = string.Format("{0}/{1}", VersionFolderPath, ABHelper.NativeFileName); IsVersionFileExist = true; IsManifestFileExist = true; } else { bool fromNativePath = true; VersionFolderPath = string.Format("{0}/{1}/{2}", ABHelper.AppVersionPath, VersionId.Id1A2, VersionId.Id3rd.ToString()); VersionFilePath = string.Format("{0}/{1}", VersionFolderPath, ABHelper.VersionFileName); IsVersionFileExist = File.Exists(VersionFilePath); IsManifestFileExist = !string.IsNullOrEmpty(GetABFullPath(ABHelper.ManifestFileName, ref fromNativePath)); if (IsValid) { string versionNumPath = GetABFullPath(ABHelper.VersionNumFileName, ref fromNativePath); if (!string.IsNullOrEmpty(versionNumPath)) { VersionId.Update(ABHelper.ReadVersionNumFileByPath(versionNumPath)); } } } }
// 加载本地所有版本 public static void LoadAllVersionInfo() { LocalVersionList.Clear(); // 首包 OriginalVersionInfo = new VersionInfo(OriginalVersionId, true); LocalVersionList.Add(OriginalVersionId.Id3rd, OriginalVersionInfo); // 获取本地的所有版本 DirectoryInfo dirInfo = new DirectoryInfo(LocalStorgePath); foreach (DirectoryInfo info in dirInfo.GetDirectories()) { int id3rd = 0; if (!int.TryParse(info.Name, out id3rd)) { continue; } if (id3rd <= OriginalVersionId.Id3rd) { continue; } VersionNum versionId = new VersionNum(OriginalVersionId.Id1st, OriginalVersionId.Id2nd, id3rd); if (!LoadVersionInfo(versionId)) { continue; } if (null == CurVersionId || versionId.Id3rd > CurVersionId.Id3rd) { CurVersionId = LocalVersionList[versionId.Id3rd].VersionId; } } }
// 初始化AB public static void InitABVersion() { Debug.Log(ABHelper.AppVersionPath); Debug.Log(ABHelper.AppNativeVersionPath); // 实例化 LocalVersionList = new Dictionary <int, VersionInfo>(); // 需要的文件夹 if (!Directory.Exists(ABHelper.AppVersionPath)) { Directory.CreateDirectory(ABHelper.AppVersionPath); } // 版号信息 Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile(); OriginalVersionId = new VersionNum(versionInfo["ResVersion"]); ABHelper.ABFolderRoot = versionInfo["ABFolderRoot"]; ABHelper.ApkFolderRoot = versionInfo["ApkFolderRoot"]; // 当前版号 CurVersionId = new VersionNum(OriginalVersionId.Id1st, OriginalVersionId.Id2nd, OriginalVersionId.Id3rd, OriginalVersionId.Id4th); // 本地更新地址 LocalStorgePath = string.Format("{0}/{1}", ABHelper.AppVersionPath, OriginalVersionId.Id1A2); if (!Directory.Exists(LocalStorgePath)) { Directory.CreateDirectory(LocalStorgePath); } // 获取本地的所有版本 LoadAllVersionInfo(); // 现在在用的版本号 SetCurVersionNum(CurVersionId); }
/// <summary> /// 是否需要去商店更新 /// </summary> /// <param name="resNum"></param> /// <returns></returns> public bool IsNeedGoStore(string versionNum = null) { if (ABHelper.IgnoreHotfix) { return(false); } VersionNum versionId; if (null == versionNum) { versionId = ABVersion.ServerVersionId; } else { versionId = new VersionNum(versionNum); } // 前两位版本号不等于本地发布的版本号,那么无需更新,直接去store重新下载包吧! if (versionId.Id1A2 != ABVersion.OriginalVersionId.Id1A2) { return(true); } // 所需版本号小于本地最小版号 if (versionId.Id3rd < ABVersion.OriginalVersionId.Id3rd) { return(true); } return(false); }
/// <summary> /// 是否需要热更新 /// </summary> /// <param name="resNum"></param> /// <returns></returns> public bool IsNeedHotter(string versionNum = null) { VersionNum versionId; if (null == versionNum) { versionId = ABVersion.ServerVersionId; } else { versionId = new VersionNum(versionNum); } // 初始版本 if (versionId.Id3rd == ABVersion.OriginalVersionId.Id3rd) { return(false); } // 本地已更新到服务器给到的版本号资源 if (ABVersion.LocalVersionList.ContainsKey(versionId.Id3rd)) { Debug.Log("无需更新!!服务器资源版本为:" + ABVersion.ServerVersionId.Id3rd + " 本地资源版本为:" + ABVersion.CurVersionId.Id3rd); return(false); } return(true); }
// 设置当前版号资源 public static void SetCurVersionNum(VersionNum curVersion) { // 设置为当前使用版号 CurVersionId = curVersion; // 将更新下的版本加载进来 LoadVersionInfo(curVersion); Debug.Log("当前使用版本:" + curVersion.Id); }
// 初始化AB public static void InitABVersion() { // 实例化 LocalVersionList = new Dictionary <int, VersionInfo>(); // 需要的文件夹 if (!Directory.Exists(ABHelper.AppTempCachePath)) { Directory.CreateDirectory(ABHelper.AppTempCachePath); } // 本地发包时的版本号 TextAsset resInfo = Resources.Load <TextAsset>(ABHelper.GetFileNameWithoutSuffix(ABHelper.OriginalVersionName)); if (null == resInfo) { throw new Exception("本地资源版本号不可为空!!!"); } // 初始时的版号 OriginalVersionId = new VersionNum(resInfo.text.Replace("\r", "")); CurVersionId = OriginalVersionId; // 本地更新地址 LocalStorgePath = string.Format("{0}/{1}", ABHelper.AppTempCachePath, OriginalVersionId.Id1A2); if (!Directory.Exists(LocalStorgePath)) { Directory.CreateDirectory(LocalStorgePath); } // 获取本地的所有版本 DirectoryInfo dirInfo = new DirectoryInfo(LocalStorgePath); DirectoryInfo[] dirInfos = dirInfo.GetDirectories(); // 遍历本地所有版号 foreach (DirectoryInfo info in dirInfos) { int id3rd = int.Parse(info.Name); if (id3rd < OriginalVersionId.Id3rd) { continue; } VersionNum versionId = new VersionNum(OriginalVersionId.Id1st, OriginalVersionId.Id2nd, id3rd); if (!LoadVersionInfo(versionId)) { continue; } if (null == CurVersionId || versionId.Id3rd > CurVersionId.Id3rd) { CurVersionId = LocalVersionList[versionId.Id3rd].VersionId; } } // 现在在用的版本号 SetCursVersionNum(CurVersionId); }
public VersionInfo(VersionNum versionId) { VersionId = versionId; VersionFolderPath = string.Format("{0}/{1}/{2}", ABHelper.AppTempCachePath, VersionId.Id1A2, VersionId.Id3rd.ToString()); VersionFilePath = string.Format("{0}/{1}", VersionFolderPath, ABHelper.VersionFileName); IsVersionFileExist = File.Exists(VersionFilePath); VersionNumFilePath = GetABFullPath(ABHelper.VersionNumFileName); IsVersionNumFileExist = null == VersionNumFilePath ? false : File.Exists(VersionNumFilePath); ManifestFilePath = GetABFullPath(ABHelper.ManifestFileName); IsManifestFileExist = null == ManifestFilePath ? false : File.Exists(ManifestFilePath); if (IsValid) { VersionId.Update(ABHelper.ReadVersionNumFile(VersionNumFilePath)); } }
private static void Prepare() { m_process = new System.Diagnostics.Process(); m_process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; m_process.StartInfo.CreateNoWindow = true; m_process.StartInfo.UseShellExecute = false; m_process.StartInfo.RedirectStandardOutput = true; m_process.StartInfo.RedirectStandardError = true; // combine luajit working path DirectoryInfo parentInfo = Directory.GetParent(Application.dataPath); m_luajitWorkingPath = parentInfo.FullName + m_luajitWorkingPath; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN m_luajitExePath = m_luajitWorkingPath + "luajit.exe"; #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX m_luajitExePath = m_luajitWorkingPath + "luajit"; #endif Dictionary <string, string> versionInfo = ABHelper.ReadVersionIdFile(); m_versionNum = new VersionNum(versionInfo["ResVersion"]); m_apkFolderPath = versionInfo["ApkFolderRoot"]; XLua.Hotfix.HotfixInject(); }