예제 #1
0
        public static void Move(string sourceFileName, string destFileName)
        {
            if (unix.IsUnix)
            {
                System.IO.File.Move(sourceFileName, destFileName);
                return;
            }

            if (sourceFileName == null || destFileName == null)
            {
                throw new ArgumentNullException((sourceFileName == null ? "sourceFileName" : "destFileName"), "ArgumentNull_FileName");
            }
            if (sourceFileName.Length == 0 || destFileName.Length == 0)
            {
                throw new ArgumentException("Argument_EmptyFileName", (sourceFileName.Length == 0 ? "sourceFileName" : "destFileName"));
            }

            string fullSourceFileName = NameFix.AddLongPathPrefix(sourceFileName);
            string fullDestFileName   = NameFix.AddLongPathPrefix(destFileName);

            if (!Exists(fullSourceFileName))
            {
                throw new Exception("ERROR_FILE_NOT_FOUND" + fullSourceFileName);
            }

            if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName))
            {
                int hr = Marshal.GetLastWin32Error();
                throw new Exception(GetErrorCode(hr), new Exception("ERROR_MOVING_FILE. (" + fullSourceFileName + " to " + fullDestFileName + ")"));
            }
        }
예제 #2
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
        public FileInfo[] GetFiles(string SearchPattern = "*")
        {
            List <FileInfo> files = new List <FileInfo>();

            try
            {
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(NameFix.AddLongPathPrefix(FullName));
                if (!di.Exists)
                {
                    return(files.ToArray());
                }

                System.IO.FileInfo[] arrDi = di.GetFiles(SearchPattern);
                foreach (System.IO.FileInfo tDi in arrDi)
                {
                    FileInfo lDi = new FileInfo
                    {
                        Name           = tDi.Name,
                        FullName       = Path.Combine(FullName, tDi.Name),
                        Length         = tDi.Length,
                        LastWriteTime  = tDi.LastWriteTimeUtc.Ticks,
                        LastAccessTime = tDi.LastAccessTimeUtc.Ticks,
                        CreationTime   = tDi.CreationTimeUtc.Ticks
                    };
                    files.Add(lDi);
                }
            }
            catch
            {
            }

            return(files.ToArray());
        }
예제 #3
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
        public DirectoryInfo[] GetDirectories()
        {
            List <DirectoryInfo> dirs = new List <DirectoryInfo>();

            try
            {
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(NameFix.AddLongPathPrefix(FullName));
                if (!di.Exists)
                {
                    return(dirs.ToArray());
                }

                System.IO.DirectoryInfo[] arrDi = di.GetDirectories();
                foreach (System.IO.DirectoryInfo tDi in arrDi)
                {
                    DirectoryInfo lDi = new DirectoryInfo
                    {
                        Name           = tDi.Name,
                        FullName       = Path.Combine(FullName, tDi.Name),
                        LastWriteTime  = tDi.LastWriteTimeUtc.Ticks,
                        LastAccessTime = tDi.LastAccessTimeUtc.Ticks,
                        CreationTime   = tDi.CreationTimeUtc.Ticks
                    };
                    dirs.Add(lDi);
                }
            }
            catch
            {
            }
            return(dirs.ToArray());
        }
예제 #4
0
        public FileInfo(string path)
        {
            FullName = path;
            Name     = Path.GetFileName(path);

            if (unix.IsUnix)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(path);

                if (!fi.Exists)
                {
                    return;
                }

                Length        = fi.Length;
                LastWriteTime = fi.LastWriteTimeUtc.Ticks;
                return;
            }

            string fileName = NameFix.AddLongPathPrefix(path);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA wIn32FileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();

            bool b = Win32Native.GetFileAttributesEx(fileName, 0, ref wIn32FileAttributeData);

            if (!b || (wIn32FileAttributeData.fileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0)
            {
                return;
            }

            Length        = Convert.Length(wIn32FileAttributeData.fileSizeHigh, wIn32FileAttributeData.fileSizeLow);
            LastWriteTime = Convert.Time(wIn32FileAttributeData.ftLastWriteTimeHigh, wIn32FileAttributeData.ftLastWriteTimeLow);
        }
