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
7 * PROGRAMMERS: Lee Schroeder
10 /* INCLUDES ******************************************************************/
13 /* FUNCTIONS ******************************************************************/
16 PrintResourceString(INT resID
, ...)
21 va_start(arg_ptr
, resID
);
22 LoadStringW(GetModuleHandle(NULL
), resID
, szMsg
, 3072);
23 vwprintf(szMsg
, arg_ptr
);
30 WCHAR szComputerName
[MAX_STRING_SIZE
];
31 DWORD comp_size
= MAX_STRING_SIZE
;
33 /* Get the name of the computer for us and change the value of comp_name */
34 GetComputerNameW(szComputerName
, &comp_size
);
36 /* TODO: Remove this section of code when program becomes stable enough for production use. */
37 wprintf(L
"\n*WARNING*: This program is incomplete and may not work properly.\n");
39 /* Print the header information */
40 PrintResourceString(IDS_APP_HEADER
);
41 PrintResourceString(IDS_APP_LICENSE
);
42 PrintResourceString(IDS_APP_CURR_COMPUTER
, szComputerName
);
46 * RunScript(const char *filename):
47 * opens the file, reads the contents, convert the text into readable
48 * code for the computer, and then execute commands in order.
51 RunScript(LPCWSTR filename
)
54 WCHAR tmp_string
[MAX_STRING_SIZE
];
56 /* Open the file for processing */
57 script
= _wfopen(filename
, L
"r");
60 /* if there was problems opening the file */
61 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT
, filename
);
62 return FALSE
; /* if there is no script, exit the program */
65 /* Read and process the script */
66 while (fgetws(tmp_string
, MAX_STRING_SIZE
, script
) != NULL
)
68 if (InterpretScript(tmp_string
) == FALSE
)
80 * Main entry point of the application.
82 int wmain(int argc
, const WCHAR
*argv
[])
84 LPCWSTR script
= NULL
;
85 LPCWSTR tmpBuffer
= NULL
;
88 /* Sets the timeout value to 0 just in case the user doesn't
92 /* If there are no command arguments, then go straight to the interpreter */
98 /* If there are command arguments, then process them */
101 for (index
= 1; index
< argc
; index
++)
103 /* checks for flags */
104 if ((argv
[index
][0] == '/')||
105 (argv
[index
][0] == '-'))
107 tmpBuffer
= argv
[index
] + 1;
111 /* If there is no flag, then return an error */
112 PrintResourceString(IDS_ERROR_MSG_BAD_ARG
, argv
[index
]);
116 /* Checks for the /? flag first since the program
117 exits as soon as the usage list is shown. */
118 if (_wcsicmp(tmpBuffer
, L
"?") == 0)
120 PrintResourceString(IDS_APP_USAGE
);
123 /* Checks for the script flag */
124 else if (_wcsicmp(tmpBuffer
, L
"s") == 0)
126 if ((index
+ 1) < argc
)
129 script
= argv
[index
];
132 /* Checks for the timeout flag */
133 else if (_wcsicmp(tmpBuffer
, L
"t") == 0)
135 if ((index
+ 1) < argc
)
138 timeout
= _wtoi(argv
[index
]);
140 /* If the number is a negative number, then
141 change it so that the time is executed properly. */
148 /* Assume that the flag doesn't exist. */
149 PrintResourceString(IDS_ERROR_MSG_BAD_ARG
, tmpBuffer
);
154 /* Shows the program information */
157 /* Now we process the filename if it exists */
160 /* if the timeout is greater than 0, then assume
161 that the user specified a specific time. */
163 Sleep(timeout
* 1000);
165 if (RunScript(script
) == FALSE
)
170 /* Exit failure since the user wanted to run a script */
171 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT
, script
);
176 /* Let the user know the program is exiting */
177 PrintResourceString(IDS_APP_LEAVING
);