コード例 #1
0
        public static ImportResourceResult CopyToDic(ResourceFolder parentDic, IEnumerable <string> files, IProgressMonitor monitor, CancellationToken token, IEnumerable <string> fileTypeSuffix = null)
        {
            ImportResourceResult importResult = new ImportResourceResult();

            importResult.FileTypeSuffix = fileTypeSuffix;
            importResult.Token          = token;
            List <FileOptionHelp.FileData> dealDithFiles = new List <FileOptionHelp.FileData>();

            FileOptionHelp.IsMainThread();
            int pathsFileSystemCount = FileOptionHelp.GetPathsFileSystemCount(files);

            monitor.BeginTask(LanguageInfo.Menu_File_ImportFile, pathsFileSystemCount);
            foreach (FileOptionHelp.FileData fileData in FileOptionHelp.CreateFileDatas(files))
            {
                if (!token.IsCancellationRequested)
                {
                    ResourceItem resourceItem = !File.Exists((string)fileData.FilePath) || fileData.Attributes.HasFlag((Enum)FileAttributes.Hidden) ? FileOptionHelp.CopyDir(parentDic, fileData, ref importResult, dealDithFiles, monitor) : FileOptionHelp.CopyFile(parentDic, fileData, ref importResult, dealDithFiles, monitor);
                    if (resourceItem != null)
                    {
                        importResult.ImportResources.Add(resourceItem);
                        importResult.AddResourcePanelItems.Add(resourceItem);
                    }
                }
                else
                {
                    break;
                }
            }
            return(importResult);
        }
コード例 #2
0
        private static ResourceItem CopyDir(ResourceFolder parent, FileOptionHelp.FileData dirPath, ref ImportResourceResult importResult, List <FileOptionHelp.FileData> dealDithFiles, IProgressMonitor monitor)
        {
            ResourceFolder resourceFolder = (ResourceFolder)null;

            if (importResult.Token.IsCancellationRequested)
            {
                return((ResourceItem)resourceFolder);
            }
            ResourceFolder parent1;

            if (dirPath.FilePath.IsChildPathOf(parent.BaseDirectory))
            {
                if (!FileOptionHelp.VerifyPath(dirPath.FilePath))
                {
                    monitor.Step(1);
                    monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, (object)dirPath.FilePath), (Exception)null);
                    return((ResourceItem)null);
                }
                ResourceItem importRoot = (ResourceItem)null;
                parent1 = Services.ProjectOperations.AddResourceItem(parent, dirPath.FilePath, monitor, out importRoot) as ResourceFolder;
                importResult.AddResourcePanelItems.Add(importRoot);
            }
            else
            {
                FilePath filePath = parent.BaseDirectory.Combine(new string[1] {
                    dirPath.Name
                });
                if (!FileOptionHelp.VerifyPath(filePath))
                {
                    monitor.Step(1);
                    monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, (object)dirPath.FilePath), (Exception)null);
                    return((ResourceItem)null);
                }
                if (!Directory.Exists((string)filePath))
                {
                    Directory.CreateDirectory((string)filePath);
                }
                parent1 = Services.ProjectOperations.AddResourceItem(parent, filePath, monitor) as ResourceFolder;
            }
            DirectoryInfo directoryInfo1 = new DirectoryInfo((string)dirPath.FilePath);

            FileInfo[]      files       = directoryInfo1.GetFiles();
            DirectoryInfo[] directories = directoryInfo1.GetDirectories();
            SortedSet <FileOptionHelp.FileData> fileDatas = FileOptionHelp.CreateFileDatas(((IEnumerable <FileInfo>)files).Select <FileInfo, string>((Func <FileInfo, string>)(a => a.FullName)));

            foreach (DirectoryInfo directoryInfo2 in directories)
            {
                if (!directoryInfo2.Attributes.HasFlag((Enum)FileAttributes.Hidden))
                {
                    FileOptionHelp.FileData dirPath1 = new FileOptionHelp.FileData(directoryInfo2.FullName);
                    FileOptionHelp.CopyDir(parent1, dirPath1, ref importResult, dealDithFiles, monitor);
                }
            }
            foreach (FileOptionHelp.FileData filePath in fileDatas)
            {
                if (!filePath.Attributes.HasFlag((Enum)FileAttributes.Hidden))
                {
                    FileOptionHelp.CopyFile(parent1, filePath, ref importResult, dealDithFiles, monitor);
                }
            }
            return((ResourceItem)parent1);
        }