importers.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, Json &res)
  28. {
  29. if (!os_file_exists(path.c_str())) {
  30. return IMPORTER_FILE_NOT_FOUND;
  31. }
  32. for (size_t i = 0; i < importers.size(); i++) {
  33. if (program == importers[i]->Prog()) {
  34. return importers[i]->ImportScenes(path, name, res);
  35. }
  36. }
  37. return IMPORTER_UNKNOWN_ERROR;
  38. }
  39. int ImportSC(const string &path, std::string &name, Json &res)
  40. {
  41. if (!os_file_exists(path.c_str())) {
  42. return IMPORTER_FILE_NOT_FOUND;
  43. }
  44. string prog = DetectProgram(path);
  45. if (prog == "Null") {
  46. return IMPORTER_FILE_NOT_RECOGNISED;
  47. }
  48. return ImportSCFromProg(path, name, prog, res);
  49. }
  50. string DetectProgram(const string &path)
  51. {
  52. if (!os_file_exists(path.c_str())) {
  53. return "Null";
  54. }
  55. for (size_t i = 0; i < importers.size(); i++) {
  56. if (importers[i]->Check(path)) {
  57. return importers[i]->Prog();
  58. }
  59. }
  60. return "Null";
  61. }
  62. string GetSCName(const string &path, const string &prog)
  63. {
  64. for (size_t i = 0; i < importers.size(); i++) {
  65. if (importers[i]->Prog() == prog) {
  66. return importers[i]->Name(path);
  67. }
  68. }
  69. return "Null";
  70. }
  71. OBSImporterFiles ImportersFindFiles()
  72. {
  73. OBSImporterFiles f;
  74. for (size_t i = 0; i < importers.size(); i++) {
  75. OBSImporterFiles f2 = importers[i]->FindFiles();
  76. if (f2.size() != 0) {
  77. f.insert(f.end(), f2.begin(), f2.end());
  78. }
  79. }
  80. return f;
  81. }