private void FillStandardPage(string file_name) { IntPtr file_handle = IntPtr.Zero; string nt_file_name = IOhelper.GetUnicodePath(file_name); try { textBoxName.Text = string.Format ("{0}", Path.GetFileName(file_name)); // find data -------------------------------------- WIN32_FIND_DATA f_data = new WIN32_FIND_DATA(); WinAPiFSwrapper.GetFileInfo(file_name, ref f_data); textBoxAttributes.Text = f_data.dwFileAttributes.ToString(); textBoxAltname.Text = f_data.cAlternateFileName; textBoxReaprseTag.Text = f_data.ReparseTag.ToString(); //-------------------------------------------------- fileSystemSecurityViewer1.FillContains(file_name); try { fill_basic_info(); //fill_device(); fill_standard_info(); //fill_volume_attr(); //fill_volume_info(); fill_links(f_data.ReparseTag); fill_dir_size(); } catch (Exception ex) { Messages.ShowException(ex); } try { streamViewer1.FillContents(file_name); } catch (Exception) { } } catch (Exception ex) { Messages.ShowException(ex); } finally { if ((file_handle != IntPtr.Zero) && (file_handle.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE)) { WinApiFS.CloseHandle(file_handle); } } }
} //end of proc /// <summary> /// work only if source and destination on one volume /// </summary> /// <param name="source">can be file or dir</param> /// <param name="destination">file or dir</param> private void move_one_item(FileInfoEx source, string destination) { //prepare callback buffer if (callback_data != IntPtr.Zero) { Marshal.FreeHGlobal(callback_data); } callback_data = IOhelper.strings_to_buffer(source.FullName, destination); //prepare uni names var source_uni = IOhelper.GetUnicodePath(source.FullName); var destination_uni = IOhelper.GetUnicodePath(destination); //call update dialog before... var e_begin_move = new UpdateProgressArgs(); e_begin_move.DestinationFile = destination; e_begin_move.EnableTotalProgress = false; e_begin_move.Reason = UpdateProgressReason.StreamSwitch; e_begin_move.SourceFile = source.FullName; update_progress_safe(e_begin_move); //and call MoveFileWithProgress var res = WinApiFS.MoveFileWithProgress (source_uni, destination_uni, move_progress_delegate_holder, callback_data, options_api); if (res == 0) { var win_err = Marshal.GetLastWin32Error(); var win_ex = new Win32Exception(win_err); AbortJobSafe = !process_errors (string.Format (Options.GetLiteral(Options.LANG_CANNOT_MOVE_0_ARROW_1), source, destination), win_ex); return; } //success move //notify item done - not needed, source item deleted }
private void search_in_directory_with_subdirs(string dir_path) { //first find matches in current dir search_in_directory(dir_path); //check abort if (Abort) { return; } //see directories var search_path = IOhelper.GetUnicodePath(dir_path); search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar }); search_path = search_path + Path.DirectorySeparatorChar + "*"; var fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_path, true); foreach (var data in fs_enum) { //check abort if (Abort) { break; } //skip some entries if (data.cFileName == "..") { continue; } if (data.cFileName == ".") { continue; } if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory) { //recursive call search_in_directory_with_subdirs(Path.Combine(dir_path, data.cFileName)); } } }
private void copy_one_file(FileInfoEx source_info, string destination_file) { //check mask if (!Wildcard.Match(initial_mask, source_info.FileName)) { return; } var success = false; //now prepare callback buffer if (callback_data != IntPtr.Zero) { Marshal.FreeHGlobal(callback_data); } callback_data = IOhelper.strings_to_buffer(source_info.FullName, destination_file); //prepare uni names var source_uni = IOhelper.GetUnicodePath(source_info.FullName); var dest_uni = IOhelper.GetUnicodePath(destination_file); //string source_uni = source_info.FullName; //string dest_uni = destination_file; //and call CopyFileEx first time var res = WinApiFS.CopyFileEx (source_uni, dest_uni, copy_progress_routine_delegate_holder, callback_data, IntPtr.Zero, copyFileEx_options); if (res == 0) { var win_err = Marshal.GetLastWin32Error(); //process win_err and do second take if needed var temp_copy_options = copyFileEx_options; if (process_CopyFileEx_errors(source_info, destination_file, win_err, ref temp_copy_options)) { //second take res = WinApiFS.CopyFileEx (source_uni, dest_uni, copy_progress_routine_delegate_holder, callback_data, IntPtr.Zero, temp_copy_options); if (res == 0) { win_err = Marshal.GetLastWin32Error(); var win_ex_2 = new Win32Exception(win_err); if (!process_error (string.Format (Options.GetLiteral(Options.LANG_CANNOT_COPY_0_ARROW_1), source_info.FullName, destination_file), win_ex_2)) { stop(); } } else { success = true; } } }//end of res==0 brunch else { //copy success success = true; } if (success) { //update counts total_bytes_transferred += current_file_bytes_transferred; current_file_bytes_transferred = 0; total_files_copied++; //time to notify current panel -> unset selection var e_file_done = new ItemEventArs(source_info.FileName); OnCopyItemDone(e_file_done); //set sec attributes if needed if ((options & CopyEngineOptions.CopySecurityAttributes) == CopyEngineOptions.CopySecurityAttributes) { try { File.SetAccessControl(destination_file, File.GetAccessControl(source_info.FullName)); } catch (Exception ex) { if (!process_error (string.Format (Options.GetLiteral(Options.LANG_CANNOT_SET_SEC_ATTRIBUTES_0), destination_file), ex)) { stop(); } } } } }
protected override void internal_refill() { //stop change file system notyfications internal_watcher.EnableRaisingEvents = false; //we will fill new_list first //if errors will not occurs, fill work list List <WIN32_FIND_DATA> new_list = new List <WIN32_FIND_DATA>(); try { string search_path = IOhelper.GetUnicodePath(directory_path); search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar }); search_path = search_path + Path.DirectorySeparatorChar + "*"; WinAPiFSwrapper.WIN32_FIND_DATA_enumerable fs_enum = new WinAPiFSwrapper.WIN32_FIND_DATA_enumerable(search_path); foreach (WIN32_FIND_DATA data in fs_enum) { if (data.cFileName == ".") //skip entry "." - that is current directory { continue; } new_list.Add(data); } //workaround for directory path like \\server_name\share$ //for that path there is no '..' entry returned from fs_enum if ((directory_path.EndsWith("$")) && (directory_path.StartsWith(@"\\"))) { bool need_add = true; for (int i = 0; i < new_list.Count; i++) { if (new_list[i].cFileName == "..") { need_add = false; break; } } if (need_add) { WIN32_FIND_DATA fake_net_data = new WIN32_FIND_DATA(); fake_net_data.cFileName = ".."; fake_net_data.dwFileAttributes = FileAttributes.Directory; new_list.Add(fake_net_data); } } //if no errors... internal_list.Clear(); cache_directory_count = 0; cache_directory_selected_count = 0; cache_files_count = 0; cache_files_selected_count = 0; cache_selected_indices = new int[] { }; cache_size = 0UL; cache_size_selected = 0UL; //update internal_list, counts, skip parent dir entry foreach (WIN32_FIND_DATA data in new_list) { internal_list.Add(data, null); if (data.cFileName == "..") { continue; } if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory) { cache_directory_count++; } else { cache_files_count++; cache_size += data.FileSize; } } //set notificator internal_watcher.Filter = string.Empty; internal_watcher.Path = directory_path; try { internal_watcher.EnableRaisingEvents = true; } catch (Exception ex) { //Messages.ShowException(ex); } } catch (Exception ex) { throw ex; } }