예제 #1
0
        public static void LinkDirectory(string root, DirectoryInfo currentDir, string destination, out int exitCode,
                                         string[] dirExclusions, string[] fileExclusions, string[] fileCopyInstead, bool overrideSpecial = false)
        {
            Console.WriteLine($"Symlinking folder {root} to {destination}");

            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);
                WinDirectoryUtil.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);
                Kernel32Interop.CreateSymbolicLink(destination, currentDir.FullName, SymbolicLink.Directory);
            }
        }
예제 #2
0
        public static void LinkDirectory(string root, DirectoryInfo currentDir, string destination, out int exitCode,
                                         string[] dirExclusions, string[] fileExclusions, string[] fileCopyInstead, bool hardLink, bool symFolders, bool firstRun = true)
        {
            Console.WriteLine($"Symlinking folder {root} to {destination}");

            exitCode = 1;

            //bool special = overrideSpecial;
            bool special = false;
            bool skip    = false;


            if (!string.IsNullOrEmpty(dirExclusions[0]))
            {
                for (int j = 0; j < dirExclusions.Length; j++)
                {
                    string exclusion = dirExclusions[j];
                    string fullPath;
                    if (exclusion.StartsWith("direxskip"))
                    {
                        fullPath = Path.Combine(root, exclusion.Substring(9).ToLower());
                    }
                    else
                    {
                        fullPath = Path.Combine(root, exclusion).ToLower();
                    }

                    if (!string.IsNullOrEmpty(exclusion) && fullPath.Contains(currentDir.FullName.ToLower()))
                    {
                        if (exclusion.StartsWith("direxskip"))
                        {
                            skip = true;
                            break;
                        }

                        // special case, one of our subfolders is excluded
                        special = true;
                        break;
                    }
                }
            }

            //if (!special)
            //{
            // this folder has a child that cant be symlinked
            //CmdUtil.MkLinkDirectory(currentDir.FullName, destination, out exitCode);
            //Kernel32Interop.CreateSymbolicLink(destination, currentDir.FullName, Nucleus.Gaming.Platform.Windows.Interop.SymbolicLink.Directory);
            if (!skip || firstRun)
            {
                if (symFolders)
                {
                    if (!special && !firstRun)
                    {
                        Kernel32Interop.CreateSymbolicLink(destination, currentDir.FullName, Interop.SymbolicLink.Directory);
                    }
                    else
                    {
                        Directory.CreateDirectory(destination);
                    }
                }
                else
                {
                    Directory.CreateDirectory(destination);
                }

                //CmdUtil.LinkFiles(currentDir.FullName, destination, out exitCode, fileExclusions, fileCopyInstead, true);
                WinDirectoryUtil.LinkFiles(currentDir.FullName, destination, out exitCode, fileExclusions, fileCopyInstead, hardLink);

                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, hardLink, symFolders, false);
                }
            }
            //}
            //else
            //{
            //    // we symlink this directly
            //    //CmdUtil.MkLinkDirectory(currentDir.FullName, destination, out exitCode);

            //    //Kernel32Interop.CreateSymbolicLink(destination, currentDir.FullName, Nucleus.Gaming.Platform.Windows.Interop.SymbolicLink.Directory);
            //    //System.IO.DriveInfo di = new System.IO.DriveInfo(destination);
            //    //System.IO.DirectoryInfo dirInfo = di.RootDirectory;
            //    //Console.WriteLine("createsymboliclink: " + dirInfo.Attributes.ToString());

            //    //if (symFolders)
            //   // {
            //       // Kernel32Interop.CreateSymbolicLink(destination, currentDir.FullName, Nucleus.Gaming.Platform.Windows.Interop.SymbolicLink.Directory);
            //   // }
            //   // else
            //   // {
            //        Directory.CreateDirectory(destination);
            //   // }
            //}
        }