예제 #1
0
        } //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
        }
예제 #2
0
        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();
                        }
                    }
                }
            }
        }