ReactOS 0.4.16-dev-2104-gb84fa49
diskpart.c
Go to the documentation of this file.
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 an interactive way.
6 * PROGRAMMERS: Lee Schroeder
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "diskpart.h"
12
13/* FUNCTIONS ******************************************************************/
14
15VOID
17{
18 WCHAR szComputerName[MAX_STRING_SIZE];
19 DWORD comp_size = MAX_STRING_SIZE;
20
21 /* Get the name of the computer for us and change the value of comp_name */
22 GetComputerNameW(szComputerName, &comp_size);
23
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");
26
27 /* Print the header information */
28 ConPuts(StdOut, L"\n");
30 ConPuts(StdOut, L"\n");
33}
34
35/*
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.
39 */
42{
43 FILE *script;
44 WCHAR tmp_string[MAX_STRING_SIZE];
46
47 /* Open the file for processing */
48 script = _wfopen(filename, L"r");
49 if (script == NULL)
50 {
51 /* if there was problems opening the file */
53 return FALSE; /* if there is no script, exit the program */
54 }
55
56 /* Read and process the script */
57 while (fgetws(tmp_string, MAX_STRING_SIZE, script) != NULL)
58 {
59 Result = InterpretScript(tmp_string);
60 if (Result != EXIT_SUCCESS)
61 {
63 return (Result == EXIT_EXIT) ? EXIT_SUCCESS : Result;
64 }
65 }
66
67 /* Close the file */
69
70 return EXIT_SUCCESS;
71}
72
73/*
74 * wmain():
75 * Main entry point of the application.
76 */
77int wmain(int argc, const LPWSTR argv[])
78{
80 LPCWSTR tmpBuffer = NULL;
81 WCHAR appTitle[50];
82 int index, timeout;
83 int result = EXIT_SUCCESS;
84
85 /* Initialize the Console Standard Streams */
87
88 /* Sets the title of the program so the user will have an easier time
89 determining the current program, especially if diskpart is running a
90 script */
92 SetConsoleTitleW(appTitle);
93
94 /* Sets the timeout value to 0 just in case the user doesn't
95 specify a value */
96 timeout = 0;
97
100
101 /* If there are no command arguments, then go straight to the interpreter */
102 if (argc < 2)
103 {
104 ShowHeader();
106 }
107 /* If there are command arguments, then process them */
108 else
109 {
110 for (index = 1; index < argc; index++)
111 {
112 /* checks for flags */
113 if ((argv[index][0] == '/')||
114 (argv[index][0] == '-'))
115 {
116 tmpBuffer = argv[index] + 1;
117 }
118 else
119 {
120 /* If there is no flag, then return an error */
123 goto done;
124 }
125
126 /* Checks for the /? flag first since the program
127 exits as soon as the usage list is shown. */
128 if (_wcsicmp(tmpBuffer, L"?") == 0)
129 {
132 goto done;
133 }
134 /* Checks for the script flag */
135 else if (_wcsicmp(tmpBuffer, L"s") == 0)
136 {
137 if ((index + 1) < argc)
138 {
139 index++;
140 script = argv[index];
141 }
142 }
143 /* Checks for the timeout flag */
144 else if (_wcsicmp(tmpBuffer, L"t") == 0)
145 {
146 if ((index + 1) < argc)
147 {
148 index++;
150
151 /* If the number is a negative number, then
152 change it so that the time is executed properly. */
153 if (timeout < 0)
154 timeout = 0;
155 }
156 }
157 else
158 {
159 /* Assume that the flag doesn't exist. */
162 goto done;
163 }
164 }
165
166 /* Shows the program information */
167 ShowHeader();
168
169 /* Now we process the filename if it exists */
170 if (script != NULL)
171 {
172 /* if the timeout is greater than 0, then assume
173 that the user specified a specific time. */
174 if (timeout > 0)
175 Sleep(timeout * 1000);
176
178 if (result != EXIT_SUCCESS)
179 goto done;
180 }
181 else
182 {
183 /* Exit failure since the user wanted to run a script */
186 goto done;
187 }
188 }
189
190 /* Let the user know the program is exiting */
192
193done:
196
197 return result;
198}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define index(s, c)
Definition: various.h:29
#define MAX_STRING_SIZE
Definition: precomp.h:40
#define IDS_APP_USAGE
Definition: resource.h:12
#define IDS_ERROR_MSG_NO_SCRIPT
Definition: resource.h:227
#define IDS_APP_CURR_COMPUTER
Definition: resource.h:17
#define IDS_APP_LICENSE
Definition: resource.h:16
#define IDS_APP_HEADER
Definition: resource.h:14
#define IDS_APP_LEAVING
Definition: resource.h:18
#define IDS_ERROR_MSG_BAD_ARG
Definition: resource.h:228
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
VOID ShowHeader(VOID)
Definition: diskpart.c:16
EXIT_CODE RunScript(LPCWSTR filename)
Definition: diskpart.c:41
enum _EXIT_CODE EXIT_CODE
VOID DestroyVolumeList(VOID)
Definition: partlist.c:2005
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1967
VOID InterpretMain(VOID)
Definition: interpreter.c:232
EXIT_CODE InterpretScript(_In_ LPWSTR line)
@ EXIT_EXIT
Definition: diskpart.h:81
@ EXIT_SYNTAX
Definition: diskpart.h:80
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleTitleW(LPCWSTR lpConsoleTitle)
Definition: console.c:2292
int CDECL fclose(FILE *file)
Definition: file.c:3757
wchar_t *CDECL fgetws(wchar_t *s, int size, FILE *file)
Definition: file.c:4043
FILE *CDECL _wfopen(const wchar_t *path, const wchar_t *mode)
Definition: file.c:4335
_ACRTIMP int __cdecl _wtoi(const wchar_t *)
Definition: wcs.c:2773
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint index
Definition: glext.h:6031
GLuint64EXT * result
Definition: glext.h:11304
const char * filename
Definition: ioapi.h:137
#define argv
Definition: mplay32.c:18
script
Definition: msipriv.h:383
int wmain()
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:173
VOID NTAPI DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2074
PPARTLIST NTAPI CreatePartitionList(VOID)
Definition: partlist.c:1988
Definition: dhcpd.h:248
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define GetModuleHandle
Definition: winbase.h:3576
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184