Skip to content

Commit

Permalink
New function rename file or folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Stricker committed Oct 28, 2019
1 parent 570bf34 commit 23f7685
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 50 deletions.
11 changes: 7 additions & 4 deletions Logical/mappFileExplorer/ExplorerTypes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ TYPE
EXP_COPY_ALL,
EXP_FILE_COPY,
EXP_FILE_DELETE,
EXP_FILE_RENAME,
EXP_DIR_COPY,
EXP_DIR_CREATE,
EXP_DIR_DELETE
EXP_DIR_DELETE,
EXP_DIR_RENAME
);
expERR : STRUCT
text : STRING[100]; (* Error text *)
Expand All @@ -35,13 +37,14 @@ TYPE
copy : BOOL; (* Copy selected item from device a TO device b *)
copy_all : BOOL; (* Copy all items from device a TO device b *)
delete : BOOL; (* Delete selected file *)
rename : BOOL;
END_STRUCT;
expPAR : STRUCT
device_active : STRING[40]; (*Active device name *)
device_list : ARRAY[0..4]OF STRING[40]; (*List of all devices*)
item_filter : STRING[EXPL_ITEM_LENGTH]; (* Only show files with this extension *)
dir_name : STRING[EXPL_ITEM_LENGTH]; (* Directory name for create *)
dir_path : STRING[EXPL_DIR_PATH_LENGTH]; (* Current directory path *)
item_filter : STRING[EXPL_ITEM_LENGTH]; (*Only show files with this extension *)
new_name : STRING[EXPL_ITEM_LENGTH]; (*Name for for directory create and rename*)
dir_path : STRING[EXPL_DIR_PATH_LENGTH]; (*Current directory path *)
END_STRUCT;
expDAT : STRUCT
item_list : ARRAY[0..EXPL_LIST_NUM]OF STRING[EXPL_ITEM_LENGTH]; (* List with file names *)
Expand Down
83 changes: 77 additions & 6 deletions Logical/mappFileExplorer/FileExplorer/Main.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ PROGRAM _INIT
brsmemcpy(ADR(EXPL.PAR[1].device_list), ADR(EXPL_DEVICE_LIST), SIZEOF(EXPL_DEVICE_LIST));
brsstrcpy(ADR(EXPL.PAR[0].device_active), ADR(EXPL.PAR[0].device_list[0]));
brsstrcpy(ADR(EXPL.PAR[1].device_active), ADR(EXPL.PAR[1].device_list[0]));

END_PROGRAM

PROGRAM _CYCLIC
Expand Down Expand Up @@ -95,7 +94,7 @@ PROGRAM _CYCLIC

// ------------------------------------------------------------------------------------------------
// Break if no command is set
IF (EXPL.CMD[side].refresh = 0 AND EXPL.CMD[side].dir_change = 0 AND EXPL.CMD[side].dir_create = 0 AND EXPL.CMD[side].copy = 0 AND EXPL.CMD[side].copy_all = 0 AND EXPL.CMD[side].delete = 0) THEN
IF (EXPL.CMD[side].refresh = 0 AND EXPL.CMD[side].dir_change = 0 AND EXPL.CMD[side].dir_create = 0 AND EXPL.CMD[side].copy = 0 AND EXPL.CMD[side].copy_all = 0 AND EXPL.CMD[side].delete = 0 AND EXPL.CMD[side].rename = 0) THEN
// --------------------------------------------------------------------------------------------
// Show current state
EXPL.status := 'Waiting...';
Expand Down Expand Up @@ -150,13 +149,13 @@ PROGRAM _CYCLIC
IF (EXPL.CMD[side].dir_create = 1) THEN
// ------------------------------------------------------------------------------------
// Check if new directory name is empty
IF (EXPL.PAR[side].dir_name = '') THEN
IF (EXPL.PAR[side].new_name = '') THEN
step := CreateError(ERR_EMPTY_ITEM, side, step, 'directory name is empty', ADR(EXPL));
// Check if new directory name fits into path string
ELSIF(brsstrlen(ADR(EXPL.PAR[side].dir_name)) + brsstrlen(ADR(EXPL.PAR[side].dir_path)) + 1 >= EXPL_DIR_PATH_LENGTH) THEN
ELSIF(brsstrlen(ADR(EXPL.PAR[side].new_name)) + brsstrlen(ADR(EXPL.PAR[side].dir_path)) + 1 >= EXPL_DIR_PATH_LENGTH) THEN
step := CreateError(ERR_PATH_EXCEEDS_MAX, side, step, 'directory path name exceeds maximum length', ADR(EXPL));
// Check if new directory name fits into directory name string
ELSIF(brsstrlen(ADR(EXPL.PAR[side].dir_name)) + 5 >= EXPL_ITEM_LENGTH) THEN
ELSIF(brsstrlen(ADR(EXPL.PAR[side].new_name)) + 5 >= EXPL_ITEM_LENGTH) THEN
step := CreateError(ERR_DIR_EXCEEDS_MAX, side, step, 'directory name exceeds maximum length', ADR(EXPL));
ELSE
step := EXP_DIR_CREATE;
Expand Down Expand Up @@ -202,6 +201,22 @@ PROGRAM _CYCLIC
END_IF
END_IF
// ----------------------------------------------------------------------------------------
// Command rename
IF (EXPL.CMD[side].rename = 1) THEN
// ------------------------------------------------------------------------------------
// Check if new directory name is empty
IF (EXPL.PAR[side].new_name = '') THEN
step := CreateError(ERR_EMPTY_ITEM, side, step, 'new name is empty', ADR(EXPL));
// Make sure that user chooses a valid item
ELSIF (EXPL.DAT[side].item_list[EXPL.VIS[side].item_selected] = '..') THEN
step := CreateError(ERR_INVALID_ITEM_NAME, side, step, 'this is not a valid item name', ADR(EXPL));
ELSIF(brsmemcmp(ADR(EXPL.DAT[side].item_list[EXPL.VIS[side].item_selected]), ADR('(DIR)'), 5) = 0) THEN
step := EXP_DIR_RENAME;
ELSE
step := EXP_FILE_RENAME;
END_IF
END_IF
// ----------------------------------------------------------------------------------------
// Clear errors
IF (EXPL.CMD[side].refresh = 1 OR EXPL.CMD[side].copy = 1 OR EXPL.CMD[side].copy_all = 1 OR EXPL.CMD[side].dir_create = 1 OR EXPL.CMD[side].delete = 1) THEN
EXPL.ERR.text := '';
Expand Down Expand Up @@ -577,6 +592,34 @@ PROGRAM _CYCLIC
step := CreateError(FDelete.status, side, step, 'error deleting file', ADR(EXPL));
END_IF
//**********************************************************************************************
// Rename selected file
//**********************************************************************************************
EXP_FILE_RENAME:
// Show current state
animation := WorkingStatus(ADR(EXPL), ADR('renaming file...'), animation);

