From 245bc3f44aaa54f0c104c8778fee100c4e6b51aa Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 14 Sep 2025 22:14:21 +0200 Subject: [PATCH] [NETSH] Simplify the code by naming the root context 'netsh' - --- base/applications/network/netsh/context.c | 2 +- base/applications/network/netsh/help.c | 12 ++++-------- base/applications/network/netsh/interpreter.c | 9 +++------ base/applications/network/netsh/lang/en-US.rc | 8 +++++--- base/applications/network/netsh/resource.h | 2 ++ 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/base/applications/network/netsh/context.c b/base/applications/network/netsh/context.c index 34e98a28294..5c6dfcefac6 100644 --- a/base/applications/network/netsh/context.c +++ b/base/applications/network/netsh/context.c @@ -436,7 +436,7 @@ CreateRootContext(VOID) { PCOMMAND_GROUP pGroup; - pRootContext = AddContext(NULL, NULL, NULL); + pRootContext = AddContext(NULL, L"netsh", NULL); DPRINT("pRootContext: %p\n", pRootContext); if (pRootContext == NULL) return FALSE; diff --git a/base/applications/network/netsh/help.c b/base/applications/network/netsh/help.c index 6f099cbaa7d..9a43ef19baf 100644 --- a/base/applications/network/netsh/help.c +++ b/base/applications/network/netsh/help.c @@ -21,7 +21,7 @@ GetContextFullName( _Inout_ LPWSTR pszBuffer, _In_ DWORD cchLength) { - if (pContext->pParentContext != NULL) + if (pContext != pRootContext) { GetContextFullName(pContext->pParentContext, pszBuffer, cchLength); wcscat(pszBuffer, L" "); @@ -29,7 +29,7 @@ GetContextFullName( } else { - wcscpy(pszBuffer, L"netsh"); + wcscpy(pszBuffer, pContext->pszContextName); } } @@ -43,16 +43,12 @@ PrintCurrentContextHeader( if (pContext == pCurrentContext) { - ConPrintf(StdOut, L"\nCommands in this context:\n"); - } - else if (pContext == pRootContext) - { - ConPrintf(StdOut, L"\nCommands in the netsh-context:\n"); + ConResPrintf(StdOut, IDS_THIS_COMMANDS); } else { GetContextFullName(pContext, szBuffer, 80); - ConPrintf(StdOut, L"\nCommands in the %s-context:\n", szBuffer); + ConResPrintf(StdOut, IDS_CONTEXT_COMMANDS, szBuffer); } } diff --git a/base/applications/network/netsh/interpreter.c b/base/applications/network/netsh/interpreter.c index 336d12e9869..3c197cc881a 100644 --- a/base/applications/network/netsh/interpreter.c +++ b/base/applications/network/netsh/interpreter.c @@ -224,16 +224,13 @@ VOID PrintPrompt( PCONTEXT_ENTRY pContext) { - if (pContext == pRootContext) - { - ConPuts(StdOut, L"netsh"); - } - else + if (pContext != pRootContext) { PrintPrompt(pContext->pParentContext); ConPuts(StdOut, L" "); - ConPuts(StdOut, pContext->pszContextName); } + + ConPuts(StdOut, pContext->pszContextName); } diff --git a/base/applications/network/netsh/lang/en-US.rc b/base/applications/network/netsh/lang/en-US.rc index cd767618065..88e09e45eb5 100644 --- a/base/applications/network/netsh/lang/en-US.rc +++ b/base/applications/network/netsh/lang/en-US.rc @@ -12,9 +12,11 @@ STRINGTABLE BEGIN IDS_APP_USAGE "\nUsage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] \ \n [Command | -f ScriptFile]\n" - IDS_INVALID_COMMAND "The following command was not found: %ls.\n" - IDS_OPEN_FAILED "The file %ls could not be openend.\n" - IDS_INVALID_SYNTAX "The syntax supplied for this command is not valid. Check help for the correct syntax.\n\n" + IDS_INVALID_COMMAND "The following command was not found: %ls.\n" + IDS_OPEN_FAILED "The file %ls could not be openend.\n" + IDS_INVALID_SYNTAX "The syntax supplied for this command is not valid. Check help for the correct syntax.\n\n" + IDS_THIS_COMMANDS "\nCommands in this context:\n" + IDS_CONTEXT_COMMANDS "\nCommands in the %s-context:\n" END STRINGTABLE diff --git a/base/applications/network/netsh/resource.h b/base/applications/network/netsh/resource.h index 64c640acfaa..02b7d493961 100644 --- a/base/applications/network/netsh/resource.h +++ b/base/applications/network/netsh/resource.h @@ -14,6 +14,8 @@ #define IDS_INVALID_COMMAND 102 #define IDS_OPEN_FAILED 103 #define IDS_INVALID_SYNTAX 104 +#define IDS_THIS_COMMANDS 105 +#define IDS_CONTEXT_COMMANDS 106 #define IDS_HELP_HEADER 200 #define IDS_HELP_FOOTER 201