예제 #1
0
        public void Delete_CalledOnAFile()
        {
            File.Create(Path.Combine(tempFolder, "AFile")).Close();

            Assert.Throws <IOException>(() => JunctionPoint.Delete(Path.Combine(tempFolder, "AFile")),
                                        "Path is not a junction point.");
        }
 protected override void ProcessRecord()
 {
     if (ShouldProcess("Deleting link from {0}"))
     {
         JunctionPoint.Delete(path);
     }
 }
예제 #3
0
        public void ShouldCreateJunctionPoint()
        {
            var path = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Path.GetRandomFileName());

            Directory.CreateDirectory(path);
            var file = Path.Combine(path, "file.txt");

            using (File.Create(file))
            {
            }

            var junctionPath = string.Format("{0}+junction", path);

            JunctionPoint.Create(junctionPath, path, true);
            var junctionFiles = Directory.GetFiles(junctionPath);

            Assert.That(junctionFiles.Length, Is.EqualTo(1));
            Assert.That(junctionFiles[0], Is.EqualTo(Path.Combine(junctionPath, "file.txt")));


            JunctionPoint.Delete(junctionPath);

            Assert.That(Directory.Exists(junctionPath), Is.False);
            Assert.That(File.Exists(file), Is.True);
        }
            static void Delete(DirectoryInfo directory, int depth, IOResult logger)
            {
                if (JunctionPoint.Exists(directory.FullName))
                {
                    JunctionPoint.Delete(directory.FullName);
                }
                else if (!Directory.Exists(directory.FullName))
                {
                    return;
                }

                try
                {
                    foreach (var fileInfo in directory.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
                    {
                        File.Delete(fileInfo.FullName);
                    }

                    foreach (var directoryInfo in directory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
                    {
                        var back = string.Join("\\", Enumerable.Repeat("..", depth));
                        Delete(directoryInfo, depth + 1, logger);
                    }

                    Directory.Delete(directory.FullName);
                }
                catch (Exception ex)
                {
                    logger.Fail(ex);
                }
            }
예제 #5
0
    public void MklinkJ()
    {
        SetFor(LinkType.J);
        var j = J();

        JunctionPoint.Delete(j);
        JunctionPoint.MklinkJ(j, target);
    }
예제 #6
0
        public static bool MoveStorageToSource(Assignment prof, IProgress <long> sizeFromHell, object _lock, CancellationToken ct)
        {
            string sourceDir = prof.Source.FullName;
            string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name;

            Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " started");
            bool returnStatus = false;

            try
            {
                /// find a junction, which has a different name, than the folder to be moved
                List <string> ListOfJunctions             = prof.Source.GetDirectories().Select(dir => dir.FullName).ToList().Where(str => JunctionPoint.Exists(@str)).ToList();
                List <string> ListOfTargets               = ListOfJunctions.Select(str => JunctionPoint.GetTarget(@str)).ToList();
                List <Tuple <string, string> > pairsOfJaT = new List <Tuple <string, string> >();
                for (int i = 0; i < ListOfJunctions.Count; i++)
                {
                    string JunctionName = (new DirectoryInfo(ListOfJunctions[i])).Name;
                    string TargetName   = (new DirectoryInfo(ListOfTargets[i])).Name;
                    if (JunctionName != TargetName)
                    {
                        pairsOfJaT.Add(new Tuple <string, string>(JunctionName, TargetName));
                    }
                }
                string renamedJunction = null;
                if (pairsOfJaT.Count > 0)
                {
                    renamedJunction = pairsOfJaT.FirstOrDefault(str => str.Item2 == prof.Source.Name).Item1;
                }
                if (renamedJunction != null)
                {
                    renamedJunction = prof.Target.Parent + @"\" + renamedJunction;
                }

                if (JunctionPoint.Exists(@targetDir))
                {
                    JunctionPoint.Delete(@targetDir);
                    returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct);
                }
                else if (JunctionPoint.Exists(@renamedJunction))
                {
                    JunctionPoint.Delete(@renamedJunction);
                    returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct);
                }
                if (returnStatus == true)
                {
                    DirectoryInfo deletableDirInfo = prof.Source;
                    deletableDirInfo.Delete(true);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
            Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " finished with " + returnStatus);
            return(returnStatus);
        }