// ----------------------------------------------------------------------------------------
// Initialize file delete structure
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.DAT[side].item_list[EXPL.VIS[side].item_selected], ADR(tmp_str2));
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.PAR[side].new_name, ADR(tmp_str3));
FRename.enable := 1;
FRename.pDevice := ADR(EXPL.PAR[side].device_active);
FRename.pName := ADR(tmp_str2);
FRename.pNewName := ADR(tmp_str3);
FRename();

// ----------------------------------------------------------------------------------------
// OK
IF (FRename.status = OK) THEN
// Reset command and return to wait state
EXPL.CMD[side].rename := 0;
EXPL.CMD[side].refresh := 1;
step := EXP_WAIT;
// Error
ELSIF (FRename.status <> ERR_FUB_BUSY) THEN
step := CreateError(FRename.status, side, step, 'error renaming file', ADR(EXPL));
END_IF
//**********************************************************************************************
// Create new directory
//**********************************************************************************************
EXP_DIR_CREATE:
Expand All @@ -585,7 +628,7 @@ PROGRAM _CYCLIC

// ----------------------------------------------------------------------------------------
// Initialize directory create structure
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.PAR[side].dir_name, ADR(tmp_str3));
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.PAR[side].new_name, ADR(tmp_str3));
DCreate.enable := 1;
DCreate.pDevice := ADR(EXPL.PAR[side].device_active);
DCreate.pName := ADR(tmp_str3);
Expand Down Expand Up @@ -628,6 +671,34 @@ PROGRAM _CYCLIC
ELSIF (DDelete.status <> ERR_FUB_BUSY) THEN
step := CreateError(DDelete.status, side, step, 'error deleting directory', ADR(EXPL));
END_IF
//**********************************************************************************************
// Rename selected directory
//**********************************************************************************************
EXP_DIR_RENAME:
// Show current state
animation := WorkingStatus(ADR(EXPL), ADR('renaming directory...'), animation);

// ----------------------------------------------------------------------------------------
// Initialize file delete structure
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.DAT[side].item_list[EXPL.VIS[side].item_selected], ADR(tmp_str2));
CreateCompletePath(EXPL.PAR[side].dir_path, EXPL.PAR[side].new_name, ADR(tmp_str3));
DRename.enable := 1;
DRename.pDevice := ADR(EXPL.PAR[side].device_active);
DRename.pName := ADR(tmp_str2);
DRename.pNewName := ADR(tmp_str3);
DRename();

// ----------------------------------------------------------------------------------------
// OK
IF (DRename.status = OK) THEN
// Reset command and return to wait state
EXPL.CMD[side].rename := 0;
EXPL.CMD[side].refresh := 1;
step := EXP_WAIT;
// Error
ELSIF (DRename.status <> ERR_FUB_BUSY) THEN
step := CreateError(DRename.status, side, step, 'error renaming directory', ADR(EXPL));
END_IF
END_CASE

END_PROGRAM
2 changes: 2 additions & 0 deletions Logical/mappFileExplorer/FileExplorer/Variables.var
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ VAR
DClose : DirClose;
FCopy : FileCopy;
FDelete : FileDelete;
FRename : FileRename;
DCopy : DirCopy;
DCreate : DirCreate;
DDelete : DirDeleteEx;
DRename : DirRename;
lDirReadData : fiDIR_READ_EX_DATA;
END_VAR
(*Local constants*)
Expand Down
5 changes: 5 additions & 0 deletions Logical/mappFileExplorer/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.7
- New function rename file or folder
- Fixed memory leak when last entry in list is used
- Code optimizations

Version 0.6
- Changed upper limit of USB polling interval
- Removed obsolete error numbers
Expand Down
Binary file modified Logical/mappView/Resources/Media/screenshot_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 23f7685

Please sign in to comment.