@@ -28,6 +28,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
28
28
#include < QMetaObject>
29
29
#include < vector>
30
30
#include < string>
31
+ #include < filesystem>
31
32
#include < stdio.h>
32
33
#include < algorithm>
33
34
#include < zip_file.hpp>
@@ -46,7 +47,10 @@ const std::map<std::string, std::string> extensionMap{
46
47
{" .mkv" , " /video/" }, {" .mp3" , " /audio/" },
47
48
{" .wav" , " /aduio/" }, {" .effect" , " /shaders/" },
48
49
{" .shader" , " /shaders/" }, {" .hlsl" , " /shaders/" },
49
- {" .lua" , " /scripts/" }, {" .py" , " /scripts/" }};
50
+ {" .lua" , " /scripts/" }, {" .py" , " /scripts/" },
51
+ {" .html" , " /browser-sources/" },
52
+ {" .htm" , " /browser-sources/" }
53
+ };
50
54
51
55
// Filter IDs of incompatible filter types, e.g. filters
52
56
// that require external libraries or executables.
@@ -305,11 +309,26 @@ SceneBundleStatus SceneBundle::ToElgatoCloudFile(
305
309
std::string collection_json = _collection.dump (2 );
306
310
std::string bundleInfo_json = bundleInfo.dump (2 );
307
311
312
+ std::vector<std::string> browserSourceDirs;
313
+
308
314
ecFile.writestr (" collection.json" , collection_json);
309
315
ecFile.writestr (" bundle_info.json" , bundleInfo_json);
310
316
// Write all assets to zip archive.
311
317
for (const auto &file : _fileMap) {
312
318
std::string oFilename = file.first ;
319
+
320
+ std::string filename = oFilename.substr (oFilename.rfind (" /" ) + 1 );
321
+ std::string parentDir = oFilename.substr (0 , oFilename.rfind (" /" ));
322
+ std::string zipParent = file.second .substr (0 , file.second .rfind (" /" ));
323
+ bool hasExtension = filename.rfind (" ." ) != std::string::npos;
324
+ std::string extension =
325
+ hasExtension ? os_get_path_extension (oFilename.c_str ())
326
+ : " " ;
327
+ bool isBrowserSource = extension == " .html" || extension == " .htm" ;
328
+ bool addBrowser = isBrowserSource && std::find (browserSourceDirs.begin (), browserSourceDirs.end (), parentDir) == browserSourceDirs.end ();
329
+ if (addBrowser) {
330
+ browserSourceDirs.push_back (parentDir);
331
+ }
313
332
struct stat st;
314
333
os_stat (oFilename.c_str (), &st);
315
334
if ((st.st_mode & S_IFMT) == S_IFDIR) {
@@ -322,13 +341,24 @@ SceneBundleStatus SceneBundle::ToElgatoCloudFile(
322
341
}
323
342
return SceneBundleStatus::Error;
324
343
}
325
- } else if (!_AddFileToZip (file.first , file.second , ecFile)) {
326
- bool wasInterrupted = _interrupt;
327
- _interrupt = false ;
328
- if (wasInterrupted) {
329
- return _interruptReason;
344
+ } else if (addBrowser) {
345
+ if (!_AddBrowserSourceContentsToZip (parentDir, zipParent, ecFile)) {
346
+ bool wasInterrupted = _interrupt;
347
+ _interrupt = false ;
348
+ if (wasInterrupted) {
349
+ return _interruptReason;
350
+ }
351
+ return SceneBundleStatus::Error;
352
+ }
353
+ } else if (!isBrowserSource) {
354
+ if (!_AddFileToZip (file.first , file.second , ecFile)) {
355
+ bool wasInterrupted = _interrupt;
356
+ _interrupt = false ;
357
+ if (wasInterrupted) {
358
+ return _interruptReason;
359
+ }
360
+ return SceneBundleStatus::Error;
330
361
}
331
- return SceneBundleStatus::Error;
332
362
}
333
363
}
334
364
@@ -505,6 +535,13 @@ void SceneBundle::_CreateFileMap(nlohmann::json &item)
505
535
} else {
506
536
directory = " /misc/" ;
507
537
}
538
+ bool isBrowserSource = extension == " .htm" || extension == " .html" ;
539
+ if (isBrowserSource) {
540
+ std::filesystem::path pathObj (value);
541
+ auto parentPath = pathObj.parent_path ();
542
+ std::string parent = parentPath.filename ().string ();
543
+ directory += parent + " /" ;
544
+ }
508
545
std::string newFileName = " Assets" + directory + filename;
509
546
auto result =
510
547
std::find_if (std::begin (_fileMap), std::end (_fileMap),
@@ -538,6 +575,51 @@ bool SceneBundle::_AddFileToZip(std::string filePath, std::string zipPath,
538
575
return true ;
539
576
}
540
577
578
+ bool SceneBundle::_AddBrowserSourceContentsToZip (std::string dirPath, std::string zipDir,
579
+ miniz_cpp::zip_file& ecFile)
580
+ {
581
+ // Iterate the files in the directory and add them to the zip.
582
+ // Ignore sub-directories
583
+ os_dir_t * dir = os_opendir (dirPath.c_str ());
584
+ if (dir) {
585
+ struct os_dirent * ent;
586
+ for (;;) {
587
+ ent = os_readdir (dir);
588
+ if (!ent)
589
+ break ;
590
+ if (ent->directory ) {
591
+ std::string dName = ent->d_name ;
592
+ if (dName == " ." || dName == " .." ) {
593
+ continue ;
594
+ }
595
+ std::string dPath = dirPath + " /" + dName;
596
+ std::string zipDPath = zipDir + " /" + dName;
597
+ if (!_AddBrowserSourceContentsToZip (dPath, zipDPath, ecFile)) {
598
+ os_closedir (dir);
599
+ return false ;
600
+ }
601
+ } else {
602
+ std::string filename = ent->d_name ;
603
+ std::string filePath = dirPath + " /" + filename;
604
+ std::string zipFilePath = zipDir + " /" + filename;
605
+ if (!_AddFileToZip (filePath, zipFilePath, ecFile)) {
606
+ os_closedir (dir);
607
+ return false ;
608
+ }
609
+ }
610
+ }
611
+ }
612
+ else {
613
+ obs_log (LOG_ERROR, " Fatal: Could not open directory: %s" ,
614
+ dirPath.c_str ());
615
+ return false ;
616
+ }
617
+
618
+ os_closedir (dir);
619
+
620
+ return true ;
621
+ }
622
+
541
623
bool SceneBundle::_AddDirContentsToZip (std::string dirPath, std::string zipDir,
542
624
miniz_cpp::zip_file &ecFile)
543
625
{
0 commit comments