|
39 | 39 | #include "target/electron/ElectronUtils.h" |
40 | 40 |
|
41 | 41 | #if( USE_BATCH_TOOLS ) |
| 42 | +#include "SpecUtils/StringAlgo.h" |
| 43 | +#include "SpecUtils/Filesystem.h" |
| 44 | + |
| 45 | +#include "InterSpec/InterSpec.h" |
42 | 46 | #include "InterSpec/BatchCommandLine.h" |
43 | 47 | #endif |
44 | 48 |
|
@@ -542,16 +546,69 @@ namespace InterSpecAddOn |
542 | 546 | Napi::Value element = jsArray.Get(i); |
543 | 547 |
|
544 | 548 | // Check if the element is a string |
545 | | - if (!element.IsString()) { |
| 549 | + if( !element.IsString() ) |
| 550 | + { |
546 | 551 | Napi::TypeError::New(env, "Array elements must be strings").ThrowAsJavaScriptException(); |
547 | 552 | return Napi::Number(); |
548 | | - } |
| 553 | + }//if( !element.IsString() ) |
549 | 554 |
|
550 | 555 | str_args[i] = element.ToString(); |
551 | 556 | if( str_args[i].empty() ) |
552 | 557 | str_args[i] = " "; |
553 | 558 | str_args_ptrs[i] = &(str_args[i][0]); |
554 | | - } |
| 559 | + |
| 560 | + |
| 561 | + auto checkarg = [&str_args,i,numargs]( const std::string &teststr ) -> std::string { |
| 562 | + |
| 563 | + if( !SpecUtils::istarts_with(str_args[i], teststr) ) |
| 564 | + return ""; |
| 565 | + std::string docroot; |
| 566 | + if( (str_args[i].length() > (teststr.size()+1)) && (str_args[i][teststr.size()] == '=') ) |
| 567 | + docroot = str_args[i].substr(teststr.size() + 1); |
| 568 | + else if( (i+1) < numargs ) |
| 569 | + docroot = str_args[i+1]; |
| 570 | + else |
| 571 | + return ""; |
| 572 | + |
| 573 | + if( docroot.length() && ((docroot.front()=='\"') || (docroot.front()=='\'')) ) |
| 574 | + docroot = docroot.substr(1); |
| 575 | + if( docroot.length() && ((docroot.back()=='\"') || (docroot.back()=='\'')) ) |
| 576 | + docroot = docroot.substr(0, docroot.size() - 1); |
| 577 | + return docroot; |
| 578 | + };//checkarg lambda |
| 579 | + |
| 580 | + // TODO: this setting directories should either be brought out to node.js stuff, or integrated into BatchCommandLine::run_batch_command(...) |
| 581 | + const std::string docroot = checkarg( "--docroot" ); |
| 582 | + const std::string userdatadir = checkarg( "--userdatadir" ); |
| 583 | + |
| 584 | + if( !docroot.empty() ) |
| 585 | + { |
| 586 | + const std::string datadir = SpecUtils::append_path( docroot, "data" ); |
| 587 | + |
| 588 | + try |
| 589 | + { |
| 590 | + InterSpec::setStaticDataDirectory( datadir ); |
| 591 | + }catch( std::exception &e ) |
| 592 | + { |
| 593 | + std::cerr << "Failed to set static data directory: " << e.what() << std::endl; |
| 594 | + Napi::Number::New( env, -7 ); |
| 595 | + } |
| 596 | + }//if( !docroot.empty() ) |
| 597 | + |
| 598 | + if( !userdatadir.empty() ) |
| 599 | + { |
| 600 | + try |
| 601 | + { |
| 602 | + InterSpec::setWritableDataDirectory( userdatadir ); |
| 603 | + }catch( std::exception &e ) |
| 604 | + { |
| 605 | + std::cerr << "Warning: Failed to set user data directory: " << e.what() << std::endl |
| 606 | + << "Use the '--userdatadir' option to set this to the same one the InterSpec GUI app" |
| 607 | + << " uses, if you would like to share detectors, or other files." << std::endl; |
| 608 | + //return -8; |
| 609 | + } |
| 610 | + }//if( !userdatadir.empty() ) |
| 611 | + }//for( uint32_t i = 0; i < numargs; i++ ) |
555 | 612 |
|
556 | 613 | const int rcode = BatchCommandLine::run_batch_command( static_cast<int>(numargs), &(str_args_ptrs[0]) ); |
557 | 614 |
|
|
0 commit comments