Example #1
0
        private void Link()
        {
            if (Path.GetPathRoot(this._outputBaseFolder) != Path.GetPathRoot(this._sourceFolder))
            {
                this.UpdateStatusFormat(
                    "Link failed, the output basefolder and the source folder must be in the same driver!");
                return;
            }
            if (this._unlocatedCount != 0)
            {
                MessageBoxResult result = MessageBox.Show(this._unlocatedCount + " files unlocated, hard link anyway?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
                if (result != MessageBoxResult.OK)
                {
                    return;
                }
            }

            this.UpdateStatusFormat("Linking...");
            var helper = new HardLinkHelper();

            helper.HardLink(this._locateResult.TorrentFileLinks, this._copyLimitSize, this._outputName,
                            this._outputBaseFolder);
            // copy .torrent file
            string targetTorrentFile = Path.Combine(Path.Combine(this._outputBaseFolder, this._outputName), Path.GetFileName(_torrentFile));

            helper.Copy(_torrentFile, targetTorrentFile);
            this.UpdateStatusFormat("Done.");
            Process.Start("explorer.exe", Path.Combine(this._outputBaseFolder, this._outputName));
        }
Example #2
0
        public async Task HardLink()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.Inconclusive("Testing running on macOS, can't run hard link test due to no Hard Link support for macOS");
            }

            //Get some random text
            var randomText = TestContext.CurrentContext.Random.GetString();

            // Make a random file and fill it with some content
            var baseFile = Path.GetRandomFileName();
            await File.WriteAllTextAsync(baseFile, randomText);

            //Make up another random filename and make a hard link to the first random filename
            var randomFile = Path.GetRandomFileName();

            Assert.True(HardLinkHelper.CreateHardLink(baseFile, randomFile), "Wasn't able to create hard link");

            //Check that the file does now exist on disk
            Assert.True(File.Exists(randomFile), "Hard link was created but file doesn't exist...");

            //Check that both random files contains the same content
            var randomFileContent = await File.ReadAllTextAsync(randomFile);

            Assert.True(randomFileContent == randomText, "Content in file {0} should be '{1}' but was '{2}'", randomFile, randomText, randomFileContent);

            //Check that both random files contains the same content after changing the contents of both, starting with the random file
            var moreRandomText = TestContext.CurrentContext.Random.GetString();

            randomText += moreRandomText;
            await File.AppendAllTextAsync(randomFile, moreRandomText);

            randomFileContent = await File.ReadAllTextAsync(baseFile);

            Assert.True(randomFileContent == randomText, "Content in file {0} should be '{1}' but was '{2}'", baseFile, randomText, randomFileContent);

            //Now the base file
            moreRandomText = Path.GetRandomFileName();
            randomText    += moreRandomText;
            await File.AppendAllTextAsync(baseFile, moreRandomText);

            randomFileContent = await File.ReadAllTextAsync(randomFile);

            Assert.True(randomFileContent == randomText, "Content in file {0} should be '{1}' but was '{2}'", randomFile, randomText, randomFileContent);
        }
Example #3
0
        public void InitCommands()
        {
            this._selectSourceFolderCommand = new RelayCommand(() =>
            {
                var dialog = new VistaFolderBrowserDialog();
                dialog.ShowNewFolderButton = true;
                dialog.ShowDialog();
                if (!string.IsNullOrWhiteSpace(dialog.SelectedPath))
                {
                    this.Set(() => this.SourceFolder, ref this._sourceFolder, dialog.SelectedPath);
                    this.Set(() => this.ParentFolder, ref this._parentFolder, Directory.GetParent(dialog.SelectedPath).FullName);
                    this.Set(() => this.FolderName, ref this._folderName, Path.GetFileName(dialog.SelectedPath) + "_Copy");
                }
            });

            this._selectParentFolderCommand = new RelayCommand(() =>
            {
                var dialog = new VistaFolderBrowserDialog();
                dialog.ShowNewFolderButton = true;
                dialog.ShowDialog();
                if (dialog.SelectedPath != null)
                {
                    this.Set(() => this.ParentFolder, ref this._parentFolder, dialog.SelectedPath);
                }
            });

            this._defaultCommand = new RelayCommand(() =>
            {
                if (string.IsNullOrWhiteSpace(this._sourceFolder))
                {
                    this.Set(() => this.FolderName, ref this._folderName, "");
                }
                else
                {
                    this.Set(() => this.FolderName, ref this._folderName,
                             Path.GetDirectoryName(_folderName) + "_HLinked");
                }
            });

            this._linkCommand = new RelayCommand(() =>
            {
                var helper = new HardLinkHelper();
                helper.HardLink(this._sourceFolder, this._parentFolder, this._folderName, 1024000);
                Process.Start("explorer.exe", Path.Combine(this._parentFolder, this._folderName));
            }, () => !string.IsNullOrWhiteSpace(this._sourceFolder) && !string.IsNullOrWhiteSpace(this._parentFolder) && !string.IsNullOrWhiteSpace(this._folderName));
        }