예제 #5
0
        public static int OpenFileWrite(string path, out Stream stream)
        {
            if (unix.IsUnix)
            {
                try
                {
                    stream = new System.IO.FileStream(path, FileMode.Create, FileAccess.ReadWrite);
                    return(0);
                }
                catch (Exception)
                {
                    stream = null;
                    return(Marshal.GetLastWin32Error());
                }
            }


            string         filename = NameFix.AddLongPathPrefix(path);
            SafeFileHandle hFile    = Win32Native.CreateFile(filename,
                                                             GENERIC_READ | GENERIC_WRITE,
                                                             System.IO.FileShare.None,
                                                             IntPtr.Zero,
                                                             FileMode.Create,
                                                             FILE_ATTRIBUTE_NORMAL,
                                                             IntPtr.Zero);

            if (hFile.IsInvalid)
            {
                stream = null;
                return(Marshal.GetLastWin32Error());
            }

            stream = new System.IO.FileStream(hFile, FileAccess.ReadWrite);
            return(0);
        }
예제 #6
0
        public FileInfo[] GetFiles(string SearchPattern, bool includeHidden = true)
        {
            List <FileInfo> files = new List <FileInfo>();

            if (unix.IsUnix)
            {
                System.IO.DirectoryInfo di    = new System.IO.DirectoryInfo(FullName);
                System.IO.FileInfo[]    arrDi = di.GetFiles(SearchPattern);
                foreach (System.IO.FileInfo tDi in arrDi)
                {
                    FileInfo lDi = new FileInfo
                    {
                        Name          = tDi.Name,
                        FullName      = Path.Combine(FullName, tDi.Name),
                        Length        = tDi.Length,
                        LastWriteTime = tDi.LastWriteTimeUtc.Ticks
                    };
                    files.Add(lDi);
                }
                return(files.ToArray());
            }

            string dirName = NameFix.AddLongPathPrefix(FullName);

            Win32Native.WIN32_FIND_DATA findData = new Win32Native.WIN32_FIND_DATA();
            SafeFindHandle findHandle            = Win32Native.FindFirstFile(dirName + @"\" + SearchPattern, findData);

            if (!findHandle.IsInvalid)
            {
                do
                {
                    string currentFileName = findData.cFileName;

                    // if this is a directory, find its contents
                    if ((findData.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0)
                    {
                        continue;
                    }
                    if (!includeHidden && (findData.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_HIDDEN) != 0)
                    {
                        continue;
                    }

                    FileInfo fi = new FileInfo
                    {
                        Name          = currentFileName,
                        FullName      = Path.Combine(FullName, currentFileName),
                        Length        = Convert.Length(findData.nFileSizeHigh, findData.nFileSizeLow),
                        LastWriteTime = Convert.Time(findData.ftLastWriteTimeHigh, findData.ftLastWriteTimeLow)
                    };
                    files.Add(fi);
                }while (Win32Native.FindNextFile(findHandle, findData));
            }

            // close the find handle
            findHandle.Dispose();

            return(files.ToArray());
        }
예제 #7
0
        public static void Delete(string path)
        {
            if (unix.IsUnix)
            {
                System.IO.Directory.Delete(path);
                return;
            }

            string fullPath = NameFix.AddLongPathPrefix(path);

            Win32Native.RemoveDirectory(fullPath);
        }
예제 #8
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static bool SetAttributes(string path, FileAttributes fileAttributes)
 {
     try
     {
         System.IO.File.SetAttributes(NameFix.AddLongPathPrefix(path), (System.IO.FileAttributes)fileAttributes);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #9
0
        public static void Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            if (unix.IsUnix)
            {
                System.IO.File.Copy(sourceFileName, destFileName, overwrite);
                return;
            }

            if (sourceFileName == null || destFileName == null)
            {
                throw new ArgumentNullException((sourceFileName == null ? "sourceFileName" : "destFileName"), "ArgumentNull_FileName");
            }
            if (sourceFileName.Length == 0 || destFileName.Length == 0)
            {
                throw new ArgumentException("Argument_EmptyFileName", (sourceFileName.Length == 0 ? "sourceFileName" : "destFileName"));
            }

            string fullSourceFileName = NameFix.AddLongPathPrefix(sourceFileName);
            string fullDestFileName   = NameFix.AddLongPathPrefix(destFileName);

            bool r = Win32Native.CopyFile(fullSourceFileName, fullDestFileName, !overwrite);

            if (!r)
            {
                // Save Win32 error because subsequent checks will overwrite this HRESULT.
                int    errorCode = Marshal.GetLastWin32Error();
                string fileName  = destFileName;

                /*
                 * if (errorCode != Win32Native.ERROR_FILE_EXISTS)
                 * {
                 *  // For a number of error codes (sharing violation, path
                 *  // not found, etc) we don't know if the problem was with
                 *  // the source or dest file.  Try reading the source file.
                 *  using (SafeFileHandle handle = Win32Native.UnsafeCreateFile(fullSourceFileName, FileStream.GENERIC_READ, FileShare.Read, null, FileMode.Open, 0, IntPtr.Zero))
                 *  {
                 *      if (handle.IsInvalid)
                 *          fileName = sourceFileName;
                 *  }
                 *
                 *  if (errorCode == Win32Native.ERROR_ACCESS_DENIED)
                 *  {
                 *      if (Directory.InternalExists(fullDestFileName))
                 *          throw new IOException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_FileIsDirectory_Name"), destFileName), Win32Native.ERROR_ACCESS_DENIED, fullDestFileName);
                 *  }
                 * }
                 *
                 * __Error.WinIOError(errorCode, fileName);
                 *
                 */
            }
        }
예제 #10
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static int OpenFileWrite(string path, out Stream stream)
 {
     try
     {
         stream = new System.IO.FileStream(NameFix.AddLongPathPrefix(path), FileMode.Create, FileAccess.ReadWrite);
         return(0);
     }
     catch (Exception)
     {
         stream = null;
         return(Marshal.GetLastWin32Error());
     }
 }
예제 #11
0
        public DirectoryInfo(string path)
        {
            FullName = path;
            Name     = Path.GetFileName(path);

            System.IO.DirectoryInfo fi = new System.IO.DirectoryInfo(NameFix.AddLongPathPrefix(path));

            if (!fi.Exists)
            {
                return;
            }

            LastWriteTime = fi.LastWriteTimeUtc.Ticks;
        }
예제 #12
0
파일: RVIO.cs 프로젝트: RomVault/RVWorld
        public DirectoryInfo(string path)
        {
            FullName = path;
            Name     = Path.GetFileName(path);

            System.IO.DirectoryInfo fi = new System.IO.DirectoryInfo(NameFix.AddLongPathPrefix(path));

            if (!fi.Exists)
            {
                return;
            }

            try { LastWriteTime = fi.LastWriteTimeUtc.Ticks; } catch { LastWriteTime = 0; }
            try { LastAccessTime = fi.LastAccessTimeUtc.Ticks; } catch { LastAccessTime = 0; }
            try { CreationTime = fi.CreationTimeUtc.Ticks; } catch { CreationTime = 0; }
        }
예제 #13
0
        public static bool Exists(string path)
        {
            if (unix.IsUnix)
            {
                return(System.IO.File.Exists(path));
            }


            string fixPath = NameFix.AddLongPathPrefix(path);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA wIn32FileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();

            bool b = Win32Native.GetFileAttributesEx(fixPath, 0, ref wIn32FileAttributeData);

            return(b && (wIn32FileAttributeData.fileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) == 0);
        }
예제 #14
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
        public FileInfo(string path)
        {
            FullName = path;
            Name     = Path.GetFileName(path);

            System.IO.FileInfo fi = new System.IO.FileInfo(NameFix.AddLongPathPrefix(path));

            if (!fi.Exists)
            {
                return;
            }

            Length         = fi.Length;
            LastWriteTime  = fi.LastWriteTimeUtc.Ticks;
            LastAccessTime = fi.LastAccessTimeUtc.Ticks;
            CreationTime   = fi.CreationTimeUtc.Ticks;
        }
예제 #15
0
        public static void Move(string sourceDirName, string destDirName)
        {
            if (unix.IsUnix)
            {
                System.IO.Directory.Move(sourceDirName, destDirName);
                return;
            }


            if (sourceDirName == null)
            {
                throw new ArgumentNullException("sourceDirName");
            }
            if (sourceDirName.Length == 0)
            {
                throw new ArgumentException("Argument_EmptyFileName", "sourceDirName");
            }

            if (destDirName == null)
            {
                throw new ArgumentNullException("destDirName");
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException("Argument_EmptyFileName", "destDirName");
            }

            string fullsourceDirName = NameFix.AddLongPathPrefix(sourceDirName);

            string fulldestDirName = NameFix.AddLongPathPrefix(destDirName);

            if (!Win32Native.MoveFile(fullsourceDirName, fulldestDirName))
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr == Win32Native.ERROR_FILE_NOT_FOUND) // Source dir not found
                {
                    throw new Exception("ERROR_PATH_NOT_FOUND " + fullsourceDirName);
                }
                if (hr == Win32Native.ERROR_ACCESS_DENIED) // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp.
                {
                    throw new Exception("UnauthorizedAccess_IODenied_Path" + sourceDirName);
                }
            }
        }
예제 #16
0
        public static bool SetAttributes(string path, FileAttributes fileAttributes)
        {
            if (unix.IsUnix)
            {
                try
                {
                    System.IO.File.SetAttributes(path, (System.IO.FileAttributes)fileAttributes);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            string fullPath = NameFix.AddLongPathPrefix(path);

            return(Win32Native.SetFileAttributes(fullPath, (int)fileAttributes));
        }
예제 #17
0
파일: RVIO.cs 프로젝트: WinCoder/RomVault
        public static void Delete(String path)
        {
            if (unix.IsUnix)
            {
                System.IO.File.Delete(path);
                return;
            }


            string fixPath = NameFix.AddLongPathPrefix(path);

            if (!Win32Native.DeleteFile(fixPath))
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr != Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    throw new Exception("Error while deleting file :" + path);
                }
            }
        }
예제 #18
0
        public static void Delete(string path)
        {
            if (unix.IsUnix)
            {
                System.IO.File.Delete(path);
                return;
            }


            string fixPath = NameFix.AddLongPathPrefix(path);

            if (!Win32Native.DeleteFile(fixPath))
            {
                int hr = Marshal.GetLastWin32Error();
                if (hr != Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    throw new Exception(GetErrorCode(hr), new Exception("ERROR_DELETING_FILE. (" + path + ")"));
                }
            }
        }
예제 #19
0
        public static void CreateDirectory(string path)
        {
            if (unix.IsUnix)
            {
                System.IO.Directory.CreateDirectory(path);
                return;
            }


            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length == 0)
            {
                throw new ArgumentException("Argument_PathEmpty");
            }

            string fullPath = NameFix.AddLongPathPrefix(path);

            Win32Native.CreateDirectory(fullPath, IntPtr.Zero);
        }
예제 #20
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static void Move(string sourceDirName, string destDirName)
 {
     System.IO.Directory.Move(NameFix.AddLongPathPrefix(sourceDirName), NameFix.AddLongPathPrefix(destDirName));
 }
예제 #21
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static void CreateDirectory(string path)
 {
     System.IO.Directory.CreateDirectory(NameFix.AddLongPathPrefix(path));
 }
예제 #22
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static bool Exists(string path)
 {
     return(System.IO.File.Exists(NameFix.AddLongPathPrefix(path)));
 }
예제 #23
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static void Copy(string sourceFileName, string destFileName, bool overwrite)
 {
     System.IO.File.Copy(NameFix.AddLongPathPrefix(sourceFileName), NameFix.AddLongPathPrefix(destFileName), overwrite);
 }
예제 #24
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static void Move(string sourceFileName, string destFileName)
 {
     System.IO.File.Move(NameFix.AddLongPathPrefix(sourceFileName), NameFix.AddLongPathPrefix(destFileName));
 }
예제 #25
0
파일: RVIO.cs 프로젝트: artifexor/RVWorld
 public static void Delete(string path)
 {
     System.IO.File.Delete(NameFix.AddLongPathPrefix(path));
 }