コード例 #1
0
        public static Task CopyOrMoveAsync(IProgressMonitor monitor, Ares.Data.IProject project, String musicDir, String soundsDir, System.Collections.Generic.Dictionary <String, object> uniqueElements,
                                           bool move, String targetPath, CancellationToken token)
        {
            FileOperations privateInstance = new FileOperations(monitor, token);
            FileOpData     data            = new FileOpData();

            data.TargetPath      = targetPath;
            data.UniqueElements  = uniqueElements;
            data.Project         = project;
            data.Move            = move;
            data.MusicDirectory  = musicDir;
            data.SoundsDirectory = soundsDir;
            return(Task.Factory.StartNew(() => { privateInstance.DoCopyOrMove(data); }));
        }
コード例 #2
0
        private void DoCopyOrMove(FileOpData data)
        {
            m_Monitor.SetProgress(0, String.Empty);

            // determine amount to copy / move
            long allBytes = 0;

            foreach (String file in data.UniqueElements.Keys)
            {
                allBytes += GetBytes(file);
            }

            System.Collections.Generic.Dictionary <String, String> filesMoved = new Dictionary <String, String>();

            long currentBytes = 0;
            int  lastPercent  = 0;

            foreach (String file in data.UniqueElements.Keys)
            {
                String nameOnly       = System.IO.Path.GetFileName(file);
                String fileTargetPath = System.IO.Path.Combine(data.TargetPath, nameOnly);
                if (file.Equals(fileTargetPath, StringComparison.InvariantCultureIgnoreCase))
                {
                    currentBytes += GetBytes(fileTargetPath);
                    ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath);
                    continue;
                }
                if (System.IO.Directory.Exists(file))
                {
                    AddMovedFiles(file, fileTargetPath, filesMoved);
                    if (data.Move)
                    {
                        System.IO.Directory.Move(file, fileTargetPath);
                        currentBytes += GetBytes(fileTargetPath);
                        ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath);
                    }
                    else
                    {
                        CopyDirectory(file, fileTargetPath, ref currentBytes, allBytes, ref lastPercent);
                    }
                }
                else if (System.IO.File.Exists(file))
                {
                    filesMoved[file] = fileTargetPath;
                    if (data.Move)
                    {
                        System.IO.File.Move(file, fileTargetPath);
                    }
                    else
                    {
                        System.IO.File.Copy(file, fileTargetPath, true);
                    }
                    currentBytes += GetBytes(fileTargetPath);
                    ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath);
                }
                m_Token.ThrowIfCancellationRequested();
            }

            if (data.Move)
            {
                AdaptElementPaths(filesMoved, data.MusicDirectory, data.SoundsDirectory, data.Project);
            }
            AdaptTags(filesMoved, data.MusicDirectory, data.Move);
        }