importers.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /******************************************************************************
  2. Copyright (C) 2019-2020 by Dillon Pentz <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "importers.hpp"
  15. #include <memory>
  16. using namespace std;
  17. using namespace json11;
  18. vector<unique_ptr<Importer>> importers;
  19. void ImportersInit()
  20. {
  21. importers.clear();
  22. importers.push_back(make_unique<StudioImporter>());
  23. importers.push_back(make_unique<ClassicImporter>());
  24. importers.push_back(make_unique<SLImporter>());
  25. importers.push_back(make_unique<XSplitImporter>());
  26. }
  27. int ImportSCFromProg(const string &path, string &name, const string &program,
  28. Json &res)
  29. {
  30. if (!os_file_exists(path.c_str())) {
  31. return IMPORTER_FILE_NOT_FOUND;
  32. }
  33. for (size_t i = 0; i < importers.size(); i++) {
  34. if (program == importers[i]->Prog()) {
  35. return importers[i]->ImportScenes(path, name, res);
  36. }
  37. }
  38. return IMPORTER_UNKNOWN_ERROR;
  39. }
  40. int ImportSC(const string &path, std::string &name, Json &res)
  41. {
  42. if (!os_file_exists(path.c_str())) {
  43. return IMPORTER_FILE_NOT_FOUND;
  44. }
  45. string prog = DetectProgram(path);
  46. if (prog == "Null") {
  47. return IMPORTER_FILE_NOT_RECOGNISED;
  48. }
  49. return ImportSCFromProg(path, name, prog, res);
  50. }
  51. string DetectProgram(const string &path)
  52. {
  53. if (!os_file_exists(path.c_str())) {
  54. return "Null";
  55. }
  56. for (size_t i = 0; i < importers.size(); i++) {
  57. if (importers[i]->Check(path)) {
  58. return importers[i]->Prog();
  59. }
  60. }
  61. return "Null";
  62. }
  63. string GetSCName(const string &path, const string &prog)
  64. {
  65. for (size_t i = 0; i < importers.size(); i++) {
  66. if (importers[i]->Prog() == prog) {
  67. return importers[i]->Name(path);
  68. }
  69. }
  70. return "Null";
  71. }
  72. OBSImporterFiles ImportersFindFiles()
  73. {
  74. OBSImporterFiles f;
  75. for (size_t i = 0; i < importers.size(); i++) {
  76. OBSImporterFiles f2 = importers[i]->FindFiles();
  77. if (f2.size() != 0) {
  78. f.insert(f.end(), f2.begin(), f2.end());
  79. }
  80. }
  81. return f;
  82. }