コード例 #1
0
ファイル: FileModel.cs プロジェクト: netnutch/FileExplorer
        private void Rename(string oldPath, string newPath)
        {
            FileModelCache.TryRemove(FullPath, out _);

            FullPath   = FullPath.Replace(oldPath, newPath);
            ParentPath = ParentPath.Replace(oldPath, newPath);

            FileModelCache.TryAdd(FullPath, this);

            if (Folders != null)
            {
                foreach (FileModel folder in Folders)
                {
                    folder.Rename(oldPath, newPath);
                }
            }

            if (Files != null)
            {
                foreach (FileModel file in Files)
                {
                    file.Rename(oldPath, newPath);
                }
            }
        }
コード例 #2
0
ファイル: FileModel.cs プロジェクト: netnutch/FileExplorer
        public static FileModel FromPath(string path)
        {
            FileModel fileModel = FileModelCache.GetOrAdd(path, Create);

            if (fileModel.IsRoot)
            {
                return(fileModel);
            }

            if (FileSystemHelper.IsDrive(path))
            {
                DriveInfo driveInfo = new DriveInfo(path);
                fileModel.Initialize(driveInfo);
            }
            else if (Directory.Exists(path))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                fileModel.Initialize(directoryInfo);
            }
            else
            {
                FileInfo fileInfo = new FileInfo(path);
                fileModel.Initialize(fileInfo);
            }

            return(fileModel);
        }
コード例 #3
0
ファイル: FileModel.cs プロジェクト: netnutch/FileExplorer
        public static FileModel FromDriveInfo(DriveInfo driveInfo)
        {
            FileModel fileModel = FileModelCache.GetOrAdd(driveInfo.Name, Create);

            fileModel.Initialize(driveInfo);

            return(fileModel);
        }
コード例 #4
0
ファイル: FileModel.cs プロジェクト: netnutch/FileExplorer
        public static FileModel FromFileInfo(FileInfo fileInfo)
        {
            FileModel fileModel = FileModelCache.GetOrAdd(fileInfo.FullName, Create);

            fileModel.Initialize(fileInfo);

            return(fileModel);
        }
コード例 #5
0
ファイル: FileModel.cs プロジェクト: netnutch/FileExplorer
        public static FileModel FromDirectoryInfo(DirectoryInfo directoryInfo)
        {
            FileModel fileModel = FileModelCache.GetOrAdd(directoryInfo.FullName, Create);

            fileModel.Initialize(directoryInfo);

            return(fileModel);
        }
コード例 #6
0
ファイル: FileModel.cs プロジェクト: omeryanar/FileExplorer
        public static FileModel FromPath(string path)
        {
            FileModel fileModel = FileModelCache.GetOrAdd(path, Create);

            if (fileModel.IsRoot)
            {
                return(fileModel);
            }

            if (FileSystemHelper.IsDrive(path))
            {
                DriveInfo driveInfo = new DriveInfo(path);
                fileModel.Initialize(driveInfo);
            }
            else if (FileSystemHelper.IsNetworkHost(path))
            {
                string hostName = FileSystemHelper.GetHostName(path);

                fileModel.Name      = hostName;
                fileModel.FullName  = hostName;
                fileModel.FullPath  = path;
                fileModel.Extension = String.Empty;

                fileModel.IsRoot      = true;
                fileModel.IsDirectory = true;

                fileModel.Parent     = FileSystemHelper.Network;
                fileModel.ParentPath = FileSystemHelper.NetworkPath;

                FileSystemHelper.Network.Folders.Add(fileModel);
            }
            else if (FileSystemHelper.IsNetworkShare(path))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                fileModel.Initialize(directoryInfo);

                fileModel.ParentPath = FileSystemHelper.GetParentFolderPath(path);
                fileModel.Parent     = FromPath(fileModel.ParentPath);
            }
            else if (Directory.Exists(path))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                fileModel.Initialize(directoryInfo);
            }
            else
            {
                FileInfo fileInfo = new FileInfo(path);
                fileModel.Initialize(fileInfo);
            }

            return(fileModel);
        }