243eadf7e5271f0f591541a15e9d1de0ea1a4569
[reactos.git] / reactos / base / system / diskpart / diskpart.c
1 /*
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
6 * an interactive way
7 * PROGRAMMERS: Lee Schroeder
8 */
9
10 /* INCLUDES ******************************************************************/
11 #include "diskpart.h"
12
13 /* FUNCTIONS ******************************************************************/
14
15 VOID
16 PrintResourceString(INT resID, ...)
17 {
18 WCHAR szMsg[3072];
19 va_list arg_ptr;
20
21 va_start(arg_ptr, resID);
22 LoadStringW(GetModuleHandle(NULL), resID, szMsg, 3072);
23 vwprintf(szMsg, arg_ptr);
24 va_end(arg_ptr);
25 }
26
27
28 /*
29 * run_script(const char *filename):
30 * opens the file, reads the contents, convert the text into readable
31 * code for the computer, and then execute commands in order.
32 */
33 BOOL run_script(LPCWSTR filename)
34 {
35 FILE *script_file;
36 WCHAR tmp_string[MAX_STRING_SIZE];
37
38 /* Open the file for processing */
39 script_file = _wfopen(filename, L"r");
40 if (script_file == NULL)
41 {
42 /* if there was problems opening the file */
43 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT, filename);
44 return FALSE; /* if there is no script, exit the program */
45 }
46
47 /* Read and process the script */
48 while (fgetws(tmp_string, MAX_STRING_SIZE, script_file) != NULL)
49 {
50 if (interpret_script(tmp_string) == FALSE)
51 return FALSE;
52 }
53
54 /* Close the file */
55 fclose(script_file);
56
57 return TRUE;
58 }
59
60 /*
61 * main():
62 * Main entry point of the application.
63 */
64 int wmain(int argc, const WCHAR *argv[])
65 {
66 /* Gets the current name of the computer */
67 WCHAR comp_name[MAX_STRING_SIZE]; //used to store the name of the computer */
68 DWORD comp_size = MAX_STRING_SIZE; // used for the char size of comp_name */
69 BOOL interpreter_running = TRUE; //used for the main program loop */
70
71 /* Get the name of the computer for us and change the value of comp_name */
72 GetComputerName(comp_name, &comp_size);
73
74 /* TODO: Remove this section of code when program becomes stable enough for production use. */
75 wprintf(L"\n*WARNING*: This program is incomplete and may not work properly.\n");
76
77 /* Print the header information */
78 PrintResourceString(IDS_APP_HEADER, DISKPART_VERSION);
79 PrintResourceString(IDS_APP_LICENSE);
80 PrintResourceString(IDS_APP_CURR_COMPUTER, comp_name);
81
82 /* Find out if the user is loading a script */
83 if (argc >= 2)
84 {
85 /* if there are arguments when starting the program
86 determine if the script flag is enabled */
87 if ((wcsicmp(argv[1], L"/s") == 0) ||
88 (wcsicmp(argv[1], L"-s") == 0))
89 {
90 /* see if the user has put anything after the script flag; if not,
91 then it doesn't run the run_script() command. */
92 /* Alternative comment: Fail if the script name is missing */
93 if (argc == 3)
94 return EXIT_FAILURE;
95
96 interpreter_running = run_script(argv[2]);
97 }
98 }
99
100 /* the main program loop */
101 while (interpreter_running)
102 {
103 interpreter_running = interpret_main();
104 }
105
106 /* Let the user know the program is exiting */
107 PrintResourceString(IDS_APP_LEAVING);
108
109 return EXIT_SUCCESS;
110 }