三国卡牌客户端基础资源仓库
yyl
2025-05-20 ad754b0ed9a65f2ca8d705210beab9b055fe2664
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
using UnityEngine;
using System.IO;
using System.Collections.Generic;
 
namespace LaunchCommon
{
    public class AssetVersion
    {
        //参考文本 logicbytes/Assembly-CSharp.dll.bytes    .bytes    7360512    71157bfdecb53e8a580432621f3725c7
        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; } }       //字节     
 
 
        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.LastIndexOf('.');
            if (index != -1)
            {
                m_FileName = lastPath.Substring(0, index);
            }
            else
            {
                m_FileName = lastPath;
            }
        }
 
        //checkList 用于外部检查文件下载后是否一致,不包含没有文件的情况
        public bool CheckLocalFileValid(List<bool> checkList = null)
        {
            string path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
            var fileInfo = new FileInfo(path);
 
            if (!fileInfo.Exists)
            {
                Debug.LogFormat("文件不存在 {0}", path);
                return false;
            }
            if (fileInfo.Length != size)
            {
                if (checkList != null && checkList.Count == 0)
                {
                    checkList.Add(false);
                }
                Debug.LogFormat("{0}文件大小不对{1}-{2}", path, size, fileInfo.Length);
                return false;
            }
            var fileMD5 = FileExtersion.GetMD5HashFromFile(path);
            if (fileMD5 != md5)
            {
                if (checkList != null && checkList.Count == 0)
                {
                    checkList.Add(false);
                }
                Debug.LogFormat("{0}文件md5不对{1}-{2}", path, md5, fileMD5);
                return false;
            }
            return true;
 
        }
 
        // 检查外部存储文件是否存在
        // 不存在则读取随包文件进行比较
        // 存在则比较
        public bool CheckLocalFileValid(AssetVersion otherAssetInfo)
        {
            string path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, m_RelativePath);
 
            if (!File.Exists(path))
            {
                Debug.LogFormat("转查StreamingAssetPath - 文件不存在 {0}", path);
                if (otherAssetInfo == null || string.IsNullOrEmpty(otherAssetInfo.relativePath))
                    return false;
 
                if (otherAssetInfo.size != size)
                {
                    Debug.LogFormat("StreamingAssetPath 文件大小不对{0}-{1}", size, otherAssetInfo.size);
                    return false;
                }
 
                if (otherAssetInfo.md5 != md5)
                {
                    Debug.LogFormat("StreamingAssetPath 文件md5不对{0}-{1}", md5, otherAssetInfo.md5);
                    return false;
                }
 
                return true;
            }
 
            return CheckLocalFileValid();
 
        }
    }
}