少年修仙传客户端基础资源
client_Wu Xijin
2018-11-01 6b6d10e0cf634dcfa862f88aa140602103e5a733
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
 
public class SevenZipUtility
{
    static string m_SevenZipToolPath = string.Empty;
    static string sevenZipToolPath {
        get {
            if (string.IsNullOrEmpty(m_SevenZipToolPath))
            {
                if (Directory.Exists("C:/Program Files/7-Zip"))
                {
                    m_SevenZipToolPath = "C:/Program Files/7-Zip";
                }
                else
                {
                    m_SevenZipToolPath = "C:/Program Files (x86)/7-Zip";
                }
            }
 
            return m_SevenZipToolPath;
        }
    }
 
    public static void Compress(string from, string to)
    {
        if (File.Exists(to))
        {
            File.Delete(to);
        }
 
        var cmd = string.Format("\"{0}\\7z\" a {1} {2} -mx9", sevenZipToolPath, to, from);
        SystemCMD.RunCmd(cmd);
    }
 
    public static CompressProgress CompressStreamingAssets()
    {
        var files = new List<FileInfo>();
        FileExtersion.GetAllDirectoryFileInfos(Application.streamingAssetsPath, files);
 
        var progress = new CompressProgress();
        progress.total = files.Count;
 
        foreach (var item in files)
        {
            var fullName = item.FullName;
            var extension = Path.GetExtension(item.FullName);
            if (extension == ".meta")
            {
                continue;
            }
 
            var to = string.Empty;
            if (string.IsNullOrEmpty(extension))
            {
                to = fullName + ".7z";
            }
            else
            {
                to = fullName.Replace(extension, ".7z");
            }
 
            Compress(fullName, to);
            progress.complete++;
        }
 
        return progress;
    }
 
    public class CompressProgress
    {
        public int total;
        public int complete;
        public float progress {
            get {
                return complete / (float)total;
            }
        }
 
        public bool done {
            get {
                return complete >= total;
            }
        }
    }
 
}