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
);
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.
34 run_script(LPCWSTR filename
)
37 WCHAR tmp_string
[MAX_STRING_SIZE
];
39 /* Open the file for processing */
40 script_file
= _wfopen(filename
, L
"r");
41 if (script_file
== NULL
)
43 /* if there was problems opening the file */
44 PrintResourceString(IDS_ERROR_MSG_NO_SCRIPT
, filename
);
45 return FALSE
; /* if there is no script, exit the program */
48 /* Read and process the script */
49 while (fgetws(tmp_string
, MAX_STRING_SIZE
, script_file
) != NULL
)
51 if (interpret_script(tmp_string
) == FALSE
)
63 * Main entry point of the application.
65 int wmain(int argc
, const WCHAR
*argv
[])
67 WCHAR szComputerName
[MAX_STRING_SIZE
];
68 DWORD comp_size
= MAX_STRING_SIZE
;
69 LPCWSTR file_name
= NULL
;
73 /* Get the name of the computer for us and change the value of comp_name */
74 GetComputerName(szComputerName
, &comp_size
);
76 /* TODO: Remove this section of code when program becomes stable enough for production use. */
77 wprintf(L
"\n*WARNING*: This program is incomplete and may not work properly.\n");
79 /* Print the header information */
80 PrintResourceString(IDS_APP_HEADER
, DISKPART_VERSION
);
81 PrintResourceString(IDS_APP_LICENSE
);
82 PrintResourceString(IDS_APP_CURR_COMPUTER
, szComputerName
);
84 /* Process arguments */
85 for (i
= 1; i
< argc
; i
++)
87 if ((argv
[i
][0] == L
'-') || (argv
[i
][0] == L
'/'))
89 if (wcsicmp(&argv
[i
][1], L
"s") == 0)
92 * Get the file name only if there is at least one more
93 * argument and it is not another option
96 (argv
[i
+ 1][0] != L
'-') &&
97 (argv
[i
+ 1][0] != L
'/'))
102 /* Get the file name */
106 else if (wcsicmp(&argv
[i
][1], L
"t") == 0)
109 * Get the timeout value only if there is at least one more
110 * argument and it is not another option
112 if ((i
+ 1 < argc
) &&
113 (argv
[i
+ 1][0] != L
'-') &&
114 (argv
[i
+ 1][0] != L
'/'))
119 /* Get the timeout value */
120 timeout
= _wtoi(argv
[i
]);
123 else if (wcscmp(&argv
[i
][1], L
"?") == 0)
125 PrintResourceString(IDS_APP_USAGE
);
131 /* Run the script if we got a script name or call the interpreter otherwise */
132 if (file_name
!= NULL
)
134 if (run_script(file_name
) == FALSE
)
142 /* Let the user know the program is exiting */
143 PrintResourceString(IDS_APP_LEAVING
);