2020-05-06 17:53:34 +02:00
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
2021-06-30 13:38:29 +02:00
|
|
|
// SELECTION //
|
2020-05-06 17:53:34 +02:00
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2021-06-30 13:38:29 +02:00
|
|
|
void unselectAll() {
|
|
|
|
selected_count[active_panel] = 0;
|
|
|
|
if (active_panel) {
|
|
|
|
selected0.drop();
|
|
|
|
} else {
|
|
|
|
selected1.drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dword getSelectedCount() {
|
|
|
|
return selected_count[active_panel];
|
|
|
|
}
|
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
void setElementSelectedFlag(dword n, int state) {
|
2021-06-30 13:38:29 +02:00
|
|
|
if (n==0) && (strncmp(items.get(n)*304+buf+72,"..",2)==0) return;
|
|
|
|
if (active_panel) {
|
|
|
|
selected0.set(n, state);
|
|
|
|
} else {
|
|
|
|
selected1.set(n, state);
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
2021-06-30 13:38:29 +02:00
|
|
|
if (state==true) selected_count[active_panel]++;
|
2021-07-04 14:21:21 +02:00
|
|
|
if (state==false) && (selected_count[active_panel]>0) selected_count[active_panel]--;
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int getElementSelectedFlag(dword n) {
|
2021-06-30 13:38:29 +02:00
|
|
|
if (active_panel) {
|
|
|
|
return selected0.get(n);
|
|
|
|
} else {
|
|
|
|
return selected1.get(n);
|
|
|
|
}
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dword GetFilesCount(dword _in_path)
|
|
|
|
{
|
|
|
|
BDVK file_info_count;
|
|
|
|
DIR_SIZE paste_dir_size;
|
|
|
|
|
|
|
|
GetFileInfo(_in_path, #file_info_count);
|
|
|
|
if ( file_info_count.isfolder ) {
|
|
|
|
return paste_dir_size.get(_in_path);
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// COPY AND PASTE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
byte copy_to[4096];
|
|
|
|
byte copy_from[4096];
|
|
|
|
bool cut_active = false;
|
|
|
|
|
2021-06-15 20:22:58 +02:00
|
|
|
enum {COPY, CUT, DELETE};
|
2020-05-06 17:53:34 +02:00
|
|
|
|
2021-06-15 20:22:58 +02:00
|
|
|
void CopyFilesListToClipboard(bool _cut_active)
|
2020-05-06 17:53:34 +02:00
|
|
|
{
|
|
|
|
byte copy_t[4096];
|
|
|
|
dword buff_data;
|
|
|
|
dword path_len = 0;
|
|
|
|
dword size_buf = 0;
|
|
|
|
dword copy_buf_offset = 0;
|
|
|
|
dword i;
|
|
|
|
|
|
|
|
if (files.count<=0) return; //no files
|
|
|
|
|
2021-06-17 19:06:34 +02:00
|
|
|
if (_cut_active!=DELETE) cut_active = _cut_active;
|
2020-05-06 17:53:34 +02:00
|
|
|
|
|
|
|
//if no element selected by "Insert" key, then we copy current element
|
2021-06-30 13:38:29 +02:00
|
|
|
if (!getSelectedCount()) {
|
2020-05-06 17:53:34 +02:00
|
|
|
setElementSelectedFlag(files.cur_y, true);
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:38:29 +02:00
|
|
|
if (!getSelectedCount()) return;
|
2020-05-06 17:53:34 +02:00
|
|
|
|
2021-06-25 11:52:19 +02:00
|
|
|
size_buf = 10;
|
2020-05-06 17:53:34 +02:00
|
|
|
for (i=0; i<files.count; i++)
|
|
|
|
{
|
|
|
|
if (getElementSelectedFlag(i) == true) {
|
2021-06-27 11:28:59 +02:00
|
|
|
sprintf(#copy_t,"%s/%s",path,items.get(i)*304+buf+72);
|
2020-05-06 17:53:34 +02:00
|
|
|
path_len = strlen(#copy_t);
|
|
|
|
size_buf += path_len + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buff_data = malloc(size_buf);
|
|
|
|
ESDWORD[buff_data] = size_buf;
|
|
|
|
ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
|
2021-06-30 13:38:29 +02:00
|
|
|
ESINT[buff_data+8] = getSelectedCount();
|
2020-05-06 17:53:34 +02:00
|
|
|
copy_buf_offset = buff_data + 10;
|
|
|
|
for (i=0; i<files.count; i++)
|
|
|
|
{
|
|
|
|
if (getElementSelectedFlag(i) == true) {
|
2021-06-27 11:28:59 +02:00
|
|
|
sprintf(copy_buf_offset,"%s/%s",path,items.get(i)*304+buf+72);
|
2020-05-06 17:53:34 +02:00
|
|
|
copy_buf_offset += strlen(copy_buf_offset) + 1;
|
2020-05-29 12:54:04 +02:00
|
|
|
|
|
|
|
if (cut_active) {
|
|
|
|
if (i>=files.first) && (i<files.first+files.visible)
|
2021-06-24 22:51:21 +02:00
|
|
|
PutShadow(files.x+4,i-files.first*files.item_h+files.y,icons16_default.w,files.item_h,1,-3);
|
2020-05-29 12:54:04 +02:00
|
|
|
}
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-29 12:54:04 +02:00
|
|
|
if (cut_active) {
|
|
|
|
pause(20);
|
2020-05-29 13:05:55 +02:00
|
|
|
List_ReDraw();
|
2020-05-29 12:54:04 +02:00
|
|
|
}
|
2021-06-30 13:38:29 +02:00
|
|
|
if (getSelectedCount()==1) setElementSelectedFlag(files.cur_y, false);
|
2020-05-06 17:53:34 +02:00
|
|
|
Clipboard__SetSlotData(size_buf, buff_data);
|
|
|
|
free(buff_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PasteThread()
|
|
|
|
{
|
|
|
|
char copy_rezult;
|
2021-06-12 23:12:15 +02:00
|
|
|
int j, i, slash_count=0;
|
2020-05-06 17:53:34 +02:00
|
|
|
int paste_elements_count = 0;
|
2021-06-28 00:16:37 +02:00
|
|
|
dword clipbuf;
|
2020-05-06 17:53:34 +02:00
|
|
|
dword path_offset;
|
|
|
|
|
2021-06-28 00:16:37 +02:00
|
|
|
clipbuf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
|
|
|
|
if (DSDWORD[clipbuf+4] != 3) return;
|
|
|
|
paste_elements_count = ESINT[clipbuf+8];
|
|
|
|
path_offset = clipbuf + 10;
|
2020-05-06 17:53:34 +02:00
|
|
|
|
|
|
|
if (cut_active) {
|
|
|
|
DisplayOperationForm(MOVE_FLAG);
|
|
|
|
} else {
|
|
|
|
DisplayOperationForm(COPY_FLAG);
|
|
|
|
}
|
|
|
|
|
2021-06-12 23:12:15 +02:00
|
|
|
if (cut_active) {
|
|
|
|
for (j = 0; j < paste_elements_count; j++) {
|
2021-06-27 11:28:59 +02:00
|
|
|
sprintf(#copy_to, "%s/%s", path, path_offset+strrchr(path_offset,'/'));
|
2021-06-12 23:12:15 +02:00
|
|
|
slash_count = 0;
|
|
|
|
for (i=0; i<=10; i++) {
|
|
|
|
if (copy_to[i]=='/') slash_count++;
|
|
|
|
if (slash_count==3) break;
|
|
|
|
}
|
|
|
|
if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
|
|
|
|
RenameMove(#copy_to+i, path_offset);
|
|
|
|
if (EAX!=0) goto _DIFFERENT_DRIVES;
|
|
|
|
path_offset += strlen(path_offset) + 1;
|
|
|
|
}
|
|
|
|
DialogExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
_DIFFERENT_DRIVES:
|
2021-06-28 00:16:37 +02:00
|
|
|
path_offset = clipbuf + 10;
|
2020-05-06 17:53:34 +02:00
|
|
|
for (j = 0; j < paste_elements_count; j++) {
|
|
|
|
copy_bar.max += GetFilesCount(path_offset);
|
|
|
|
path_offset += strlen(path_offset) + 1;
|
|
|
|
}
|
|
|
|
|
2021-06-28 00:16:37 +02:00
|
|
|
path_offset = clipbuf + 10;
|
2020-05-06 17:53:34 +02:00
|
|
|
for (j = 0; j < paste_elements_count; j++) {
|
|
|
|
strcpy(#copy_from, path_offset);
|
|
|
|
if (!copy_from) DialogExit();
|
2021-06-27 11:28:59 +02:00
|
|
|
sprintf(#copy_to, "%s/%s", path, #copy_from+strrchr(#copy_from,'/'));
|
2020-06-01 20:18:22 +02:00
|
|
|
if (streq(#copy_from,#copy_to))
|
2020-05-06 17:53:34 +02:00
|
|
|
{
|
2020-06-01 20:18:22 +02:00
|
|
|
if (cut_active) continue;
|
2021-06-27 11:28:59 +02:00
|
|
|
sprintf(#copy_to, "%s/NEW_%s", path, #copy_from+strrchr(#copy_from,'/'));
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
|
|
|
if (strstr(#copy_to, #copy_from))
|
|
|
|
{
|
2021-06-15 20:22:58 +02:00
|
|
|
notify("'Not possible to copy directory into itself.\nProcess terminated.' -E");
|
2020-05-06 17:53:34 +02:00
|
|
|
DialogExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_rezult = copyf(#copy_from,#copy_to))
|
|
|
|
{
|
|
|
|
Write_Error(copy_rezult);
|
|
|
|
if (copy_rezult==8) DialogExit(); //not enough space
|
|
|
|
}
|
|
|
|
else if (cut_active)
|
|
|
|
{
|
|
|
|
strcpy(#file_path, #copy_from);
|
2021-06-15 20:22:58 +02:00
|
|
|
RecursiveDelete(#copy_from, false);
|
2020-05-06 17:53:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
path_offset += strlen(path_offset) + 1;
|
|
|
|
}
|
|
|
|
DialogExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// DELETE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
int del_error;
|
2021-06-15 20:22:58 +02:00
|
|
|
int RecursiveDelete(dword way, bool show_progress)
|
2020-05-06 17:53:34 +02:00
|
|
|
{
|
|
|
|
dword dirbuf, fcount, i, filename;
|
|
|
|
int error;
|
|
|
|
char del_from[4096];
|
|
|
|
if (dir_exists(way))
|
|
|
|
{
|
|
|
|
if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
|
|
|
|
for (i=0; i<fcount; i++)
|
|
|
|
{
|
|
|
|
//if (CheckEvent()==evReDraw) draw_window();
|
|
|
|
filename = i*304+dirbuf+72;
|
|
|
|
sprintf(#del_from,"%s/%s",way,filename);
|
2021-06-25 15:21:42 +02:00
|
|
|
if ( ESDWORD[filename-40] & ATR_FOLDER ) {
|
2021-06-15 20:22:58 +02:00
|
|
|
RecursiveDelete(#del_from, true);
|
2021-06-25 15:21:42 +02:00
|
|
|
} else {
|
2021-06-15 20:22:58 +02:00
|
|
|
if (show_progress) Operation_Draw_Progress(filename);
|
2020-05-06 17:53:34 +02:00
|
|
|
if (error = DeleteFile(#del_from)) del_error = error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error = DeleteFile(way)) del_error = error;
|
|
|
|
}
|
|
|
|
|
2021-06-15 20:22:58 +02:00
|
|
|
void DeleteThread()
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int elements_count = 0;
|
2021-06-28 00:16:37 +02:00
|
|
|
dword clipbuf;
|
2021-06-15 20:22:58 +02:00
|
|
|
dword path_offset;
|
2020-05-06 17:53:34 +02:00
|
|
|
|
|
|
|
DisplayOperationForm(DELETE_FLAG);
|
|
|
|
|
2021-06-28 00:16:37 +02:00
|
|
|
clipbuf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
|
2021-06-15 20:22:58 +02:00
|
|
|
Clipboard__DeleteLastSlot();
|
2021-06-28 00:16:37 +02:00
|
|
|
if (DSDWORD[clipbuf+4] != 3) return;
|
|
|
|
elements_count = ESINT[clipbuf+8];
|
2020-05-06 17:53:34 +02:00
|
|
|
|
2021-06-28 00:16:37 +02:00
|
|
|
path_offset = clipbuf + 10;
|
2021-06-15 20:22:58 +02:00
|
|
|
for (j = 0; j < elements_count; j++) {
|
|
|
|
copy_bar.max += GetFilesCount(path_offset);
|
|
|
|
path_offset += strlen(path_offset) + 1;
|
|
|
|
}
|
|
|
|
|
2021-06-28 00:16:37 +02:00
|
|
|
path_offset = clipbuf + 10;
|
2021-06-15 20:22:58 +02:00
|
|
|
for (j = 0; j < elements_count; j++) {
|
|
|
|
RecursiveDelete(path_offset, true);
|
|
|
|
path_offset += strlen(path_offset) + 1;
|
2020-05-06 17:53:34 +02:00
|
|
|
}
|
|
|
|
if (del_error) Write_Error(del_error);
|
|
|
|
DialogExit();
|
2021-06-15 20:22:58 +02:00
|
|
|
}
|