예제 #7
0
 public override void Delete()
 {
     if (IsHardLink)
     {
         JunctionPoint.Delete(Path.FullPath);
     }
     else
     {
         base.Delete();
     }
 }
예제 #8
0
 public static void MoveReplaceJunction(string origin, string target)
 {
     //Delete the junction
     JunctionPoint.Delete(origin);
     //Copy the folder back and delete the original folder (essentially moving the function)
     Program.CopyFolder(target, origin);
     Directory.Delete(target, true);
     //Update the SQLite database with the removal of the junction
     SQLiteManager.RemoveJunction(origin);
     Program.Log("INFO: Moved " + target + " to " + origin);
 }
예제 #9
0
 private void removeAllLinksToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (var v in model.Settings.InstalledVersions.OrderByDescending(version => version.VersionNumber))
     {
         if (JunctionPoint.Exists(Path.Combine(v.Folder, "mlc01", "usr", "title")))
         {
             JunctionPoint.Delete(Path.Combine(v.Folder, "mlc01", "usr", "title"));
         }
     }
     button3_Click(null, null);
 }
예제 #10
0
 public override void Delete()
 {
     if (IsHardLink)
     {
         JunctionPoint.Delete(Path);
     }
     else
     {
         LongPathDirectory.Delete(Path, true);
     }
 }
