2 * PROJECT: ReactOS DiskPart
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/diskpart/diskpart.c
5 * PURPOSE: Manages all the partitions of the OS in an interactive way.
6 * PROGRAMMERS: Lee Schroeder
9 /* INCLUDES ******************************************************************/
13 /* FUNCTIONS ******************************************************************/
18 WCHAR szComputerName
[MAX_STRING_SIZE
];
19 DWORD comp_size
= MAX_STRING_SIZE
;
21 /* Get the name of the computer for us and change the value of comp_name */
22 GetComputerNameW(szComputerName
, &comp_size
);
24 /* TODO: Remove this section of code when program becomes stable enough for production use. */
25 ConPuts(StdOut
, L
"\n*WARNING*: This program is incomplete and may not work properly.\n");
27 /* Print the header information */
28 ConPuts(StdOut
, L
"\n");
29 ConResPuts(StdOut
, IDS_APP_HEADER
);
30 ConPuts(StdOut
, L
"\n");
31 ConResPuts(StdOut
, IDS_APP_LICENSE
);
32 ConResPrintf(StdOut
, IDS_APP_CURR_COMPUTER
, szComputerName
);
36 * RunScript(const char *filename):
37 * opens the file, reads the contents, convert the text into readable
38 * code for the computer, and then execute commands in order.
41 RunScript(LPCWSTR filename
)
44 WCHAR tmp_string
[MAX_STRING_SIZE
];
46 /* Open the file for processing */
47 script
= _wfopen(filename
, L
"r");
50 /* if there was problems opening the file */
51 ConResPrintf(StdErr
, IDS_ERROR_MSG_NO_SCRIPT
, filename
);
52 return FALSE
; /* if there is no script, exit the program */
55 /* Read and process the script */
56 while (fgetws(tmp_string
, MAX_STRING_SIZE
, script
) != NULL
)
58 if (InterpretScript(tmp_string
) == FALSE
)
73 * Main entry point of the application.
75 int wmain(int argc
, const LPWSTR argv
[])
77 LPCWSTR script
= NULL
;
78 LPCWSTR tmpBuffer
= NULL
;
81 int result
= EXIT_SUCCESS
;
83 /* Initialize the Console Standard Streams */
86 /* Sets the title of the program so the user will have an easier time
87 determining the current program, especially if diskpart is running a
89 K32LoadStringW(GetModuleHandle(NULL
), IDS_APP_HEADER
, appTitle
, ARRAYSIZE(appTitle
));
90 SetConsoleTitleW(appTitle
);
92 /* Sets the timeout value to 0 just in case the user doesn't
96 CreatePartitionList();
98 /* If there are no command arguments, then go straight to the interpreter */
104 /* If there are command arguments, then process them */
107 for (index
= 1; index
< argc
; index
++)
109 /* checks for flags */
110 if ((argv
[index
][0] == '/')||
111 (argv
[index
][0] == '-'))
113 tmpBuffer
= argv
[index
] + 1;
117 /* If there is no flag, then return an error */
118 ConResPrintf(StdErr
, IDS_ERROR_MSG_BAD_ARG
, argv
[index
]);
119 result
= EXIT_FAILURE
;
123 /* Checks for the /? flag first since the program
124 exits as soon as the usage list is shown. */
125 if (_wcsicmp(tmpBuffer
, L
"?") == 0)
127 ConResPuts(StdOut
, IDS_APP_USAGE
);
128 result
= EXIT_SUCCESS
;
131 /* Checks for the script flag */
132 else if (_wcsicmp(tmpBuffer
, L
"s") == 0)
134 if ((index
+ 1) < argc
)
137 script
= argv
[index
];
140 /* Checks for the timeout flag */
141 else if (_wcsicmp(tmpBuffer
, L
"t") == 0)
143 if ((index
+ 1) < argc
)
146 timeout
= _wtoi(argv
[index
]);
148 /* If the number is a negative number, then
149 change it so that the time is executed properly. */
156 /* Assume that the flag doesn't exist. */
157 ConResPrintf(StdErr
, IDS_ERROR_MSG_BAD_ARG
, tmpBuffer
);
158 result
= EXIT_FAILURE
;
163 /* Shows the program information */
166 /* Now we process the filename if it exists */
169 /* if the timeout is greater than 0, then assume
170 that the user specified a specific time. */
172 Sleep(timeout
* 1000);
174 if (RunScript(script
) == FALSE
)
176 result
= EXIT_FAILURE
;
182 /* Exit failure since the user wanted to run a script */
183 ConResPrintf(StdErr
, IDS_ERROR_MSG_NO_SCRIPT
, script
);
184 result
= EXIT_FAILURE
;
189 /* Let the user know the program is exiting */
190 ConResPuts(StdOut
, IDS_APP_LEAVING
);
193 DestroyPartitionList();