少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
 
 
public class AssetVersion
{
    string m_RelativePath = string.Empty;
    public string relativePath { get { return m_RelativePath; } }
 
    string m_FileName;
    public string fileName { get { return m_FileName; } }
 
    string m_Extersion = string.Empty;
    public string extersion { get { return m_Extersion; } }
 
    string m_Md5 = string.Empty;
    public string md5 { get { return m_Md5; } }
 
    int m_Size = 0;
    public int size { get { return m_Size; } }       //字节     
 
    StorageLocation m_FileLocation = StorageLocation.ExternalStore;
    public StorageLocation fileLocation { get { return m_FileLocation; } }
 
    bool m_LocalValid = false;
    public bool localValid {
        get { return m_LocalValid; }
        set { m_LocalValid = value; }
    }
 
    public AssetVersion(string _versionString)
    {
        var strings = _versionString.Split('\t');
 
        m_RelativePath = strings[0];
        m_Extersion = strings[1];
        int.TryParse(strings[2], out m_Size);
        m_Md5 = strings[3];
 
        var paths = m_RelativePath.Split('/');
 
        var lastPath = paths[paths.Length - 1];
        var index = lastPath.IndexOf('.');
        if (index != -1)
        {
            m_FileName = lastPath.Substring(0, index);
        }
        else
        {
            m_FileName = lastPath;
        }
    }
 
    public AssetCategory GetAssetCategory()
    {
        if (extersion == ".dll")
        {
            return AssetCategory.Dll;
        }
        else if (m_RelativePath.StartsWith("ui/"))
        {
            return AssetCategory.UI;
        }
        else if (m_RelativePath.StartsWith("audio/"))
        {
            return AssetCategory.Audio;
        }
        else if (m_RelativePath.StartsWith("mob/"))
        {
            return AssetCategory.Mob;
        }
        else if (m_RelativePath.StartsWith("maps/"))
        {
            return AssetCategory.Scene;
        }
        else if (m_RelativePath.StartsWith("effect/"))
        {
            return AssetCategory.Effect;
        }
        else if (m_RelativePath.StartsWith("config/"))
        {
            return AssetCategory.Config;
        }
        else if (m_RelativePath.StartsWith("graphic/"))
        {
            return AssetCategory.Shader;
        }
        else
        {
            return AssetCategory.Other;
        }
    }
 
    public bool CheckLocalFileValid(bool _completeFile)
    {
        if (_completeFile)
        {
            var path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
            var fileInfo = new FileInfo(path);
 
            return fileInfo.Exists && fileInfo.Length == size && md5 == FileExtersion.GetMD5HashFromFile(path);
        }
        else
        {
            if (extersion == ".manifest" || extersion == ".bytes" || extersion == ".txt" || extersion == ".dll")
            {
                var path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
                var fileInfo = new FileInfo(path);
 
                if (!fileInfo.Exists || fileInfo.Length != size || md5 != FileExtersion.GetMD5HashFromFile(path))
                {
                    return false;
                }
            }
            else if (string.IsNullOrEmpty(extersion) || extersion.Length == 0)
            {
                var path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
                var fileInfo = new FileInfo(path);
 
                var manifestAssetVersion = AssetVersionUtility.GetAssetVersion(StringUtility.Contact(m_RelativePath, ".manifest"));
                if (!fileInfo.Exists || fileInfo.Length != size || manifestAssetVersion == null || !manifestAssetVersion.CheckLocalFileValid(false))
                {
                    return false;
                }
            }
            else
            {
                var path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
                var fileInfo = new FileInfo(path);
                if (!fileInfo.Exists || fileInfo.Length != size)
                {
                    return false;
                }
            }
        }
 
        return true;
    }
 
    public bool IsPriorAsset()
    {
        if (VersionConfig.Get().partAssetPackage)
        {
            //如果这台机器曾经完整的下载过所有资源,那么就不再使用分包下载策略,在资源热更新的时候这种情况会触发。
            if (AssetVersionUtility.hasDownLoadFullAsset)
            {
                return true;
            }
            else
            {
                var category = GetAssetCategory();
                var prior = PriorBundleConfig.GetAssetPrior(category, m_FileName);
                return prior <= 1;
            }
        }
        else
        {
            return true;
        }
 
    }
 
    public enum StorageLocation
    {
        StreamingAsset,
        ExternalStore
    }
 
    public enum AssetCategory
    {
        UI,
        Audio,
        Mob,
        Scene,
        Effect,
        Config,
        Shader,
        Dll,
        Other,
    }
 
}