Exemplo n.º 1
0
        private void CreateFSIFolder(DirectoryInfo fsobject, IFsiDirectoryItem diritem)
        {
            if (fsobject == null || diritem == null || _cancel)
            {
                return;
            }
            DirectoryInfo pysicalFolder = null;

            pysicalFolder = new DirectoryInfo(UniqueListFileSystemInfo.GetPhysicalPath(fsobject.FullName.TrimEnd('\\')));
            IFsiDirectoryItem crtdiritem = null;

            if (diritem.FullPath.Length == 0)
            {
                try
                {
                    var newpath = string.Format("{0}\\{1}", diritem.FullPath, pysicalFolder.Name);
                    if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
                    {
                        diritem.AddDirectory(pysicalFolder.Name);
                    }
                }
                catch
                {
                }
                crtdiritem = diritem[pysicalFolder.Name] as IFsiDirectoryItem;
            }
            else
            {
                crtdiritem = diritem;
            }
            var files = pysicalFolder.GetFiles("*"); //all files

            foreach (var file in files)
            {
                if (_cancel)
                {
                    return;
                }
                CreateFSIFile(file, crtdiritem);
            }

            DirectoryInfo[] folders = null;
            folders = pysicalFolder.GetDirectories("*");
            if (folders != null && folders.Length > 0)
            {
                foreach (var folder in folders)
                {
                    if (_cancel)
                    {
                        return;
                    }
                    try
                    {
                        var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, folder.Name);
                        if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
                        {
                            crtdiritem.AddDirectory(folder.Name);
                        }
                    }
                    catch
                    {
                        Cancel = true;
                        throw;
                    }
                    var subdir = crtdiritem[folder.Name] as IFsiDirectoryItem;
                    CreateFSIFolder(folder, subdir);
                }
            }
        }