2 Defines the Main Editor data type -
4 - Instances of the other objects of the editor
7 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "HexEditor.h"
13 #include "EditStatusBar.h"
14 #include "EditInputBar.h"
16 HEFI_EDITOR_COLOR_ATTRIBUTES HOriginalColors
;
20 // the first time editor launch
25 // it's time editor should exit
29 BOOLEAN HEditorMouseAction
;
31 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
32 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
34 extern BOOLEAN HBufferImageMouseNeedRefresh
;
35 extern BOOLEAN HBufferImageNeedRefresh
;
36 extern BOOLEAN HBufferImageOnlyLineNeedRefresh
;
38 HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
39 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
42 // basic initialization for MainEditor
44 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst
= {
63 Help info that will be displayed.
65 EFI_STRING_ID HexMainMenuHelpInfo
[] = {
66 STRING_TOKEN(STR_HEXEDIT_HELP_TITLE
),
67 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
68 STRING_TOKEN(STR_HEXEDIT_HELP_LIST_TITLE
),
69 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
70 STRING_TOKEN(STR_HEXEDIT_HELP_GO_TO_OFFSET
),
71 STRING_TOKEN(STR_HEXEDIT_HELP_SAVE_BUFFER
),
72 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT
),
73 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_START
),
74 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_END
),
75 STRING_TOKEN(STR_HEXEDIT_HELP_CUT
),
76 STRING_TOKEN(STR_HEXEDIT_HELP_PASTE
),
77 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_FILE
),
78 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_DISK
),
79 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_MEMORY
),
80 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
81 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT_HELP
),
82 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
83 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
84 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
85 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
86 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
87 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
88 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
96 @retval EFI_SUCCESS The operation was successful.
99 HMainCommandDisplayHelp (
105 EFI_KEY_DATA KeyData
;
112 for (CurrentLine
= 0; 0 != HexMainMenuHelpInfo
[CurrentLine
]; CurrentLine
++) {
113 InfoString
= HiiGetString(gShellDebug1HiiHandle
, HexMainMenuHelpInfo
[CurrentLine
]
115 ShellPrintEx (0,CurrentLine
+1,L
"%E%s%N",InfoString
);
122 Status
= gBS
->WaitForEvent (1, &HMainEditor
.TextInputEx
->WaitForKeyEx
, &EventIndex
);
123 if (EFI_ERROR (Status
) || (EventIndex
!= 0)) {
126 Status
= HMainEditor
.TextInputEx
->ReadKeyStrokeEx (HMainEditor
.TextInputEx
, &KeyData
);
127 if (EFI_ERROR (Status
)) {
131 if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) ||
132 (KeyData
.KeyState
.KeyShiftState
== EFI_SHIFT_STATE_VALID
)) {
134 // For consoles that don't support/report shift state,
135 // CTRL+W is translated to L'W' - L'A' + 1.
137 if (KeyData
.Key
.UnicodeChar
== L
'W' - L
'A' + 1) {
140 } else if (((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) != 0) &&
141 ((KeyData
.KeyState
.KeyShiftState
& (EFI_LEFT_CONTROL_PRESSED
| EFI_RIGHT_CONTROL_PRESSED
)) != 0) &&
142 ((KeyData
.KeyState
.KeyShiftState
& ~(EFI_SHIFT_STATE_VALID
| EFI_LEFT_CONTROL_PRESSED
| EFI_RIGHT_CONTROL_PRESSED
)) == 0)) {
144 // For consoles that supports/reports shift state,
145 // make sure that only CONTROL shift key is pressed.
147 if ((KeyData
.Key
.UnicodeChar
== 'w') || (KeyData
.Key
.UnicodeChar
== 'W')) {
153 // update screen with buffer's info
154 HBufferImageNeedRefresh
= TRUE
;
155 HBufferImageOnlyLineNeedRefresh
= FALSE
;
156 HBufferImageRefresh ();
162 Move cursor to specified lines.
164 @retval EFI_SUCCESS The operation was successful.
167 HMainCommandGoToOffset (
178 // variable initialization
188 Status
= InputBarSetPrompt (L
"Go To Offset: ");
189 if (EFI_ERROR (Status
)) {
193 Status
= InputBarSetStringSize (8);
194 if (EFI_ERROR (Status
)) {
199 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
204 if (Status
== EFI_NOT_READY
) {
209 // THE input string length should > 0
211 if (StrLen (InputBarGetString()) > 0) {
212 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
213 if (EFI_ERROR (Status
)) {
214 StatusBarSetStatusString (L
"Invalid Offset");
222 Size
= HBufferImageGetTotalSize ();
223 if (Offset
>= Size
) {
224 StatusBarSetStatusString (L
"Invalid Offset");
228 FRow
= (UINTN
)DivU64x32(Offset
, 0x10) + 1;
229 FCol
= (UINTN
)ModU64x32(Offset
, 0x10) + 1;
231 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
233 HBufferImageNeedRefresh
= TRUE
;
234 HBufferImageOnlyLineNeedRefresh
= FALSE
;
235 HBufferImageMouseNeedRefresh
= TRUE
;
241 Save current opened buffer.
242 If is file buffer, you can save to current file name or
243 save to another file name.
245 @retval EFI_SUCCESS The operation was successful.
246 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
247 @retval EFI_LOAD_ERROR A load error occured.
250 HMainCommandSaveBuffer (
260 SHELL_FILE_HANDLE ShellFileHandle
;
262 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
263 if (!HMainEditor
.BufferImage
->Modified
) {
267 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
268 if (EFI_ERROR (Status
)) {
272 // the answer is just one character
274 Status
= InputBarSetStringSize (1);
275 if (EFI_ERROR (Status
)) {
279 // loop for user's answer
280 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
283 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
288 if (Status
== EFI_NOT_READY
) {
292 switch (InputBarGetString()[0]) {
296 // want to save this buffer first
298 Status
= HBufferImageSave (
300 HMainEditor
.BufferImage
->DiskImage
->Name
,
301 HMainEditor
.BufferImage
->DiskImage
->Offset
,
302 HMainEditor
.BufferImage
->DiskImage
->Size
,
303 HMainEditor
.BufferImage
->MemImage
->Offset
,
304 HMainEditor
.BufferImage
->MemImage
->Size
,
305 HMainEditor
.BufferImage
->BufferType
308 if (EFI_ERROR (Status
)) {
309 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
318 // the file won't be saved
335 // ENDOF != FILEBUFFER
337 // This command will save currently opened file to disk.
338 // You can choose save to another file name or just save to
339 // current file name.
340 // Below is the scenario of Save File command: (
341 // Suppose the old file name is A )
342 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
343 // IF user press ESC, Save File command ends .
344 // IF user press Enter, input file name will be A.
345 // IF user inputs a new file name B, input file name will be B.
347 // 2. IF input file name is A, go to do Step 3.
348 // IF input file name is B, go to do Step 4.
350 // 3. IF A is read only, Status Bar will show "Access Denied"
351 // and Save File commands ends.
352 // IF A is not read only, save file buffer to disk
353 // and remove Modified flag in Title Bar , then Save File command ends.
355 // 4. IF B does not exist, create this file and save file buffer to it.
357 // IF B exits, do Step 5.
359 // 5. An Input Bar will be prompted:
360 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
361 // IF user press 'y' or 'Y', do Step 6.
362 // IF user press 'n' or 'N', Save File commands ends.
363 // IF user press 'c' or 'C' or ESC, Save File commands ends.
365 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
366 // and Save File commands ends.
367 // IF B can be read and write, save file buffer to B.
369 // 7. Update File Name field in Title Bar to B
370 // and remove the Modified flag in Title Bar.
372 Str
= CatSPrint(NULL
,
373 L
"File to Save: [%s]",
374 HMainEditor
.BufferImage
->FileImage
->FileName
377 return EFI_OUT_OF_RESOURCES
;
380 if (StrLen (Str
) >= 50) {
382 // replace the long file name with "..."
391 Status
= InputBarSetPrompt (Str
);
392 if (EFI_ERROR (Status
)) {
396 Status
= InputBarSetStringSize (100);
397 if (EFI_ERROR (Status
)) {
403 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
406 // if user pressed ESC
408 if (Status
== EFI_NOT_READY
) {
409 SHELL_FREE_NON_NULL (Str
);
413 SHELL_FREE_NON_NULL (Str
);
416 // if just enter pressed, so think save to current file name
418 if (StrLen (InputBarGetString()) == 0) {
419 FileName
= CatSPrint(NULL
,
421 HMainEditor
.BufferImage
->FileImage
->FileName
424 FileName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
427 if (FileName
== NULL
) {
428 return EFI_OUT_OF_RESOURCES
;
431 if (!IsValidFileName (FileName
)) {
432 StatusBarSetStatusString (L
"Invalid File Name");
433 SHELL_FREE_NON_NULL (FileName
);
440 // save to the old file
442 if (StringNoCaseCompare (
444 &HMainEditor
.BufferImage
->FileImage
->FileName
451 // if the file is read only, so can not write back to it.
453 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
) {
454 StatusBarSetStatusString (L
"Access Denied");
455 SHELL_FREE_NON_NULL (FileName
);
459 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
461 if (!EFI_ERROR (Status
)) {
463 Info
= ShellGetFileInfo(ShellFileHandle
);
465 ShellCloseFile(&ShellFileHandle
);
467 // check if read only
469 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
470 StatusBarSetStatusString (L
"Access Denied");
471 SHELL_FREE_NON_NULL (FileName
);
475 SHELL_FREE_NON_NULL(Info
);
477 // ask user whether to overwrite this file
479 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
480 if (EFI_ERROR (Status
)) {
481 SHELL_FREE_NON_NULL (FileName
);
485 Status
= InputBarSetStringSize (1);
486 if (EFI_ERROR (Status
)) {
487 SHELL_FREE_NON_NULL (FileName
);
493 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
495 if (Status
== EFI_NOT_READY
) {
496 SHELL_FREE_NON_NULL (FileName
);
500 switch (InputBarGetString()[0]) {
507 SHELL_FREE_NON_NULL (FileName
);
511 SHELL_FREE_NON_NULL (FileName
);
515 } // if opened existing file
519 // save file back to disk
521 Status
= HBufferImageSave (
523 HMainEditor
.BufferImage
->DiskImage
->Name
,
524 HMainEditor
.BufferImage
->DiskImage
->Offset
,
525 HMainEditor
.BufferImage
->DiskImage
->Size
,
526 HMainEditor
.BufferImage
->MemImage
->Offset
,
527 HMainEditor
.BufferImage
->MemImage
->Size
,
530 SHELL_FREE_NON_NULL (FileName
);
532 if (EFI_ERROR (Status
)) {
533 return EFI_LOAD_ERROR
;
540 Load a disk buffer editor.
542 @retval EFI_SUCCESS The operation was successful.
543 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
544 @retval EFI_LOAD_ERROR A load error occured.
547 HMainCommandSelectStart (
553 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
558 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
559 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
560 StatusBarSetStatusString (L
"Invalid Block Start");
561 return EFI_LOAD_ERROR
;
565 if (HMainEditor
.SelectEnd
!= 0 && Start
> HMainEditor
.SelectEnd
) {
566 StatusBarSetStatusString (L
"Invalid Block Start");
567 return EFI_LOAD_ERROR
;
570 HMainEditor
.SelectStart
= Start
;
572 HBufferImageNeedRefresh
= TRUE
;
578 Load a disk buffer editor.
580 @retval EFI_SUCCESS The operation was successful.
581 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
582 @retval EFI_LOAD_ERROR A load error occured.
585 HMainCommandSelectEnd (
591 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
596 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
597 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
598 StatusBarSetStatusString (L
"Invalid Block End");
599 return EFI_LOAD_ERROR
;
603 if (HMainEditor
.SelectStart
!= 0 && End
< HMainEditor
.SelectStart
) {
604 StatusBarSetStatusString (L
"Invalid Block End");
608 HMainEditor
.SelectEnd
= End
;
610 HBufferImageNeedRefresh
= TRUE
;
616 Cut current line to clipboard.
618 @retval EFI_SUCCESS The operation was successful.
619 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
620 @retval EFI_LOAD_ERROR A load error occured.
633 // not select, so not allowed to cut
635 if (HMainEditor
.SelectStart
== 0) {
636 StatusBarSetStatusString (L
"No Block is Selected");
640 // not select, so not allowed to cut
642 if (HMainEditor
.SelectEnd
== 0) {
643 StatusBarSetStatusString (L
"No Block is Selected");
647 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
648 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
649 Link
= Link
->ForwardLink
;
652 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
653 Buffer
= AllocateZeroPool (Count
);
654 if (Buffer
== NULL
) {
655 return EFI_OUT_OF_RESOURCES
;
658 // cut the selected area
660 HBufferImageDeleteCharacterFromBuffer (
661 HMainEditor
.SelectStart
- 1,
669 HClipBoardSet (Buffer
, Count
);
671 HBufferImageNeedRefresh
= TRUE
;
672 HBufferImageOnlyLineNeedRefresh
= FALSE
;
674 if (!HMainEditor
.BufferImage
->Modified
) {
675 HMainEditor
.BufferImage
->Modified
= TRUE
;
679 // now no select area
681 HMainEditor
.SelectStart
= 0;
682 HMainEditor
.SelectEnd
= 0;
688 Paste line to file buffer.
690 @retval EFI_SUCCESS The operation was successful.
691 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
692 @retval EFI_LOAD_ERROR A load error occured.
700 BOOLEAN OnlyLineRefresh
;
701 HEFI_EDITOR_LINE
*Line
;
706 Count
= HClipBoardGet (&Buffer
);
707 if (Count
== 0 || Buffer
== NULL
) {
708 StatusBarSetStatusString (L
"Nothing to Paste");
712 Line
= HMainEditor
.BufferImage
->CurrentLine
;
714 OnlyLineRefresh
= FALSE
;
715 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
&& Line
->Size
+ Count
< 0x10) {
717 // is at last line, and after paste will not exceed
718 // so only this line need to be refreshed
720 // if after add, the line is 0x10, then will append a new line
721 // so the whole page will need be refreshed
723 OnlyLineRefresh
= TRUE
;
727 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
729 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
731 if (OnlyLineRefresh
) {
732 HBufferImageNeedRefresh
= FALSE
;
733 HBufferImageOnlyLineNeedRefresh
= TRUE
;
735 HBufferImageNeedRefresh
= TRUE
;
736 HBufferImageOnlyLineNeedRefresh
= FALSE
;
739 if (!HMainEditor
.BufferImage
->Modified
) {
740 HMainEditor
.BufferImage
->Modified
= TRUE
;
750 @retval EFI_SUCCESS The operation was successful.
751 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
752 @retval EFI_LOAD_ERROR A load error occured.
762 // Below is the scenario of Exit command:
763 // 1. IF currently opened file is not modified, exit the editor and
764 // Exit command ends.
765 // IF currently opened file is modified, do Step 2
767 // 2. An Input Bar will be prompted:
768 // "File modified. Save ( Yes/No/Cancel )?"
769 // IF user press 'y' or 'Y', currently opened file will be saved and
771 // IF user press 'n' or 'N', currently opened file will not be saved
773 // IF user press 'c' or 'C' or ESC, Exit command ends.
776 // if file has been modified, so will prompt user
777 // whether to save the changes
779 if (HMainEditor
.BufferImage
->Modified
) {
781 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
782 if (EFI_ERROR (Status
)) {
786 Status
= InputBarSetStringSize (1);
787 if (EFI_ERROR (Status
)) {
792 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
797 if (Status
== EFI_NOT_READY
) {
801 switch (InputBarGetString()[0]) {
805 // write file back to disk
807 Status
= HBufferImageSave (
808 HMainEditor
.BufferImage
->FileImage
->FileName
,
809 HMainEditor
.BufferImage
->DiskImage
->Name
,
810 HMainEditor
.BufferImage
->DiskImage
->Offset
,
811 HMainEditor
.BufferImage
->DiskImage
->Size
,
812 HMainEditor
.BufferImage
->MemImage
->Offset
,
813 HMainEditor
.BufferImage
->MemImage
->Size
,
814 HMainEditor
.BufferImage
->BufferType
816 if (!EFI_ERROR (Status
)) {
841 Load a file from disk to editor.
843 @retval EFI_SUCCESS The operation was successful.
844 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
845 @retval EFI_LOAD_ERROR A load error occured.
848 HMainCommandOpenFile (
854 EDIT_FILE_TYPE BufferType
;
856 BufferType
= HMainEditor
.BufferImage
->BufferType
;
859 // This command will open a file from current working directory.
860 // Read-only file can also be opened. But it can not be modified.
861 // Below is the scenario of Open File command:
862 // 1. IF currently opened file has not been modified, directly go to step .
863 // IF currently opened file has been modified, an Input Bar will be
865 // "File Modified. Save ( Yes/No/Cancel) ?"
866 // IF user press 'y' or 'Y', currently opened file will be saved.
867 // IF user press 'n' or 'N', currently opened file will
869 // IF user press 'c' or 'C' or ESC, Open File command ends and
870 // currently opened file is still opened.
872 // 2. An Input Bar will be prompted as : "File Name to Open: "
873 // IF user press ESC, Open File command ends and
874 // currently opened file is still opened.
875 // Any other inputs with a Return will cause
876 // currently opened file close.
878 // 3. IF user input file name is an existing file ,
879 // this file will be read and opened.
880 // IF user input file name is a new file, this file will be created
881 // and opened. This file's type ( UNICODE or ASCII ) is the same with
885 // if current file is modified, so you need to choose whether to
888 if (HMainEditor
.BufferImage
->Modified
) {
890 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
891 if (EFI_ERROR (Status
)) {
895 // the answer is just one character
897 Status
= InputBarSetStringSize (1);
898 if (EFI_ERROR (Status
)) {
902 // loop for user's answer
903 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
907 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
912 if (Status
== EFI_NOT_READY
) {
916 switch (InputBarGetString()[0]) {
920 // want to save this buffer first
922 Status
= HBufferImageSave (
923 HMainEditor
.BufferImage
->FileImage
->FileName
,
924 HMainEditor
.BufferImage
->DiskImage
->Name
,
925 HMainEditor
.BufferImage
->DiskImage
->Offset
,
926 HMainEditor
.BufferImage
->DiskImage
->Size
,
927 HMainEditor
.BufferImage
->MemImage
->Offset
,
928 HMainEditor
.BufferImage
->MemImage
->Size
,
929 HMainEditor
.BufferImage
->BufferType
931 if (EFI_ERROR (Status
)) {
935 MainTitleBarRefresh (
936 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
937 HMainEditor
.BufferImage
->BufferType
,
938 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
940 HMainEditor
.ScreenSize
.Column
,
941 HMainEditor
.ScreenSize
.Row
,
942 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
943 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
951 // the file won't be saved
963 // TO get the open file name
965 Status
= InputBarSetPrompt (L
"File Name to Open: ");
966 if (EFI_ERROR (Status
)) {
968 HMainEditor
.BufferImage
->FileImage
->FileName
,
969 HMainEditor
.BufferImage
->DiskImage
->Name
,
970 HMainEditor
.BufferImage
->DiskImage
->Offset
,
971 HMainEditor
.BufferImage
->DiskImage
->Size
,
972 HMainEditor
.BufferImage
->MemImage
->Offset
,
973 HMainEditor
.BufferImage
->MemImage
->Size
,
980 Status
= InputBarSetStringSize (100);
981 if (EFI_ERROR (Status
)) {
982 Status
= HBufferImageRead (
983 HMainEditor
.BufferImage
->FileImage
->FileName
,
984 HMainEditor
.BufferImage
->DiskImage
->Name
,
985 HMainEditor
.BufferImage
->DiskImage
->Offset
,
986 HMainEditor
.BufferImage
->DiskImage
->Size
,
987 HMainEditor
.BufferImage
->MemImage
->Offset
,
988 HMainEditor
.BufferImage
->MemImage
->Size
,
996 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1001 if (Status
== EFI_NOT_READY
) {
1002 Status
= HBufferImageRead (
1003 HMainEditor
.BufferImage
->FileImage
->FileName
,
1004 HMainEditor
.BufferImage
->DiskImage
->Name
,
1005 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1006 HMainEditor
.BufferImage
->DiskImage
->Size
,
1007 HMainEditor
.BufferImage
->MemImage
->Offset
,
1008 HMainEditor
.BufferImage
->MemImage
->Size
,
1016 // THE input string length should > 0
1018 if (StrLen (InputBarGetString()) > 0) {
1020 // CHECK if filename's valid
1022 if (!IsValidFileName (InputBarGetString())) {
1024 HMainEditor
.BufferImage
->FileImage
->FileName
,
1025 HMainEditor
.BufferImage
->DiskImage
->Name
,
1026 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1027 HMainEditor
.BufferImage
->DiskImage
->Size
,
1028 HMainEditor
.BufferImage
->MemImage
->Offset
,
1029 HMainEditor
.BufferImage
->MemImage
->Size
,
1034 StatusBarSetStatusString (L
"Invalid File Name");
1044 Status
= HBufferImageRead (
1045 InputBarGetString(),
1046 HMainEditor
.BufferImage
->DiskImage
->Name
,
1047 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1048 HMainEditor
.BufferImage
->DiskImage
->Size
,
1049 HMainEditor
.BufferImage
->MemImage
->Offset
,
1050 HMainEditor
.BufferImage
->MemImage
->Size
,
1055 if (EFI_ERROR (Status
)) {
1057 HMainEditor
.BufferImage
->FileImage
->FileName
,
1058 HMainEditor
.BufferImage
->DiskImage
->Name
,
1059 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1060 HMainEditor
.BufferImage
->DiskImage
->Size
,
1061 HMainEditor
.BufferImage
->MemImage
->Offset
,
1062 HMainEditor
.BufferImage
->MemImage
->Size
,
1067 return EFI_LOAD_ERROR
;
1074 Load a disk buffer editor.
1076 @retval EFI_SUCCESS The operation was successful.
1077 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1078 @retval EFI_LOAD_ERROR A load error occured.
1079 @retval EFI_NOT_FOUND The disk was not found.
1082 HMainCommandOpenDisk (
1092 EDIT_FILE_TYPE BufferType
;
1095 // variable initialization
1099 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1102 // if current file is modified, so you need to choose
1103 // whether to save it first.
1105 if (HMainEditor
.BufferImage
->Modified
) {
1107 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1108 if (EFI_ERROR (Status
)) {
1112 // the answer is just one character
1114 Status
= InputBarSetStringSize (1);
1115 if (EFI_ERROR (Status
)) {
1119 // loop for user's answer
1120 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1124 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1129 if (Status
== EFI_NOT_READY
) {
1133 switch (InputBarGetString()[0]) {
1137 // want to save this buffer first
1139 Status
= HBufferImageSave (
1140 HMainEditor
.BufferImage
->FileImage
->FileName
,
1141 HMainEditor
.BufferImage
->DiskImage
->Name
,
1142 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1143 HMainEditor
.BufferImage
->DiskImage
->Size
,
1144 HMainEditor
.BufferImage
->MemImage
->Offset
,
1145 HMainEditor
.BufferImage
->MemImage
->Size
,
1148 if (EFI_ERROR (Status
)) {
1152 MainTitleBarRefresh (
1153 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1154 HMainEditor
.BufferImage
->BufferType
,
1155 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1157 HMainEditor
.ScreenSize
.Column
,
1158 HMainEditor
.ScreenSize
.Row
,
1159 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1160 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1168 // the file won't be saved
1180 // get disk block device name
1182 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1183 if (EFI_ERROR (Status
)) {
1187 Status
= InputBarSetStringSize (100);
1188 if (EFI_ERROR (Status
)) {
1193 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1198 if (Status
== EFI_NOT_READY
) {
1203 // THE input string length should > 0
1205 if (StrLen (InputBarGetString()) > 0) {
1210 DeviceName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
1211 if (DeviceName
== NULL
) {
1212 return EFI_OUT_OF_RESOURCES
;
1215 // get starting offset
1217 Status
= InputBarSetPrompt (L
"First Block No.: ");
1218 if (EFI_ERROR (Status
)) {
1222 Status
= InputBarSetStringSize (16);
1223 if (EFI_ERROR (Status
)) {
1228 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1233 if (Status
== EFI_NOT_READY
) {
1238 // THE input string length should > 0
1240 if (StrLen (InputBarGetString()) > 0) {
1241 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1242 if (EFI_ERROR (Status
)) {
1250 // get Number of Blocks:
1252 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1253 if (EFI_ERROR (Status
)) {
1257 Status
= InputBarSetStringSize (8);
1258 if (EFI_ERROR (Status
)) {
1263 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1268 if (Status
== EFI_NOT_READY
) {
1273 // THE input string length should > 0
1275 if (StrLen (InputBarGetString()) > 0) {
1276 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1277 if (EFI_ERROR (Status
)) {
1289 Status
= HBufferImageRead (
1300 if (EFI_ERROR (Status
)) {
1303 HMainEditor
.BufferImage
->FileImage
->FileName
,
1304 HMainEditor
.BufferImage
->DiskImage
->Name
,
1305 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1306 HMainEditor
.BufferImage
->DiskImage
->Size
,
1307 HMainEditor
.BufferImage
->MemImage
->Offset
,
1308 HMainEditor
.BufferImage
->MemImage
->Size
,
1312 return EFI_NOT_FOUND
;
1319 Load memory content to editor
1321 @retval EFI_SUCCESS The operation was successful.
1322 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1323 @retval EFI_LOAD_ERROR A load error occured.
1324 @retval EFI_NOT_FOUND The disk was not found.
1327 HMainCommandOpenMemory (
1335 EDIT_FILE_TYPE BufferType
;
1338 // variable initialization
1342 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1345 // if current buffer is modified, so you need to choose
1346 // whether to save it first.
1348 if (HMainEditor
.BufferImage
->Modified
) {
1350 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1351 if (EFI_ERROR (Status
)) {
1355 // the answer is just one character
1357 Status
= InputBarSetStringSize (1);
1358 if (EFI_ERROR (Status
)) {
1362 // loop for user's answer
1363 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1367 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1372 if (Status
== EFI_NOT_READY
) {
1376 switch (InputBarGetString()[0]) {
1380 // want to save this buffer first
1382 Status
= HBufferImageSave (
1383 HMainEditor
.BufferImage
->FileImage
->FileName
,
1384 HMainEditor
.BufferImage
->DiskImage
->Name
,
1385 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1386 HMainEditor
.BufferImage
->DiskImage
->Size
,
1387 HMainEditor
.BufferImage
->MemImage
->Offset
,
1388 HMainEditor
.BufferImage
->MemImage
->Size
,
1391 if (EFI_ERROR (Status
)) {
1395 MainTitleBarRefresh (
1396 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1397 HMainEditor
.BufferImage
->BufferType
,
1398 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1400 HMainEditor
.ScreenSize
.Column
,
1401 HMainEditor
.ScreenSize
.Row
,
1402 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1403 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1411 // the file won't be saved
1423 // get starting offset
1425 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1426 if (EFI_ERROR (Status
)) {
1430 Status
= InputBarSetStringSize (8);
1431 if (EFI_ERROR (Status
)) {
1436 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1441 if (Status
== EFI_NOT_READY
) {
1446 // THE input string length should > 0
1448 if (StrLen (InputBarGetString()) > 0) {
1449 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1450 if (EFI_ERROR (Status
)) {
1458 // get Number of Blocks:
1460 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1461 if (EFI_ERROR (Status
)) {
1465 Status
= InputBarSetStringSize (8);
1466 if (EFI_ERROR (Status
)) {
1471 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1476 if (Status
== EFI_NOT_READY
) {
1481 // THE input string length should > 0
1483 if (StrLen (InputBarGetString()) > 0) {
1484 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1485 if (EFI_ERROR (Status
)) {
1497 if ((Offset
+ Size
- 1)> 0xffffffff) {
1498 StatusBarSetStatusString (L
"Invalid parameter");
1499 return EFI_LOAD_ERROR
;
1502 Status
= HBufferImageRead (
1513 if (EFI_ERROR (Status
)) {
1514 StatusBarSetStatusString (L
"Read Device Error!");
1516 HMainEditor
.BufferImage
->FileImage
->FileName
,
1517 HMainEditor
.BufferImage
->DiskImage
->Name
,
1518 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1519 HMainEditor
.BufferImage
->DiskImage
->Size
,
1520 HMainEditor
.BufferImage
->MemImage
->Offset
,
1521 HMainEditor
.BufferImage
->MemImage
->Size
,
1525 return EFI_NOT_FOUND
;
1531 MENU_ITEM_FUNCTION HexMainControlBasedMenuFunctions
[] = {
1533 NULL
, /* Ctrl - A */
1534 NULL
, /* Ctrl - B */
1535 NULL
, /* Ctrl - C */
1536 HMainCommandSelectEnd
, /* Ctrl - D */
1537 HMainCommandDisplayHelp
, /* Ctrl - E */
1538 NULL
, /* Ctrl - F */
1539 HMainCommandGoToOffset
, /* Ctrl - G */
1540 NULL
, /* Ctrl - H */
1541 HMainCommandOpenDisk
, /* Ctrl - I */
1542 NULL
, /* Ctrl - J */
1543 NULL
, /* Ctrl - K */
1544 NULL
, /* Ctrl - L */
1545 HMainCommandOpenMemory
, /* Ctrl - M */
1546 NULL
, /* Ctrl - N */
1547 HMainCommandOpenFile
, /* Ctrl - O */
1548 NULL
, /* Ctrl - P */
1549 HMainCommandExit
, /* Ctrl - Q */
1550 NULL
, /* Ctrl - R */
1551 HMainCommandSaveBuffer
, /* Ctrl - S */
1552 HMainCommandSelectStart
, /* Ctrl - T */
1553 NULL
, /* Ctrl - U */
1554 HMainCommandPaste
, /* Ctrl - V */
1555 NULL
, /* Ctrl - W */
1556 HMainCommandCut
, /* Ctrl - X */
1557 NULL
, /* Ctrl - Y */
1558 NULL
, /* Ctrl - Z */
1561 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1563 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1564 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F1
),
1565 HMainCommandGoToOffset
1568 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1569 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F2
),
1570 HMainCommandSaveBuffer
1573 STRING_TOKEN(STR_EDIT_LIBMENUBAR_EXIT
),
1574 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F3
),
1579 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1580 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F4
),
1581 HMainCommandSelectStart
1584 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1585 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F5
),
1586 HMainCommandSelectEnd
1589 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_CUT
),
1590 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F6
),
1594 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_PASTE
),
1595 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F7
),
1600 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1601 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F8
),
1602 HMainCommandOpenFile
1605 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1606 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9
),
1607 HMainCommandOpenDisk
1610 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1611 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F10
),
1612 HMainCommandOpenMemory
1623 Init function for MainEditor
1625 @retval EFI_SUCCESS The operation was successful.
1626 @retval EFI_LOAD_ERROR A load error occured.
1634 EFI_HANDLE
*HandleBuffer
;
1639 // basic initialization
1641 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1644 // set screen attributes
1646 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1648 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
) (gST
->ConOut
->Mode
->Attribute
>> 4);
1650 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1652 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1655 // query screen size
1657 gST
->ConOut
->QueryMode (
1659 gST
->ConOut
->Mode
->Mode
,
1660 &(HMainEditor
.ScreenSize
.Column
),
1661 &(HMainEditor
.ScreenSize
.Row
)
1665 // Find TextInEx in System Table ConsoleInHandle
1666 // Per UEFI Spec, TextInEx is required for a console capable platform.
1668 Status
= gBS
->HandleProtocol (
1669 gST
->ConsoleInHandle
,
1670 &gEfiSimpleTextInputExProtocolGuid
,
1671 (VOID
**)&HMainEditor
.TextInputEx
1673 if (EFI_ERROR (Status
)) {
1678 // Find mouse in System Table ConsoleInHandle
1680 Status
= gBS
->HandleProtocol (
1681 gST
->ConsoleInHandle
,
1682 &gEfiSimplePointerProtocolGuid
,
1683 (VOID
**)&HMainEditor
.MouseInterface
1685 if (EFI_ERROR (Status
)) {
1687 // If there is no Simple Pointer Protocol on System Table
1689 HandleBuffer
= NULL
;
1690 HMainEditor
.MouseInterface
= NULL
;
1691 Status
= gBS
->LocateHandleBuffer (
1693 &gEfiSimplePointerProtocolGuid
,
1698 if (!EFI_ERROR (Status
) && HandleCount
> 0) {
1700 // Try to find the first available mouse device
1702 for (Index
= 0; Index
< HandleCount
; Index
++) {
1703 Status
= gBS
->HandleProtocol (
1704 HandleBuffer
[Index
],
1705 &gEfiSimplePointerProtocolGuid
,
1706 (VOID
**)&HMainEditor
.MouseInterface
1708 if (!EFI_ERROR (Status
)) {
1713 if (HandleBuffer
!= NULL
) {
1714 FreePool (HandleBuffer
);
1718 if (!EFI_ERROR (Status
) && HMainEditor
.MouseInterface
!= NULL
) {
1719 HMainEditor
.MouseAccumulatorX
= 0;
1720 HMainEditor
.MouseAccumulatorY
= 0;
1721 HMainEditor
.MouseSupported
= TRUE
;
1725 // below will call the five components' init function
1727 Status
= MainTitleBarInit (L
"UEFI HEXEDIT");
1728 if (EFI_ERROR (Status
)) {
1729 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1730 return EFI_LOAD_ERROR
;
1733 Status
= ControlHotKeyInit (HexMainControlBasedMenuFunctions
);
1734 if (EFI_ERROR (Status
)) {
1735 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1736 return EFI_LOAD_ERROR
;
1738 Status
= MenuBarInit (HexEditorMenuItems
);
1739 if (EFI_ERROR (Status
)) {
1740 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1741 return EFI_LOAD_ERROR
;
1744 Status
= StatusBarInit ();
1745 if (EFI_ERROR (Status
)) {
1746 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1747 return EFI_LOAD_ERROR
;
1750 InputBarInit (HMainEditor
.TextInputEx
);
1752 Status
= HBufferImageInit ();
1753 if (EFI_ERROR (Status
)) {
1754 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1755 return EFI_LOAD_ERROR
;
1758 Status
= HClipBoardInit ();
1759 if (EFI_ERROR (Status
)) {
1760 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1761 return EFI_LOAD_ERROR
;
1764 // clear whole screen and enable cursor
1766 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1767 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1770 // initialize EditorFirst and EditorExit
1772 HEditorFirst
= TRUE
;
1773 HEditorExit
= FALSE
;
1774 HEditorMouseAction
= FALSE
;
1780 Cleanup function for MainEditor.
1782 @retval EFI_SUCCESS The operation was successful.
1783 @retval EFI_LOAD_ERROR A load error occured.
1786 HMainEditorCleanup (
1793 // call the five components' cleanup function
1795 MainTitleBarCleanup ();
1799 StatusBarCleanup ();
1803 Status
= HBufferImageCleanup ();
1804 if (EFI_ERROR (Status
)) {
1805 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1808 Status
= HClipBoardCleanup ();
1809 if (EFI_ERROR (Status
)) {
1810 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1815 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1816 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1819 gST
->ConOut
->SetAttribute (
1821 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1823 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1829 Refresh function for MainEditor.
1831 @retval EFI_SUCCESS The operation was successful.
1834 HMainEditorRefresh (
1844 if (HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
) {
1845 if (HMainEditor
.BufferImage
->DiskImage
!= NULL
&&
1846 HBufferImageBackupVar
.DiskImage
!= NULL
&&
1847 (HMainEditor
.BufferImage
->DiskImage
->Offset
!= HBufferImageBackupVar
.DiskImage
->Offset
||
1848 HMainEditor
.BufferImage
->DiskImage
->Size
!= HBufferImageBackupVar
.DiskImage
->Size
) ){
1851 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
) {
1852 if (HMainEditor
.BufferImage
->MemImage
!= NULL
&&
1853 HBufferImageBackupVar
.MemImage
!= NULL
&&
1854 (HMainEditor
.BufferImage
->MemImage
->Offset
!= HBufferImageBackupVar
.MemImage
->Offset
||
1855 HMainEditor
.BufferImage
->MemImage
->Size
!= HBufferImageBackupVar
.MemImage
->Size
) ){
1858 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
) {
1859 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1860 HMainEditor
.BufferImage
->FileImage
->FileName
!= NULL
&&
1861 HBufferImageBackupVar
.FileImage
!= NULL
&&
1862 HBufferImageBackupVar
.FileImage
->FileName
!= NULL
&&
1863 StrCmp (HMainEditor
.BufferImage
->FileImage
->FileName
, HBufferImageBackupVar
.FileImage
->FileName
) != 0 ) {
1867 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1868 HBufferImageBackupVar
.FileImage
!= NULL
&&
1869 HMainEditor
.BufferImage
->FileImage
->ReadOnly
!= HBufferImageBackupVar
.FileImage
->ReadOnly
) {
1874 // to aVOID screen flicker
1875 // the stall value is from experience
1880 // call the components refresh function
1884 || HMainEditor
.BufferImage
->BufferType
!= HBufferImageBackupVar
.BufferType
1885 || HBufferImageBackupVar
.Modified
!= HMainEditor
.BufferImage
->Modified
1888 MainTitleBarRefresh (
1889 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
&&HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1890 HMainEditor
.BufferImage
->BufferType
,
1891 (BOOLEAN
)(HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->ReadOnly
:FALSE
),
1892 HMainEditor
.BufferImage
->Modified
,
1893 HMainEditor
.ScreenSize
.Column
,
1894 HMainEditor
.ScreenSize
.Row
,
1895 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
&&HMainEditor
.BufferImage
->MemImage
!=NULL
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1896 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
&&HMainEditor
.BufferImage
->MemImage
!=NULL
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1898 HBufferImageRefresh ();
1901 || HBufferImageBackupVar
.DisplayPosition
.Row
!= HMainEditor
.BufferImage
->DisplayPosition
.Row
1902 || HBufferImageBackupVar
.DisplayPosition
.Column
!= HMainEditor
.BufferImage
->DisplayPosition
.Column
1903 || StatusBarGetRefresh()) {
1907 HMainEditor
.ScreenSize
.Row
,
1908 HMainEditor
.ScreenSize
.Column
,
1913 HBufferImageRefresh ();
1917 HBufferImageRefresh ();
1921 // EditorFirst is now set to FALSE
1923 HEditorFirst
= FALSE
;
1929 Handle the mouse input.
1931 @param[in] MouseState The current mouse state.
1932 @param[out] BeforeLeftButtonDown helps with selections.
1934 @retval EFI_SUCCESS The operation was successful.
1935 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1936 @retval EFI_LOAD_ERROR A load error occured.
1937 @retval EFI_NOT_FOUND The disk was not found.
1940 HMainEditorHandleMouseInput (
1941 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1942 OUT BOOLEAN
*BeforeLeftButtonDown
1952 HEFI_EDITOR_LINE
*Line
;
1959 // have mouse movement
1961 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1965 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1966 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1968 HBufferImageAdjustMousePosition (TextX
, TextY
);
1974 if (MouseState
.LeftButton
) {
1975 HighBits
= HBufferImageIsAtHighBits (
1976 HMainEditor
.BufferImage
->MousePosition
.Column
,
1981 // not at an movable place
1985 // now just move mouse pointer to legal position
1988 // move mouse position to legal position
1990 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
1991 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
1992 HMainEditor
.BufferImage
->MousePosition
.Column
--;
1993 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1995 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
1996 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
2009 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
2010 HMainEditor
.BufferImage
->MousePosition
.Row
-
2011 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2013 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
2018 // now just move mouse pointer to legal position
2020 FRow
= HMainEditor
.BufferImage
->NumLines
;
2024 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2025 for (Index
= 0; Index
< FRow
- 1; Index
++) {
2026 Link
= Link
->ForwardLink
;
2029 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2035 // now just move mouse pointer to legal position
2037 if (FCol
> Line
->Size
) {
2038 if (*BeforeLeftButtonDown
) {
2041 if (Line
->Size
== 0) {
2054 FCol
= Line
->Size
+ 1;
2059 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
2061 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2063 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
2065 *BeforeLeftButtonDown
= TRUE
;
2070 // else of if LButton
2074 if (*BeforeLeftButtonDown
) {
2080 *BeforeLeftButtonDown
= FALSE
;
2087 return EFI_NOT_FOUND
;
2091 Handle user key input. will route it to other components handle function.
2093 @retval EFI_SUCCESS The operation was successful.
2094 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
2095 @retval EFI_LOAD_ERROR A load error occured.
2098 HMainEditorKeyInput (
2102 EFI_KEY_DATA KeyData
;
2104 EFI_SIMPLE_POINTER_STATE MouseState
;
2105 BOOLEAN NoShiftState
;
2106 BOOLEAN LengthChange
;
2109 BOOLEAN BeforeMouseIsDown
;
2110 BOOLEAN MouseIsDown
;
2115 UINTN SelectStartBackup
;
2116 UINTN SelectEndBackup
;
2119 // variable initialization
2124 LengthChange
= FALSE
;
2126 MouseIsDown
= FALSE
;
2132 Status
= EFI_SUCCESS
;
2134 HEditorMouseAction
= FALSE
;
2137 // backup some key elements, so that can aVOID some refresh work
2139 HMainEditorBackup ();
2142 // wait for user key input
2145 // change priority of checking mouse/keyboard activity dynamically
2146 // so prevent starvation of keyboard.
2147 // if last time, mouse moves then this time check keyboard
2149 if (HMainEditor
.MouseSupported
) {
2150 Status
= HMainEditor
.MouseInterface
->GetState (
2151 HMainEditor
.MouseInterface
,
2154 if (!EFI_ERROR (Status
)) {
2156 BeforeMouseIsDown
= MouseIsDown
;
2158 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2160 if (!EFI_ERROR (Status
)) {
2161 if (!BeforeMouseIsDown
) {
2166 FRow
= HBufferImage
.BufferPosition
.Row
;
2167 FCol
= HBufferImage
.BufferPosition
.Column
;
2168 SelectStartBackup
= HMainEditor
.SelectStart
;
2169 SelectEndBackup
= HMainEditor
.SelectEnd
;
2175 SelectStartBackup
= HMainEditor
.SelectStart
;
2176 SelectEndBackup
= HMainEditor
.SelectEnd
;
2183 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2184 HMainEditor
.SelectStart
= 0;
2185 HMainEditor
.SelectEnd
= 0;
2186 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2193 (HBufferImage
.BufferPosition
.Row
- 1) *
2195 HBufferImage
.BufferPosition
.Column
2196 ) >= HMainEditor
.SelectStart
2198 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2200 HBufferImage
.BufferPosition
.Column
;
2202 HMainEditor
.SelectEnd
= 0;
2206 // end of if RelativeX/Y
2213 if (HBufferImageGetTotalSize () == 0) {
2214 HMainEditor
.SelectStart
= 0;
2215 HMainEditor
.SelectEnd
= 0;
2221 (HBufferImage
.BufferPosition
.Row
- 1) *
2223 HBufferImage
.BufferPosition
.Column
2224 ) >= HMainEditor
.SelectStart
2226 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2228 HBufferImage
.BufferPosition
.Column
;
2230 HMainEditor
.SelectEnd
= 0;
2233 if (HMainEditor
.SelectEnd
== 0) {
2234 HMainEditor
.SelectStart
= 0;
2242 if (SelectStartBackup
!= HMainEditor
.SelectStart
|| SelectEndBackup
!= HMainEditor
.SelectEnd
) {
2243 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2244 HBufferImageNeedRefresh
= TRUE
;
2246 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2247 HBufferImageNeedRefresh
= TRUE
;
2249 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2255 HEditorMouseAction
= TRUE
;
2256 HBufferImageMouseNeedRefresh
= TRUE
;
2258 } else if (Status
== EFI_LOAD_ERROR
) {
2259 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2265 // CheckEvent() returns Success when non-partial key is pressed.
2267 Status
= gBS
->CheckEvent (HMainEditor
.TextInputEx
->WaitForKeyEx
);
2268 if (!EFI_ERROR (Status
)) {
2269 Status
= HMainEditor
.TextInputEx
->ReadKeyStrokeEx (HMainEditor
.TextInputEx
, &KeyData
);
2270 if (!EFI_ERROR (Status
)) {
2272 // dispatch to different components' key handling function
2273 // so not everywhere has to set this variable
2275 HBufferImageMouseNeedRefresh
= TRUE
;
2278 // clear previous status string
2280 StatusBarSetRefresh();
2282 // NoShiftState: TRUE when no shift key is pressed.
2284 NoShiftState
= ((KeyData
.KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) || (KeyData
.KeyState
.KeyShiftState
== EFI_SHIFT_STATE_VALID
);
2286 // dispatch to different components' key handling function
2288 if (EFI_SUCCESS
== MenuBarDispatchControlHotKey(&KeyData
)) {
2289 Status
= EFI_SUCCESS
;
2290 } else if (NoShiftState
&& KeyData
.Key
.ScanCode
== SCAN_NULL
) {
2291 Status
= HBufferImageHandleInput (&KeyData
.Key
);
2292 } else if (NoShiftState
&& ((KeyData
.Key
.ScanCode
>= SCAN_UP
) && (KeyData
.Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2293 Status
= HBufferImageHandleInput (&KeyData
.Key
);
2294 } else if (NoShiftState
&& ((KeyData
.Key
.ScanCode
>= SCAN_F1
) && KeyData
.Key
.ScanCode
<= SCAN_F12
)) {
2295 Status
= MenuBarDispatchFunctionKey (&KeyData
.Key
);
2297 StatusBarSetStatusString (L
"Unknown Command");
2299 HBufferImageMouseNeedRefresh
= FALSE
;
2302 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_OUT_OF_RESOURCES
) {
2304 // not already has some error status
2306 if (StrCmp (L
"", StatusBarGetString()) == 0) {
2307 StatusBarSetStatusString (L
"Disk Error. Try Again");
2312 // decide if has to set length warning
2314 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2315 LengthChange
= FALSE
;
2318 // still the old buffer
2320 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2321 Size
= HBufferImageGetTotalSize ();
2323 switch (HBufferImage
.BufferType
) {
2324 case FileTypeDiskBuffer
:
2325 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2328 case FileTypeMemBuffer
:
2329 OldSize
= HBufferImage
.MemImage
->Size
;
2337 if (!LengthChange
) {
2338 if (OldSize
!= Size
) {
2339 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2343 if (OldSize
!= Size
) {
2344 LengthChange
= TRUE
;
2346 LengthChange
= FALSE
;
2352 // after handling, refresh editor
2354 HMainEditorRefresh ();
2356 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2362 Backup function for MainEditor.
2369 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2370 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2371 HBufferImageBackup ();