The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

796 lines
31KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "../Project/jucer_Project.h"
  19. #include "../Project/jucer_Module.h"
  20. #include "../Utility/jucer_TranslationHelpers.h"
  21. #include "jucer_CommandLine.h"
  22. //==============================================================================
  23. namespace
  24. {
  25. static const char* getLineEnding() { return "\r\n"; }
  26. struct CommandLineError
  27. {
  28. CommandLineError (const String& s) : message (s) {}
  29. String message;
  30. };
  31. static void hideDockIcon()
  32. {
  33. #if JUCE_MAC
  34. Process::setDockIconVisible (false);
  35. #endif
  36. }
  37. static bool matchArgument (const String& arg, const String& possible)
  38. {
  39. return arg == possible
  40. || arg == "-" + possible
  41. || arg == "--" + possible;
  42. }
  43. static void checkArgumentCount (const StringArray& args, int minNumArgs)
  44. {
  45. if (args.size() < minNumArgs)
  46. throw CommandLineError ("Not enough arguments!");
  47. }
  48. static File getFile (const String& filename)
  49. {
  50. return File::getCurrentWorkingDirectory().getChildFile (filename.unquoted());
  51. }
  52. static File getDirectoryCheckingForExistence (const String& filename)
  53. {
  54. File f = getFile (filename);
  55. if (! f.isDirectory())
  56. throw CommandLineError ("Could not find folder: " + f.getFullPathName());
  57. return f;
  58. }
  59. static File getFileCheckingForExistence (const String& filename)
  60. {
  61. File f = getFile (filename);
  62. if (! f.exists())
  63. throw CommandLineError ("Could not find file: " + f.getFullPathName());
  64. return f;
  65. }
  66. static Array<File> findAllSourceFiles (const File& folder)
  67. {
  68. Array<File> files;
  69. for (DirectoryIterator di (folder, true, "*.cpp;*.cxx;*.cc;*.c;*.h;*.hpp;*.hxx;*.hpp;*.mm;*.m", File::findFiles); di.next();)
  70. if (! di.getFile().isSymbolicLink())
  71. files.add (di.getFile());
  72. return files;
  73. }
  74. static String joinLinesIntoSourceFile (StringArray& lines)
  75. {
  76. while (lines.size() > 10 && lines [lines.size() - 1].isEmpty())
  77. lines.remove (lines.size() - 1);
  78. return lines.joinIntoString (getLineEnding()) + getLineEnding();
  79. }
  80. static void replaceFile (const File& file, const String& newText, const String& message)
  81. {
  82. std::cout << message << file.getFullPathName() << std::endl;
  83. TemporaryFile temp (file);
  84. if (! temp.getFile().replaceWithText (newText, false, false))
  85. throw CommandLineError ("!!! ERROR Couldn't write to temp file!");
  86. if (! temp.overwriteTargetFileWithTemporary())
  87. throw CommandLineError ("!!! ERROR Couldn't write to file!");
  88. }
  89. //==============================================================================
  90. struct LoadedProject
  91. {
  92. LoadedProject (const String& fileToLoad)
  93. {
  94. hideDockIcon();
  95. File projectFile = getFileCheckingForExistence (fileToLoad);
  96. if (! projectFile.hasFileExtension (Project::projectFileExtension))
  97. throw CommandLineError (projectFile.getFullPathName() + " isn't a valid jucer project file!");
  98. project = new Project (projectFile);
  99. if (! project->loadFrom (projectFile, true))
  100. {
  101. project = nullptr;
  102. throw CommandLineError ("Failed to load the project file: " + projectFile.getFullPathName());
  103. }
  104. }
  105. void save (bool justSaveResources)
  106. {
  107. if (project != nullptr)
  108. {
  109. Result error (justSaveResources ? project->saveResourcesOnly (project->getFile())
  110. : project->saveProject (project->getFile(), true));
  111. project = nullptr;
  112. if (error.failed())
  113. throw CommandLineError ("Error when saving: " + error.getErrorMessage());
  114. }
  115. }
  116. ScopedPointer<Project> project;
  117. };
  118. //==============================================================================
  119. /* Running a command-line of the form "projucer --resave foobar.jucer" will try to load
  120. that project and re-export all of its targets.
  121. */
  122. static void resaveProject (const StringArray& args, bool justSaveResources)
  123. {
  124. checkArgumentCount (args, 2);
  125. LoadedProject proj (args[1]);
  126. std::cout << (justSaveResources ? "Re-saving project resources: "
  127. : "Re-saving file: ")
  128. << proj.project->getFile().getFullPathName() << std::endl;
  129. proj.save (justSaveResources);
  130. }
  131. //==============================================================================
  132. static void getVersion (const StringArray& args)
  133. {
  134. checkArgumentCount (args, 2);
  135. LoadedProject proj (args[1]);
  136. std::cout << proj.project->getVersionString() << std::endl;
  137. }
  138. //==============================================================================
  139. static void setVersion (const StringArray& args)
  140. {
  141. checkArgumentCount (args, 3);
  142. LoadedProject proj (args[2]);
  143. String version (args[1].trim());
  144. std::cout << "Setting project version: " << version << std::endl;
  145. proj.project->getVersionValue() = version;
  146. proj.save (false);
  147. }
  148. //==============================================================================
  149. static void bumpVersion (const StringArray& args)
  150. {
  151. checkArgumentCount (args, 2);
  152. LoadedProject proj (args[1]);
  153. String version = proj.project->getVersionString();
  154. version = version.upToLastOccurrenceOf (".", true, false)
  155. + String (version.getTrailingIntValue() + 1);
  156. std::cout << "Bumping project version to: " << version << std::endl;
  157. proj.project->getVersionValue() = version;
  158. proj.save (false);
  159. }
  160. static void gitTag (const StringArray& args)
  161. {
  162. checkArgumentCount (args, 2);
  163. LoadedProject proj (args[1]);
  164. String version (proj.project->getVersionValue().toString());
  165. if (version.trim().isEmpty())
  166. throw CommandLineError ("Cannot read version number from project!");
  167. StringArray command;
  168. command.add ("git");
  169. command.add ("tag");
  170. command.add ("-a");
  171. command.add (version);
  172. command.add ("-m");
  173. command.add (version.quoted());
  174. std::cout << "Performing command: " << command.joinIntoString(" ") << std::endl;
  175. ChildProcess c;
  176. if (! c.start (command, 0))
  177. throw CommandLineError ("Cannot run git!");
  178. c.waitForProcessToFinish (10000);
  179. if (c.getExitCode() != 0)
  180. throw CommandLineError ("git command failed!");
  181. }
  182. //==============================================================================
  183. static void showStatus (const StringArray& args)
  184. {
  185. hideDockIcon();
  186. checkArgumentCount (args, 2);
  187. LoadedProject proj (args[1]);
  188. std::cout << "Project file: " << proj.project->getFile().getFullPathName() << std::endl
  189. << "Name: " << proj.project->getTitle() << std::endl
  190. << "UID: " << proj.project->getProjectUID() << std::endl;
  191. EnabledModuleList& modules = proj.project->getModules();
  192. if (int numModules = modules.getNumModules())
  193. {
  194. std::cout << "Modules:" << std::endl;
  195. for (int i = 0; i < numModules; ++i)
  196. std::cout << " " << modules.getModuleID (i) << std::endl;
  197. }
  198. }
  199. //==============================================================================
  200. static String getModulePackageName (const LibraryModule& module)
  201. {
  202. return module.getID() + ".jucemodule";
  203. }
  204. static void zipModule (const File& targetFolder, const File& moduleFolder)
  205. {
  206. jassert (targetFolder.isDirectory());
  207. const File moduleFolderParent (moduleFolder.getParentDirectory());
  208. LibraryModule module (moduleFolder);
  209. if (! module.isValid())
  210. throw CommandLineError (moduleFolder.getFullPathName() + " is not a valid module folder!");
  211. const File targetFile (targetFolder.getChildFile (getModulePackageName (module)));
  212. ZipFile::Builder zip;
  213. {
  214. DirectoryIterator i (moduleFolder, true, "*", File::findFiles);
  215. while (i.next())
  216. if (! i.getFile().isHidden())
  217. zip.addFile (i.getFile(), 9, i.getFile().getRelativePathFrom (moduleFolderParent));
  218. }
  219. std::cout << "Writing: " << targetFile.getFullPathName() << std::endl;
  220. TemporaryFile temp (targetFile);
  221. ScopedPointer<FileOutputStream> out (temp.getFile().createOutputStream());
  222. bool ok = out != nullptr && zip.writeToStream (*out, nullptr);
  223. out = nullptr;
  224. ok = ok && temp.overwriteTargetFileWithTemporary();
  225. if (! ok)
  226. throw CommandLineError ("Failed to write to the target file: " + targetFile.getFullPathName());
  227. }
  228. static void buildModules (const StringArray& args, const bool buildAllWithIndex)
  229. {
  230. hideDockIcon();
  231. checkArgumentCount (args, 3);
  232. const File targetFolder (getFile (args[1]));
  233. if (! targetFolder.isDirectory())
  234. throw CommandLineError ("The first argument must be the directory to put the result.");
  235. if (buildAllWithIndex)
  236. {
  237. const File folderToSearch (getFile (args[2]));
  238. DirectoryIterator i (folderToSearch, false, "*", File::findDirectories);
  239. var infoList;
  240. while (i.next())
  241. {
  242. LibraryModule module (i.getFile());
  243. if (module.isValid())
  244. {
  245. zipModule (targetFolder, i.getFile());
  246. var moduleInfo (new DynamicObject());
  247. moduleInfo.getDynamicObject()->setProperty ("file", getModulePackageName (module));
  248. moduleInfo.getDynamicObject()->setProperty ("info", module.moduleInfo.moduleInfo);
  249. infoList.append (moduleInfo);
  250. }
  251. }
  252. const File indexFile (targetFolder.getChildFile ("modulelist"));
  253. std::cout << "Writing: " << indexFile.getFullPathName() << std::endl;
  254. indexFile.replaceWithText (JSON::toString (infoList), false, false);
  255. }
  256. else
  257. {
  258. for (int i = 2; i < args.size(); ++i)
  259. zipModule (targetFolder, getFile (args[i]));
  260. }
  261. }
  262. //==============================================================================
  263. struct CleanupOptions
  264. {
  265. bool removeTabs;
  266. bool fixDividerComments;
  267. };
  268. static void cleanWhitespace (const File& file, CleanupOptions options)
  269. {
  270. const String content (file.loadFileAsString());
  271. if (content.contains ("%""%") && content.contains ("//["))
  272. return; // ignore projucer GUI template files
  273. StringArray lines;
  274. lines.addLines (content);
  275. bool anyTabsRemoved = false;
  276. for (int i = 0; i < lines.size(); ++i)
  277. {
  278. String& line = lines.getReference(i);
  279. if (options.removeTabs && line.containsChar ('\t'))
  280. {
  281. anyTabsRemoved = true;
  282. for (;;)
  283. {
  284. const int tabPos = line.indexOfChar ('\t');
  285. if (tabPos < 0)
  286. break;
  287. const int spacesPerTab = 4;
  288. const int spacesNeeded = spacesPerTab - (tabPos % spacesPerTab);
  289. line = line.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  290. }
  291. }
  292. if (options.fixDividerComments)
  293. {
  294. String afterIndent (line.trim());
  295. if (afterIndent.startsWith ("//") && afterIndent.length() > 20)
  296. {
  297. afterIndent = afterIndent.substring (2);
  298. if (afterIndent.containsOnly ("=")
  299. || afterIndent.containsOnly ("/")
  300. || afterIndent.containsOnly ("-"))
  301. {
  302. line = line.substring (0, line.indexOfChar ('/'))
  303. + "//" + String::repeatedString ("=", 78);
  304. }
  305. }
  306. }
  307. line = line.trimEnd();
  308. }
  309. if (options.removeTabs && ! anyTabsRemoved)
  310. return;
  311. const String newText = joinLinesIntoSourceFile (lines);
  312. if (newText != content && newText != content + getLineEnding())
  313. replaceFile (file, newText, options.removeTabs ? "Removing tabs in: "
  314. : "Cleaning file: ");
  315. }
  316. static void scanFilesForCleanup (const StringArray& args, CleanupOptions options)
  317. {
  318. checkArgumentCount (args, 2);
  319. for (auto it = args.begin() + 1; it < args.end(); ++it)
  320. {
  321. const File target (getFileCheckingForExistence (*it));
  322. Array<File> files;
  323. if (target.isDirectory())
  324. files = findAllSourceFiles (target);
  325. else
  326. files.add (target);
  327. for (int i = 0; i < files.size(); ++i)
  328. cleanWhitespace (files.getReference(i), options);
  329. }
  330. }
  331. static void cleanWhitespace (const StringArray& args, bool replaceTabs)
  332. {
  333. CleanupOptions options = { replaceTabs, false };
  334. scanFilesForCleanup (args, options);
  335. }
  336. static void tidyDividerComments (const StringArray& args)
  337. {
  338. CleanupOptions options = { false, true };
  339. scanFilesForCleanup (args, options);
  340. }
  341. //==============================================================================
  342. static File findSimilarlyNamedHeader (const Array<File>& allFiles, const String& name, const File& sourceFile)
  343. {
  344. File result;
  345. for (auto& f : allFiles)
  346. {
  347. if (f.getFileName().equalsIgnoreCase (name) && f != sourceFile)
  348. {
  349. if (result.exists())
  350. return {}; // multiple possible results, so don't change it!
  351. result = f;
  352. }
  353. }
  354. return result;
  355. }
  356. static void fixIncludes (const File& file, const Array<File>& allFiles)
  357. {
  358. const String content (file.loadFileAsString());
  359. StringArray lines;
  360. lines.addLines (content);
  361. bool hasChanged = false;
  362. for (int i = 0; i < lines.size(); ++i)
  363. {
  364. String line = lines[i];
  365. if (line.trimStart().startsWith ("#include \""))
  366. {
  367. const String includedFile (line.fromFirstOccurrenceOf ("\"", true, false)
  368. .upToLastOccurrenceOf ("\"", true, false)
  369. .trim()
  370. .unquoted());
  371. const File target (file.getSiblingFile (includedFile));
  372. if (! target.exists())
  373. {
  374. File header = findSimilarlyNamedHeader (allFiles, target.getFileName(), file);
  375. if (header.exists())
  376. {
  377. lines.set (i, line.upToFirstOccurrenceOf ("#include \"", true, false)
  378. + header.getRelativePathFrom (file.getParentDirectory())
  379. .replaceCharacter ('\\', '/')
  380. + "\"");
  381. hasChanged = true;
  382. }
  383. }
  384. }
  385. }
  386. if (hasChanged)
  387. {
  388. const String newText = joinLinesIntoSourceFile (lines);
  389. if (newText != content && newText != content + getLineEnding())
  390. replaceFile (file, newText, "Fixing includes in: ");
  391. }
  392. }
  393. static void fixRelativeIncludePaths (const StringArray& args)
  394. {
  395. checkArgumentCount (args, 2);
  396. const File target (getDirectoryCheckingForExistence (args[1]));
  397. Array<File> files = findAllSourceFiles (target);
  398. for (int i = 0; i < files.size(); ++i)
  399. fixIncludes (files.getReference(i), files);
  400. }
  401. //==============================================================================
  402. static String getStringConcatenationExpression (Random& rng, int start, int length)
  403. {
  404. jassert (length > 0);
  405. if (length == 1)
  406. return "s" + String (start);
  407. int breakPos = jlimit (1, length - 1, (length / 3) + rng.nextInt (length / 3));
  408. return "(" + getStringConcatenationExpression (rng, start, breakPos)
  409. + " + " + getStringConcatenationExpression (rng, start + breakPos, length - breakPos) + ")";
  410. }
  411. static void generateObfuscatedStringCode (const StringArray& args)
  412. {
  413. checkArgumentCount (args, 2);
  414. const String originalText (args[1]);
  415. struct Section
  416. {
  417. String text;
  418. int position, index;
  419. void writeGenerator (MemoryOutputStream& out) const
  420. {
  421. String name ("s" + String (index));
  422. out << " String " << name << "; " << name;
  423. for (int i = 0; i < text.length(); ++i)
  424. out << " << '" << String::charToString (text[i]) << "'";
  425. out << ";" << newLine;
  426. }
  427. };
  428. Array<Section> sections;
  429. String text = originalText;
  430. Random rng;
  431. while (text.isNotEmpty())
  432. {
  433. int pos = jmax (0, text.length() - (1 + rng.nextInt (6)));
  434. Section s = { text.substring (pos), pos, 0 };
  435. sections.insert (0, s);
  436. text = text.substring (0, pos);
  437. }
  438. for (int i = 0; i < sections.size(); ++i)
  439. sections.getReference(i).index = i;
  440. for (int i = 0; i < sections.size(); ++i)
  441. sections.swap (i, rng.nextInt (sections.size()));
  442. MemoryOutputStream out;
  443. out << "String createString()" << newLine
  444. << "{" << newLine;
  445. for (int i = 0; i < sections.size(); ++i)
  446. sections.getReference(i).writeGenerator (out);
  447. out << newLine
  448. << " String result = " << getStringConcatenationExpression (rng, 0, sections.size()) << ";" << newLine
  449. << newLine
  450. << " jassert (result == " << originalText.quoted() << ");" << newLine
  451. << " return result;" << newLine
  452. << "}" << newLine;
  453. std::cout << out.toString() << std::endl;
  454. }
  455. static void scanFoldersForTranslationFiles (const StringArray& args)
  456. {
  457. checkArgumentCount (args, 2);
  458. StringArray translations;
  459. for (auto it = args.begin() + 1; it != args.end(); ++it)
  460. {
  461. const File directoryToSearch (getDirectoryCheckingForExistence (*it));
  462. TranslationHelpers::scanFolderForTranslations (translations, directoryToSearch);
  463. }
  464. std::cout << TranslationHelpers::mungeStrings (translations) << std::endl;
  465. }
  466. static void createFinishedTranslationFile (const StringArray& args)
  467. {
  468. checkArgumentCount (args, 3);
  469. auto preTranslated = getFileCheckingForExistence (args[1]).loadFileAsString();
  470. auto postTranslated = getFileCheckingForExistence (args[2]).loadFileAsString();
  471. auto localisedContent = (args.size() > 3 ? getFileCheckingForExistence (args[3]).loadFileAsString() : String());
  472. auto localised = LocalisedStrings (localisedContent, false);
  473. using TH = TranslationHelpers;
  474. std::cout << TH::createFinishedTranslationFile (TH::withTrimmedEnds (TH::breakApart (preTranslated)),
  475. TH::withTrimmedEnds (TH::breakApart (postTranslated)),
  476. localised) << std::endl;
  477. }
  478. //==============================================================================
  479. static void encodeBinary (const StringArray& args)
  480. {
  481. checkArgumentCount (args, 3);
  482. const File source (getFileCheckingForExistence (args[1]));
  483. const File target (getFile (args[2]));
  484. MemoryOutputStream literal;
  485. size_t dataSize = 0;
  486. {
  487. MemoryBlock data;
  488. FileInputStream input (source);
  489. input.readIntoMemoryBlock (data);
  490. CodeHelpers::writeDataAsCppLiteral (data, literal, true, true);
  491. dataSize = data.getSize();
  492. }
  493. auto variableName = CodeHelpers::makeBinaryDataIdentifierName (source);
  494. MemoryOutputStream header, cpp;
  495. header << "// Auto-generated binary data by the Projucer" << newLine
  496. << "// Source file: " << source.getRelativePathFrom (target.getParentDirectory()) << newLine
  497. << newLine;
  498. cpp << header.toString();
  499. if (target.hasFileExtension (headerFileExtensions))
  500. {
  501. header << "static constexpr unsigned char " << variableName << "[] =" << newLine
  502. << literal.toString() << newLine
  503. << newLine;
  504. replaceFile (target, header.toString(), "Writing: ");
  505. }
  506. else if (target.hasFileExtension (cppFileExtensions))
  507. {
  508. header << "extern const char* " << variableName << ";" << newLine
  509. << "const unsigned int " << variableName << "Size = " << (int) dataSize << ";" << newLine
  510. << newLine;
  511. cpp << CodeHelpers::createIncludeStatement (target.withFileExtension (".h").getFileName()) << newLine
  512. << newLine
  513. << "static constexpr unsigned char " << variableName << "_local[] =" << newLine
  514. << literal.toString() << newLine
  515. << newLine
  516. << "const char* " << variableName << " = (const char*) " << variableName << "_local;" << newLine;
  517. replaceFile (target, cpp.toString(), "Writing: ");
  518. replaceFile (target.withFileExtension (".h"), header.toString(), "Writing: ");
  519. }
  520. else
  521. {
  522. throw CommandLineError ("You need to specify a .h or .cpp file as the target");
  523. }
  524. }
  525. //==============================================================================
  526. static void showHelp()
  527. {
  528. hideDockIcon();
  529. const String appName (JUCEApplication::getInstance()->getApplicationName());
  530. std::cout << appName << std::endl
  531. << std::endl
  532. << "Usage: " << std::endl
  533. << std::endl
  534. << " " << appName << " --resave project_file" << std::endl
  535. << " Resaves all files and resources in a project." << std::endl
  536. << std::endl
  537. << " " << appName << " --resave-resources project_file" << std::endl
  538. << " Resaves just the binary resources for a project." << std::endl
  539. << std::endl
  540. << " " << appName << " --get-version project_file" << std::endl
  541. << " Returns the version number of a project." << std::endl
  542. << std::endl
  543. << " " << appName << " --set-version version_number project_file" << std::endl
  544. << " Updates the version number in a project." << std::endl
  545. << std::endl
  546. << " " << appName << " --bump-version project_file" << std::endl
  547. << " Updates the minor version number in a project by 1." << std::endl
  548. << std::endl
  549. << " " << appName << " --git-tag-version project_file" << std::endl
  550. << " Invokes 'git tag' to attach the project's version number to the current git repository." << std::endl
  551. << std::endl
  552. << " " << appName << " --status project_file" << std::endl
  553. << " Displays information about a project." << std::endl
  554. << std::endl
  555. << " " << appName << " --buildmodule target_folder module_folder" << std::endl
  556. << " Zips a module into a downloadable file format." << std::endl
  557. << std::endl
  558. << " " << appName << " --buildallmodules target_folder module_folder" << std::endl
  559. << " Zips all modules in a given folder and creates an index for them." << std::endl
  560. << std::endl
  561. << " " << appName << " --trim-whitespace target_folder" << std::endl
  562. << " Scans the given folder for C/C++ source files (recursively), and trims any trailing whitespace from their lines, as well as normalising their line-endings to CR-LF." << std::endl
  563. << std::endl
  564. << " " << appName << " --remove-tabs target_folder" << std::endl
  565. << " Scans the given folder for C/C++ source files (recursively), and replaces any tab characters with 4 spaces." << std::endl
  566. << std::endl
  567. << " " << appName << " --tidy-divider-comments target_folder" << std::endl
  568. << " Scans the given folder for C/C++ source files (recursively), and normalises any juce-style comment division lines (i.e. any lines that look like //===== or //------- or /////////// will be replaced)." << std::endl
  569. << std::endl
  570. << " " << appName << " --fix-broken-include-paths target_folder" << std::endl
  571. << " Scans the given folder for C/C++ source files (recursively). Where a file contains an #include of one of the other filenames, it changes it to use the optimum relative path. Helpful for auto-fixing includes when re-arranging files and folders in a project." << std::endl
  572. << std::endl
  573. << " " << appName << " --obfuscated-string-code string_to_obfuscate" << std::endl
  574. << " Generates a C++ function which returns the given string, but in an obfuscated way." << std::endl
  575. << std::endl
  576. << " " << appName << " --encode-binary source_binary_file target_cpp_file" << std::endl
  577. << " Converts a binary file to a C++ file containing its contents as a block of data. Provide a .h file as the target if you want a single output file, or a .cpp file if you want a pair of .h/.cpp files." << std::endl
  578. << std::endl
  579. << " " << appName << " --trans target_folders..." << std::endl
  580. << " Scans each of the given folders (recursively) for any NEEDS_TRANS macros, and generates a translation file that can be used with Projucer's translation file builder" << std::endl
  581. << std::endl
  582. << " " << appName << " --trans-finish pre_translated_file post_translated_file optional_existing_translation_file" << std::endl
  583. << " Creates a completed translations mapping file, that can be used to initialise a LocalisedStrings object. This allows you to localise the strings in your project" << std::endl
  584. << std::endl;
  585. }
  586. }
  587. //==============================================================================
  588. int performCommandLine (const String& commandLine)
  589. {
  590. StringArray args;
  591. args.addTokens (commandLine, true);
  592. args.trim();
  593. String command (args[0]);
  594. try
  595. {
  596. if (matchArgument (command, "help")) { showHelp(); return 0; }
  597. if (matchArgument (command, "h")) { showHelp(); return 0; }
  598. if (matchArgument (command, "resave")) { resaveProject (args, false); return 0; }
  599. if (matchArgument (command, "resave-resources")) { resaveProject (args, true); return 0; }
  600. if (matchArgument (command, "get-version")) { getVersion (args); return 0; }
  601. if (matchArgument (command, "set-version")) { setVersion (args); return 0; }
  602. if (matchArgument (command, "bump-version")) { bumpVersion (args); return 0; }
  603. if (matchArgument (command, "git-tag-version")) { gitTag (args); return 0; }
  604. if (matchArgument (command, "buildmodule")) { buildModules (args, false); return 0; }
  605. if (matchArgument (command, "buildallmodules")) { buildModules (args, true); return 0; }
  606. if (matchArgument (command, "status")) { showStatus (args); return 0; }
  607. if (matchArgument (command, "trim-whitespace")) { cleanWhitespace (args, false); return 0; }
  608. if (matchArgument (command, "remove-tabs")) { cleanWhitespace (args, true); return 0; }
  609. if (matchArgument (command, "tidy-divider-comments")) { tidyDividerComments (args); return 0; }
  610. if (matchArgument (command, "fix-broken-include-paths")) { fixRelativeIncludePaths (args); return 0; }
  611. if (matchArgument (command, "obfuscated-string-code")) { generateObfuscatedStringCode (args); return 0; }
  612. if (matchArgument (command, "encode-binary")) { encodeBinary (args); return 0; }
  613. if (matchArgument (command, "trans")) { scanFoldersForTranslationFiles (args); return 0; }
  614. if (matchArgument (command, "trans-finish")) { createFinishedTranslationFile (args); return 0; }
  615. }
  616. catch (const CommandLineError& error)
  617. {
  618. std::cout << error.message << std::endl << std::endl;
  619. return 1;
  620. }
  621. return commandLineNotPerformed;
  622. }