From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C454981E19 for ; Tue, 17 Jan 2017 18:50:33 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 17 Jan 2017 18:50:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,247,1477983600"; d="scan'208";a="923750990" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga003.jf.intel.com with ESMTP; 17 Jan 2017 18:50:33 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 17 Jan 2017 18:50:33 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 17 Jan 2017 18:50:33 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.132]) with mapi id 14.03.0248.002; Wed, 18 Jan 2017 10:50:23 +0800 From: "Dong, Eric" To: "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Yao, Jiewen" Thread-Topic: [patch 3/3] MdeModulePkg/FileExplorer: Enable functionality of creating new file/folder Thread-Index: AQHSb72Y7rCu8YaFskqBv4o/pInNKKE9i5Yw Date: Wed, 18 Jan 2017 02:50:22 +0000 Message-ID: References: <1484546246-54936-1-git-send-email-dandan.bi@intel.com> <1484546246-54936-3-git-send-email-dandan.bi@intel.com> In-Reply-To: <1484546246-54936-3-git-send-email-dandan.bi@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch 3/3] MdeModulePkg/FileExplorer: Enable functionality of creating new file/folder X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jan 2017 02:50:33 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Eric Dong -----Original Message----- From: Bi, Dandan=20 Sent: Monday, January 16, 2017 1:57 PM To: edk2-devel@lists.01.org Cc: Dong, Eric ; Gao, Liming ; Y= ao, Jiewen Subject: [patch 3/3] MdeModulePkg/FileExplorer: Enable functionality of cre= ating new file/folder https://bugzilla.tianocore.org/show_bug.cgi?id=3D324 Enhance the FileExplorerlib so that user can create a new file/folder throu= gh the UI page. Cc: Eric Dong Cc: Liming Gao Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi --- .../Library/FileExplorerLib/FileExplorer.c | 170 +++++++++++++++++= +++- .../Library/FileExplorerLib/FileExplorer.h | 4 + .../Library/FileExplorerLib/FileExplorerString.uni | 32 +++- .../Library/FileExplorerLib/FileExplorerVfr.vfr | 56 ++++++- MdeModulePkg/Library/FileExplorerLib/FormGuid.h | 11 +- 5 files changed, 267 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModul= ePkg/Library/FileExplorerLib/FileExplorer.c index 315868a..5eedad7 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c @@ -71,10 +71,28 @@ HII_VENDOR_DEVICE_PATH FeHiiVendorDevicePath =3D { VOID *mLibStartOpCodeHandle =3D NULL; VOID *mLibEndOpCodeHandle =3D NULL; EFI_IFR_GUID_LABEL *mLibStartLabel =3D NULL; EFI_IFR_GUID_LABEL *mLibEn= dLabel =3D NULL; UINT16 mQuestionIdUpdate; +CHAR16 mNewFileName[MAX_FILE_NAME_LEN]; +CHAR16 mNewFolderName[MAX_FOLDER_NAME_LEN]; +UINTN mNewFileQuestionId =3D NEW_FILE_QUESTION_ID_BASE; +UINTN mNewFolderQuestionId =3D NEW_FOLDER_QUESTION_ID_BASE; + +/** + Create a new file or folder in current directory. + + @param FileName Point to the fileNmae or folder. + @param CreateFile CreateFile=3D=3D TRUE means create a new f= ile. + CreateFile=3D=3D FALSE means create a new F= older. + +**/ +EFI_STATUS +LibCreateNewFile ( + IN CHAR16 *FileName, + IN BOOLEAN CreateFile + ); =20 /** This function allows a caller to extract the current configuration for o= ne or more named elements from the target driver. =20 @@ -173,13 +191,17 @@ LibCallback ( OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest ) { EFI_STATUS Status; BOOLEAN NeedExit; + CHAR16 *NewFileName; + CHAR16 *NewFolderName; =20 NeedExit =3D TRUE; - =20 + NewFileName =3D NULL; + NewFolderName =3D NULL; + if (Action !=3D EFI_BROWSER_ACTION_CHANGING && Action !=3D EFI_BROWSER_A= CTION_CHANGED) { // // Do nothing for other UEFI Action. Only do call back when data is ch= anged. // return EFI_UNSUPPORTED; @@ -187,11 +209,59 @@ LibCallback ( =20 if (Action =3D=3D EFI_BROWSER_ACTION_CHANGED) { if ((Value =3D=3D NULL) || (ActionRequest =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } - =20 + + if (QuestionId =3D=3D KEY_VALUE_CREATE_FILE_AND_EXIT) { + *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_EXIT; + if (!IsZeroBuffer (mNewFileName, sizeof (mNewFileName))) { + Status =3D LibCreateNewFile (mNewFileName,TRUE); + ZeroMem (mNewFileName,sizeof (mNewFileName)); + } + } + + if (QuestionId =3D=3D KEY_VALUE_NO_CREATE_FILE_AND_EXIT) { + ZeroMem (mNewFileName,sizeof (mNewFileName)); + *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_EXIT; + } + + if (QuestionId =3D=3D KEY_VALUE_CREATE_FOLDER_AND_EXIT) { + *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_EXIT; + if (!IsZeroBuffer (mNewFolderName, sizeof (mNewFolderName))) { + Status =3D LibCreateNewFile (mNewFolderName, FALSE); + ZeroMem (mNewFolderName,sizeof (mNewFolderName)); + } + } + + if (QuestionId =3D=3D KEY_VALUE_NO_CREATE_FOLDER_AND_EXIT) { + ZeroMem (mNewFolderName,sizeof (mNewFolderName)); + *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_EXIT; + } + + if (QuestionId =3D=3D NEW_FILE_NAME_ID) { + NewFileName =3D HiiGetString (gFileExplorerPrivate.FeHiiHandle, Valu= e->string, NULL); + if (NewFileName !=3D NULL) { + StrCpyS (mNewFileName, MAX_FILE_NAME_LEN, NewFileName); + FreePool (NewFileName); + NewFileName =3D NULL; + } else { + return EFI_INVALID_PARAMETER; + } + } + + if (QuestionId =3D=3D NEW_FOLDER_NAME_ID) { + NewFolderName =3D HiiGetString (gFileExplorerPrivate.FeHiiHandle, Va= lue->string, NULL); + if (NewFolderName !=3D NULL) { + StrCpyS (mNewFolderName, MAX_FOLDER_NAME_LEN, NewFolderName); + FreePool (NewFolderName); + NewFolderName =3D NULL; + } else { + return EFI_INVALID_PARAMETER; + } + } + if (QuestionId >=3D FILE_OPTION_OFFSET) { LibGetDevicePath(QuestionId); =20 // // Process the extra action. @@ -206,12 +276,12 @@ LibCallback ( } } else if (Action =3D=3D EFI_BROWSER_ACTION_CHANGING) { if (Value =3D=3D NULL) { return EFI_INVALID_PARAMETER; } - =20 if (QuestionId >=3D FILE_OPTION_OFFSET) { + LibGetDevicePath(QuestionId); Status =3D LibUpdateFileExplorer (QuestionId); if (EFI_ERROR (Status)) { return Status; } } @@ -984,10 +1054,76 @@ Done: =20 return Status; } =20 /** + Create a new file or folder in current directory. + + @param FileName Point to the fileNmae or folder name. + @param CreateFile CreateFile=3D=3D TRUE means create a new f= ile. + CreateFile=3D=3D FALSE means create a new F= older. + +**/ +EFI_STATUS +LibCreateNewFile ( + IN CHAR16 *FileName, + IN BOOLEAN CreateFile + ) +{ + EFI_FILE_HANDLE FileHandle; + EFI_FILE_HANDLE NewHandle; + EFI_HANDLE DeviceHandle; + EFI_STATUS Status; + CHAR16 *ParentName; + CHAR16 *FullFileName; + + NewHandle =3D NULL; + FullFileName =3D NULL; + + LibGetFileHandleFromDevicePath(gFileExplorerPrivate.RetDevicePath,=20 + &FileHandle, &ParentName, &DeviceHandle); FullFileName =3D=20 + LibAppendFileName (ParentName, FileName); if (FullFileName =3D=3D NULL) = { + return EFI_OUT_OF_RESOURCES; + } + if (CreateFile) { + Status =3D FileHandle->Open( + FileHandle, + &NewHandle, + FullFileName, + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FI= LE_MODE_CREATE, + 0 + ); + if (EFI_ERROR (Status)) { + FileHandle->Close (FileHandle); + return Status; + } + } else { + Status =3D FileHandle->Open( + FileHandle, + &NewHandle, + FullFileName, + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FI= LE_MODE_CREATE, + EFI_FILE_DIRECTORY + ); + if (EFI_ERROR (Status)) { + FileHandle->Close (FileHandle); + return Status; + } + } + + FileHandle->Close (FileHandle); + + // + // Return the DevicePath of the new created file or folder. + // + gFileExplorerPrivate.RetDevicePath =3D FileDevicePath (DeviceHandle,=20 + FullFileName); + + return EFI_SUCCESS; + +} + +/** Find files under current directory. =20 All files and sub-directories in current directory will be stored in DirectoryMenu for future use. =20 @@ -1175,23 +1311,51 @@ LibUpdateFileExplorePage ( { UINTN Index; MENU_ENTRY *NewMenuEntry; FILE_CONTEXT *NewFileContext; MENU_OPTION *MenuOption; + BOOLEAN CreateNewFile; =20 NewMenuEntry =3D NULL; NewFileContext =3D NULL; + CreateNewFile =3D FALSE; =20 LibRefreshUpdateData (); MenuOption =3D gFileExplorerPrivate.FsOptionMenu; =20 mQuestionIdUpdate +=3D QUESTION_ID_UPDATE_STEP; =20 for (Index =3D 0; Index < MenuOption->MenuNumber; Index++) { NewMenuEntry =3D LibGetMenuEntry (MenuOption, Index); NewFileContext =3D (FILE_CONTEXT *) NewMenuEntry->VariableContext; =20 + if (!NewFileContext->IsRoot && !CreateNewFile) { + HiiCreateGotoOpCode ( + mLibStartOpCodeHandle, + FORM_ADD_NEW_FILE_ID, + STRING_TOKEN (STR_NEW_FILE), + STRING_TOKEN (STR_NEW_FILE_HELP), + EFI_IFR_FLAG_CALLBACK, + (UINT16) (mNewFileQuestionId++) + ); + HiiCreateGotoOpCode ( + mLibStartOpCodeHandle, + FORM_ADD_NEW_FOLDER_ID, + STRING_TOKEN (STR_NEW_FOLDER), + STRING_TOKEN (STR_NEW_FOLDER_HELP), + EFI_IFR_FLAG_CALLBACK, + (UINT16) (mNewFolderQuestionId++) + ); + HiiCreateTextOpCode( + mLibStartOpCodeHandle, + STRING_TOKEN (STR_NULL_STRING), + STRING_TOKEN (STR_NULL_STRING), + 0 + ); + CreateNewFile =3D TRUE; + } + if (!NewFileContext->IsDir) { // // Create Text opcode for directory, also create Text opcode for fil= e in FileExplorerStateBootFromFile. // HiiCreateActionOpCode ( diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h b/MdeModul= ePkg/Library/FileExplorerLib/FileExplorer.h index ea0ad3d..b9a84fb 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h @@ -112,10 +112,14 @@ extern UINT8 FileExplorerVfrBin[]; /// #define MAX_CHAR 480 #define FILE_OPTION_OFFSET 0x8000 #define FILE_OPTION_MASK 0x7FFF #define QUESTION_ID_UPDATE_STEP 200 +#define MAX_FILE_NAME_LEN 20 +#define MAX_FOLDER_NAME_LEN 20 +#define NEW_FILE_QUESTION_ID_BASE 0x5000; +#define NEW_FOLDER_QUESTION_ID_BASE 0x6000; =20 /** This function processes the results of changes in configuration. When user select a interactive opcode, this callback will be triggered. Based on the Question(QuestionId) that triggers the callback, the corres= ponding diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorerStrin= g.uni b/MdeModulePkg/Library/FileExplorerLib/FileExplorerString.uni index 2e28c27..e16adb6 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorerString.uni +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorerString.uni @@ -1,8 +1,8 @@ ///** @file // -// Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
+// Copyright (c) 2007 - 2017, Intel Corporation. All rights=20 +reserved.
// This program and the accompanying materials =20 // are licensed and made available under the terms and conditions of the B= SD License =20 // which accompanies this distribution. The full text of the license may = be found at =20 // http://opensource.org/licenses/bsd-license.php = =20 // = =20 @@ -27,5 +27,35 @@ =20 #string STR_NULL_STRING #language en-US " " #language fr-FR " " #string STR_FILE_EXPLORER_TITLE #language en-US "File Explorer" #language fr-FR "File Explorer" +#string STR_NEW_FILE #language en-US "***NEW FILE***" + #language fr-FR "***NEW FILE***" +#string STR_NEW_FILE_HELP #language en-US "This menu used to= create a new file in current directory, jump to next page to name the new = file" + #language fr-FR "This menu used to= create a new file in current directory, jump to next page to name the new = file" +#string STR_ADD_NEW_FILE_TITLE #language en-US "Create a new file= " + #language fr-FR "Create a new file= " +#string STR_ADD_NEW_FOLDER_TITLE #language en-US "Create a new fold= er" + #language fr-FR "Create a new fold= er" +#string STR_NEW_FILE_NAME_PROMPT #language en-US "File Name" + #language fr-FR "File Name" +#string STR_NEW_FILE_NAME_HELP #language en-US "Please input a na= me for the new file" + #language fr-FR "Please input a na= me for the new file" +#string STR_CREATE_FILE_AND_EXIT #language en-US "Create File and E= xit" + #language fr-FR "Create File and E= xit" +#string STR_NO_CREATE_FILE_AND_EXIT #language en-US "Discard Create an= d Exit" + #language fr-FR "Discard Create an= d Exit" +#string STR_NEW_FOLDER #language en-US "***NEW FOLDER***" + #language fr-FR "***NEW FOLDER***" +#string STR_NEW_FOLDER_HELP #language en-US "This menu used to= create a new folder in current directory, jump to next page to name the ne= w folder" + #language fr-FR "This menu used to= create a new folder in current directory, jump to next page to name the ne= w folder" +#string STR_ADD_NEW_FOLDER_TITLE #language en-US "Create a new fold= er" + #language fr-FR "Create a new fold= er" +#string STR_NEW_FOLDER_NAME_PROMPT #language en-US "Folder Name" + #language fr-FR "Folder Name" +#string STR_NEW_FOLDER_NAME_HELP #language en-US "Please input a na= me for the new folder" + #language fr-FR "Please input a na= me for the new folder" +#string STR_CREATE_FOLDER_AND_EXIT #language en-US "Create Folder and= Exit" + #language fr-FR "Create Folder and= Exit" +#string STR_NO_CREATE_FOLDER_AND_EXIT #language en-US "Discard Create an= d Exit" + #language fr-FR "Discard Create an= d Exit" diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorerVfr.vfr b/Mde= ModulePkg/Library/FileExplorerLib/FileExplorerVfr.vfr index ef7c99c..b2bf94d 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorerVfr.vfr +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorerVfr.vfr @@ -1,10 +1,10 @@ ///** @file // // File Explorer Formset // -// Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+// Copyright (c) 2004 - 2017, Intel Corporation. All rights=20 +reserved.
// This program and the accompanying materials // are licensed and made= available under the terms and conditions of the BSD License // which acc= ompanies this distribution. The full text of the license may be found at = // http://opensource.org/licenses/bsd-license.php // @@ -26,6 +26,60 @@ formset =20 label FORM_FILE_EXPLORER_ID; label LABEL_END; endform; =20 + form formid =3D FORM_ADD_NEW_FILE_ID, + title =3D STRING_TOKEN(STR_ADD_NEW_FILE_TITLE); + + string + prompt =3D STRING_TOKEN(STR_NEW_FILE_NAME_PROMPT), + help =3D STRING_TOKEN(STR_NEW_FILE_NAME_HELP), + flags =3D INTERACTIVE, + key =3D NEW_FILE_NAME_ID, + minsize =3D 2, + maxsize =3D 20, + endstring; + + subtitle text =3D STRING_TOKEN(STR_NULL_STRING); + + text + help =3D STRING_TOKEN(STR_CREATE_FILE_AND_EXIT), + text =3D STRING_TOKEN(STR_CREATE_FILE_AND_EXIT), + flags =3D INTERACTIVE, + key =3D KEY_VALUE_CREATE_FILE_AND_EXIT; + + text + help =3D STRING_TOKEN(STR_NO_CREATE_FILE_AND_EXIT), + text =3D STRING_TOKEN(STR_NO_CREATE_FILE_AND_EXIT), + flags =3D INTERACTIVE, + key =3D KEY_VALUE_NO_CREATE_FILE_AND_EXIT; + endform; + + form formid =3D FORM_ADD_NEW_FOLDER_ID, + title =3D STRING_TOKEN(STR_ADD_NEW_FOLDER_TITLE); + + string + prompt =3D STRING_TOKEN(STR_NEW_FOLDER_NAME_PROMPT), + help =3D STRING_TOKEN(STR_NEW_FOLDER_NAME_HELP), + flags =3D INTERACTIVE, + key =3D NEW_FOLDER_NAME_ID, + minsize =3D 2, + maxsize =3D 20, + endstring; + + subtitle text =3D STRING_TOKEN(STR_NULL_STRING); + + text + help =3D STRING_TOKEN(STR_CREATE_FOLDER_AND_EXIT), + text =3D STRING_TOKEN(STR_CREATE_FOLDER_AND_EXIT), + flags =3D INTERACTIVE, + key =3D KEY_VALUE_CREATE_FOLDER_AND_EXIT; + + text + help =3D STRING_TOKEN(STR_NO_CREATE_FOLDER_AND_EXIT), + text =3D STRING_TOKEN(STR_NO_CREATE_FOLDER_AND_EXIT), + flags =3D INTERACTIVE, + key =3D KEY_VALUE_NO_CREATE_FOLDER_AND_EXIT; + endform; + endformset; \ No newline at end of file diff --git a/MdeModulePkg/Library/FileExplorerLib/FormGuid.h b/MdeModulePkg= /Library/FileExplorerLib/FormGuid.h index d0a43a9..a243e9f 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FormGuid.h +++ b/MdeModulePkg/Library/FileExplorerLib/FormGuid.h @@ -1,9 +1,9 @@ /** @file Formset guids, form id and VarStore data structure for File explorer libra= ry. =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under the terms and conditions of the BSD License that accompanies this = distribution. The full text of the license may be found at http://opensource.org/licens= es/bsd-license.php. =20 @@ -21,9 +21,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. { \ 0xfe561596, 0xe6bf, 0x41a6, {0x83, 0x76, 0xc7, 0x2b, 0x71, 0x98, 0x74, 0= xd0} \ } =20 #define FORM_FILE_EXPLORER_ID 0x1000 +#define FORM_ADD_NEW_FILE_ID 0x2000 +#define NEW_FILE_NAME_ID 0x2001 +#define KEY_VALUE_CREATE_FILE_AND_EXIT 0x2002 +#define KEY_VALUE_NO_CREATE_FILE_AND_EXIT 0x2003 +#define FORM_ADD_NEW_FOLDER_ID 0x3000 +#define NEW_FOLDER_NAME_ID 0x3001 +#define KEY_VALUE_CREATE_FOLDER_AND_EXIT 0x3002 +#define KEY_VALUE_NO_CREATE_FOLDER_AND_EXIT 0x3003 + #define LABEL_END 0xffff =20 #endif =20 -- 1.9.5.msysgit.1