1
2 #include "studiox_includes.h"
3 #include <time.h>
4
5 CString DispHelp(
6 "Usage: guix_studio [OPTION] [ARGUMENT]\n"
7 "Open .gxp project.\n"
8 "Load specified project and generate ALL output files.\n"
9 "Load specified project and generate specified output files."
10 "\n"
11 " -n, --nogui Run the command line, do not \n"
12 " start the Studio UI interface.\n"
13 " -o pathname, --log Specify a log file.\n"
14 " -b, --binary Generate binary format resource.\n"
15 " -d display_1, display_2, .. --display Specify display names included in any generated reosurce file.\n"
16 " Otherwise all display are included.\n"
17 " -t theme1, theme2, .. --theme Specify theme names included in the generated reosource file,\n"
18 " if the option is not used, all themes will be included.\n"
19 " -l langage1, language2, .. --language Specify language names included in the generated resource file,\n"
20 " if the option is not used, all languages will be included.\n"
21 " -r filename, --resource Specify that studio should produce a resource file.\n"
22 " -s filename, --specification Specify that studio should produce a specification file\n"
23 " -p project_pathname Specify project pathname.\n"
24 " -i pathname, --import Import string from xliff or csv format file\n"
25 " --big_endian Generate data as big endian.\n"
26 " --no_res_header Not generating resource header.\n"
27 " -x pathname, --xml Specify the input resource XML file.\n"
28 " --output_path pathname Specify the output directory. If not specified, the project directory will be used for the output files.\n"
29 "\n"
30 "Examples:\n"
31 " demo.gxp Open demo.gxp project.\n"
32 " guix_studio -p demo.gxp Open demo.gxp project.\n"
33 " guix_studio -n -r -s -p demo.gxp Generate All output files of demo.gxp project.\n"
34 " guix_studio -x resource.xml -b Generate binary resource file from a resource project resource.xml.\n"
35 );
36
37 // Options for internal use.
38 // --clone_guix_repo local_path Run GUIX repository clone.
39 // --write_pipe_handle handle Specify named pipe memory write handle.
40
CCommandInfo(void)41 CCommandInfo::CCommandInfo(void)
42 {
43 nogui = FALSE;
44 binary = FALSE;
45 xml = FALSE;
46 log_file = NULL;
47 gen_resource = FALSE;
48 gen_res_header = TRUE;
49 gen_specification = FALSE;
50 big_endian = FALSE;
51
52 num_of_language = -1;
53 num_of_theme = -1;
54 num_of_display = -1;
55
56 string_import_filename = "";
57 output_path = "";
58 guix_repo_local_path = "";
59 guix_clone_write_pipe_handle = 0;
60 }
61
62
~CCommandInfo(void)63 CCommandInfo::~CCommandInfo(void)
64 {
65 }
66
ReadArgument(CString & cmd,CString option,CString & argument)67 BOOL CCommandInfo::ReadArgument(CString &cmd, CString option, CString &argument)
68 {
69 int index = cmd.Find(L" " + option + L" ");
70 if (index >= 0)
71 {
72 cmd.Replace(option, _T(""));
73
74 argument = cmd.Mid(index + 1);
75 index = argument.Find(_T(" -"));
76
77 if (index >= 0)
78 {
79 argument = argument.Left(index);
80 }
81
82 cmd.Replace(argument, _T(""));
83
84 // Trim all leading and tailing whitespaces.
85 argument.Trim();
86 return TRUE;
87 }
88
89 return FALSE;
90 }
91
ReadCommandLineInfo(LPTSTR m_lpCmdLine)92 void CCommandInfo::ReadCommandLineInfo(LPTSTR m_lpCmdLine)
93 {
94 int index;
95
96 CString cmd(m_lpCmdLine);
97 CString option;
98 CString argument;
99 CString error_msg("");
100 BOOL show_help = FALSE;
101 BOOL set_project = FALSE;
102
103 cmd.Insert(0, _T(" "));
104 cmd.Append(_T(" "));
105
106 // Read GUIX repo local path.
107 if(ReadArgument(cmd, L"--clone_guix_repo", guix_repo_local_path))
108 {
109 // Trim all leading and trailing quotation marks.
110 guix_repo_local_path.Trim(L"\"");
111
112 // Read named pipe memory write handle.
113 if(ReadArgument(cmd, L"--write_pipe_handle", argument))
114 {
115 guix_clone_write_pipe_handle = (HANDLE)_wtoi(argument);
116 }
117 return;
118 }
119
120 /* Read .gxp project pathname. */
121 index = cmd.Find(_T(".gxp"));
122 if (index >= 0)
123 {
124 CString pathname = cmd.Left(index + 4);
125 index = pathname.Find(_T(" -p "));
126
127 if (index < 0)
128 {
129 index = pathname.ReverseFind(' ');
130 pathname = pathname.Mid(index);
131
132 cmd.Replace(pathname, _T(""));
133
134 ReadPathName(pathname, project_path, project_name);
135 }
136 }
137
138 /* Find first option. */
139 index = cmd.Find(_T(" -"));
140
141 while (index >= 0)
142 {
143 cmd = cmd.Mid(index + 1);
144
145 index = cmd.Find(_T(" "));
146
147 // pick up option
148 option = cmd.Left(index);
149
150 // remove option from command line string
151 cmd = cmd.Mid(index);
152
153 index = cmd.Find(_T(" -"));
154
155 if (index >= 0)
156 {
157 // pick up argument
158 argument = cmd.Left(index);
159 }
160 else
161 {
162 argument = cmd;
163 }
164
165 if (option == "-h" || option == "--help")
166 {
167 show_help = TRUE;
168 }
169 else if (option == "-o" || option == "--log")
170 {
171 ReadPathName(argument, log_pathname);
172 }
173 else if (option == "-p" || option == "--project")
174 {
175 ReadPathName(argument, project_path, project_name);
176 }
177 else if (option == "-n" || option == "--nogui")
178 {
179 nogui = TRUE;
180 }
181 else if (option == "-b" ||option == "--binary")
182 {
183 binary = TRUE;
184 }
185 else if (option == "-x" || option == "--xml")
186 {
187 ReadPathName(argument, project_path, project_name);
188
189 xml = TRUE;
190 nogui = TRUE;
191 gen_specification = FALSE;
192 gen_resource = TRUE;
193 gen_res_header = FALSE;
194
195 // Set default output resource file name.
196 if (resource_filename.IsEmpty())
197 {
198 resource_filename = RemoveFileExtension(project_name);
199 }
200 }
201 else if (option == "--big_endian")
202 {
203 big_endian = TRUE;
204 }
205 else if (option == "-r" || option == "--resource")
206 {
207 ReadPathName(argument, resource_filename);
208 gen_resource = TRUE;
209 }
210 else if (option == "--no_res_header")
211 {
212 gen_res_header = FALSE;
213 }
214 else if (option == "-s" || option == "--specification")
215 {
216 ReadPathName(argument, specification_filename);
217 gen_specification = TRUE;
218 }
219 else if (option == "-l" || option == "--language")
220 {
221 ReadMultiParameter(argument, language, num_of_language);
222 }
223 else if (option == "-t" || option == "--theme")
224 {
225 ReadMultiParameter(argument, theme, num_of_theme);
226 }
227 else if (option == "-d" || option == "--display")
228 {
229 ReadMultiParameter(argument, display, num_of_display);
230 }
231 else if (option == "-i" || option == "--import")
232 {
233 ReadPathName(argument, string_import_filename);
234 }
235 else if (option == "--output_path")
236 {
237 ReadPathName(argument, output_path);
238 }
239 else
240 {
241 error_msg.Format(L"\nCommand: %s\nNo such option: [%s]\n", m_lpCmdLine, option);
242 }
243 }
244
245 if (!log_pathname.IsEmpty())
246 {
247 if (log_pathname.GetAt(1) != ':')
248 {
249 CString path = output_path;
250
251 if (!path.IsEmpty())
252 {
253 if (path.GetAt(1) != ':')
254 {
255 // If output path is a relative path, concat it to project path as the log file path.
256 path = ConcatPathNames(project_path, path);
257 }
258 }
259 else
260 {
261 // Use project path as the log file path.
262 path = project_path;
263 }
264
265 log_pathname = ConcatPathNames(path, log_pathname);
266 }
267
268 /* Open the log file. */
269 log_file = _tfopen(log_pathname, _T("a"));
270
271 if (log_file)
272 {
273 struct tm* newTime;
274 time_t szClock;
275
276 // Get time in seconds
277 time(&szClock);
278
279 // Convert time to struct tm form
280 newTime = localtime(&szClock);
281
282 // Print local time as a string.
283 fprintf(log_file, "\nDate: %s\n", asctime(newTime));
284 }
285 }
286
287 if (log_file && show_help)
288 {
289 // Log help information.
290 fprintf(log_file, "\n%s\n", (char*)CW2A(DispHelp));
291
292 exit(0);
293 }
294
295 if (project_name.IsEmpty())
296 {
297 if (xml)
298 {
299 error_msg.Append(L"\nMissing xml filename!\n");
300 }
301 else
302 {
303 error_msg.Append(L"\nMissing gxp project filename!\n");
304 }
305 }
306
307 if (!error_msg.IsEmpty())
308 {
309 if (log_file)
310 {
311 fprintf(log_file, "\n%s\n", (char*)CW2A(error_msg));
312 }
313 exit(0);
314 }
315
316 if ((gen_resource == FALSE) && (gen_specification == FALSE))
317 {
318 gen_resource = TRUE;
319 gen_specification = TRUE;
320 }
321 }
322
ReadMultiParameter(CString argument,CString parameter[],int & num)323 void CCommandInfo::ReadMultiParameter(CString argument, CString parameter[], int &num)
324 {
325 num = 0;
326
327 argument.Remove(' ');
328
329 CStringArray arrays;
330 SplitString(argument, ',', &arrays);
331
332 for (int index = 0; index < arrays.GetCount(); index++)
333 {
334 parameter[num++] = arrays.GetAt(index);
335 }
336 }
337
ReadPathName(CString cmd,CString & path,CString & name)338 void CCommandInfo::ReadPathName(CString cmd, CString &path, CString &name)
339 {
340 int index;
341
342 // Trims leading and trailing whitespace characters from the string.
343 cmd.Trim();
344
345 // Trims leading and trailing quatation mark characters from the string.
346 cmd.Trim('\"');
347
348 name = cmd;
349
350 FormatPath(name);
351 index = name.ReverseFind('\\');
352
353 if (index > 0)
354 {
355 path = name.Left(index);
356 name = name.Mid(index + 1);
357 }
358 else
359 {
360 path = ".";
361 }
362 }
363
ReadPathName(CString argument,CString & pathname)364 void CCommandInfo::ReadPathName(CString argument, CString &pathname)
365 {
366 // Trims leading and trailing whitespace characters from the string.
367 argument.Trim();
368
369 // Trims leading and trailing quatation mark characters from the string.
370 argument.Trim('\"');
371
372 pathname = argument;
373 }
374
IsThemeEnabled(CString name)375 BOOL CCommandInfo::IsThemeEnabled(CString name)
376 {
377 if ((num_of_theme == -1) || FindString(theme, num_of_theme, name))
378 {
379 return TRUE;
380 }
381
382 return FALSE;
383 }
384
IsLanguageEnabled(CString name)385 BOOL CCommandInfo::IsLanguageEnabled(CString name)
386 {
387 if ((num_of_language == -1) || FindString(language, num_of_language, name))
388 {
389 return TRUE;
390 }
391
392 return FALSE;
393 }
394
IsDisplayEnabled(CString name)395 BOOL CCommandInfo::IsDisplayEnabled(CString name)
396 {
397 if ((num_of_display == -1) || FindString(display, num_of_display, name))
398 {
399 return TRUE;
400 }
401
402 return FALSE;
403 }
404
FindString(CString str_table[],int table_size,CString find_str)405 BOOL CCommandInfo::FindString(CString str_table[], int table_size, CString find_str)
406 {
407 int index;
408
409 for (index = 0; index < table_size; index++)
410 {
411 if (!find_str.CompareNoCase(str_table[index]))
412 {
413 return TRUE;
414 }
415 }
416 return FALSE;
417 }
418
419