2011-09-24 10:33:33 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS DiskPart
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/system/diskpart/diskpart.c
|
|
|
|
* PURPOSE: Manages all the partitions of the OS in
|
2011-10-22 19:52:17 +00:00
|
|
|
* an interactive way
|
2011-09-24 10:33:33 +00:00
|
|
|
* PROGRAMMERS: Lee Schroeder
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
#include "diskpart.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
PrintResourceString(INT resID, ...)
|
|
|
|
{
|
|
|
|
WCHAR szMsg[3072];
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
va_start(arg_ptr, resID);
|
|
|
|
LoadStringW(GetModuleHandle(NULL), resID, szMsg, 3072);
|
|
|
|
vwprintf(szMsg, arg_ptr);
|
|
|
|
va_end(arg_ptr);
|
|
|
|
}
|
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
VOID
|
|
|
|
ShowHeader(VOID)
|
|
|
|
{
|
|
|
|
WCHAR szComputerName[MAX_STRING_SIZE];
|
|
|
|
DWORD comp_size = MAX_STRING_SIZE;
|
|
|
|
|
|
|
|
/* Get the name of the computer for us and change the value of comp_name */
|
2012-11-17 16:01:29 +00:00
|
|
|
GetComputerNameW(szComputerName, &comp_size);
|
2012-07-24 20:23:24 +00:00
|
|
|
|
|
|
|
/* TODO: Remove this section of code when program becomes stable enough for production use. */
|
|
|
|
wprintf(L"\n*WARNING*: This program is incomplete and may not work properly.\n");
|
|
|
|
|
|
|
|
/* Print the header information */
|
|
|
|
PrintResourceString(IDS_APP_HEADER);
|
|
|
|
PrintResourceString(IDS_APP_LICENSE);
|
|
|
|
PrintResourceString(IDS_APP_CURR_COMPUTER, szComputerName);
|
|
|
|
}
|
2011-09-24 10:33:33 +00:00
|
|
|
|
|
|
|
/*
|
2012-07-24 20:23:24 +00:00
|
|
|
* RunScript(const char *filename):
|
2011-09-24 10:33:33 +00:00
|
|
|
* opens the file, reads the contents, convert the text into readable
|
|
|
|
* code for the computer, and then execute commands in order.
|
|
|
|
*/
|
2011-10-22 19:52:17 +00:00
|
|
|
BOOL
|
2012-07-24 20:23:24 +00:00
|
|
|
RunScript(LPCWSTR filename)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
FILE *script;
|
2011-09-24 10:33:33 +00:00
|
|
|
WCHAR tmp_string[MAX_STRING_SIZE];
|
|
|
|
|
|
|
|
/* Open the file for processing */
|
2012-07-24 20:23:24 +00:00
|
|
|
script = _wfopen(filename, L"r");
|
|
|
|
if (script == NULL)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
|
|
|
/* if there was problems opening the file */
|
|
|
|
PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT, filename);
|
|
|
|
return FALSE; /* if there is no script, exit the program */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read and process the script */
|
2012-07-24 20:23:24 +00:00
|
|
|
while (fgetws(tmp_string, MAX_STRING_SIZE, script) != NULL)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
if (InterpretScript(tmp_string) == FALSE)
|
2011-09-24 10:33:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the file */
|
2012-07-24 20:23:24 +00:00
|
|
|
fclose(script);
|
2011-09-24 10:33:33 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-10-22 19:52:17 +00:00
|
|
|
* wmain():
|
2011-09-24 10:33:33 +00:00
|
|
|
* Main entry point of the application.
|
|
|
|
*/
|
|
|
|
int wmain(int argc, const WCHAR *argv[])
|
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
LPCWSTR script = NULL;
|
|
|
|
LPCWSTR tmpBuffer = NULL;
|
|
|
|
int index, timeout;
|
2011-09-24 10:33:33 +00:00
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Sets the timeout value to 0 just in case the user doesn't
|
|
|
|
specify a value. */
|
|
|
|
timeout = 0;
|
2011-09-24 10:33:33 +00:00
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* If there are no command arguments, then go straight to the interpreter */
|
|
|
|
if (argc < 2)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
ShowHeader();
|
|
|
|
InterpretMain();
|
|
|
|
}
|
|
|
|
/* If there are command arguments, then process them */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (index = 1; index < argc; index++)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
/* checks for flags */
|
|
|
|
if ((argv[index][0] == '/')||
|
|
|
|
(argv[index][0] == '-'))
|
2011-10-22 19:52:17 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
tmpBuffer = argv[index] + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If there is no flag, then return an error */
|
|
|
|
PrintResourceString(IDS_ERROR_MSG_BAD_ARG, argv[index]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2011-10-22 19:52:17 +00:00
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Checks for the /? flag first since the program
|
|
|
|
exits as soon as the usage list is shown. */
|
|
|
|
if (_wcsicmp(tmpBuffer, L"?") == 0)
|
|
|
|
{
|
|
|
|
PrintResourceString(IDS_APP_USAGE);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
/* Checks for the script flag */
|
|
|
|
else if (_wcsicmp(tmpBuffer, L"s") == 0)
|
|
|
|
{
|
|
|
|
if ((index + 1) < argc)
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
script = argv[index];
|
2011-10-22 19:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Checks for the timeout flag */
|
|
|
|
else if (_wcsicmp(tmpBuffer, L"t") == 0)
|
2011-10-22 19:52:17 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
if ((index + 1) < argc)
|
2011-10-22 19:52:17 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
index++;
|
|
|
|
timeout = _wtoi(argv[index]);
|
2011-10-22 19:52:17 +00:00
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* If the number is a negative number, then
|
|
|
|
change it so that the time is executed properly. */
|
|
|
|
if (timeout < 0)
|
|
|
|
timeout = 0;
|
2011-10-22 19:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-24 20:23:24 +00:00
|
|
|
else
|
2011-10-23 12:04:48 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Assume that the flag doesn't exist. */
|
|
|
|
PrintResourceString(IDS_ERROR_MSG_BAD_ARG, tmpBuffer);
|
|
|
|
return EXIT_FAILURE;
|
2011-10-23 12:04:48 +00:00
|
|
|
}
|
2011-09-24 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Shows the program information */
|
|
|
|
ShowHeader();
|
|
|
|
|
|
|
|
/* Now we process the filename if it exists */
|
|
|
|
if (script != NULL)
|
|
|
|
{
|
|
|
|
/* if the timeout is greater than 0, then assume
|
|
|
|
that the user specified a specific time. */
|
|
|
|
if (timeout > 0)
|
|
|
|
Sleep(timeout * 1000);
|
|
|
|
|
|
|
|
if (RunScript(script) == FALSE)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Exit failure since the user wanted to run a script */
|
|
|
|
PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT, script);
|
2011-10-22 19:52:17 +00:00
|
|
|
return EXIT_FAILURE;
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
2011-09-24 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Let the user know the program is exiting */
|
|
|
|
PrintResourceString(IDS_APP_LEAVING);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|