示例#1
0
        private void SaschasFunction()
        {
            IFolderInfo di = IOServices.GetFolderInfo(IOServices.Path.Combine(Properties.Settings.Default.SourcePath, "_RecentFiles"));

            IEnumerable <IFileInfo> fis = di.GetFiles("RecentFiles.*.xml");

            DateTime lastUsed = LastUsed.ToUniversalTime();

            DateTime undefined = (new DateTime(2000, 1, 1, 0, 0, 1)).ToUniversalTime();

            if (lastUsed != undefined)
            {
                foreach (IFileInfo fi in fis)
                {
                    DateTime fileTime = fi.LastWriteTime.ToUniversalTime();

                    if (fileTime > lastUsed)
                    {
                        Model.ReadXml(fi.FullName);
                    }
                }
            }

            RaiseFileEntriesChanged();
        }
示例#2
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;
        }
示例#3
0
        private void Copy(List <SourceTarget> fileInfos)
        {
            Boolean taskCancelled = false;

            try
            {
                foreach (SourceTarget fileInfo in fileInfos)
                {
                    if (CancellationToken.IsCancellationRequested)
                    {
                        UIServices.ShowMessageBox("The Copy process was aborted.", String.Empty, Buttons.OK, Icon.Warning);

                        taskCancelled = true;

                        return;
                    }

                    if (PreserveSubFolders)
                    {
                        EnsureSubFolders(fileInfo);
                    }
                    else
                    {
                        fileInfo.TargetFolder = IOServices.GetFolderInfo(TargetLocation);
                    }
                }

                taskCancelled = CommenceCopy(fileInfos);
            }
            catch (System.IO.IOException ioEx)
            {
                UIServices.ShowMessageBox(ioEx.Message, "?!?", Buttons.OK, Icon.Error);
            }
            catch (Exception ex)
            {
                UIServices.ShowMessageBox(ex.Message, "?!?", Buttons.OK, Icon.Error);
            }
            finally
            {
                ProgressChanged?.Invoke(this, EventArgs.Empty);

                if (taskCancelled == false)
                {
                    UIServices.ShowMessageBox("Copy Finished.", String.Empty, Buttons.OK, Icon.Information);
                }
            }
        }
示例#4
0
        private void EnsureSubFolders(SourceTarget fileInfo)
        {
            String directoryName = fileInfo.SourceFile.FolderName;

            String newPath;

            if (directoryName.StartsWith(Properties.Settings.Default.SourcePath))
            {
                newPath = directoryName.Replace(Properties.Settings.Default.SourcePath, String.Empty);
            }
            else
            {
                Int32 indexOfFirstBackSlash;

                indexOfFirstBackSlash = directoryName.IndexOf(@"\");

                newPath = directoryName.Substring(indexOfFirstBackSlash + 1);
            }

            if (IgnoreResolutionFolders)
            {
                if ((newPath.EndsWith(@"\SD")) || (newPath.EndsWith(@"\HD")))
                {
                    newPath = newPath.Substring(0, newPath.Length - 3);
                }
            }

            String path = IOServices.Path.Combine(TargetLocation, newPath);

            fileInfo.TargetFolder = IOServices.GetFolderInfo(path);

            if (fileInfo.TargetFolder.Exists == false)
            {
                fileInfo.TargetFolder.Create();
            }
        }