Beispiel #1
0
        /// <summary>
        /// 输出需要更新文件
        /// </summary>
        public void OutUpdateFile(string fileDir, string outDir)
        {
            string[] file = Directory.GetFiles(fileDir);
            foreach (var item in file)
            {
                FileInfo fileInfo = new FileInfo(item);
                if (IgnoreFileName.Contains(fileInfo.Name.ToLower()) || IgnoreFileSuffix.Contains(fileInfo.Extension.ToLower()))
                {
                    continue;
                }
                string relativePath = item.Replace(ProjectInfo.ReleasePath, "");

                bool isJump = false;
                foreach (var item2 in IgnoreDir)
                {
                    if (relativePath.ToLower().StartsWith(item2.ToLower()))
                    {
                        isJump = true;
                        continue;
                    }
                }
                if (isJump)
                {
                    continue;
                }

                string outFilePath = outDir + item.Replace(fileDir, "");
                string hashValue   = GetMD5HashFromFile(item);

                var fileVersion = ListFileVersion.FirstOrDefault(f => f.FilePath == relativePath);
                if (fileVersion == null)
                {
                    if (!Directory.Exists(outDir))
                    {
                        Directory.CreateDirectory(outDir);
                    }
                    File.Copy(item, outFilePath, true);
                    fileVersion           = new FileVersion();
                    fileVersion.FilePath  = relativePath;
                    fileVersion.HashValue = hashValue;
                    ListFileVersion.Add(fileVersion);
                }
                else if (fileVersion.HashValue != hashValue)
                {
                    if (!Directory.Exists(outDir))
                    {
                        Directory.CreateDirectory(outDir);
                    }
                    File.Copy(item, outFilePath, true);
                    fileVersion.HashValue = hashValue;
                }
            }
            string[] dir = Directory.GetDirectories(fileDir);
            for (int i = 0; i < dir.Length; i++)
            {
                OutUpdateFile(dir[i], outDir + dir[i].Replace(fileDir, ""));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取文件总数
        /// </summary>
        /// <returns></returns>
        public void GetFileNumber(string dir, ref int fileNumber)
        {
            string[] arrDir = Directory.GetDirectories(dir);
            for (int i = 0; i < arrDir.Length; i++)
            {
                // 跳过忽略目录
                string currentDirName = GetDirectoryNameByPath(arrDir[i]).ToLower();
                if (IgnoreDir.Contains(currentDirName))
                {
                    if (currentDirName == "upload")
                    {
                        string[] arrUploadChildDir = Directory.GetDirectories(arrDir[i]);
                        for (int j = 0; j < arrUploadChildDir.Length; j++)
                        {
                            string currentUploadChildDir = GetDirectoryNameByPath(arrUploadChildDir[j]).ToLower();
                            if (currentUploadChildDir == "initialize" || currentUploadChildDir == "site")
                            {
                                GetFileNumber(arrUploadChildDir[j], ref fileNumber);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    continue;
                }

                // 递归
                GetFileNumber(arrDir[i], ref fileNumber);
            }

            string[] file = Directory.GetFiles(dir);
            for (int i = 0; i < file.Length; i++)
            {
                FileInfo fi = new FileInfo(file[i]);
                if (!IgnoreFileSuffix.Contains(fi.Extension.ToLower()) && !IgnoreFileName.Contains(fi.Name.ToLower()))
                {
                    fileNumber++;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 删除指定后缀的文件
        /// </summary>
        /// <param name="parentDir"></param>
        public void DeleteTheSuffixSpecifiedFile(string parentDir)
        {
            //获取目录文件下的所有的子文件夹
            string[] dir = Directory.GetDirectories(parentDir);
            for (int i = 0; i < dir.Length; i++)
            {
                // 递归
                DeleteTheSuffixSpecifiedFile(dir[i]);
            }

            //获取目录parentDir下的所有的文件,并删除指定后缀文件
            string[] file        = Directory.GetFiles(parentDir);
            string   fileContent = string.Empty;

            for (int i = 0; i < file.Length; i++)
            {
                FileInfo fi = new FileInfo(file[i]);
                if (IgnoreFileSuffix.Contains(fi.Extension.ToLower()))
                {
                    fi.Delete();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 生成版本文件
        /// </summary>
        /// <param name="dir"></param>
        public string GenerateVersionStr(string dir)
        {
            string[] file        = Directory.GetFiles(dir);
            string   fileContent = string.Empty;

            foreach (var item in file)
            {
                string suffix = item.Substring(item.LastIndexOf(".") + 1);
                if (!IgnoreFileSuffix.Contains(suffix))
                {
                    string hashValue = GetMD5HashFromFile(item);
                    fileContent += $"{item}={hashValue}\r\n";
                }
            }
            string[] chidrenDir = Directory.GetDirectories(dir);
            foreach (var item in chidrenDir)
            {
                if (!IgnoreDir.Contains(item))
                {
                    fileContent += GenerateVersionStr(item);
                }
            }
            return(fileContent);
        }