private ulong calc_size(FileInfoEx info) { var ret = 0UL; if (((options & CopyEngineOptions.CopyFilesRecursive) == CopyEngineOptions.CopyFilesRecursive) && (info.Directory)) { if ((destination_remote) || (((options & CopyEngineOptions.CopySymlinkAsSymlink) != CopyEngineOptions.CopySymlinkAsSymlink) || (info.LinkInformation == null))) { var dir_enum = new FileInfoExEnumerable (Path.Combine(info.FullName, "*"), true, true, true, true); foreach (var ch_info in dir_enum) { ret += calc_size(ch_info); } } } else { if (Wildcard.Match(initial_mask, info.FileName, false)) { ret += info.Size; } } return(ret); }
private void calc_size_count(FileInfoEx dir_info, ref long size, ref long allocation, ref long file_count, ref long dir_count) { FileInfoExEnumerable dir_enum = new FileInfoExEnumerable (Path.Combine(dir_info.FullName, "*"), true, true, true, true); foreach (FileInfoEx info in dir_enum) { IntPtr h_file = IntPtr.Zero; try { h_file = WinAPiFSwrapper.CreateFileHandle (info.FullName, Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA, FileShare.ReadWrite | FileShare.Delete, FileMode.Open, info.Directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None); NT_FILE_STANDARD_INFORMATION s_info = ntApiFSwrapper.GetFileInfo_standard(h_file); size += s_info.EndOfFile; allocation += s_info.AllocationSize; //if (s_info.AllocationSize < s_info.EndOfFile) //{ // /*DEBUG*/ // long delta = s_info.EndOfFile - s_info.AllocationSize; //} } catch (Exception) { //Messages.ShowException // (ex, // string.Format // (Options.GetLiteral(Options.LANG_CANNOT_READ_ATTRIBUTES_0), // info.FullName)); break; } finally { if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero)) { WinApiFS.CloseHandle(h_file); } } if (info.Directory) { calc_size_count(info, ref size, ref allocation, ref file_count, ref dir_count); dir_count++; } else { file_count++; } } }
private void copy_dir(FileInfoEx source_info, string destination_dir) { if ((source_info.LinkInformation != null) && (!destination_remote) && ((options & CopyEngineOptions.CopySymlinkAsSymlink) == CopyEngineOptions.CopySymlinkAsSymlink)) { try { //copy link as link and returns Directory.CreateDirectory (destination_dir); switch (source_info.ReparseTag) { case IO_REPARSE_TAG.MOUNT_POINT: WinAPiFSwrapper.SetMountpoint(destination_dir, source_info.LinkInformation.SubstituteName, source_info.LinkInformation.PrintName); break; case IO_REPARSE_TAG.SYMLINK: //need test //link_target and unparsed prefix! need testing behavior of CreateSymbolicLink WinAPiFSwrapper.CreateSymbolicLink(destination_dir, source_info.LinkInformation.SubstituteName, true); //WinAPiFSwrapper.SetSymbolicLink(destination_dir, source_info.LinkInformation.SubstituteName, source_info.LinkInformation.PrintName, false); break; } } catch (Exception ex) { if (!process_error (string.Format (Options.GetLiteral(Options.LANG_CANNOT_CREATE_SOFT_LINK_0), destination_dir), ex)) { stop(); } } OnCopyItemDone(new ItemEventArs(source_info.FileName)); return; } if ((options & CopyEngineOptions.CopyFilesRecursive) == CopyEngineOptions.CopyFilesRecursive) { var dir_enum = new FileInfoExEnumerable (Path.Combine(source_info.FullName, "*"), true, true, true, true); foreach (var info in dir_enum) { if (abort_job) { return; } if (info.Directory) { copy_dir(info, Path.Combine(destination_dir, info.FileName)); } else { copy_one_file(info, Path.Combine(destination_dir, info.FileName)); } } } if ((options & CopyEngineOptions.CreateEmptyDirectories) == CopyEngineOptions.CreateEmptyDirectories) { create_empty_dir(source_info.FullName, destination_dir); OnCopyItemDone(new ItemEventArs(source_info.FileName)); } }
private void delete_entry(FileInfoEx entry) { /* * We first try to delete directory (if set flag DeleteEmptyDirectories) * if it is link, DeleteFile finction deletes link, not target, even if target not empty * and return. * If flag DeleteEmptyDirectories not setted, we check LinkInformation and * if it not null (that is entry is soft link) -> return, else * remove its contains. */ int win_err = 0; int res = 0; if (abort) { return; } if (!check_readonly(entry)) { return; } if (entry.Directory) { if (!check_readonly(entry)) { return; } //first try to delete dir, assume it is empty if ((opts & DeleteFileOptions.DeleteEmptyDirectories) == DeleteFileOptions.DeleteEmptyDirectories) { res = WinApiFS.RemoveDirectory(entry.FullName); if (res == 0) { win_err = Marshal.GetLastWin32Error(); if (win_err == WinApiFS.ERROR_DIR_NOT_EMPTY) { //directory not empty if ((opts & DeleteFileOptions.RecursiveDeleteFiles) == DeleteFileOptions.RecursiveDeleteFiles) { //recursive delete needed FileInfoExEnumerable dir_enum = new FileInfoExEnumerable (Path.Combine(entry.FullName, "*"), false, false, false, true); try { foreach (FileInfoEx info in dir_enum) { delete_entry(info); } } catch (Exception ex) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), ex); } }//end of dir enum //now dir probably empty res = WinApiFS.RemoveDirectory(entry.FullName); if (res == 0) { //not success win_err = Marshal.GetLastWin32Error(); if (win_err != WinApiFS.ERROR_DIR_NOT_EMPTY) //supress -> when delete on mask, //dir may be not empty { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(win_err)); } } }//end of dir not empty else { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(win_err)); } }//end of error process } else { //not to delete empty dirs //recursive delete needed (if not link) but directory not will remove //check reparse tag if ((opts & DeleteFileOptions.RecursiveDeleteFiles) == DeleteFileOptions.RecursiveDeleteFiles) { if (entry.LinkInformation == null) { FileInfoExEnumerable dir_enum = new FileInfoExEnumerable (Path.Combine(entry.FullName, "*"), false, false, false, true); try { foreach (FileInfoEx info in dir_enum) { delete_entry(info); } } catch (Exception ex) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), ex); } } } } }//end of if(entry.Directory) else { //entry is file //check mask if (Wildcard.Match(delete_mask, entry.FileName, false)) { if (check_readonly(entry)) { if (main_window != null) { main_window.NotifyLongOperation (string.Format(Options.GetLiteral(Options.LANG_DELETE_NOW_0), entry.FullName), true); } res = WinApiFS.DeleteFile(entry.FullName); if (res == 0) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(Marshal.GetLastWin32Error())); } } } } }