@@ -42,6 +42,12 @@ static std::string getRemoteData(std::string &url)
4242 return readBuffer;
4343}
4444
45+ void MacroConditionFile::SetCondition (Condition condition)
46+ {
47+ _condition = condition;
48+ SetupTempVars ();
49+ }
50+
4551bool MacroConditionFile::MatchFileContent (QString &filedata)
4652{
4753 if (_onlyMatchIfChanged) {
@@ -65,6 +71,7 @@ bool MacroConditionFile::CheckRemoteFileContent()
6571 std::string path = _file;
6672 std::string data = getRemoteData (path);
6773 SetVariableValue (data);
74+ SetTempVarValue (" content" , data);
6875 QString qdata = QString::fromStdString (data);
6976 return MatchFileContent (qdata);
7077}
@@ -86,6 +93,7 @@ bool MacroConditionFile::CheckLocalFileContent()
8693
8794 QString filedata = QTextStream (&file).readAll ();
8895 SetVariableValue (filedata.toStdString ());
96+ SetTempVarValue (" content" , filedata.toStdString ());
8997 bool match = MatchFileContent (filedata);
9098
9199 file.close ();
@@ -114,6 +122,7 @@ bool MacroConditionFile::CheckChangeContent()
114122 break ;
115123 }
116124
125+ SetTempVarValue (" content" , filedata.toStdString ());
117126 size_t newHash = strHash (filedata.toUtf8 ().constData ());
118127 const bool contentChanged = newHash != _lastHash;
119128 _lastHash = newHash;
@@ -131,24 +140,39 @@ bool MacroConditionFile::CheckChangeDate()
131140 SetVariableValue (newLastMod.toString ().toStdString ());
132141 const bool dateChanged = _lastMod != newLastMod;
133142 _lastMod = newLastMod;
143+ SetTempVarValue (" date" , newLastMod.toString (Qt::ISODate).toStdString ());
134144 return dateChanged;
135145}
136146
147+ void MacroConditionFile::SetupTempVars ()
148+ {
149+ MacroCondition::SetupTempVars ();
150+ if (_condition == Condition::DATE_CHANGE) {
151+ AddTempvar (
152+ " date" ,
153+ obs_module_text (" AdvSceneSwitcher.tempVar.file.date" ));
154+ } else {
155+ AddTempvar (" content" ,
156+ obs_module_text (
157+ " AdvSceneSwitcher.tempVar.file.content" ));
158+ }
159+ }
160+
137161bool MacroConditionFile::CheckCondition ()
138162{
139163 bool ret = false ;
140164 switch (_condition) {
141- case MacroConditionFile::ConditionType ::MATCH:
165+ case Condition ::MATCH:
142166 if (_fileType == FileType::REMOTE) {
143167 ret = CheckRemoteFileContent ();
144168 break ;
145169 }
146170 ret = CheckLocalFileContent ();
147171 break ;
148- case MacroConditionFile::ConditionType ::CONTENT_CHANGE:
172+ case Condition ::CONTENT_CHANGE:
149173 ret = CheckChangeContent ();
150174 break ;
151- case MacroConditionFile::ConditionType ::DATE_CHANGE:
175+ case Condition ::DATE_CHANGE:
152176 ret = CheckChangeDate ();
153177 break ;
154178 default :
@@ -158,7 +182,6 @@ bool MacroConditionFile::CheckCondition()
158182 if (GetVariableValue ().empty ()) {
159183 SetVariableValue (ret ? " true" : " false" );
160184 }
161-
162185 return ret;
163186}
164187
@@ -187,8 +210,8 @@ bool MacroConditionFile::Load(obs_data_t *obj)
187210 _file.Load (obj, " file" );
188211 _text.Load (obj, " text" );
189212 _fileType = static_cast <FileType>(obs_data_get_int (obj, " fileType" ));
190- _condition =
191- static_cast <ConditionType >(obs_data_get_int (obj, " condition" ));
213+ SetCondition (
214+ static_cast <Condition >(obs_data_get_int (obj, " condition" ) ));
192215 _useTime = obs_data_get_bool (obj, " useTime" );
193216 _onlyMatchIfChanged = obs_data_get_bool (obj, " onlyMatchIfChanged" );
194217 return true ;
@@ -292,7 +315,8 @@ void MacroConditionFileEdit::UpdateEntryData()
292315 }
293316
294317 _fileTypes->setCurrentIndex (static_cast <int >(_entryData->_fileType ));
295- _conditions->setCurrentIndex (static_cast <int >(_entryData->_condition ));
318+ _conditions->setCurrentIndex (
319+ static_cast <int >(_entryData->GetCondition ()));
296320 _filePath->SetPath (_entryData->_file );
297321 _matchText->setPlainText (_entryData->_text );
298322 _regex->SetRegexConfig (_entryData->_regex );
@@ -338,8 +362,8 @@ void MacroConditionFileEdit::ConditionChanged(int index)
338362 }
339363
340364 auto lock = LockContext ();
341- _entryData->_condition =
342- static_cast <MacroConditionFile::ConditionType >(index);
365+ _entryData->SetCondition (
366+ static_cast <MacroConditionFile::Condition >(index) );
343367 SetWidgetVisibility ();
344368}
345369
@@ -406,18 +430,18 @@ void MacroConditionFileEdit::SetWidgetVisibility()
406430 return ;
407431 }
408432
409- _matchText->setVisible (_entryData->_condition ==
410- MacroConditionFile::ConditionType ::MATCH);
411- _regex->setVisible (_entryData->_condition ==
412- MacroConditionFile::ConditionType ::MATCH);
433+ _matchText->setVisible (_entryData->GetCondition () ==
434+ MacroConditionFile::Condition ::MATCH);
435+ _regex->setVisible (_entryData->GetCondition () ==
436+ MacroConditionFile::Condition ::MATCH);
413437 _checkModificationDate->setVisible (
414438 _entryData->_useTime &&
415- _entryData->_condition ==
416- MacroConditionFile::ConditionType ::MATCH);
439+ _entryData->GetCondition () ==
440+ MacroConditionFile::Condition ::MATCH);
417441 _checkFileContent->setVisible (
418442 _entryData->_onlyMatchIfChanged &&
419- _entryData->_condition ==
420- MacroConditionFile::ConditionType ::MATCH);
443+ _entryData->GetCondition () ==
444+ MacroConditionFile::Condition ::MATCH);
421445 adjustSize ();
422446 updateGeometry ();
423447}
0 commit comments