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
|
2016-10-01 22:58:21 +00:00
|
|
|
* PURPOSE: Manages all the partitions of the OS in an interactive way.
|
2011-09-24 10:33:33 +00:00
|
|
|
* PROGRAMMERS: Lee Schroeder
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
2014-01-13 13:07:50 +00:00
|
|
|
|
2011-09-24 10:33:33 +00:00
|
|
|
#include "diskpart.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
2015-07-20 19:17:06 +00:00
|
|
|
|
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. */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n*WARNING*: This program is incomplete and may not work properly.\n");
|
2012-07-24 20:23:24 +00:00
|
|
|
|
|
|
|
/* Print the header information */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPuts(StdOut, IDS_APP_HEADER);
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPuts(StdOut, IDS_APP_LICENSE);
|
|
|
|
ConResPrintf(StdOut, IDS_APP_CURR_COMPUTER, szComputerName);
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
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 */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdErr, IDS_ERROR_MSG_NO_SCRIPT, filename);
|
2011-09-24 10:33:33 +00:00
|
|
|
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)
|
2014-04-05 15:26:12 +00:00
|
|
|
{
|
|
|
|
fclose(script);
|
2011-09-24 10:33:33 +00:00
|
|
|
return FALSE;
|
2014-04-05 15:26:12 +00:00
|
|
|
}
|
2011-09-24 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2013-05-29 11:40:43 +00:00
|
|
|
int wmain(int argc, const LPWSTR argv[])
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2012-07-24 20:23:24 +00:00
|
|
|
LPCWSTR script = NULL;
|
|
|
|
LPCWSTR tmpBuffer = NULL;
|
2013-05-29 11:40:43 +00:00
|
|
|
WCHAR appTitle[50];
|
2012-07-24 20:23:24 +00:00
|
|
|
int index, timeout;
|
2015-07-20 19:17:06 +00:00
|
|
|
int result = EXIT_SUCCESS;
|
2011-09-24 10:33:33 +00:00
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
/* Initialize the Console Standard Streams */
|
|
|
|
ConInitStdStreams();
|
|
|
|
|
2013-05-29 11:40:43 +00:00
|
|
|
/* Sets the title of the program so the user will have an easier time
|
|
|
|
determining the current program, especially if diskpart is running a
|
|
|
|
script */
|
2016-10-07 22:50:32 +00:00
|
|
|
K32LoadStringW(GetModuleHandle(NULL), IDS_APP_HEADER, appTitle, ARRAYSIZE(appTitle));
|
2013-05-29 11:40:43 +00:00
|
|
|
SetConsoleTitleW(appTitle);
|
2015-07-20 19:17:06 +00:00
|
|
|
|
2012-07-24 20:23:24 +00:00
|
|
|
/* Sets the timeout value to 0 just in case the user doesn't
|
2013-05-29 11:40:43 +00:00
|
|
|
specify a value */
|
2012-07-24 20:23:24 +00:00
|
|
|
timeout = 0;
|
2011-09-24 10:33:33 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
CreatePartitionList();
|
|
|
|
|
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 */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdErr, IDS_ERROR_MSG_BAD_ARG, argv[index]);
|
2015-07-20 19:17:06 +00:00
|
|
|
result = EXIT_FAILURE;
|
|
|
|
goto done;
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_APP_USAGE);
|
2015-07-20 19:17:06 +00:00
|
|
|
result = EXIT_SUCCESS;
|
|
|
|
goto done;
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
|
|
|
/* 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. */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdErr, IDS_ERROR_MSG_BAD_ARG, tmpBuffer);
|
2015-07-20 19:17:06 +00:00
|
|
|
result = EXIT_FAILURE;
|
|
|
|
goto done;
|
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)
|
2015-07-20 19:17:06 +00:00
|
|
|
{
|
|
|
|
result = EXIT_FAILURE;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Exit failure since the user wanted to run a script */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdErr, IDS_ERROR_MSG_NO_SCRIPT, script);
|
2015-07-20 19:17:06 +00:00
|
|
|
result = EXIT_FAILURE;
|
|
|
|
goto done;
|
2012-07-24 20:23:24 +00:00
|
|
|
}
|
2011-09-24 10:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Let the user know the program is exiting */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_APP_LEAVING);
|
2011-09-24 10:33:33 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
done:
|
|
|
|
DestroyPartitionList();
|
|
|
|
|
|
|
|
return result;
|
2011-09-24 10:33:33 +00:00
|
|
|
}
|