少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using UnityEngine;
using UnityEditor;
using System.IO;
using LitJson;
using vnxbqy.UI;
using System;
using System.Threading;
using StartAot;
using StartAotSDK;
using UnityEngine.Networking;
using Codice.CM.Client.Differences;
using System.Collections;
using System.Collections.Generic;
 
public class CheckCDN : EditorWindow
{
    [MenuItem("Tools/检查CDN")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow<CheckCDN>("检查CDN").Show();
    }
 
    [SerializeField]
    private string centerUrl;
 
    VersionUtility.VersionInfo versionInfo { get; set; }
    long remoteLength;
    private System.DateTime remoteLastModified; //远端文件最后修改时间
 
    private void OnGUI()
    {
        //从version获得CDN地址,检查
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("中心地址");
        EditorGUILayout.EndHorizontal();
 
        centerUrl = GUILayout.TextField(centerUrl, GUILayout.MinWidth(300));
 
        GUILayout.BeginHorizontal();
        GUI.color = Color.red;
        GUILayout.Label("必须在游戏运行的情况下才能检测!!!!! ");
        GUILayout.EndHorizontal();
 
        GUI.color = Color.white;
        GUILayout.BeginHorizontal();
        GUILayout.Label("没有配置默认取本版本代码的中心地址 " + VersionUtility.VERSION_URL[0]);
        GUILayout.EndHorizontal();
 
        GUILayout.BeginHorizontal();
        if (string.IsNullOrEmpty(centerUrl))
            GUILayout.Label("当前测试地址为:" + VersionUtility.VERSION_URL[0]);
        else
            GUILayout.Label("当前测试地址为:" + centerUrl);
        GUILayout.EndHorizontal();
 
        GUILayout.BeginHorizontal();
        GUILayout.Label("根据versionsconfig 检查CDN的 AssetsVersion.txt配置文件和资源 1.是否存在文件,2.大小是否一致");
        GUILayout.EndHorizontal();
 
        if (GUILayout.Button("检测"))
        {
            QueryCDN();
        }
    }
 
    private void QueryCDN()
    {
        string url = string.IsNullOrEmpty(centerUrl) ? VersionUtility.VERSION_URL[0] : centerUrl;
 
        var tables = new Dictionary<string, string>();
        tables["channel"] = VersionConfig.Get().appId;
        tables["versioncode"] = VersionConfig.Get().version;
        if (VersionConfig.Get().branch != 0)
        {
            tables["branch"] = VersionConfig.Get().branch.ToString();
        }
 
        tables["game"] = VersionConfig.Get().gameId;
 
        url = StringUtility.Contact(url, HttpRequest.HashtablaToString(tables));
 
 
        HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnVersionCheckResult);
    }
    private void OnVersionCheckResult(bool _ok, string _result)
    {
        if (_ok)
        {
            versionInfo = JsonMapper.ToObject<VersionUtility.VersionInfo>(_result);
            var assetVersionUrl = StringUtility.Contact(GetResourcesURL(), Language.fixPath, "/AssetsVersion.txt");
            Debug.Log("请求CDN的AssetsVersion:" + assetVersionUrl);
            HttpRequest.Instance.RequestHttpGet(assetVersionUrl, HttpRequest.defaultHttpContentType, 3, OnGetAssetVersionFile);
        }
        else
        {
            Debug.Log("请求失败" + _result);
        }
    }
 
    public string GetResourcesURL()
    {
        int _branch = VersionConfig.Get().branch;
        if (versionInfo.resource_url != null)
        {
            return versionInfo.resource_url[_branch.ToString()].ToString();
        }
        else
        {
            return string.Empty;
        }
    }
 
    private void OnGetAssetVersionFile(bool ok, string result)
    {
        Debug.LogFormat("获取资源版本文件结果:时间 {0},结果 {1}, 文件大小 {2}", DateTime.Now, ok, result.Length);
        if (ok)
        {
            AssetVersionUtility.UpdateAssetVersions(result);
            BeginCheckAssets();
        }
        else
        {
            Debug.Log("请求CDN的AssetsVersion失败!");
        }
    }
 
    private void BeginCheckAssets()
    {
        foreach (var assetVersion in AssetVersionUtility.GetVersionsInfo().Values)
        {
            SnxxzGame.Instance.StartCoroutine(Co_GetHeader(assetVersion));
        }
 
    }
 
    private IEnumerator Co_GetHeader(AssetVersion assetVersion)
    {
        var remoteUrl = StringUtility.Contact(GetResourcesURL(), Language.fixPath, "/", assetVersion.relativePath);
 
 
        using (var www = UnityWebRequest.Head(remoteUrl))
        {
            www.timeout = DownloadMgr.TimeOut;
            yield return www.SendWebRequest();
            if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
            {
                DebugEx.LogErrorFormat("头信息获取失败:{0};error:{1}", remoteUrl, www.error);
                www.Dispose();
                yield break;
            }
            long.TryParse(www.GetResponseHeader(HttpHeader.ContentLength), out this.remoteLength);
            this.remoteLastModified = DateTime.Parse(www.GetResponseHeader(HttpHeader.LastModified));
            var acceptRange = www.GetResponseHeader(HttpHeader.AcceptRanges);
            DebugEx.LogFormat("头信息获取成功:{0};大小:{1};修改时间:{2};是否支持续传:{3}", remoteUrl, remoteLength, remoteLastModified, acceptRange);
            if (remoteLength != assetVersion.size)
            {
                DebugEx.LogErrorFormat("文件信息不一致:{0};记录大小:{1};远端大小:{2}", remoteUrl, assetVersion.size, remoteLength);
                www.Dispose();
                yield break;
            }
            www.Dispose();
            
        }
    }
}