Esempio n. 1
0
        public void Copy(String targetLocation
                         , String overwrite
                         , CancellationToken cancellationToken)
        {
            TargetLocation    = targetLocation;
            Overwrite         = overwrite;
            CancellationToken = cancellationToken;

            ProgressValue = 0;

            List <SourceTarget> fileInfos = new List <SourceTarget>();

            foreach (String entry in Entries)
            {
                if (IOServices.Folder.Exists(entry))
                {
                    IEnumerable <String> files = IOServices.Folder.GetFiles(entry, searchOption: System.IO.SearchOption.AllDirectories);

                    fileInfos.AddRange(files.Select(file => new SourceTarget(IOServices.GetFileInfo(file))));
                }
                else if (IOServices.File.Exists(entry))
                {
                    fileInfos.Add(new SourceTarget(IOServices.GetFileInfo(entry)));
                }
                else
                {
                    UIServices.ShowMessageBox("Something is weird about\n" + entry, "?!?", Buttons.OK, Icon.Error);

                    return;
                }
            }

            ResetSize();

            IDriveInfo driveInfo = IOServices.GetDriveInfo(IOServices.GetFolderInfo(TargetLocation).Root.Name.Substring(0, 1));

            if (driveInfo.AvailableFreeSpace <= Size)
            {
                FileSize spaceSize = new FileSize(driveInfo.AvailableFreeSpace);

                FileSize bytesSize = new FileSize(Size);

                UIServices.ShowMessageBox($"Target is Full!{Environment.NewLine}Available: {spaceSize}{Environment.NewLine}Needed: {bytesSize}", "Target Full", Buttons.OK, Icon.Warning);

                return;
            }

            Copy(fileInfos);

            ProgressValue = 0;

            App.WasCopied = true;
        }