InstallCommandLine.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <string>
  17. #include <vector>
  18. #include "InstallOptions.h"
  19. /**
  20. * Command line of the installer.
  21. *
  22. * Without arguments the installer opens its window. With "--cli", or any of the installation options, it installs
  23. * from the command line instead.
  24. */
  25. namespace InstallCommandLine{
  26. /**
  27. * What the installer must do.
  28. */
  29. enum class Mode{
  30. /**
  31. * Open the installer window.
  32. */
  33. GUI,
  34. /**
  35. * Install from the command line.
  36. */
  37. INSTALL,
  38. /**
  39. * Verify an installation from the command line.
  40. */
  41. VERIFY,
  42. /**
  43. * Print the list of installable parts.
  44. */
  45. LIST_PARTS,
  46. /**
  47. * Print the usage.
  48. */
  49. HELP,
  50. /**
  51. * Print the version.
  52. */
  53. VERSION,
  54. /**
  55. * The command line is wrong. The error is in Arguments::error.
  56. */
  57. INVALID
  58. };
  59. /**
  60. * The parsed command line.
  61. */
  62. struct Arguments{
  63. /**
  64. * What to do.
  65. */
  66. Mode mode = Mode::GUI;
  67. /**
  68. * Why the command line is wrong, when the mode is INVALID.
  69. */
  70. std::string error;
  71. /**
  72. * Path of the disk image.
  73. */
  74. std::string iso;
  75. /**
  76. * Installation directory. Empty to use the default one.
  77. */
  78. std::string output;
  79. /**
  80. * The preset the options start from.
  81. */
  82. InstallPreset preset = InstallPreset::EVERYTHING;
  83. /**
  84. * The parts to install: the preset, with the parts added and removed by the user.
  85. */
  86. InstallOptions options;
  87. /**
  88. * True to copy the V-Gears data files (configuration, scripts...) to the installation directory.
  89. */
  90. bool copy_data = true;
  91. /**
  92. * Path to the V-Gears data folder to copy. Empty to look for it.
  93. */
  94. std::string data_dir;
  95. /**
  96. * True to keep the original data after converting it: the extracted install disk, the temporary files and
  97. * the original sounds, music and images.
  98. */
  99. bool keep_originals = false;
  100. /**
  101. * True to delete the data of a previous installation in the directory first.
  102. */
  103. bool clean = false;
  104. /**
  105. * True to end with an error status when the installation finished with errors in its log.
  106. */
  107. bool strict = false;
  108. /**
  109. * Path to FFmpeg. Empty to look for it.
  110. */
  111. std::string ffmpeg;
  112. /**
  113. * Path to TiMidity. Empty to look for it.
  114. */
  115. std::string timidity;
  116. /**
  117. * True to continue when there are warnings or the audio tools are missing, instead of stopping.
  118. */
  119. bool yes = false;
  120. };
  121. /**
  122. * Name and description of an installable part.
  123. */
  124. struct Part{
  125. /**
  126. * Name used in the command line.
  127. */
  128. const char* name;
  129. /**
  130. * Description shown to the user.
  131. */
  132. const char* description;
  133. /**
  134. * The option of the part.
  135. */
  136. bool InstallOptions::* option;
  137. };
  138. /**
  139. * Gets the installable parts.
  140. */
  141. const std::vector<Part>& Parts();
  142. /**
  143. * Parses the command line.
  144. *
  145. * Arguments that are not installer options are left for Qt when the window is opened (for example "-platform"),
  146. * and are an error from the command line.
  147. *
  148. * @param[in] args The arguments, without the program name.
  149. */
  150. Arguments Parse(const std::vector<std::string>& args);
  151. /**
  152. * Gets the usage text.
  153. *
  154. * @param[in] program Name of the program.
  155. */
  156. std::string Usage(const std::string& program);
  157. }