コード例 #1
0
ファイル: CmdUtil.cs プロジェクト: Sphaxtoast/nucleuscoop
        public static void LinkDirectories(string rootFolder, string destination, out int exitCode, params string[] exclusions)
        {
            exitCode = 1;

            DirectoryInfo[] dirs = new DirectoryInfo(rootFolder).GetDirectories();

            for (int i = 0; i < dirs.Length; i++)
            {
                DirectoryInfo dir = dirs[i];

                if (exclusions.Contains(dir.Name.ToLower()))
                {
                    continue;
                }

                string relative = dir.FullName.Replace(rootFolder, "");
                if (relative.StartsWith(@"\") || relative.StartsWith("/"))
                {
                    relative = relative.Remove(0, 1);
                }

                string linkPath = Path.Combine(destination, relative);
                CmdUtil.MkLinkDirectory(dir.FullName, linkPath, out exitCode);
            }
        }
コード例 #2
0
        public static void LinkDirectory(string root, DirectoryInfo currentDir, string destination, out int exitCode, string[] dirExclusions, string[] fileExclusions, string[] fileCopyInstead, bool overrideSpecial = false)
        {
            exitCode = 1;

            bool special = overrideSpecial;

            for (int j = 0; j < dirExclusions.Length; j++)
            {
                string exclusion = dirExclusions[j];
                string fullPath  = Path.Combine(root, exclusion).ToLower();

                if (fullPath.Contains(currentDir.FullName.ToLower()))
                {
                    // special case, one of our subfolders is excluded
                    special = true;
                    break;
                }
            }

            if (special)
            {
                // this folder has a child that cant be symlinked
                Directory.CreateDirectory(destination);
                CmdUtil.LinkFiles(currentDir.FullName, destination, out exitCode, fileExclusions, fileCopyInstead);

                DirectoryInfo[] children = currentDir.GetDirectories();
                for (int i = 0; i < children.Length; i++)
                {
                    DirectoryInfo child = children[i];
                    LinkDirectory(root, child, Path.Combine(destination, child.Name), out exitCode, dirExclusions, fileExclusions, fileCopyInstead);
                }
            }
            else
            {
                // we symlink this directly
                CmdUtil.MkLinkDirectory(currentDir.FullName, destination, out exitCode);
            }
        }