예제 #11
0
        public void Create_VerifyExists_GetTarget_Delete()
        {
            string targetFolder  = Path.Combine(tempFolder, "ADirectory");
            string junctionPoint = Path.Combine(tempFolder, "SymLink");

            Directory.CreateDirectory(targetFolder);
            try
            {
                File.Create(Path.Combine(targetFolder, "AFile")).Close();
                try
                {
                    // Verify behavior before junction point created.
                    Assert.IsFalse(File.Exists(Path.Combine(junctionPoint, "AFile")),
                                   "File should not be located until junction point created.");

                    Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point not created yet.");

                    // Create junction point and confirm its properties.
                    JunctionPoint.Create(junctionPoint, targetFolder, overwrite: false);

                    Assert.IsTrue(JunctionPoint.Exists(junctionPoint), "Junction point exists now.");

                    Assert.AreEqual(targetFolder, JunctionPoint.GetTarget(junctionPoint));

                    Assert.IsTrue(File.Exists(Path.Combine(junctionPoint, "AFile")),
                                  "File should be accessible via the junction point.");

                    // Delete junction point.
                    JunctionPoint.Delete(junctionPoint);

                    Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point should not exist now.");

                    Assert.IsFalse(File.Exists(Path.Combine(junctionPoint, "AFile")),
                                   "File should not be located after junction point deleted.");

                    Assert.IsFalse(Directory.Exists(junctionPoint), "Ensure directory was deleted too.");
                }
                finally
                {
                    File.Delete(Path.Combine(targetFolder, "AFile"));
                }
            }
            finally
            {
                Directory.Delete(targetFolder);
            }
        }
        /// <summary>
        /// 删除指定路径的文件夹,此操作会递归删除文件夹内的所有文件,最后删除此文件夹自身。
        /// 如果目标文件夹是个连接点(Junction Point, Symbolic Link),则只会删除连接点而已,不会删除连接点所指目标文件夹中的文件。
        /// </summary>
        /// <param name="directory">要删除的文件夹。</param>
        /// <returns>包含执行成功和失败的信息,以及中间执行中方法自动决定的一些细节。</returns>
        public static IOResult Delete(DirectoryInfo directory)
        {
            if (directory is null)
            {
                throw new ArgumentNullException(nameof(directory));
            }

            var logger = new IOResult();

            logger.Log($"删除目录“{directory.FullName}”。");

            if (JunctionPoint.Exists(directory.FullName))
            {
                JunctionPoint.Delete(directory.FullName);
            }
            else if (!Directory.Exists(directory.FullName))
            {
                logger.Log($"要删除的目录“{directory.FullName}”不存在。");
                return(logger);
            }

            Delete(directory, 0, logger);
        public void DeleteTest()
        {
            Helper.DemandTestDriveAvailable(TestDrive);
            //Helper.DemandElevated();

            var testFolder = Helper.GetTestFolder(TestDrive, "WriteTests", this);

            _fixture = new Fixture(() => Directory.Delete(testFolder, true));

            Directory.CreateDirectory(testFolder);
            var originalFolder = Path.Combine(testFolder, "original");

            Directory.CreateDirectory(originalFolder);
            var junction = Path.Combine(testFolder, "junction");

            JunctionPoint.Create(junction, originalFolder, true);
            Assert.IsTrue(Directory.Exists(junction));

            JunctionPoint.Delete(junction);

            Assert.IsFalse(Directory.Exists(junction));
        }
예제 #14
0
        public void Delete_NonExistentJunctionPoint() =>

        // Should do nothing.
        JunctionPoint.Delete(this.tempFolder.Combine("SymLink"));
예제 #15
0
        static int Main(string[] args)
        {
            string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().FullName);
            string mappingsFile     = Path.Combine(currentDirectory, "mappings.txt");
            string lastGameModeFile = Path.Combine(currentDirectory, "lastGameMode.bin");

            // create missing files
            if (!File.Exists(mappingsFile))
            {
                using (var writer = File.CreateText(mappingsFile))
                {
                    writer.Write(@"################################################################################################################
# whitespace characters (space, tab, ...) and equal sign (=) all count as separators.
# 1st word is the name of folder (usually gamemode prefix) containing paks for this gamemode.
# all other words in the line are names for this gamemode (case insensitive).
# all names have to be unique. if not, they are ignored.
# whitespace in gamemode's name entered from input or as argument in UTPreparePaks.exe is not accounted for
# 
# example: you enter ""CaP t ure the fLA     G, bt"" it will be changed to ""CaPturethefLAG, bt""
# this string will then be compared to all names in this file (case insensitive)
# and then junctions to CTF and BT directory will be created in target directory
################################################################################################################
# lastGameMode.bin contains which gamemodes were last set for every target directory
# file is litle bit encrypted so that users wouldnt edit its content and potentially
# make it so that some unwanted junctions would not be deleted when no longer needed
################################################################################################################

AS		= AS Assault
BR		= BR BombingRun
BT		= BT BunnyTrack
CTF		= CTF CaptureTheFlag CaptureFlag
DM		= DM Deathmatch
Duel	= Duel 1v1 pvp
Elim	= Elim Elimination
FR		= FR FlagRun Blitz
KO		= KO Knockout"        );
                }
            }

            if (!File.Exists(lastGameModeFile))
            {
                File.Create(lastGameModeFile).Close();
            }



            // get target directory and gameModePrefix
            string        targetDirectory       = null;
            List <string> selectedGameModeNames = null;

            if (args.Length > 0)
            {
                targetDirectory = Path.GetFullPath(args[0]);
                if (args.Length > 1)
                {
                    selectedGameModeNames = new List <string>(args[1].Replace(" ", "").ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                }
                else
                {
                    Console.Write("Enter one or more gamemode names (comma separated): ");
                    selectedGameModeNames = new List <string>(Console.ReadLine().Replace(" ", "").ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                }

                var lastGameModeTargets = ParseLastGameModesFile(lastGameModeFile);
                var mappings            = ParseMappingsFile(mappingsFile);
                var selectedGameModes   = new List <string>();

                // get selected gamemodes
                foreach (var selectedGameModeName in selectedGameModeNames)
                {
                    if (mappings.TryGetValue(selectedGameModeName, out string selectedGameMode))
                    {
                        selectedGameModes.Add(selectedGameMode);
                    }
                    else
                    {
                        Console.WriteLine($"No mapping defined for '{selectedGameModeName}'. skipped.");
                    }
                }

                // get games modes used last time
                if (lastGameModeTargets.TryGetValue(targetDirectory, out List <string> lastGameModes))
                {
                    // go through every gamemode from last time
                    foreach (var lastGameMode in lastGameModes)
                    {
                        string lastJunctionDestination = Path.Combine(targetDirectory, lastGameMode);
                        if (!selectedGameModes.Contains(lastGameMode) && JunctionPoint.Exists(lastJunctionDestination)) // if supposed to delete and exists
                        {
                            JunctionPoint.Delete(lastJunctionDestination);                                              // delete
                        }
                    }
                }

                // go through every selected gamemode
                foreach (var selectedGameMode in selectedGameModes)
                {
                    string junctionSource      = Path.Combine(currentDirectory, selectedGameMode);
                    string junctionDestination = Path.Combine(targetDirectory, selectedGameMode);

                    if (!Directory.Exists(junctionSource))                           // directory on which junction will point doesnt exist yet
                    {
                        Directory.CreateDirectory(junctionSource);                   // make that directory
                    }
                    JunctionPoint.Create(junctionDestination, junctionSource, true); // finally create junction from targetDirectory to out gamemode directory
                }

                lastGameModeTargets[targetDirectory] = selectedGameModes;                 // sets which gamemodes were set this time
                WriteLastGameModes(lastGameModeFile, lastGameModeTargets);                // save used gamemodes
            }
            else
            {
                Console.WriteLine("UTPreparePaks <TargetDirectory> [GameModeName]");
                return(1);
            }

            return(0);
        }
예제 #16
0
        private void refreshDataGrid()
        {
            SQLiteDataReader reader          = SQLiteManager.ExecuteSQLiteCommand("SELECT * FROM junctions;");
            List <string>    sqlCommandQueue = new List <string>();

            while (reader.Read())
            {
                string origin = reader.GetString(reader.GetOrdinal("origin"));
                string target = reader.GetString(reader.GetOrdinal("target"));
                if (!JunctionPoint.Exists(origin))
                {
                    if (Directory.Exists(origin))
                    {
                        MessageBox.Show("The junction at " + origin + " that pointed to " + target + " has been replaced by a folder by the same name.  If you moved the folder back yourself this is fine, otherwise you might wanna look into this", "Junction is now a folder", MessageBoxButtons.OK);
                        sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';");
                        Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " replaced by a folder with the same name");
                        continue;
                    }
                    else
                    {
                        MessageBox.Show("The junction at " + origin + " that pointed to " + target + " is not there, it could have been moved or deleted.", "Missing junction", MessageBoxButtons.OK);
                        sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';");
                        Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " missing");
                        continue;
                    }
                }
                string realTarget = JunctionPoint.GetTarget(origin);
                if (realTarget != target)
                {
                    MessageBox.Show("The junction at " + origin + " has changed targets from " + target + " to " + realTarget + ".", "Moved junction target", MessageBoxButtons.OK);
                    sqlCommandQueue.Add("UPDATE junctions SET target = '" + realTarget + "' WHERE origin = '" + origin + "';");
                    target = realTarget;
                    Program.Log("WARNING: Junction at " + origin + " is now pointing to " + realTarget + ", was pointing to " + target);
                }
                if (!Directory.Exists(realTarget))
                {
                    MessageBox.Show("The folder at " + target + " is missing, the junction " + origin + " pointed to it.", "Folder missing", MessageBoxButtons.OK);
                    JunctionPoint.Delete(origin);
                    sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';");
                    Program.Log("WARNING: " + target + " is missing, pointed to by junction at " + origin);
                }
            }
            SQLiteManager.CloseConnection();
            foreach (string s in sqlCommandQueue)
            {
                SQLiteManager.ExecuteSQLiteCommand(s);
                SQLiteManager.CloseConnection();
            }
            SQLiteManager.CloseConnection();

            //Create a DataSet object
            DataSet dataSet = new DataSet();

            //Get the adapter for the grid view, which will contain every junction in the table
            SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM junctions;", SQLiteManager.GetSQLiteConnection());

            dataAdapter.Fill(dataSet);

            //Fill the view with the dataset
            dataGridView1.DataSource = dataSet.Tables[0].DefaultView;
            //Close the connection
            SQLiteManager.CloseConnection();

            if (dataGridView1.Rows.Count == 0)
            {
                restoreButton.Enabled = false;
                moveButton.Enabled    = false;
            }
            else
            {
                restoreButton.Enabled = true;
                moveButton.Enabled    = true;
            }
        }
예제 #17
0
 public void Delete_NonExistentJunctionPoint()
 {
     // Should do nothing.
     JunctionPoint.Delete(Path.Combine(tempFolder, "SymLink"));
 }
예제 #18
0
 public void Delete_CalledOnADirectoryThatIsNotAJunctionPoint() =>
 Assert.Throws <IOException>(() => JunctionPoint.Delete(this.tempFolder), "Unable to delete junction point.");
예제 #19
0
 public void Delete_CalledOnADirectoryThatIsNotAJunctionPoint()
 {
     JunctionPoint.Delete(tempFolder);
 }
예제 #20
0
        public void Delete_CalledOnAFile()
        {
            File.Create(Path.Combine(tempFolder, "AFile")).Close();

            JunctionPoint.Delete(Path.Combine(tempFolder, "AFile"));
        }