mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[FORMAT] Improve imports, simplify code
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
|
||||
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/fmifs)
|
||||
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
|
||||
|
||||
add_executable(format format.c format.rc)
|
||||
set_module_type(format win32cui UNICODE)
|
||||
target_link_libraries(format conutils ${PSEH_LIB} oldnames)
|
||||
add_importlibs(format fmifs msvcrt kernel32 ntdll)
|
||||
target_link_libraries(format conutils)
|
||||
add_importlibs(format fmifs msvcrt kernel32)
|
||||
if(MSVC AND ARCH STREQUAL "i386")
|
||||
add_importlibs(format ntdll) # For _allmul
|
||||
endif()
|
||||
set_target_properties(format PROPERTIES SUFFIX ".com")
|
||||
add_cd_file(TARGET format DESTINATION reactos/system32 FOR all)
|
||||
|
||||
+36
-34
@@ -40,7 +40,6 @@
|
||||
//======================================================================
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
/* PSDK/NDK Headers */
|
||||
#define WIN32_NO_STATUS
|
||||
@@ -114,9 +113,15 @@ SIZEDEFINITION LegalSizes[] = {
|
||||
// Takes the win32 error code and prints the text version.
|
||||
//
|
||||
//----------------------------------------------------------------------
|
||||
static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
|
||||
static VOID PrintWin32Error(UINT Message, DWORD ErrorCode)
|
||||
{
|
||||
ConPrintf(StdErr, L"%s: ", Message);
|
||||
PCWSTR pszMsg;
|
||||
INT Len;
|
||||
|
||||
Len = LoadStringW(NULL, Message, (PWSTR)&pszMsg, 0);
|
||||
if (Len > 0)
|
||||
ConPrintf(StdErr, L"%.*s: ", Len, pszMsg);
|
||||
|
||||
ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL, ErrorCode, LANG_USER_DEFAULT);
|
||||
ConPuts(StdErr, L"\n");
|
||||
@@ -156,7 +161,7 @@ static int ParseCommandLine(int argc, WCHAR *argv[])
|
||||
if (gotSize) return -1;
|
||||
j = 0;
|
||||
while (LegalSizes[j].ClusterSize &&
|
||||
wcsicmp(LegalSizes[j].SizeString, &argv[i][3]))
|
||||
_wcsicmp(LegalSizes[j].SizeString, &argv[i][3]))
|
||||
{
|
||||
j++;
|
||||
}
|
||||
@@ -172,13 +177,13 @@ static int ParseCommandLine(int argc, WCHAR *argv[])
|
||||
gotLabel = TRUE;
|
||||
GotALabel = TRUE;
|
||||
}
|
||||
else if (!wcsicmp(&argv[i][1], L"Q"))
|
||||
else if (!_wcsicmp(&argv[i][1], L"Q"))
|
||||
{
|
||||
if (gotQuick) return -1;
|
||||
QuickFormat = TRUE;
|
||||
gotQuick = TRUE;
|
||||
}
|
||||
else if (!wcsicmp(&argv[i][1], L"C"))
|
||||
else if (!_wcsicmp(&argv[i][1], L"C"))
|
||||
{
|
||||
if (gotCompressed) return -1;
|
||||
CompressDrive = TRUE;
|
||||
@@ -314,16 +319,13 @@ static BOOLEAN LoadFMIFSEntryPoints(VOID)
|
||||
//----------------------------------------------------------------------
|
||||
static VOID Usage(LPWSTR ProgramName)
|
||||
{
|
||||
WCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||
WCHAR szFormats[MAX_PATH];
|
||||
WCHAR szFormatW[MAX_PATH];
|
||||
DWORD Index = 0;
|
||||
BYTE dummy;
|
||||
BOOLEAN latestVersion;
|
||||
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_HELP, szMsg, ARRAYSIZE(szMsg));
|
||||
|
||||
szFormats[0] = 0;
|
||||
szFormats[0] = UNICODE_NULL;
|
||||
while (QueryAvailableFileSystemFormat(Index++, szFormatW, &dummy, &dummy, &latestVersion))
|
||||
{
|
||||
if (!latestVersion)
|
||||
@@ -333,7 +335,7 @@ static VOID Usage(LPWSTR ProgramName)
|
||||
|
||||
wcscat(szFormats, szFormatW);
|
||||
}
|
||||
ConPrintf(StdOut, szMsg, ProgramName, szFormats);
|
||||
ConResPrintf(StdOut, STRING_HELP, ProgramName, szFormats);
|
||||
}
|
||||
|
||||
|
||||
@@ -360,8 +362,9 @@ int wmain(int argc, WCHAR *argv[])
|
||||
WCHAR input[1024];
|
||||
DWORD serialNumber;
|
||||
ULARGE_INTEGER totalNumberOfBytes, totalNumberOfFreeBytes;
|
||||
WCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||
DWORD dwError;
|
||||
PCWSTR pszMsg;
|
||||
INT Len;
|
||||
|
||||
/* Initialize the Console Standard Streams */
|
||||
ConInitStdStreams();
|
||||
@@ -471,8 +474,7 @@ int wmain(int argc, WCHAR *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
|
||||
PrintWin32Error(szMsg, dwError);
|
||||
PrintWin32Error(STRING_NO_VOLUME, dwError);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -499,8 +501,7 @@ int wmain(int argc, WCHAR *argv[])
|
||||
NULL))
|
||||
{
|
||||
dwError = GetLastError();
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
|
||||
PrintWin32Error(szMsg, dwError);
|
||||
PrintWin32Error(STRING_NO_VOLUME_SIZE, dwError);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -515,9 +516,9 @@ int wmain(int argc, WCHAR *argv[])
|
||||
{
|
||||
ConResPrintf(StdOut, STRING_LABEL_NAME_EDIT, RootDirectory[0]);
|
||||
fgetws(input, ARRAYSIZE(input), stdin);
|
||||
input[wcslen(input) - 1] = 0;
|
||||
input[wcslen(input) - 1] = UNICODE_NULL;
|
||||
|
||||
if (!wcsicmp(input, volumeName))
|
||||
if (!_wcsicmp(input, volumeName))
|
||||
break;
|
||||
|
||||
ConResPuts(StdOut, STRING_ERROR_LABEL);
|
||||
@@ -526,12 +527,14 @@ int wmain(int argc, WCHAR *argv[])
|
||||
|
||||
ConResPrintf(StdOut, STRING_YN_FORMAT, RootDirectory[0]);
|
||||
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_YES_NO_FAQ, szMsg, ARRAYSIZE(szMsg));
|
||||
Len = LoadStringW(NULL, STRING_YES_NO_FAQ, (PWSTR)&pszMsg, 0);
|
||||
if (Len < 2) pszMsg = L"YN";
|
||||
while (TRUE)
|
||||
{
|
||||
fgetws(input, ARRAYSIZE(input), stdin);
|
||||
if (_wcsnicmp(&input[0], &szMsg[0], 1) == 0) break;
|
||||
if (_wcsnicmp(&input[0], &szMsg[1], 1) == 0)
|
||||
if (towupper(input[0]) == pszMsg[0])
|
||||
break;
|
||||
if (towupper(input[0]) == pszMsg[1])
|
||||
{
|
||||
ConPuts(StdOut, L"\n");
|
||||
return 0;
|
||||
@@ -544,27 +547,29 @@ int wmain(int argc, WCHAR *argv[])
|
||||
//
|
||||
if (!QuickFormat)
|
||||
{
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_VERIFYING, szMsg, ARRAYSIZE(szMsg));
|
||||
Len = LoadStringW(NULL, STRING_VERIFYING, (PWSTR)&pszMsg, 0);
|
||||
if (totalNumberOfBytes.QuadPart > 1024*1024*10)
|
||||
{
|
||||
ConPrintf(StdOut, L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
|
||||
ConPrintf(StdOut, L"%.*s %luM\n", Len, pszMsg,
|
||||
(DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ConPrintf(StdOut, L"%s %.1fM\n", szMsg,
|
||||
ConPrintf(StdOut, L"%.*s %.1fM\n", Len, pszMsg,
|
||||
((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_FAST_FMT, szMsg, ARRAYSIZE(szMsg));
|
||||
Len = LoadStringW(NULL, STRING_FAST_FMT, (PWSTR)&pszMsg, 0);
|
||||
if (totalNumberOfBytes.QuadPart > 1024*1024*10)
|
||||
{
|
||||
ConPrintf(StdOut, L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
|
||||
ConPrintf(StdOut, L"%.*s %luM\n", Len, pszMsg,
|
||||
(DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ConPrintf(StdOut, L"%s %.2fM\n", szMsg,
|
||||
ConPrintf(StdOut, L"%.*s %.2fM\n", Len, pszMsg,
|
||||
((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
|
||||
}
|
||||
ConResPuts(StdOut, STRING_CREATE_FSYS);
|
||||
@@ -595,13 +600,12 @@ int wmain(int argc, WCHAR *argv[])
|
||||
{
|
||||
ConResPuts(StdOut, STRING_ENTER_LABEL);
|
||||
fgetws(input, ARRAYSIZE(LabelString), stdin);
|
||||
input[wcslen(input) - 1] = UNICODE_NULL;
|
||||
|
||||
input[wcslen(input) - 1] = 0;
|
||||
if (!SetVolumeLabelW(RootDirectory, input))
|
||||
{
|
||||
dwError = GetLastError();
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_NO_LABEL, szMsg, ARRAYSIZE(szMsg));
|
||||
PrintWin32Error(szMsg, dwError);
|
||||
PrintWin32Error(STRING_NO_LABEL, dwError);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -615,8 +619,7 @@ int wmain(int argc, WCHAR *argv[])
|
||||
&totalNumberOfFreeBytes))
|
||||
{
|
||||
dwError = GetLastError();
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
|
||||
PrintWin32Error(szMsg, dwError);
|
||||
PrintWin32Error(STRING_NO_VOLUME_SIZE, dwError);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -632,8 +635,7 @@ int wmain(int argc, WCHAR *argv[])
|
||||
NULL, 0))
|
||||
{
|
||||
dwError = GetLastError();
|
||||
K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
|
||||
PrintWin32Error(szMsg, dwError);
|
||||
PrintWin32Error(STRING_NO_VOLUME, dwError);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define REACTOS_STR_FILE_DESCRIPTION "Disk Format Utility"
|
||||
#define REACTOS_STR_INTERNAL_NAME "format"
|
||||
#define REACTOS_STR_ORIGINAL_FILENAME "format.com"
|
||||
#define REACTOS_STR_FILE_DESCRIPTION "Disk Format Utility"
|
||||
#define REACTOS_STR_INTERNAL_NAME "format"
|
||||
#define REACTOS_STR_ORIGINAL_FILENAME "format.com"
|
||||
#include <reactos/version.rc>
|
||||
|
||||
/* UTF-8 */
|
||||
|
||||
Reference in New Issue
Block a user