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 ******************************************************************/
15 PrintResourceString(INT resID
, ...)
20 va_start(arg_ptr
, resID
);
21 LoadStringW(GetModuleHandle(NULL
), resID
, szMsg
, 3072);
22 vwprintf(szMsg
, arg_ptr
);
29 WCHAR szComputerName
[MAX_STRING_SIZE
];
30 DWORD comp_size
= MAX_STRING_SIZE
;
32 /* Get the name of the computer for us and change the value of comp_name */
33 GetComputerNameW(szComputerName
, &comp_size
);
35 /* TODO: Remove this section of code when program becomes stable enough for production use. */
36 wprintf(L
"\n*WARNING*: This program is incomplete and may not work properly.\n");
38 /* Print the header information */
40 PrintResourceString(IDS_APP_HEADER
);
42 PrintResourceString(IDS_APP_LICENSE
);
43 PrintResourceString(IDS_APP_CURR_COMPUTER
, szComputerName
);
47 * RunScript(const char *filename):
48 * opens the file, reads the contents, convert the text into readable
49 * code for the computer, and then execute commands in order.
52 RunScript(LPCWSTR filename
)
55 WCHAR tmp_string
[MAX_STRING_SIZE
];
57 /* Open the file for processing */
58 script
= _wfopen(filename
, L
"r");
61 /* if there was problems opening the file */
62 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT
, filename
);
63 return FALSE
; /* if there is no script, exit the program */
66 /* Read and process the script */
67 while (fgetws(tmp_string
, MAX_STRING_SIZE
, script
) != NULL
)
69 if (InterpretScript(tmp_string
) == FALSE
)
81 * Main entry point of the application.
83 int wmain(int argc
, const LPWSTR argv
[])
85 LPCWSTR script
= NULL
;
86 LPCWSTR tmpBuffer
= NULL
;
90 /* Sets the title of the program so the user will have an easier time
91 determining the current program, especially if diskpart is running a
93 LoadStringW(GetModuleHandle(NULL
), IDS_APP_HEADER
, (LPWSTR
)appTitle
, 50);
94 SetConsoleTitleW(appTitle
);
96 /* Sets the timeout value to 0 just in case the user doesn't
100 /* If there are no command arguments, then go straight to the interpreter */
106 /* If there are command arguments, then process them */
109 for (index
= 1; index
< argc
; index
++)
111 /* checks for flags */
112 if ((argv
[index
][0] == '/')||
113 (argv
[index
][0] == '-'))
115 tmpBuffer
= argv
[index
] + 1;
119 /* If there is no flag, then return an error */
120 PrintResourceString(IDS_ERROR_MSG_BAD_ARG
, argv
[index
]);
124 /* Checks for the /? flag first since the program
125 exits as soon as the usage list is shown. */
126 if (_wcsicmp(tmpBuffer
, L
"?") == 0)
128 PrintResourceString(IDS_APP_USAGE
);
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 PrintResourceString(IDS_ERROR_MSG_BAD_ARG
, tmpBuffer
);
162 /* Shows the program information */
165 /* Now we process the filename if it exists */
168 /* if the timeout is greater than 0, then assume
169 that the user specified a specific time. */
171 Sleep(timeout
* 1000);
173 if (RunScript(script
) == FALSE
)
178 /* Exit failure since the user wanted to run a script */
179 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT
, script
);
184 /* Let the user know the program is exiting */
185 PrintResourceString(IDS_APP_LEAVING
);