/// <summary>
 /// 获取版本更新资源列表内的单个资源地址列表
 /// </summary>
 /// <returns></returns>
 public List <string> GetVersionUpdateResourcePathList()
 {
     if (versionResourcePathList == null)
     {
         versionResourcePathList = new Dictionary <string, int>();
         try
         {
             List <string> versionUpdateList = new List <string>();
             if (resDiffToLatestVersionList != null)
             {
                 for (int i = 0; i < resDiffToLatestVersionList.Count; i++)
                 {
                     VersionUpdate versionupdate = resDiffToLatestVersionList[i];
                     for (int j = 0; j < versionList.Count; j++)
                     {
                         string versionUpdateFilePath = versionList[j].resUrl + versionupdate.versionUpdateFileName;
                         if (!versionUpdateList.Contains(versionUpdateFilePath))
                         {
                             versionUpdateList.Add(versionUpdateFilePath);
                             string temp = Global.Instance.DownloadFile(new URLWithISLocal(versionUpdateFilePath, false));
                             if (string.IsNullOrEmpty(temp))
                             {
                                 continue;
                             }
                             string[] lines = File.ReadAllLines(temp);
                             for (int k = 0; k < lines.Length; k++)
                             {
                                 if (!string.IsNullOrEmpty(lines[k]))
                                 {
                                     string path = Global.Instance.GetResourceFullPath(lines[k], versionList[j].commonResUrl, versionList[j].resUrl);
                                     if (!versionResourcePathList.ContainsKey(path))
                                     {
                                         versionResourcePathList.Add(path, 1);
                                     }
                                     else
                                     {
                                         versionResourcePathList[path]++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         catch (Exception) { versionResourcePathList?.Clear(); versionResourcePathList = null; return(null); }
     }
     return(versionResourcePathList.Keys.ToList());
 }
예제 #2
0
        //任务主体
        protected override void Thread_Starting()
        {
            base.Thread_Starting();

            #region 获取配置文件
            AppendMissionLog("获取配置文件中...");
            //下载,解析配置文件
            configDic = new Dictionary <string, ConfigFile>();
            for (int i = 0; i < configPathArray.Length; i++)
            {
                string localPath         = Global.Instance.DownloadFile(new URLWithISLocal(configPathArray[i], Regex.IsMatch(configPathArray[i], Global.Instance.PATTERN_IsLocalURL))); //将配置文件下载在本地
                string unEncryptedConfig = File.ReadAllText(localPath);
                unEncryptedConfig = EncryptTool.Instance.DeEncryptData(unEncryptedConfig);                                                                                              //解密后的数据
                ConfigFile configFile = new ConfigFile(JsonMapper.ToObject(unEncryptedConfig));
                configDic.Add(configPathArray[i], configFile);
            }
            #endregion

            #region 检查配置文件
            AppendMissionLog("开始检查配置文件...");
            //获取所有的更新列表,待检查dll文件,待检查SpecialRes.zip文件
            pathToCheckCollection = new Dictionary <string, int>();
            StringBuilder pathConnectSB = new StringBuilder();
            foreach (KeyValuePair <string, ConfigFile> pair in configDic)
            {
                ConfigFile    config     = pair.Value;
                string        configFile = pair.Key;
                List <string> resList    = new List <string>();
                if (config.versionList != null)//检查各个版本
                {
                    bool          hasDefaultVersion = false;
                    List <string> illegalVersion    = new List <string>();
                    List <string> legalVersion      = new List <string>();
                    for (int i = 0; i < config.versionList.Count; i++)
                    {
                        Version version = config.versionList[i];
                        if (version.version == "default")
                        {
                            hasDefaultVersion = true;
                        }
                        if (version.version != null && Global.Instance.CheckVersionCodeIsLegal(version.version))//版本号合法的情况下
                        {
                            string resURL = version.resUrl + '#' + version.commonResUrl;
                            if (!resList.Contains(resURL))
                            {
                                resList.Add(resURL);
                            }
                            if (version.resUpdateList != null)//检查版本内每个小更新
                            {
                                List <int> updateidlist = new List <int>();
                                for (int j = 0; j < version.resUpdateList.Count; j++)
                                {
                                    MiniResUpdate miniUpdate = version.resUpdateList[j];
                                    if (string.IsNullOrEmpty(miniUpdate.updateFileName))//检查是否缺失更新列表名一项
                                    {
                                        AppendMissionLog(string.Format(ERROR_UpdateListIsIllegal, "更新列表名缺失", configFile, version.version, miniUpdate.updateID.ToString(), version.version));
                                    }
                                    if (miniUpdate.updateID < 3)//检查更新列表ID,不能小于3,-1代表缺少更新列表ID一项
                                    {
                                        AppendMissionLog(string.Format(ERROR_UpdateListIsIllegal, "更新列表ID不合法", configFile, version.version, miniUpdate.updateID.ToString(), version.version));
                                    }
                                    if (updateidlist.Contains(miniUpdate.updateID))//检查更新列表ID是否重复
                                    {
                                        AppendMissionLog(string.Format(ERROR_UpdateListIsIllegal, "更新列表ID重复", configFile, version.version, miniUpdate.updateID.ToString(), version.version));
                                    }
                                    //向更新列表路径内添加更新列表URL
                                    updateidlist.Add(miniUpdate.updateID);
                                    pathConnectSB.Clear();
                                    pathConnectSB.Append(version.resUrl);
                                    pathConnectSB.Append(miniUpdate.updateFileName);
                                    if (!pathToCheckCollection.ContainsKey(pathConnectSB.ToString()))
                                    {
                                        pathToCheckCollection.Add(pathConnectSB.ToString(), 1);
                                    }
                                    else
                                    {
                                        pathToCheckCollection[pathConnectSB.ToString()]++;
                                    }
                                }
                            }
                            if (!legalVersion.Contains(version.version))
                            {
                                legalVersion.Add(version.version);
                            }
                            else
                            {
                                AppendMissionLog(string.Format(ERROR_VersionConflict, configFile, version.version));
                            }
                            if (version.version != version.dllVersion && version.version != "default")//dll版本与版本号不一致时,检查是否有Assembly-CSharp.dll
                            {
                                pathConnectSB.Clear();
                                pathConnectSB.Append(version.resUrl);
                                pathConnectSB.Append("Assembly-CSharp.dll");
                                if (!pathToCheckCollection.ContainsKey(pathConnectSB.ToString()))
                                {
                                    pathToCheckCollection.Add(pathConnectSB.ToString(), 1);
                                }
                                else
                                {
                                    pathToCheckCollection[pathConnectSB.ToString()]++;
                                }
                            }
                            if (version.specialResVersion != version.version && version.version != "default")//特殊资源压缩包与版本号不一致时,检查是否有SpecialRes.zip
                            {
                                pathConnectSB.Clear();
                                pathConnectSB.Append(version.resUrl);
                                pathConnectSB.Append("SpecialRes.zip");
                                if (!pathToCheckCollection.ContainsKey(pathConnectSB.ToString()))
                                {
                                    pathToCheckCollection.Add(pathConnectSB.ToString(), 1);
                                }
                                else
                                {
                                    pathToCheckCollection[pathConnectSB.ToString()]++;
                                }
                            }
                            if (!string.IsNullOrEmpty(version.cdnVersion) && version.cdnVersion[0] != '?')
                            {
                                AppendMissionLog(string.Format(ERROR_CDNVersionIllegal, configFile, version.version));
                            }
                            //检验独立资源目录中是否含有ResourceList.txt文件
                            pathConnectSB.Clear();
                            pathConnectSB.Append(version.resUrl);
                            pathConnectSB.Append(version.resList);
                            if (!pathToCheckCollection.ContainsKey(pathConnectSB.ToString()))
                            {
                                pathToCheckCollection.Add(pathConnectSB.ToString(), 1);
                            }
                            else
                            {
                                pathToCheckCollection[pathConnectSB.ToString()]++;
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(version.version))
                            {
                                illegalVersion.Add(version.version);
                            }
                            else
                            {
                                illegalVersion.Add("NULL");
                            }
                        }
                    }
                    if (!hasDefaultVersion)//没有Default版本的情况
                    {
                        AppendMissionLog(string.Format(ERROR_MissingDefaultVersion, configFile));
                    }
                    if (illegalVersion.Count > 0)//报出不合法版本号
                    {
                        StringBuilder illegalVersionSB = new StringBuilder();
                        for (int i = 0; i < illegalVersion.Count; i++)
                        {
                            illegalVersionSB.Append(illegalVersion[i]);
                            if (i != illegalVersion.Count - 1)
                            {
                                illegalVersionSB.Append(",");
                            }
                        }
                        AppendMissionLog(string.Format(WARNING_VersionIllegal, configFile, illegalVersionSB.ToString()));
                    }
                }
                else
                {
                    AppendMissionLog(string.Format(ERROR_VersionListIsNull, configFile));
                }
                if (config.resDiffToLatestVersionList != null)//检查版本更新文件
                {
                    for (int i = 0; i < config.resDiffToLatestVersionList.Count; i++)
                    {
                        VersionUpdate versionUpdate = config.resDiffToLatestVersionList[i];
                        if (!Global.Instance.CheckVersionCodeIsLegal(versionUpdate.version) || string.IsNullOrEmpty(versionUpdate.versionUpdateFileName))
                        {
                            AppendMissionLog(string.Format(ERROR_VersionUpdateIllegal, versionUpdate.version ?? "NULL", versionUpdate.versionUpdateFileName ?? "NULL"));
                        }
                    }
                }
            }
            #endregion

            #region 检查更新列表内资源
            if (checkUpdateListAtSameTime && configDic != null && configDic.Count > 0)
            {
                AppendMissionLog("向待检查列表中添加更新列表内资源...");
                SetMissionProgress(0);
                int   num  = 0;
                float unit = 1 / ((float)configDic.Count);
                foreach (var item in configDic)
                {
                    num++;
                    ConfigFile    config = item.Value;
                    List <string> paths  = new List <string>();
                    List <string> paths1 = config.GetMiniUpdateResourcePathList();
                    if (paths1 != null && paths1.Count > 0)
                    {
                        paths.AddRange(paths1);
                    }
                    List <string> paths2 = config.GetVersionUpdateResourcePathList();
                    if (paths2 != null && paths2.Count > 0)
                    {
                        paths.AddRange(paths2);
                    }
                    if (paths.Count == 0)
                    {
                        continue;
                    }
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (!pathToCheckCollection.ContainsKey(paths[i]))
                        {
                            pathToCheckCollection.Add(paths[i], 1);
                        }
                        else
                        {
                            pathToCheckCollection[paths[i]]++;
                        }
                        SetMissionProgress(num / ((float)configDic.Count) + i * unit / paths.Count);
                    }
                    SetMissionProgress(num / ((float)configDic.Count));
                }
            }
            #endregion

            #region 检查完整资源列表内资源
            if (checkResourceListAtSameTime && configDic != null && configDic.Count > 0)
            {
                AppendMissionLog("向待检查列表中添加完整资源列表内资源...");
                SetMissionProgress(0);
                int   num  = 0;
                float unit = 1 / ((float)configDic.Count);
                foreach (var item in configDic)
                {
                    num++;
                    ConfigFile    config = item.Value;
                    List <string> paths  = new List <string>();
                    List <string> paths1 = config.GetFullResourcePathList();
                    if (paths1 != null && paths1.Count > 0)
                    {
                        paths.AddRange(paths1);
                    }
                    if (paths.Count == 0)
                    {
                        continue;
                    }
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (!pathToCheckCollection.ContainsKey(paths[i]))
                        {
                            pathToCheckCollection.Add(paths[i], 1);
                        }
                        else
                        {
                            pathToCheckCollection[paths[i]]++;
                        }
                        SetMissionProgress(num / ((float)configDic.Count) + i * unit / paths.Count);
                    }
                    SetMissionProgress(num / ((float)configDic.Count));
                }
            }
            #endregion

            pathcheckEnumerator = pathToCheckCollection.Keys.GetEnumerator();
            AppendMissionLog("开始检查资源可访问性...");
            SetMissionProgress(0);
        }