コード例 #1
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
        public void CreateDirectory(string path, bool bCheckIfExist = false)
        {
            bool bExists = false;

            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            if (bCheckIfExist)
            {
                bExists = DirectoryExists(path);
            }

            if (!(bExists & bCheckIfExist))
            {
                string directoryName = GetDirectoryName(path);

                if (!IsLongPath(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                else
                {
                    Win32LongPathDirectory.CreateDirectory(path);
                }
            }
        }
コード例 #2
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
        public bool MoveDirectory(string sourcePath, string targetPath, bool bCreateFolder = false)
        {
            //  Trace.WriteLine($"Move Directory: {sourcePath} --> {targetPath}");

            bool bResult = false;

            if (bCreateFolder)
            {
                string targetDirectoryName = GetDirectoryName(targetPath);

                if (!DirectoryExists(targetDirectoryName))
                {
                    CreateDirectory(targetDirectoryName);
                }
            }

            bool bRetry = false;

            do
            {
                try
                {
                    bRetry = false;
                    if (!IsLongPath(sourcePath) && !IsLongPath(targetPath))
                    {
                        Directory.Move(sourcePath, targetPath);
                    }
                    else
                    {
                        Win32LongPathDirectory.Move(sourcePath, targetPath);
                    }
                    bResult = true;
                }
                catch (IOException ex)
                {
                    //ProfileDataRefreshTask
                    var project = BackupProjectRepository.Instance.SelectedBackupProject;
                    if (project.BackupProfileList.FirstOrDefault(p => (p.ProfileDataRefreshTask != null) && p.ProfileDataRefreshTask.IsBusy) != null)
                    {
                        Thread.Sleep(1000);
                        bRetry = true;
                    }
                    else
                    {
                        MessageBoxResult result = MessageBoxResult.None;
                        result = MessageBox.Show($"{ex.Message}\n\nPress Yes to retry or No to Cancel", "Directory Access", MessageBoxButton.YesNoCancel, MessageBoxImage.Error);

                        if (result == MessageBoxResult.Yes)
                        {
                            bRetry = true;
                        }
                    }
                }
            }while (bRetry);

            return(bResult);
        }
コード例 #3
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
 public List <string> GetFiles(string directory, string searchPattern = null, SearchOption searchOption = SearchOption.TopDirectoryOnly)
 {
     if (!IsLongPath(directory))
     {
         return(Directory.GetFiles(directory)?.ToList());
     }
     else
     {
         return(Win32LongPathDirectory.GetFiles(directory, searchPattern, searchOption));
     }
 }
コード例 #4
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
 public string[] GetDirectories(string path, string searchPattern = null, System.IO.SearchOption searchOption = SearchOption.TopDirectoryOnly)
 {
     if (!IsLongPath(path))
     {
         return(Directory.GetFiles(path, searchPattern));
     }
     else
     {
         return(Win32LongPathDirectory.GetDirectories(path, searchPattern, searchOption));
     }
 }
コード例 #5
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
 public bool DirectoryExists(string path)
 {
     if ((path == null) || (path == string.Empty))
     {
         return(false);
     }
     else if (!IsLongPath(path))
     {
         return(System.IO.Directory.Exists(path));
     }
     else
     {
         return(Win32LongPathDirectory.Exists(path));
     }
 }
コード例 #6
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
        public string[] GetDirectories(string path)
        {
            string[] setEntries = null;

            if (path != null)
            {
                if (!IsLongPath(path))
                {
                    setEntries = Directory.GetDirectories(path);
                }
                else
                {
                    setEntries = Win32LongPathDirectory.GetDirectories(path);
                }
            }

            return(setEntries);
        }
コード例 #7
0
 private static void DeleteDirectoriesRecrusive(string[] directories)
 {
     foreach (string directory in directories)
     {
         var files = Win32LongPathDirectory.GetFiles(GetWin32LongPath(directory), null, System.IO.SearchOption.TopDirectoryOnly);
         foreach (string file in files)
         {
             Win32LongPathFile.Delete(GetWin32LongPath(file));
         }
         directories = Win32LongPathDirectory.GetDirectories(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         DeleteDirectoriesRecrusive(directories);
         bool ok = Win32FileSystem.RemoveDirectory(GetWin32LongPath(directory));
         if (!ok)
         {
             ThrowWin32Exception();
         }
     }
 }
コード例 #8
0
        public static List <string> GetFiles(string path, string searchPattern = "*", System.IO.SearchOption searchOption = System.IO.SearchOption.TopDirectoryOnly)
        {
            searchPattern = searchPattern ?? "*";

            var files = new List <string>();
            var dirs  = new List <string> {
                GetWin32LongPath(path)
            };

            if (searchOption == System.IO.SearchOption.AllDirectories)
            {
                //Add all the subpaths
                dirs.AddRange(Win32LongPathDirectory.GetDirectories(path, null, System.IO.SearchOption.AllDirectories));
            }

            foreach (var dir in dirs)
            {
                Win32FileSystem.WIN32_FIND_DATA findData;
                IntPtr findHandle = Win32FileSystem.FindFirstFile(System.IO.Path.Combine(GetWin32LongPath(dir), searchPattern), out findData);

                try
                {
                    if (findHandle != new IntPtr(-1))
                    {
                        do
                        {
                            if ((findData.dwFileAttributes & System.IO.FileAttributes.Directory) == 0)
                            {
                                string filename = System.IO.Path.Combine(dir, findData.cFileName);
                                files.Add(GetCleanPath(filename));
                            }
                        } while (Win32FileSystem.FindNextFile(findHandle, out findData));
                        Win32FileSystem.FindClose(findHandle);
                    }
                }
                catch (Exception)
                {
                    Win32FileSystem.FindClose(findHandle);
                    throw;
                }
            }

            return(files);
        }
コード例 #9
0
ファイル: FileSystemStorage.cs プロジェクト: vedaker/BPTiger
        public bool DeleteDirectory(string path, bool bRecursive = false)
        {
            if (!IsLongPath(path))
            {
                //Handle read only
                //SetFileAttribute(directory, FileAttributes.Normal);
                try
                {
                    Directory.Delete(path, bRecursive);
                }
                catch (System.IO.IOException)
                {
                    //Retry if recrusive path is long path
                    Win32LongPathDirectory.Delete(path, bRecursive);
                }
            }
            else
            {
                Win32LongPathDirectory.Delete(path, bRecursive);
            }

            return(true);
        }