[CMDUTILS][ATTRIB] Support folder attributes (#2103)

CORE-16538
This commit is contained in:
Katayama Hirofumi MZ 2019-11-29 20:03:19 +09:00 committed by GitHub
parent c6b64448ce
commit 189f648584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 123 additions and 74 deletions

View File

@ -72,7 +72,7 @@ ErrorMessage(
NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&szError, 0, NULL))
{
ConPrintf(StdErr, L"%s %s\n", szError, szMessage);
ConPrintf(StdOut, L"%s %s\n", szError, szMessage);
if (szError)
LocalFree(szError);
return;
@ -81,9 +81,9 @@ ErrorMessage(
/* Fall back just in case the error is not defined */
LoadStringW(GetModuleHandle(NULL), STRING_CONSOLE_ERROR, szMsg, ARRAYSIZE(szMsg));
if (szFormat)
ConPrintf(StdErr, L"%s -- %s\n", szMsg, szMessage);
ConPrintf(StdOut, L"%s -- %s\n", szMsg, szMessage);
else
ConPrintf(StdErr, L"%s\n", szMsg);
ConPrintf(StdOut, L"%s\n", szMsg);
}
static
@ -145,9 +145,6 @@ PrintAttribute(
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
wcscpy(pszFileName, findData.cFileName);
ConPrintf(StdOut,
@ -166,7 +163,7 @@ PrintAttribute(
static
INT
BOOL
ChangeAttribute(
LPWSTR pszPath,
LPWSTR pszFile,
@ -180,75 +177,102 @@ ChangeAttribute(
DWORD dwAttribute;
WCHAR szFullName[MAX_PATH];
LPWSTR pszFileName;
BOOL bWildcard = (wcschr(pszFile, L'*') || wcschr(pszFile, L'?'));
/* prepare full file name buffer */
wcscpy(szFullName, pszPath);
pszFileName = szFullName + wcslen(szFullName);
/* change all subdirectories */
if (bRecurse)
{
/* append file name */
wcscpy(pszFileName, L"*.*");
hFind = FindFirstFileW(szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
ErrorMessage(GetLastError(), pszFile);
return 1;
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!wcscmp(findData.cFileName, L".") ||
!wcscmp(findData.cFileName, L".."))
continue;
wcscpy(pszFileName, findData.cFileName);
wcscat(pszFileName, L"\\");
ChangeAttribute(szFullName, pszFile, dwMask,
dwAttrib, bRecurse, bDirectories);
}
}
while (FindNextFileW(hFind, &findData));
FindClose(hFind);
}
/* append file name */
wcscpy(pszFileName, pszFile);
hFind = FindFirstFileW(szFullName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
return FALSE;
dwAttribute = findData.dwFileAttributes;
if (!bWildcard)
{
ErrorMessage(GetLastError(), pszFile);
return 1;
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
wcscpy(pszFileName, findData.cFileName);
dwAttribute = GetFileAttributes (szFullName);
if (dwAttribute != 0xFFFFFFFF)
FindClose(hFind);
if (dwAttribute & FILE_ATTRIBUTE_DIRECTORY)
{
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
SetFileAttributes(szFullName, dwAttribute);
if (bRecurse)
{
if (bDirectories)
{
ChangeAttribute(szFullName, L"*", dwMask, dwAttrib,
bRecurse, bDirectories);
}
else
{
if (!ChangeAttribute(szFullName, L"*", dwMask, dwAttrib,
bRecurse, FALSE))
{
return FALSE;
}
}
}
else
{
if (!bDirectories)
{
ChangeAttribute(szFullName, L"*", dwMask, dwAttrib,
bRecurse, FALSE);
}
}
return TRUE;
}
else
{
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
SetFileAttributes(szFullName, dwAttribute);
return TRUE;
}
}
while (FindNextFileW(hFind, &findData));
FindClose(hFind);
else
{
if ((dwAttribute & FILE_ATTRIBUTE_DIRECTORY) && (!bRecurse || !bDirectories))
return FALSE;
return 0;
do
{
dwAttribute = findData.dwFileAttributes;
if (dwAttribute & FILE_ATTRIBUTE_DIRECTORY)
{
if (!bDirectories)
continue;
if (!wcscmp(findData.cFileName, L".") ||
!wcscmp(findData.cFileName, L".."))
continue;
wcscpy(pszFileName, findData.cFileName);
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
SetFileAttributes(szFullName, dwAttribute);
if (bRecurse)
{
ChangeAttribute(szFullName, findData.cFileName, dwMask,
dwAttrib, bRecurse, FALSE);
}
}
else
{
wcscpy(pszFileName, findData.cFileName);
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
SetFileAttributes(szFullName, dwAttribute);
}
} while (FindNextFileW(hFind, &findData));
FindClose(hFind);
}
return TRUE;
}
int wmain(int argc, WCHAR *argv[])
{
INT i;
@ -258,6 +282,8 @@ int wmain(int argc, WCHAR *argv[])
BOOL bDirectories = FALSE;
DWORD dwAttrib = 0;
DWORD dwMask = 0;
LPWSTR p;
WCHAR szText[MAX_PATH];
/* Initialize the Console Standard Streams */
ConInitStdStreams();
@ -285,7 +311,7 @@ int wmain(int argc, WCHAR *argv[])
{
if (wcslen(argv[i]) != 2)
{
ConResPrintf(StdErr, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
ConResPrintf(StdOut, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
return -1;
}
@ -312,7 +338,7 @@ int wmain(int argc, WCHAR *argv[])
break;
default:
ConResPrintf(StdErr, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
ConResPrintf(StdOut, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
return -1;
}
}
@ -320,7 +346,7 @@ int wmain(int argc, WCHAR *argv[])
{
if (wcslen(argv[i]) != 2)
{
ConResPrintf(StdErr, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
ConResPrintf(StdOut, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
return -1;
}
@ -347,7 +373,7 @@ int wmain(int argc, WCHAR *argv[])
break;
default:
ConResPrintf(StdErr, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
ConResPrintf(StdOut, STRING_ERROR_INVALID_PARAM_FORMAT, argv[i]);
return -1;
}
}
@ -371,20 +397,21 @@ int wmain(int argc, WCHAR *argv[])
/* get full file name */
for (i = 1; i < argc; i++)
{
if ((*argv[i] != L'+') && (*argv[i] != L'-') && (*argv[i] != L'/'))
if (*argv[i] == L'+' || *argv[i] == L'-' || *argv[i] == L'/')
continue;
GetFullPathNameW(argv[i], MAX_PATH, szPath, &p);
wcscpy(szFileName, p);
*p = 0;
if (dwMask == 0)
{
LPWSTR p;
GetFullPathName(argv[i], MAX_PATH, szPath, NULL);
p = wcsrchr(szPath, L'\\') + 1;
wcscpy(szFileName, p);
*p = L'\0';
if (dwMask == 0)
PrintAttribute(szPath, szFileName, bRecurse);
else
ChangeAttribute(szPath, szFileName, dwMask,
dwAttrib, bRecurse, bDirectories);
PrintAttribute(szPath, szFileName, bRecurse);
}
else if (!ChangeAttribute(szPath, szFileName, dwMask,
dwAttrib, bRecurse, bDirectories))
{
ConResPrintf(StdOut, STRING_FILE_NOT_FOUND, argv[i]);
}
}

View File

@ -7,6 +7,7 @@ LANGUAGE LANG_CZECH, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Displays or changes file attributes.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Zeigt Dateiattribute an oder ändert sie.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] Dateiname ...\n\
[/S [/D]]\n\n\

View File

@ -7,6 +7,7 @@ LANGUAGE LANG_GREEK, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Προβολή ή αλλαγή των χαρακτηριστικών των αρχείων.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -2,6 +2,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Displays or changes file attributes.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_SPANISH, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Muestra o cambia los atributos de los archivos.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Affiche ou change des attributs de fichiers.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_HUNGARIAN, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Állományok attribútumok megjelenítése vagy beállításai.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] állomány ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_INDONESIAN, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Menampilkan atau mengubah atribut file.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -2,6 +2,7 @@ LANGUAGE LANG_ITALIAN, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Visualizza o modifica gli attributi dei file.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -2,6 +2,7 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "ファイル属性を表示または変更します。\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [ファイル] ...\n\
[/S [/D]]\n\n\

View File

@ -2,6 +2,7 @@ LANGUAGE LANG_NORWEGIAN, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Viser eller endrer filattributtene.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] fil ...\n\
[/S [/D]]\n\n\

View File

@ -11,6 +11,7 @@ LANGUAGE LANG_POLISH, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Wyświetla lub zmienia atrybuty plików.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] nazwa_pliku ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_ROMANIAN, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Afișează sau modifică atributele de fișiere.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] fișier ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Вывод и изменение атрибутов файлов.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] файл ...\n\
[/S [/D]]\n\n\

View File

@ -8,6 +8,7 @@ LANGUAGE LANG_SLOVAK, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Displays or changes file attributes.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -6,6 +6,7 @@ LANGUAGE LANG_ALBANIAN, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Shfaq ose ndryshu atributet e dokumentave.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\
[/S [/D]]\n\n\

View File

@ -2,6 +2,7 @@ LANGUAGE LANG_SWEDISH, SUBLANG_NEUTRAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Visar eller ändrar filattributen.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] fil ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_TURKISH, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Kütük öz niteliklerini görüntüler ya da değiştirir.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] kütük ...\n\
[/S [/D]]\n\n\

View File

@ -10,6 +10,7 @@ LANGUAGE LANG_UKRAINIAN, SUBLANG_DEFAULT
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "Відображення або зміна атрибутів файлу.\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] файл ...\n\
[/S [/D]]\n\n\

View File

@ -4,6 +4,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "显示或更改文件属性。\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] 文件 ...\n\
[/S [/D]]\n\n\

View File

@ -5,6 +5,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL
STRINGTABLE
BEGIN
STRING_FILE_NOT_FOUND "File not found - '%s'\n"
STRING_ATTRIB_HELP "顯示或更改檔案屬性。\n\n\
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] 檔案 ...\n\
[/S [/D]]\n\n\

View File

@ -5,3 +5,4 @@
#define STRING_ERROR_INVALID_PARAM_FORMAT 107
#define STRING_CONSOLE_ERROR 316
#define STRING_ATTRIB_HELP 600
#define STRING_FILE_NOT_FOUND 100