Beispiel #1
0
        //创建filelist
        public static bool CreateFileList(string path)
        {
            if (!XUtilities.IsFolder(path) || !Directory.Exists(path))
            {
                return(false);
            }
            var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);

            if (files.Length < 1)
            {
                return(false);
            }

            try
            {
                var result = new XFileList();
                foreach (var file in files)
                {
                    if (file.Contains(FILE_LIST_NAME))
                    {
                        continue;
                    }
                    FileInfo sysFileInfo = new FileInfo(file);

                    var fileInfo = new XFileInfo();
                    fileInfo.name = sysFileInfo.Name;
                    fileInfo.path = file.Replace(path + "\\", string.Empty);
                    var fileStream = sysFileInfo.OpenRead();
                    fileInfo.md5 = ToMD5(fileStream);
                    fileStream.Close();
                    fileInfo.length = sysFileInfo.Length;
                    result.m_dictFileInfo.Add(fileInfo.name, fileInfo);
                }
                XDebug.Log(Tag, result.ToLog());
                var json         = JsonUtility.ToJson(result);
                var filelistPath = $"{path}/{FILE_LIST_NAME}";
                File.WriteAllText(filelistPath, json);
                return(true);
            }
            catch (Exception e)
            {
                XDebug.LogError(Tag, e.ToString());
            }
            return(false);
        }
Beispiel #2
0
        //保存filelist
        public static bool SaveFileList(string path, XFileList fileList)
        {
            if (!XUtilities.IsFolder(path) || !Directory.Exists(path))
            {
                return(false);
            }
            var filelistPath = $"{path}/{FILE_LIST_NAME}";

            try
            {
                var json = JsonUtility.ToJson(fileList);
                XUtilities.SaveFile(filelistPath, json);
                XDebug.Log(Tag, json);
                return(true);
            }
            catch (Exception e)
            {
                XDebug.LogError(Tag, $"保存文件清单失败 {filelistPath}\n{e.ToString()}");
            }
            return(false);
        }