Пример #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, ""));
            }
        }
Пример #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++;
                }
            }
        }