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.

798 lines
31KB

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