コード例 #1
0
ファイル: EnCription.cs プロジェクト: FireHappy/LFramework
        /// <summary>
        /// 读取资源
        /// </summary>
        static void OpResByDirects(FileSystemInfo fileSystemInfo, string outPath, string pathNode)
        {
            if (!fileSystemInfo.Exists || fileSystemInfo.Extension == ".meta")
            {
                return;
            }
            DirectoryInfo directoryInfo = new DirectoryInfo(fileSystemInfo.FullName);

            FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos();
            foreach (var systemInfo in fileSystemInfos)
            {
                FileInfo fileInfo = systemInfo as FileInfo;
                if (fileInfo == null)//文件夹
                {
                    OpResByDirects(systemInfo, outPath, pathNode);
                }
                else//文件
                {
                    //将文件转化为字节
                    byte[] bytes = File.ReadAllBytes(fileInfo.FullName);//GetBytes(systemInfo.FullName);
                    if (bytes != null)
                    {
                        EncrytUtil.Encryption(bytes);
                        WirteFileInfo(fileInfo, outPath, pathNode, bytes);
                    }
                }
            }
            AssetDatabase.Refresh();
        }
コード例 #2
0
        /// <summary>
        /// 下载并且保存资源,实时写入配置文件
        /// </summary>
        private IEnumerator DownLoadSaveResource(Dictionary <string, string> urls, Action finish)
        {
            DownLoadProgress = 0;
            StreamWriter sw = File.AppendText(NetConst.NET_RES_PATH + "/config.bytes");

            foreach (KeyValuePair <string, string> pair in urls)
            {
                using (WWW www = new WWW(NetConst.URL_RES_HOST + pair.Value))
                {
                    while (!www.isDone)
                    {
                        oldProgress = www.progress;
                        yield return(1);

                        DownLoadProgress += (www.progress - oldProgress) / urls.Count;
                    }
                    yield return(www);

                    if (www.isDone && www.error == null)
                    {
                        //加密资源
                        int    index    = pair.Value.LastIndexOf("/", StringComparison.Ordinal);
                        string fileName = pair.Value.Substring(index);
                        string resPath  = NetConst.NET_RES_PATH + fileName;
                        File.WriteAllBytes(resPath, EncrytUtil.Encryption(www.bytes));//写入文件
                        //将加载的资源写入配置文件中
                        string line = pair.Key + "," + resPath;
                        sw.WriteLine(line);
                    }
                    else
                    {
                        Debug.LogError(www.error);
                    }
                }
            }
            sw.Close();
            sw.Dispose();
            urls.Clear();
            DownLoadProgress = 1;
            if (finish != null)
            {
                finish();
            }
        }
コード例 #3
0
ファイル: EnCription.cs プロジェクト: FireHappy/LFramework
        /// <summary>
        /// 加密文件
        /// </summary>
        static void EnCriptionFile(string resPath, string outPath, string pathNode)
        {
            if (string.IsNullOrEmpty(resPath))
            {
                Debug.LogError("资源路径为空");
                return;
            }
            DirectoryInfo dirInfo = new DirectoryInfo(resPath);

            if (!dirInfo.Exists)
            {
                Debug.LogError("不存在路径:" + resPath);
                return;
            }
            else//资源路径存在
            {
                FileSystemInfo[] fileSystemInfos = dirInfo.GetFileSystemInfos();
                for (int i = 0; i < fileSystemInfos.Length; i++)
                {
                    FileInfo fileInfo = fileSystemInfos[i] as FileInfo;
                    if (fileInfo != null)                                    //文件
                    {
                        byte[] bytes = File.ReadAllBytes(fileInfo.FullName); //GetBytes(systemInfo.FullName);
                        if (bytes != null)
                        {
                            EncrytUtil.Encryption(bytes);
                            WirteFileInfo(fileInfo, outPath, pathNode, bytes);
                        }
                    }
                    else//文件夹
                    {
                        OpResByDirects(fileSystemInfos[i], outPath, pathNode);
                    }
                }
            }
            AssetDatabase.Refresh();
        }