ReactOS  0.4.13-dev-99-g7e18b6d
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 
15 VOID
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");
32  ConResPrintf(StdOut, IDS_APP_CURR_COMPUTER, szComputerName);
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  */
40 BOOL
42 {
43  FILE *script;
44  WCHAR tmp_string[MAX_STRING_SIZE];
45 
46  /* Open the file for processing */
47  script = _wfopen(filename, L"r");
48  if (script == NULL)
49  {
50  /* if there was problems opening the file */
52  return FALSE; /* if there is no script, exit the program */
53  }
54 
55  /* Read and process the script */
56  while (fgetws(tmp_string, MAX_STRING_SIZE, script) != NULL)
57  {
58  if (InterpretScript(tmp_string) == FALSE)
59  {
60  fclose(script);
61  return FALSE;
62  }
63  }
64 
65  /* Close the file */
66  fclose(script);
67 
68  return TRUE;
69 }
70 
71 /*
72  * wmain():
73  * Main entry point of the application.
74  */
75 int wmain(int argc, const LPWSTR argv[])
76 {
78  LPCWSTR tmpBuffer = NULL;
79  WCHAR appTitle[50];
80  int index, timeout;
81  int result = EXIT_SUCCESS;
82 
83  /* Initialize the Console Standard Streams */
85 
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
88  script */
90  SetConsoleTitleW(appTitle);
91 
92  /* Sets the timeout value to 0 just in case the user doesn't
93  specify a value */
94  timeout = 0;
95 
97 
98  /* If there are no command arguments, then go straight to the interpreter */
99  if (argc < 2)
100  {
101  ShowHeader();
102  InterpretMain();
103  }
104  /* If there are command arguments, then process them */
105  else
106  {
107  for (index = 1; index < argc; index++)
108  {
109  /* checks for flags */
110  if ((argv[index][0] == '/')||
111  (argv[index][0] == '-'))
112  {
113  tmpBuffer = argv[index] + 1;
114  }
115  else
116  {
117  /* If there is no flag, then return an error */
120  goto done;
121  }
122 
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)
126  {
129  goto done;
130  }
131  /* Checks for the script flag */
132  else if (_wcsicmp(tmpBuffer, L"s") == 0)
133  {
134  if ((index + 1) < argc)
135  {
136  index++;
137  script = argv[index];
138  }
139  }
140  /* Checks for the timeout flag */
141  else if (_wcsicmp(tmpBuffer, L"t") == 0)
142  {
143  if ((index + 1) < argc)
144  {
145  index++;
146  timeout = _wtoi(argv[index]);
147 
148  /* If the number is a negative number, then
149  change it so that the time is executed properly. */
150  if (timeout < 0)
151  timeout = 0;
152  }
153  }
154  else
155  {
156  /* Assume that the flag doesn't exist. */
159  goto done;
160  }
161  }
162 
163  /* Shows the program information */
164  ShowHeader();
165 
166  /* Now we process the filename if it exists */
167  if (script != NULL)
168  {
169  /* if the timeout is greater than 0, then assume
170  that the user specified a specific time. */
171  if (timeout > 0)
172  Sleep(timeout * 1000);
173 
174  if (RunScript(script) == FALSE)
175  {
177  goto done;
178  }
179  }
180  else
181  {
182  /* Exit failure since the user wanted to run a script */
185  goto done;
186  }
187  }
188 
189  /* Let the user know the program is exiting */
191 
192 done:
194 
195  return result;
196 }
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:1840
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:173
Definition: dhcpd.h:245
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:440
#define argv
Definition: mplay32.c:18
const char * filename
Definition: ioapi.h:135
GLbitfield GLuint64 timeout
Definition: glext.h:7164
VOID InterpretMain(VOID)
Definition: interpreter.c:145
#define IDS_ERROR_MSG_NO_SCRIPT
Definition: resource.h:107
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define ConInitStdStreams()
Definition: stream.h:122
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL InterpretScript(LPWSTR line)
Definition: interpreter.c:102
smooth NULL
Definition: ftsmooth.c:416
script
Definition: msipriv.h:374
GLuint index
Definition: glext.h:6031
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
VOID ShowHeader(VOID)
Definition: diskpart.c:16
#define MAX_STRING_SIZE
Definition: diskpart.h:69
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXIT_FAILURE
Definition: jerror.c:33
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define index(s, c)
Definition: various.h:29
BOOL RunScript(LPCWSTR filename)
Definition: diskpart.c:41
static const WCHAR L[]
Definition: oid.c:1250
int wmain(int argc, const LPWSTR argv[])
Definition: diskpart.c:75
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:1917
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define GetModuleHandle
Definition: winbase.h:3641
#define IDS_APP_LEAVING
Definition: resource.h:17
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define IDS_APP_HEADER
Definition: resource.h:13
#define IDS_ERROR_MSG_BAD_ARG
Definition: resource.h:108
#define IDS_APP_CURR_COMPUTER
Definition: resource.h:16
#define StdOut
Definition: stream.h:76
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleTitleW(LPCWSTR lpConsoleTitle)
Definition: console.c:2292
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define IDS_APP_USAGE
Definition: resource.h:14
#define IDS_APP_LICENSE
Definition: resource.h:15