From 19836de888bdbfcb64113f581a0812c51f45a95f Mon Sep 17 00:00:00 2001 From: Serhii Sakhno Date: Sat, 25 Dec 2021 22:43:50 +0000 Subject: [PATCH] Eolite: dialogue for replacing files during the copying git-svn-id: svn://kolibrios.org@9471 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/eolite/include/const.h | 4 ++ programs/cmm/eolite/include/progress_dialog.h | 32 ++++++++-- programs/cmm/lib/copyf.h | 62 ++++++++++++++++--- 3 files changed, 86 insertions(+), 12 deletions(-) diff --git a/programs/cmm/eolite/include/const.h b/programs/cmm/eolite/include/const.h index 8f8cc367ad..a46f560c71 100644 --- a/programs/cmm/eolite/include/const.h +++ b/programs/cmm/eolite/include/const.h @@ -22,6 +22,8 @@ #define T_MOVE_WINDOW_TITLE "Перемещаю..." #define T_DELETE_WINDOW_TITLE "Удаляю..." #define T_ABORT_WINDOW_BUTTON "Прервать" +#define T_REPLACE_WINDOW_BUTTON "Заменить" +#define T_SKIP_WINDOW_BUTTON "Пропустить" #define T_SELECT_APP_TO_OPEN_WITH "Выберите программу для открытия файла" #define DEL_MORE_FILES_1 "выбранные элементы (" #define DEL_MORE_FILES_2 " шт.)?" @@ -117,6 +119,8 @@ char *actions[] = { #define T_MOVE_WINDOW_TITLE "Moving..." #define T_DELETE_WINDOW_TITLE "Deleting..." #define T_ABORT_WINDOW_BUTTON "Abort" +#define T_REPLACE_WINDOW_BUTTON "Replace" +#define T_SKIP_WINDOW_BUTTON "Skip" #define T_SELECT_APP_TO_OPEN_WITH "Select application to open file" #define DEL_MORE_FILES_1 "selected items(" #define DEL_MORE_FILES_2 " pcs.)?" diff --git a/programs/cmm/eolite/include/progress_dialog.h b/programs/cmm/eolite/include/progress_dialog.h index e5ed96254b..d001fb67c8 100644 --- a/programs/cmm/eolite/include/progress_dialog.h +++ b/programs/cmm/eolite/include/progress_dialog.h @@ -19,6 +19,7 @@ enum { void DisplayOperationForm(int operation_flag) { dword title; + dword id; if (operation_flag==COPY_FLAG) { title = T_COPY_WINDOW_TITLE; copy_bar.progress_color = 0x00FF00; @@ -41,16 +42,36 @@ void DisplayOperationForm(int operation_flag) switch(CheckEvent()) { case evButton: - DialogExit(); + id = GetButtonID(); + switch(id) + { + case 2: + DialogExit(); + break; + case 3: + copy_state = FILE_REPLACE; + break; + case 4: + copy_state = FILE_SKIP; + break; + } break; - case evReDraw: DefineAndDrawWindow(Form.left+Form.width-200, Form.top+90, WIN_DIALOG_W+9, - skin_height+WIN_DIALOG_H, 0x34, sc.work, title, 0); + skin_height+WIN_DIALOG_H+70, 0x34, sc.work, title, 0); GetProcessInfo(#Dialog_Form, SelfInfo); DrawCaptButton(WIN_DIALOG_W-PR_LEFT-101, PR_TOP+PR_H+6, 100,26, 2, sc.button, sc.button_text, T_ABORT_WINDOW_BUTTON); + if (copy_state == FILE_EXISTS) + { + WriteText(WIN_DIALOG_W-PR_LEFT-301, PR_TOP+PR_H+46, 0x90, sc.work_text, "File exists!!"); + DrawCaptButton(WIN_DIALOG_W-PR_LEFT-301, PR_TOP+PR_H+76, 100,26, 3, + sc.button, sc.button_text, T_REPLACE_WINDOW_BUTTON); + DrawCaptButton(WIN_DIALOG_W-PR_LEFT-101, PR_TOP+PR_H+76, 100,26, 4, + sc.button, sc.button_text, T_SKIP_WINDOW_BUTTON); + } + DrawRectangle3D(PR_LEFT-1, PR_TOP-1, PR_W+1, PR_H+1, sc.work_dark, sc.work_light); } } @@ -71,7 +92,10 @@ void Operation_Draw_Progress(dword filename) { WriteText(PR_LEFT, PR_TOP-20, 0x90, sc.work_text, filename); progressbar_draw stdcall (#copy_bar); - progressbar_progress stdcall (#copy_bar); + if (copy_state == FILE_DEFAULT) + { + progressbar_progress stdcall (#copy_bar); + } WriteTextWithBg(PR_LEFT, PR_TOP+PR_H+5, 0xD0, sc.work_text, sprintf(#param, "%i/%i", copy_bar.value, copy_bar.max), sc.work); diff --git a/programs/cmm/lib/copyf.h b/programs/cmm/lib/copyf.h index cd4534b645..786ecf377f 100644 --- a/programs/cmm/lib/copyf.h +++ b/programs/cmm/lib/copyf.h @@ -7,10 +7,20 @@ #include "../lib/fs.h" #endif +enum { + FILE_DEFAULT=0, + FILE_EXISTS, + FILE_REPLACE, + FILE_SKIP, +}; + +int copy_state = FILE_DEFAULT; + :int copyf(dword from1, in1) { dword error; BDVK CopyFile_atr1; + copy_state = FILE_DEFAULT; if (!from1) || (!in1) { @@ -25,9 +35,23 @@ if (dir_exists(from1)) return CopyFolder(from1, in1); else - { - Operation_Draw_Progress(from1+strrchr(from1, '/')); - return CopyFile(from1, in1); + { + while(1) + { + Operation_Draw_Progress(from1+strrchr(from1, '/')); + if (copy_state == FILE_DEFAULT) || (copy_state == FILE_REPLACE) + { + error = CopyFile(from1, in1); + if (error != 222) + { + return error; + } + } + if (copy_state == FILE_SKIP) + { + return 0; + } + } } } @@ -42,6 +66,11 @@ } else { + if (file_exists(copy_in3)) && (copy_state != FILE_REPLACE) + { + copy_state = FILE_EXISTS; + return 222; + } if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes { if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3)) @@ -59,7 +88,7 @@ :int CopyFolder(dword from2, in2) { dword dirbuf, fcount, i, filename; - char copy_from2[4096], copy_in2[4096], error; + char copy_from2[4096], copy_in2[4096], error; if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL)) { @@ -79,6 +108,7 @@ for (i=0; i