2 Defines the Main Editor data type -
4 - Instances of the other objects of the editor
7 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "HexEditor.h"
19 #include "EditStatusBar.h"
20 #include "EditInputBar.h"
22 HEFI_EDITOR_COLOR_ATTRIBUTES HOriginalColors
;
26 // the first time editor launch
31 // it's time editor should exit
35 BOOLEAN HEditorMouseAction
;
37 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
38 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
40 extern BOOLEAN HBufferImageMouseNeedRefresh
;
41 extern BOOLEAN HBufferImageNeedRefresh
;
42 extern BOOLEAN HBufferImageOnlyLineNeedRefresh
;
44 HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
45 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
48 // basic initialization for MainEditor
50 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst
= {
68 Help info that will be displayed.
70 EFI_STRING_ID HexMainMenuHelpInfo
[] = {
71 STRING_TOKEN(STR_HEXEDIT_HELP_TITLE
),
72 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
73 STRING_TOKEN(STR_HEXEDIT_HELP_LIST_TITLE
),
74 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
75 STRING_TOKEN(STR_HEXEDIT_HELP_GO_TO_OFFSET
),
76 STRING_TOKEN(STR_HEXEDIT_HELP_SAVE_BUFFER
),
77 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT
),
78 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_START
),
79 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_END
),
80 STRING_TOKEN(STR_HEXEDIT_HELP_CUT
),
81 STRING_TOKEN(STR_HEXEDIT_HELP_PASTE
),
82 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_FILE
),
83 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_DISK
),
84 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_MEMORY
),
85 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
86 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT_HELP
),
87 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
88 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
89 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
90 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
91 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
92 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
93 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
101 @retval EFI_SUCCESS The operation was successful.
104 HMainCommandDisplayHelp (
114 for (CurrentLine
= 0; 0 != HexMainMenuHelpInfo
[CurrentLine
]; CurrentLine
++) {
115 InfoString
= HiiGetString(gShellDebug1HiiHandle
, HexMainMenuHelpInfo
[CurrentLine
]
117 ShellPrintEx (0,CurrentLine
+1,L
"%E%s%N",InfoString
);
122 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
123 } while(SCAN_CONTROL_W
!= Key
.UnicodeChar
);
125 // update screen with buffer's info
126 HBufferImageNeedRefresh
= TRUE
;
127 HBufferImageOnlyLineNeedRefresh
= FALSE
;
128 HBufferImageRefresh ();
134 Move cursor to specified lines.
136 @retval EFI_SUCCESS The operation was successful.
139 HMainCommandGoToOffset (
150 // variable initialization
160 Status
= InputBarSetPrompt (L
"Go To Offset: ");
161 if (EFI_ERROR (Status
)) {
165 Status
= InputBarSetStringSize (8);
166 if (EFI_ERROR (Status
)) {
171 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
176 if (Status
== EFI_NOT_READY
) {
181 // THE input string length should > 0
183 if (StrLen (InputBarGetString()) > 0) {
184 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
185 if (EFI_ERROR (Status
)) {
186 StatusBarSetStatusString (L
"Invalid Offset");
194 Size
= HBufferImageGetTotalSize ();
195 if (Offset
>= Size
) {
196 StatusBarSetStatusString (L
"Invalid Offset");
200 FRow
= (UINTN
)DivU64x32(Offset
, 0x10) + 1;
201 FCol
= (UINTN
)ModU64x32(Offset
, 0x10) + 1;
203 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
205 HBufferImageNeedRefresh
= TRUE
;
206 HBufferImageOnlyLineNeedRefresh
= FALSE
;
207 HBufferImageMouseNeedRefresh
= TRUE
;
213 Save current opened buffer.
214 If is file buffer, you can save to current file name or
215 save to another file name.
217 @retval EFI_SUCCESS The operation was successful.
218 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
219 @retval EFI_LOAD_ERROR A load error occured.
222 HMainCommandSaveBuffer (
232 SHELL_FILE_HANDLE ShellFileHandle
;
234 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
235 if (!HMainEditor
.BufferImage
->Modified
) {
239 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
240 if (EFI_ERROR (Status
)) {
244 // the answer is just one character
246 Status
= InputBarSetStringSize (1);
247 if (EFI_ERROR (Status
)) {
251 // loop for user's answer
252 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
255 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
260 if (Status
== EFI_NOT_READY
) {
264 switch (InputBarGetString()[0]) {
268 // want to save this buffer first
270 Status
= HBufferImageSave (
272 HMainEditor
.BufferImage
->DiskImage
->Name
,
273 HMainEditor
.BufferImage
->DiskImage
->Offset
,
274 HMainEditor
.BufferImage
->DiskImage
->Size
,
275 HMainEditor
.BufferImage
->MemImage
->Offset
,
276 HMainEditor
.BufferImage
->MemImage
->Size
,
277 HMainEditor
.BufferImage
->BufferType
280 if (EFI_ERROR (Status
)) {
281 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
290 // the file won't be saved
307 // ENDOF != FILEBUFFER
309 // This command will save currently opened file to disk.
310 // You can choose save to another file name or just save to
311 // current file name.
312 // Below is the scenario of Save File command: (
313 // Suppose the old file name is A )
314 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
315 // IF user press ESC, Save File command ends .
316 // IF user press Enter, input file name will be A.
317 // IF user inputs a new file name B, input file name will be B.
319 // 2. IF input file name is A, go to do Step 3.
320 // IF input file name is B, go to do Step 4.
322 // 3. IF A is read only, Status Bar will show "Access Denied"
323 // and Save File commands ends.
324 // IF A is not read only, save file buffer to disk
325 // and remove Modified flag in Title Bar , then Save File command ends.
327 // 4. IF B does not exist, create this file and save file buffer to it.
329 // IF B exits, do Step 5.
331 // 5. An Input Bar will be prompted:
332 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
333 // IF user press 'y' or 'Y', do Step 6.
334 // IF user press 'n' or 'N', Save File commands ends.
335 // IF user press 'c' or 'C' or ESC, Save File commands ends.
337 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
338 // and Save File commands ends.
339 // IF B can be read and write, save file buffer to B.
341 // 7. Update File Name field in Title Bar to B
342 // and remove the Modified flag in Title Bar.
344 Str
= CatSPrint(NULL
,
345 L
"File to Save: [%s]",
346 HMainEditor
.BufferImage
->FileImage
->FileName
349 return EFI_OUT_OF_RESOURCES
;
352 if (StrLen (Str
) >= 50) {
354 // replace the long file name with "..."
363 Status
= InputBarSetPrompt (Str
);
364 if (EFI_ERROR (Status
)) {
368 Status
= InputBarSetStringSize (100);
369 if (EFI_ERROR (Status
)) {
375 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
378 // if user pressed ESC
380 if (Status
== EFI_NOT_READY
) {
381 SHELL_FREE_NON_NULL (Str
);
385 SHELL_FREE_NON_NULL (Str
);
388 // if just enter pressed, so think save to current file name
390 if (StrLen (InputBarGetString()) == 0) {
391 FileName
= CatSPrint(NULL
,
393 HMainEditor
.BufferImage
->FileImage
->FileName
396 FileName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
399 if (FileName
== NULL
) {
400 return EFI_OUT_OF_RESOURCES
;
403 if (!IsValidFileName (FileName
)) {
404 StatusBarSetStatusString (L
"Invalid File Name");
405 SHELL_FREE_NON_NULL (FileName
);
412 // save to the old file
414 if (StringNoCaseCompare (
416 &HMainEditor
.BufferImage
->FileImage
->FileName
423 // if the file is read only, so can not write back to it.
425 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
) {
426 StatusBarSetStatusString (L
"Access Denied");
427 SHELL_FREE_NON_NULL (FileName
);
431 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
433 if (!EFI_ERROR (Status
)) {
435 Info
= ShellGetFileInfo(ShellFileHandle
);
437 ShellCloseFile(&ShellFileHandle
);
439 // check if read only
441 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
442 StatusBarSetStatusString (L
"Access Denied");
443 SHELL_FREE_NON_NULL (FileName
);
447 SHELL_FREE_NON_NULL(Info
);
449 // ask user whether to overwrite this file
451 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
452 if (EFI_ERROR (Status
)) {
453 SHELL_FREE_NON_NULL (FileName
);
457 Status
= InputBarSetStringSize (1);
458 if (EFI_ERROR (Status
)) {
459 SHELL_FREE_NON_NULL (FileName
);
465 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
467 if (Status
== EFI_NOT_READY
) {
468 SHELL_FREE_NON_NULL (FileName
);
472 switch (InputBarGetString()[0]) {
479 SHELL_FREE_NON_NULL (FileName
);
483 SHELL_FREE_NON_NULL (FileName
);
487 } // if opened existing file
491 // save file back to disk
493 Status
= HBufferImageSave (
495 HMainEditor
.BufferImage
->DiskImage
->Name
,
496 HMainEditor
.BufferImage
->DiskImage
->Offset
,
497 HMainEditor
.BufferImage
->DiskImage
->Size
,
498 HMainEditor
.BufferImage
->MemImage
->Offset
,
499 HMainEditor
.BufferImage
->MemImage
->Size
,
502 SHELL_FREE_NON_NULL (FileName
);
504 if (EFI_ERROR (Status
)) {
505 return EFI_LOAD_ERROR
;
512 Load a disk buffer editor.
514 @retval EFI_SUCCESS The operation was successful.
515 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
516 @retval EFI_LOAD_ERROR A load error occured.
519 HMainCommandSelectStart (
525 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
530 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
531 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
532 StatusBarSetStatusString (L
"Invalid Block Start");
533 return EFI_LOAD_ERROR
;
537 if (HMainEditor
.SelectEnd
!= 0 && Start
> HMainEditor
.SelectEnd
) {
538 StatusBarSetStatusString (L
"Invalid Block Start");
539 return EFI_LOAD_ERROR
;
542 HMainEditor
.SelectStart
= Start
;
544 HBufferImageNeedRefresh
= TRUE
;
550 Load a disk buffer editor.
552 @retval EFI_SUCCESS The operation was successful.
553 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
554 @retval EFI_LOAD_ERROR A load error occured.
557 HMainCommandSelectEnd (
563 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
568 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
569 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
570 StatusBarSetStatusString (L
"Invalid Block End");
571 return EFI_LOAD_ERROR
;
575 if (HMainEditor
.SelectStart
!= 0 && End
< HMainEditor
.SelectStart
) {
576 StatusBarSetStatusString (L
"Invalid Block End");
580 HMainEditor
.SelectEnd
= End
;
582 HBufferImageNeedRefresh
= TRUE
;
588 Cut current line to clipboard.
590 @retval EFI_SUCCESS The operation was successful.
591 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
592 @retval EFI_LOAD_ERROR A load error occured.
605 // not select, so not allowed to cut
607 if (HMainEditor
.SelectStart
== 0) {
608 StatusBarSetStatusString (L
"No Block is Selected");
612 // not select, so not allowed to cut
614 if (HMainEditor
.SelectEnd
== 0) {
615 StatusBarSetStatusString (L
"No Block is Selected");
619 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
620 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
621 Link
= Link
->ForwardLink
;
624 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
625 Buffer
= AllocateZeroPool (Count
);
626 if (Buffer
== NULL
) {
627 return EFI_OUT_OF_RESOURCES
;
630 // cut the selected area
632 HBufferImageDeleteCharacterFromBuffer (
633 HMainEditor
.SelectStart
- 1,
641 HClipBoardSet (Buffer
, Count
);
643 HBufferImageNeedRefresh
= TRUE
;
644 HBufferImageOnlyLineNeedRefresh
= FALSE
;
646 if (!HMainEditor
.BufferImage
->Modified
) {
647 HMainEditor
.BufferImage
->Modified
= TRUE
;
651 // now no select area
653 HMainEditor
.SelectStart
= 0;
654 HMainEditor
.SelectEnd
= 0;
660 Paste line to file buffer.
662 @retval EFI_SUCCESS The operation was successful.
663 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
664 @retval EFI_LOAD_ERROR A load error occured.
672 BOOLEAN OnlyLineRefresh
;
673 HEFI_EDITOR_LINE
*Line
;
678 Count
= HClipBoardGet (&Buffer
);
679 if (Count
== 0 || Buffer
== NULL
) {
680 StatusBarSetStatusString (L
"Nothing to Paste");
684 Line
= HMainEditor
.BufferImage
->CurrentLine
;
686 OnlyLineRefresh
= FALSE
;
687 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
&& Line
->Size
+ Count
< 0x10) {
689 // is at last line, and after paste will not exceed
690 // so only this line need to be refreshed
692 // if after add, the line is 0x10, then will append a new line
693 // so the whole page will need be refreshed
695 OnlyLineRefresh
= TRUE
;
699 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
701 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
703 if (OnlyLineRefresh
) {
704 HBufferImageNeedRefresh
= FALSE
;
705 HBufferImageOnlyLineNeedRefresh
= TRUE
;
707 HBufferImageNeedRefresh
= TRUE
;
708 HBufferImageOnlyLineNeedRefresh
= FALSE
;
711 if (!HMainEditor
.BufferImage
->Modified
) {
712 HMainEditor
.BufferImage
->Modified
= TRUE
;
722 @retval EFI_SUCCESS The operation was successful.
723 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
724 @retval EFI_LOAD_ERROR A load error occured.
734 // Below is the scenario of Exit command:
735 // 1. IF currently opened file is not modified, exit the editor and
736 // Exit command ends.
737 // IF currently opened file is modified, do Step 2
739 // 2. An Input Bar will be prompted:
740 // "File modified. Save ( Yes/No/Cancel )?"
741 // IF user press 'y' or 'Y', currently opened file will be saved and
743 // IF user press 'n' or 'N', currently opened file will not be saved
745 // IF user press 'c' or 'C' or ESC, Exit command ends.
748 // if file has been modified, so will prompt user
749 // whether to save the changes
751 if (HMainEditor
.BufferImage
->Modified
) {
753 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
754 if (EFI_ERROR (Status
)) {
758 Status
= InputBarSetStringSize (1);
759 if (EFI_ERROR (Status
)) {
764 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
769 if (Status
== EFI_NOT_READY
) {
773 switch (InputBarGetString()[0]) {
777 // write file back to disk
779 Status
= HBufferImageSave (
780 HMainEditor
.BufferImage
->FileImage
->FileName
,
781 HMainEditor
.BufferImage
->DiskImage
->Name
,
782 HMainEditor
.BufferImage
->DiskImage
->Offset
,
783 HMainEditor
.BufferImage
->DiskImage
->Size
,
784 HMainEditor
.BufferImage
->MemImage
->Offset
,
785 HMainEditor
.BufferImage
->MemImage
->Size
,
786 HMainEditor
.BufferImage
->BufferType
788 if (!EFI_ERROR (Status
)) {
813 Load a file from disk to editor.
815 @retval EFI_SUCCESS The operation was successful.
816 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
817 @retval EFI_LOAD_ERROR A load error occured.
820 HMainCommandOpenFile (
826 EDIT_FILE_TYPE BufferType
;
828 BufferType
= HMainEditor
.BufferImage
->BufferType
;
831 // This command will open a file from current working directory.
832 // Read-only file can also be opened. But it can not be modified.
833 // Below is the scenario of Open File command:
834 // 1. IF currently opened file has not been modified, directly go to step .
835 // IF currently opened file has been modified, an Input Bar will be
837 // "File Modified. Save ( Yes/No/Cancel) ?"
838 // IF user press 'y' or 'Y', currently opened file will be saved.
839 // IF user press 'n' or 'N', currently opened file will
841 // IF user press 'c' or 'C' or ESC, Open File command ends and
842 // currently opened file is still opened.
844 // 2. An Input Bar will be prompted as : "File Name to Open: "
845 // IF user press ESC, Open File command ends and
846 // currently opened file is still opened.
847 // Any other inputs with a Return will cause
848 // currently opened file close.
850 // 3. IF user input file name is an existing file ,
851 // this file will be read and opened.
852 // IF user input file name is a new file, this file will be created
853 // and opened. This file's type ( UNICODE or ASCII ) is the same with
857 // if current file is modified, so you need to choose whether to
860 if (HMainEditor
.BufferImage
->Modified
) {
862 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
863 if (EFI_ERROR (Status
)) {
867 // the answer is just one character
869 Status
= InputBarSetStringSize (1);
870 if (EFI_ERROR (Status
)) {
874 // loop for user's answer
875 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
879 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
884 if (Status
== EFI_NOT_READY
) {
888 switch (InputBarGetString()[0]) {
892 // want to save this buffer first
894 Status
= HBufferImageSave (
895 HMainEditor
.BufferImage
->FileImage
->FileName
,
896 HMainEditor
.BufferImage
->DiskImage
->Name
,
897 HMainEditor
.BufferImage
->DiskImage
->Offset
,
898 HMainEditor
.BufferImage
->DiskImage
->Size
,
899 HMainEditor
.BufferImage
->MemImage
->Offset
,
900 HMainEditor
.BufferImage
->MemImage
->Size
,
901 HMainEditor
.BufferImage
->BufferType
903 if (EFI_ERROR (Status
)) {
907 MainTitleBarRefresh (
908 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
909 HMainEditor
.BufferImage
->BufferType
,
910 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
912 HMainEditor
.ScreenSize
.Column
,
913 HMainEditor
.ScreenSize
.Row
,
914 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
915 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
923 // the file won't be saved
935 // TO get the open file name
937 Status
= InputBarSetPrompt (L
"File Name to Open: ");
938 if (EFI_ERROR (Status
)) {
940 HMainEditor
.BufferImage
->FileImage
->FileName
,
941 HMainEditor
.BufferImage
->DiskImage
->Name
,
942 HMainEditor
.BufferImage
->DiskImage
->Offset
,
943 HMainEditor
.BufferImage
->DiskImage
->Size
,
944 HMainEditor
.BufferImage
->MemImage
->Offset
,
945 HMainEditor
.BufferImage
->MemImage
->Size
,
952 Status
= InputBarSetStringSize (100);
953 if (EFI_ERROR (Status
)) {
954 Status
= HBufferImageRead (
955 HMainEditor
.BufferImage
->FileImage
->FileName
,
956 HMainEditor
.BufferImage
->DiskImage
->Name
,
957 HMainEditor
.BufferImage
->DiskImage
->Offset
,
958 HMainEditor
.BufferImage
->DiskImage
->Size
,
959 HMainEditor
.BufferImage
->MemImage
->Offset
,
960 HMainEditor
.BufferImage
->MemImage
->Size
,
968 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
973 if (Status
== EFI_NOT_READY
) {
974 Status
= HBufferImageRead (
975 HMainEditor
.BufferImage
->FileImage
->FileName
,
976 HMainEditor
.BufferImage
->DiskImage
->Name
,
977 HMainEditor
.BufferImage
->DiskImage
->Offset
,
978 HMainEditor
.BufferImage
->DiskImage
->Size
,
979 HMainEditor
.BufferImage
->MemImage
->Offset
,
980 HMainEditor
.BufferImage
->MemImage
->Size
,
988 // THE input string length should > 0
990 if (StrLen (InputBarGetString()) > 0) {
992 // CHECK if filename's valid
994 if (!IsValidFileName (InputBarGetString())) {
996 HMainEditor
.BufferImage
->FileImage
->FileName
,
997 HMainEditor
.BufferImage
->DiskImage
->Name
,
998 HMainEditor
.BufferImage
->DiskImage
->Offset
,
999 HMainEditor
.BufferImage
->DiskImage
->Size
,
1000 HMainEditor
.BufferImage
->MemImage
->Offset
,
1001 HMainEditor
.BufferImage
->MemImage
->Size
,
1006 StatusBarSetStatusString (L
"Invalid File Name");
1016 Status
= HBufferImageRead (
1017 InputBarGetString(),
1018 HMainEditor
.BufferImage
->DiskImage
->Name
,
1019 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1020 HMainEditor
.BufferImage
->DiskImage
->Size
,
1021 HMainEditor
.BufferImage
->MemImage
->Offset
,
1022 HMainEditor
.BufferImage
->MemImage
->Size
,
1027 if (EFI_ERROR (Status
)) {
1029 HMainEditor
.BufferImage
->FileImage
->FileName
,
1030 HMainEditor
.BufferImage
->DiskImage
->Name
,
1031 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1032 HMainEditor
.BufferImage
->DiskImage
->Size
,
1033 HMainEditor
.BufferImage
->MemImage
->Offset
,
1034 HMainEditor
.BufferImage
->MemImage
->Size
,
1039 return EFI_LOAD_ERROR
;
1046 Load a disk buffer editor.
1048 @retval EFI_SUCCESS The operation was successful.
1049 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1050 @retval EFI_LOAD_ERROR A load error occured.
1051 @retval EFI_NOT_FOUND The disk was not found.
1054 HMainCommandOpenDisk (
1064 EDIT_FILE_TYPE BufferType
;
1067 // variable initialization
1071 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1074 // if current file is modified, so you need to choose
1075 // whether to save it first.
1077 if (HMainEditor
.BufferImage
->Modified
) {
1079 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1080 if (EFI_ERROR (Status
)) {
1084 // the answer is just one character
1086 Status
= InputBarSetStringSize (1);
1087 if (EFI_ERROR (Status
)) {
1091 // loop for user's answer
1092 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1096 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1101 if (Status
== EFI_NOT_READY
) {
1105 switch (InputBarGetString()[0]) {
1109 // want to save this buffer first
1111 Status
= HBufferImageSave (
1112 HMainEditor
.BufferImage
->FileImage
->FileName
,
1113 HMainEditor
.BufferImage
->DiskImage
->Name
,
1114 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1115 HMainEditor
.BufferImage
->DiskImage
->Size
,
1116 HMainEditor
.BufferImage
->MemImage
->Offset
,
1117 HMainEditor
.BufferImage
->MemImage
->Size
,
1120 if (EFI_ERROR (Status
)) {
1124 MainTitleBarRefresh (
1125 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1126 HMainEditor
.BufferImage
->BufferType
,
1127 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1129 HMainEditor
.ScreenSize
.Column
,
1130 HMainEditor
.ScreenSize
.Row
,
1131 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1132 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1140 // the file won't be saved
1152 // get disk block device name
1154 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1155 if (EFI_ERROR (Status
)) {
1159 Status
= InputBarSetStringSize (100);
1160 if (EFI_ERROR (Status
)) {
1165 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1170 if (Status
== EFI_NOT_READY
) {
1175 // THE input string length should > 0
1177 if (StrLen (InputBarGetString()) > 0) {
1182 DeviceName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
1183 if (DeviceName
== NULL
) {
1184 return EFI_OUT_OF_RESOURCES
;
1187 // get starting offset
1189 Status
= InputBarSetPrompt (L
"First Block No.: ");
1190 if (EFI_ERROR (Status
)) {
1194 Status
= InputBarSetStringSize (16);
1195 if (EFI_ERROR (Status
)) {
1200 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1205 if (Status
== EFI_NOT_READY
) {
1210 // THE input string length should > 0
1212 if (StrLen (InputBarGetString()) > 0) {
1213 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1214 if (EFI_ERROR (Status
)) {
1222 // get Number of Blocks:
1224 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1225 if (EFI_ERROR (Status
)) {
1229 Status
= InputBarSetStringSize (8);
1230 if (EFI_ERROR (Status
)) {
1235 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1240 if (Status
== EFI_NOT_READY
) {
1245 // THE input string length should > 0
1247 if (StrLen (InputBarGetString()) > 0) {
1248 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1249 if (EFI_ERROR (Status
)) {
1261 Status
= HBufferImageRead (
1272 if (EFI_ERROR (Status
)) {
1275 HMainEditor
.BufferImage
->FileImage
->FileName
,
1276 HMainEditor
.BufferImage
->DiskImage
->Name
,
1277 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1278 HMainEditor
.BufferImage
->DiskImage
->Size
,
1279 HMainEditor
.BufferImage
->MemImage
->Offset
,
1280 HMainEditor
.BufferImage
->MemImage
->Size
,
1284 return EFI_NOT_FOUND
;
1291 Load memory content to editor
1293 @retval EFI_SUCCESS The operation was successful.
1294 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1295 @retval EFI_LOAD_ERROR A load error occured.
1296 @retval EFI_NOT_FOUND The disk was not found.
1299 HMainCommandOpenMemory (
1307 EDIT_FILE_TYPE BufferType
;
1310 // variable initialization
1314 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1317 // if current buffer is modified, so you need to choose
1318 // whether to save it first.
1320 if (HMainEditor
.BufferImage
->Modified
) {
1322 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1323 if (EFI_ERROR (Status
)) {
1327 // the answer is just one character
1329 Status
= InputBarSetStringSize (1);
1330 if (EFI_ERROR (Status
)) {
1334 // loop for user's answer
1335 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1339 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1344 if (Status
== EFI_NOT_READY
) {
1348 switch (InputBarGetString()[0]) {
1352 // want to save this buffer first
1354 Status
= HBufferImageSave (
1355 HMainEditor
.BufferImage
->FileImage
->FileName
,
1356 HMainEditor
.BufferImage
->DiskImage
->Name
,
1357 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1358 HMainEditor
.BufferImage
->DiskImage
->Size
,
1359 HMainEditor
.BufferImage
->MemImage
->Offset
,
1360 HMainEditor
.BufferImage
->MemImage
->Size
,
1363 if (EFI_ERROR (Status
)) {
1367 MainTitleBarRefresh (
1368 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1369 HMainEditor
.BufferImage
->BufferType
,
1370 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1372 HMainEditor
.ScreenSize
.Column
,
1373 HMainEditor
.ScreenSize
.Row
,
1374 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1375 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1383 // the file won't be saved
1395 // get starting offset
1397 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1398 if (EFI_ERROR (Status
)) {
1402 Status
= InputBarSetStringSize (8);
1403 if (EFI_ERROR (Status
)) {
1408 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1413 if (Status
== EFI_NOT_READY
) {
1418 // THE input string length should > 0
1420 if (StrLen (InputBarGetString()) > 0) {
1421 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1422 if (EFI_ERROR (Status
)) {
1430 // get Number of Blocks:
1432 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1433 if (EFI_ERROR (Status
)) {
1437 Status
= InputBarSetStringSize (8);
1438 if (EFI_ERROR (Status
)) {
1443 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1448 if (Status
== EFI_NOT_READY
) {
1453 // THE input string length should > 0
1455 if (StrLen (InputBarGetString()) > 0) {
1456 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1457 if (EFI_ERROR (Status
)) {
1469 if ((Offset
+ Size
- 1)> 0xffffffff) {
1470 StatusBarSetStatusString (L
"Invalid parameter");
1471 return EFI_LOAD_ERROR
;
1474 Status
= HBufferImageRead (
1485 if (EFI_ERROR (Status
)) {
1486 StatusBarSetStatusString (L
"Read Device Error!");
1488 HMainEditor
.BufferImage
->FileImage
->FileName
,
1489 HMainEditor
.BufferImage
->DiskImage
->Name
,
1490 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1491 HMainEditor
.BufferImage
->DiskImage
->Size
,
1492 HMainEditor
.BufferImage
->MemImage
->Offset
,
1493 HMainEditor
.BufferImage
->MemImage
->Size
,
1497 return EFI_NOT_FOUND
;
1503 MENU_ITEM_FUNCTION HexMainControlBasedMenuFunctions
[] = {
1505 NULL
, /* Ctrl - A */
1506 NULL
, /* Ctrl - B */
1507 NULL
, /* Ctrl - C */
1508 HMainCommandSelectEnd
, /* Ctrl - D */
1509 HMainCommandDisplayHelp
, /* Ctrl - E */
1510 NULL
, /* Ctrl - F */
1511 HMainCommandGoToOffset
, /* Ctrl - G */
1512 NULL
, /* Ctrl - H */
1513 HMainCommandOpenDisk
, /* Ctrl - I */
1514 NULL
, /* Ctrl - J */
1515 NULL
, /* Ctrl - K */
1516 NULL
, /* Ctrl - L */
1517 HMainCommandOpenMemory
, /* Ctrl - M */
1518 NULL
, /* Ctrl - N */
1519 HMainCommandOpenFile
, /* Ctrl - O */
1520 NULL
, /* Ctrl - P */
1521 HMainCommandExit
, /* Ctrl - Q */
1522 NULL
, /* Ctrl - R */
1523 HMainCommandSaveBuffer
, /* Ctrl - S */
1524 HMainCommandSelectStart
, /* Ctrl - T */
1525 NULL
, /* Ctrl - U */
1526 HMainCommandPaste
, /* Ctrl - V */
1527 NULL
, /* Ctrl - W */
1528 HMainCommandCut
, /* Ctrl - X */
1529 NULL
, /* Ctrl - Y */
1530 NULL
, /* Ctrl - Z */
1533 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1535 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1536 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F1
),
1537 HMainCommandGoToOffset
1540 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1541 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F2
),
1542 HMainCommandSaveBuffer
1545 STRING_TOKEN(STR_EDIT_LIBMENUBAR_EXIT
),
1546 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F3
),
1551 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1552 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F4
),
1553 HMainCommandSelectStart
1556 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1557 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F5
),
1558 HMainCommandSelectEnd
1561 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_CUT
),
1562 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F6
),
1566 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_PASTE
),
1567 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F7
),
1572 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1573 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F8
),
1574 HMainCommandOpenFile
1577 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1578 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9
),
1579 HMainCommandOpenDisk
1582 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1583 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F10
),
1584 HMainCommandOpenMemory
1595 Init function for MainEditor
1597 @retval EFI_SUCCESS The operation was successful.
1598 @retval EFI_LOAD_ERROR A load error occured.
1606 EFI_HANDLE
*HandleBuffer
;
1611 // basic initialization
1613 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1616 // set screen attributes
1618 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1620 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
) (gST
->ConOut
->Mode
->Attribute
>> 4);
1622 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1624 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1627 // query screen size
1629 gST
->ConOut
->QueryMode (
1631 gST
->ConOut
->Mode
->Mode
,
1632 &(HMainEditor
.ScreenSize
.Column
),
1633 &(HMainEditor
.ScreenSize
.Row
)
1637 // Find mouse in System Table ConsoleInHandle
1639 Status
= gBS
->HandleProtocol (
1641 &gEfiSimplePointerProtocolGuid
,
1642 (VOID
**)&HMainEditor
.MouseInterface
1644 if (EFI_ERROR (Status
)) {
1646 // If there is no Simple Pointer Protocol on System Table
1648 HandleBuffer
= NULL
;
1649 HMainEditor
.MouseInterface
= NULL
;
1650 Status
= gBS
->LocateHandleBuffer (
1652 &gEfiSimplePointerProtocolGuid
,
1657 if (!EFI_ERROR (Status
) && HandleCount
> 0) {
1659 // Try to find the first available mouse device
1661 for (Index
= 0; Index
< HandleCount
; Index
++) {
1662 Status
= gBS
->HandleProtocol (
1663 HandleBuffer
[Index
],
1664 &gEfiSimplePointerProtocolGuid
,
1665 (VOID
**)&HMainEditor
.MouseInterface
1667 if (!EFI_ERROR (Status
)) {
1672 if (HandleBuffer
!= NULL
) {
1673 FreePool (HandleBuffer
);
1677 if (!EFI_ERROR (Status
) && HMainEditor
.MouseInterface
!= NULL
) {
1678 HMainEditor
.MouseAccumulatorX
= 0;
1679 HMainEditor
.MouseAccumulatorY
= 0;
1680 HMainEditor
.MouseSupported
= TRUE
;
1684 // below will call the five components' init function
1686 Status
= MainTitleBarInit (L
"UEFI HEXEDIT");
1687 if (EFI_ERROR (Status
)) {
1688 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1689 return EFI_LOAD_ERROR
;
1692 Status
= ControlHotKeyInit (HexMainControlBasedMenuFunctions
);
1693 if (EFI_ERROR (Status
)) {
1694 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1695 return EFI_LOAD_ERROR
;
1697 Status
= MenuBarInit (HexEditorMenuItems
);
1698 if (EFI_ERROR (Status
)) {
1699 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1700 return EFI_LOAD_ERROR
;
1703 Status
= StatusBarInit ();
1704 if (EFI_ERROR (Status
)) {
1705 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1706 return EFI_LOAD_ERROR
;
1711 Status
= HBufferImageInit ();
1712 if (EFI_ERROR (Status
)) {
1713 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1714 return EFI_LOAD_ERROR
;
1717 Status
= HClipBoardInit ();
1718 if (EFI_ERROR (Status
)) {
1719 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1720 return EFI_LOAD_ERROR
;
1723 // clear whole screen and enable cursor
1725 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1726 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1729 // initialize EditorFirst and EditorExit
1731 HEditorFirst
= TRUE
;
1732 HEditorExit
= FALSE
;
1733 HEditorMouseAction
= FALSE
;
1739 Cleanup function for MainEditor.
1741 @retval EFI_SUCCESS The operation was successful.
1742 @retval EFI_LOAD_ERROR A load error occured.
1745 HMainEditorCleanup (
1752 // call the five components' cleanup function
1754 MainTitleBarCleanup ();
1758 StatusBarCleanup ();
1762 Status
= HBufferImageCleanup ();
1763 if (EFI_ERROR (Status
)) {
1764 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1767 Status
= HClipBoardCleanup ();
1768 if (EFI_ERROR (Status
)) {
1769 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1774 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1775 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1778 gST
->ConOut
->SetAttribute (
1780 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1782 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1788 Refresh function for MainEditor.
1790 @retval EFI_SUCCESS The operation was successful.
1793 HMainEditorRefresh (
1803 if (HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
) {
1804 if (HMainEditor
.BufferImage
->DiskImage
!= NULL
&&
1805 HBufferImageBackupVar
.DiskImage
!= NULL
&&
1806 (HMainEditor
.BufferImage
->DiskImage
->Offset
!= HBufferImageBackupVar
.DiskImage
->Offset
||
1807 HMainEditor
.BufferImage
->DiskImage
->Size
!= HBufferImageBackupVar
.DiskImage
->Size
) ){
1810 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
) {
1811 if (HMainEditor
.BufferImage
->MemImage
!= NULL
&&
1812 HBufferImageBackupVar
.MemImage
!= NULL
&&
1813 (HMainEditor
.BufferImage
->MemImage
->Offset
!= HBufferImageBackupVar
.MemImage
->Offset
||
1814 HMainEditor
.BufferImage
->MemImage
->Size
!= HBufferImageBackupVar
.MemImage
->Size
) ){
1817 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
) {
1818 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1819 HMainEditor
.BufferImage
->FileImage
->FileName
!= NULL
&&
1820 HBufferImageBackupVar
.FileImage
!= NULL
&&
1821 HBufferImageBackupVar
.FileImage
->FileName
!= NULL
&&
1822 StrCmp (HMainEditor
.BufferImage
->FileImage
->FileName
, HBufferImageBackupVar
.FileImage
->FileName
) != 0 ) {
1826 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1827 HBufferImageBackupVar
.FileImage
!= NULL
&&
1828 HMainEditor
.BufferImage
->FileImage
->ReadOnly
!= HBufferImageBackupVar
.FileImage
->ReadOnly
) {
1833 // to aVOID screen flicker
1834 // the stall value is from experience
1839 // call the components refresh function
1843 || HMainEditor
.BufferImage
->BufferType
!= HBufferImageBackupVar
.BufferType
1844 || HBufferImageBackupVar
.Modified
!= HMainEditor
.BufferImage
->Modified
1847 MainTitleBarRefresh (
1848 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
,
1849 HMainEditor
.BufferImage
->BufferType
,
1850 (BOOLEAN
)(HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->ReadOnly
:FALSE
),
1851 HMainEditor
.BufferImage
->Modified
,
1852 HMainEditor
.ScreenSize
.Column
,
1853 HMainEditor
.ScreenSize
.Row
,
1854 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,
1855 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
1857 HBufferImageRefresh ();
1860 || HBufferImageBackupVar
.DisplayPosition
.Row
!= HMainEditor
.BufferImage
->DisplayPosition
.Row
1861 || HBufferImageBackupVar
.DisplayPosition
.Column
!= HMainEditor
.BufferImage
->DisplayPosition
.Column
1862 || StatusBarGetRefresh()) {
1866 HMainEditor
.ScreenSize
.Row
,
1867 HMainEditor
.ScreenSize
.Column
,
1872 HBufferImageRefresh ();
1876 HBufferImageRefresh ();
1880 // EditorFirst is now set to FALSE
1882 HEditorFirst
= FALSE
;
1888 Handle the mouse input.
1890 @param[in] MouseState The current mouse state.
1891 @param[out] BeforeLeftButtonDown helps with selections.
1893 @retval EFI_SUCCESS The operation was successful.
1894 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1895 @retval EFI_LOAD_ERROR A load error occured.
1896 @retval EFI_NOT_FOUND The disk was not found.
1899 HMainEditorHandleMouseInput (
1900 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1901 OUT BOOLEAN
*BeforeLeftButtonDown
1911 HEFI_EDITOR_LINE
*Line
;
1918 // have mouse movement
1920 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1924 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1925 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1927 HBufferImageAdjustMousePosition (TextX
, TextY
);
1933 if (MouseState
.LeftButton
) {
1934 HighBits
= HBufferImageIsAtHighBits (
1935 HMainEditor
.BufferImage
->MousePosition
.Column
,
1940 // not at an movable place
1944 // now just move mouse pointer to legal position
1947 // move mouse position to legal position
1949 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
1950 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
1951 HMainEditor
.BufferImage
->MousePosition
.Column
--;
1952 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1954 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
1955 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1968 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
1969 HMainEditor
.BufferImage
->MousePosition
.Row
-
1970 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1972 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
1977 // now just move mouse pointer to legal position
1979 FRow
= HMainEditor
.BufferImage
->NumLines
;
1983 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1984 for (Index
= 0; Index
< FRow
- 1; Index
++) {
1985 Link
= Link
->ForwardLink
;
1988 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1994 // now just move mouse pointer to legal position
1996 if (FCol
> Line
->Size
) {
1997 if (*BeforeLeftButtonDown
) {
2000 if (Line
->Size
== 0) {
2013 FCol
= Line
->Size
+ 1;
2018 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
2020 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2022 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
2024 *BeforeLeftButtonDown
= TRUE
;
2029 // else of if LButton
2033 if (*BeforeLeftButtonDown
) {
2039 *BeforeLeftButtonDown
= FALSE
;
2046 return EFI_NOT_FOUND
;
2050 Handle user key input. will route it to other components handle function.
2052 @retval EFI_SUCCESS The operation was successful.
2053 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
2054 @retval EFI_LOAD_ERROR A load error occured.
2057 HMainEditorKeyInput (
2063 EFI_SIMPLE_POINTER_STATE MouseState
;
2064 BOOLEAN LengthChange
;
2067 BOOLEAN BeforeMouseIsDown
;
2068 BOOLEAN MouseIsDown
;
2073 UINTN SelectStartBackup
;
2074 UINTN SelectEndBackup
;
2077 // variable initialization
2082 LengthChange
= FALSE
;
2084 MouseIsDown
= FALSE
;
2090 Status
= EFI_SUCCESS
;
2092 HEditorMouseAction
= FALSE
;
2095 // backup some key elements, so that can aVOID some refresh work
2097 HMainEditorBackup ();
2100 // wait for user key input
2103 // change priority of checking mouse/keyboard activity dynamically
2104 // so prevent starvation of keyboard.
2105 // if last time, mouse moves then this time check keyboard
2107 if (HMainEditor
.MouseSupported
) {
2108 Status
= HMainEditor
.MouseInterface
->GetState (
2109 HMainEditor
.MouseInterface
,
2112 if (!EFI_ERROR (Status
)) {
2114 BeforeMouseIsDown
= MouseIsDown
;
2116 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2118 if (!EFI_ERROR (Status
)) {
2119 if (!BeforeMouseIsDown
) {
2124 FRow
= HBufferImage
.BufferPosition
.Row
;
2125 FCol
= HBufferImage
.BufferPosition
.Column
;
2126 SelectStartBackup
= HMainEditor
.SelectStart
;
2127 SelectEndBackup
= HMainEditor
.SelectEnd
;
2133 SelectStartBackup
= HMainEditor
.SelectStart
;
2134 SelectEndBackup
= HMainEditor
.SelectEnd
;
2141 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2142 HMainEditor
.SelectStart
= 0;
2143 HMainEditor
.SelectEnd
= 0;
2144 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2151 (HBufferImage
.BufferPosition
.Row
- 1) *
2153 HBufferImage
.BufferPosition
.Column
2154 ) >= HMainEditor
.SelectStart
2156 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2158 HBufferImage
.BufferPosition
.Column
;
2160 HMainEditor
.SelectEnd
= 0;
2164 // end of if RelativeX/Y
2171 if (HBufferImageGetTotalSize () == 0) {
2172 HMainEditor
.SelectStart
= 0;
2173 HMainEditor
.SelectEnd
= 0;
2179 (HBufferImage
.BufferPosition
.Row
- 1) *
2181 HBufferImage
.BufferPosition
.Column
2182 ) >= HMainEditor
.SelectStart
2184 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2186 HBufferImage
.BufferPosition
.Column
;
2188 HMainEditor
.SelectEnd
= 0;
2191 if (HMainEditor
.SelectEnd
== 0) {
2192 HMainEditor
.SelectStart
= 0;
2200 if (SelectStartBackup
!= HMainEditor
.SelectStart
|| SelectEndBackup
!= HMainEditor
.SelectEnd
) {
2201 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2202 HBufferImageNeedRefresh
= TRUE
;
2204 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2205 HBufferImageNeedRefresh
= TRUE
;
2207 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2213 HEditorMouseAction
= TRUE
;
2214 HBufferImageMouseNeedRefresh
= TRUE
;
2216 } else if (Status
== EFI_LOAD_ERROR
) {
2217 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2222 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2223 if (!EFI_ERROR (Status
)) {
2225 // dispatch to different components' key handling function
2226 // so not everywhere has to set this variable
2228 HBufferImageMouseNeedRefresh
= TRUE
;
2231 // clear previous status string
2233 StatusBarSetRefresh();
2234 if (EFI_SUCCESS
== MenuBarDispatchControlHotKey(&Key
)) {
2235 Status
= EFI_SUCCESS
;
2236 } else if (Key
.ScanCode
== SCAN_NULL
) {
2237 Status
= HBufferImageHandleInput (&Key
);
2238 } else if (((Key
.ScanCode
>= SCAN_UP
) && (Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2239 Status
= HBufferImageHandleInput (&Key
);
2240 } else if (((Key
.ScanCode
>= SCAN_F1
) && Key
.ScanCode
<= (SCAN_F12
))) {
2241 Status
= MenuBarDispatchFunctionKey (&Key
);
2243 StatusBarSetStatusString (L
"Unknown Command");
2245 HBufferImageMouseNeedRefresh
= FALSE
;
2248 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_OUT_OF_RESOURCES
) {
2250 // not already has some error status
2252 if (StrCmp (L
"", StatusBarGetString()) == 0) {
2253 StatusBarSetStatusString (L
"Disk Error. Try Again");
2258 // decide if has to set length warning
2260 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2261 LengthChange
= FALSE
;
2264 // still the old buffer
2266 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2267 Size
= HBufferImageGetTotalSize ();
2269 switch (HBufferImage
.BufferType
) {
2270 case FileTypeDiskBuffer
:
2271 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2274 case FileTypeMemBuffer
:
2275 OldSize
= HBufferImage
.MemImage
->Size
;
2283 if (!LengthChange
) {
2284 if (OldSize
!= Size
) {
2285 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2289 if (OldSize
!= Size
) {
2290 LengthChange
= TRUE
;
2292 LengthChange
= FALSE
;
2297 // after handling, refresh editor
2299 HMainEditorRefresh ();
2301 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2307 Backup function for MainEditor.
2315 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2316 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2317 HBufferImageBackup ();