123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /******************************************************************************
- Copyright (C) 2019-2020 by Dillon Pentz <[email protected]>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- ******************************************************************************/
- #include "importers.hpp"
- #include <memory>
- using namespace std;
- using namespace json11;
- vector<unique_ptr<Importer>> importers;
- void ImportersInit()
- {
- importers.clear();
- importers.push_back(make_unique<StudioImporter>());
- importers.push_back(make_unique<ClassicImporter>());
- importers.push_back(make_unique<SLImporter>());
- importers.push_back(make_unique<XSplitImporter>());
- }
- int ImportSCFromProg(const string &path, string &name, const string &program,
- Json &res)
- {
- if (!os_file_exists(path.c_str())) {
- return IMPORTER_FILE_NOT_FOUND;
- }
- for (size_t i = 0; i < importers.size(); i++) {
- if (program == importers[i]->Prog()) {
- return importers[i]->ImportScenes(path, name, res);
- }
- }
- return IMPORTER_UNKNOWN_ERROR;
- }
- int ImportSC(const string &path, std::string &name, Json &res)
- {
- if (!os_file_exists(path.c_str())) {
- return IMPORTER_FILE_NOT_FOUND;
- }
- string prog = DetectProgram(path);
- if (prog == "Null") {
- return IMPORTER_FILE_NOT_RECOGNISED;
- }
- return ImportSCFromProg(path, name, prog, res);
- }
- string DetectProgram(const string &path)
- {
- if (!os_file_exists(path.c_str())) {
- return "Null";
- }
- for (size_t i = 0; i < importers.size(); i++) {
- if (importers[i]->Check(path)) {
- return importers[i]->Prog();
- }
- }
- return "Null";
- }
- string GetSCName(const string &path, const string &prog)
- {
- for (size_t i = 0; i < importers.size(); i++) {
- if (importers[i]->Prog() == prog) {
- return importers[i]->Name(path);
- }
- }
- return "Null";
- }
- OBSImporterFiles ImportersFindFiles()
- {
- OBSImporterFiles f;
- for (size_t i = 0; i < importers.size(); i++) {
- OBSImporterFiles f2 = importers[i]->FindFiles();
- if (f2.size() != 0) {
- f.insert(f.end(), f2.begin(), f2.end());
- }
- }
- return f;
- }
|