Improve file condition
Some checks failed
debian-build / build (push) Has been cancelled
Check locale / ubuntu64 (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled

* Add support for existence check
* Add support for "is file" check
* Add support for "is folder" check
* Add more temp vars
This commit is contained in:
WarmUpTill 2025-09-12 20:28:29 +02:00 committed by WarmUpTill
parent 37606e274c
commit 3c355ac6fe
3 changed files with 107 additions and 0 deletions

View File

@ -338,6 +338,9 @@ AdvSceneSwitcher.condition.file="File"
AdvSceneSwitcher.condition.file.type.match="matches"
AdvSceneSwitcher.condition.file.type.contentChange="content changed"
AdvSceneSwitcher.condition.file.type.dateChange="modification date changed"
AdvSceneSwitcher.condition.file.type.exists="exists"
AdvSceneSwitcher.condition.file.type.isFile="is a file"
AdvSceneSwitcher.condition.file.type.isFolder="is a folder"
AdvSceneSwitcher.condition.file.remote="Remote file"
AdvSceneSwitcher.condition.file.local="Local file"
AdvSceneSwitcher.condition.file.entry.line1="{{fileType}}{{filePath}}{{conditions}}{{useRegex}}"
@ -2092,6 +2095,19 @@ AdvSceneSwitcher.tempVar.clipboard.text.description="The text contained in the c
AdvSceneSwitcher.tempVar.file.content="File content"
AdvSceneSwitcher.tempVar.file.date="File modification date"
AdvSceneSwitcher.tempVar.file.basename="File basename"
AdvSceneSwitcher.tempVar.file.basename.description="Returns the base name of the file without the path.\nThe base name consists of all characters in the file up to (but not including) the first '.' character."
AdvSceneSwitcher.tempVar.file.basenameComplete="File basename (complete)"
AdvSceneSwitcher.tempVar.file.basenameComplete.description="Returns the complete base name of the file without the path.\nThe complete base name consists of all characters in the file up to (but not including) the last '.' character."
AdvSceneSwitcher.tempVar.file.suffix="File suffix"
AdvSceneSwitcher.tempVar.file.suffix.description="Returns the suffix (extension) of the file.\nThe suffix consists of all characters in the file after (but not including) the last '.'."
AdvSceneSwitcher.tempVar.file.suffixComplete="File suffix (complete)"
AdvSceneSwitcher.tempVar.file.suffixComplete.description="Returns the complete suffix (extension) of the file.\nThe complete suffix consists of all characters in the file after (but not including) the first '.'."
AdvSceneSwitcher.tempVar.file.filename="File name"
AdvSceneSwitcher.tempVar.file.absoluteFilePath="Absolute file path"
AdvSceneSwitcher.tempVar.file.absolutePath="Absolute path"
AdvSceneSwitcher.tempVar.file.isAbsolutePath="Path is absolute"
AdvSceneSwitcher.tempVar.folder.newFiles="New files"
AdvSceneSwitcher.tempVar.folder.changedFiles="Changed files"

View File

@ -156,6 +156,42 @@ void MacroConditionFile::SetupTempVars()
obs_module_text(
"AdvSceneSwitcher.tempVar.file.content"));
}
if (_fileType == FileType::REMOTE) {
return;
}
AddTempvar(
"basename",
obs_module_text("AdvSceneSwitcher.tempVar.file.basename"),
obs_module_text(
"AdvSceneSwitcher.tempVar.file.basename.description"));
AddTempvar(
"basenameComplete",
obs_module_text(
"AdvSceneSwitcher.tempVar.file.basenameComplete"),
obs_module_text(
"AdvSceneSwitcher.tempVar.file.basenameComplete.description"));
AddTempvar("suffix",
obs_module_text("AdvSceneSwitcher.tempVar.file.suffix"),
obs_module_text(
"AdvSceneSwitcher.tempVar.file.suffix.description"));
AddTempvar(
"suffixComplete",
obs_module_text("AdvSceneSwitcher.tempVar.file.suffixComplete"),
obs_module_text(
"AdvSceneSwitcher.tempVar.file.suffixComplete.description"));
AddTempvar("filename",
obs_module_text("AdvSceneSwitcher.tempVar.file.filename"));
AddTempvar("absoluteFilePath",
obs_module_text(
"AdvSceneSwitcher.tempVar.file.absoluteFilePath"));
AddTempvar(
"absolutePath",
obs_module_text("AdvSceneSwitcher.tempVar.file.absolutePath"));
AddTempvar("isAbsolutePath",
obs_module_text(
"AdvSceneSwitcher.tempVar.file.isAbsolutePath"));
}
bool MacroConditionFile::CheckCondition()
@ -175,10 +211,47 @@ bool MacroConditionFile::CheckCondition()
case Condition::DATE_CHANGE:
ret = CheckChangeDate();
break;
case Condition::IS_FILE: {
QFileInfo info(QString::fromStdString(_file));
ret = info.isFile();
break;
}
case Condition::IS_FOLDER: {
QFileInfo info(QString::fromStdString(_file));
ret = info.isDir();
break;
}
case Condition::EXISTS: {
QFileInfo info(QString::fromStdString(_file));
ret = info.exists();
break;
}
default:
break;
}
if (std::string(_file) != _lastFile) {
QFileInfo info(QString::fromStdString(_file));
_basename = info.baseName().toStdString();
_basenameComplete = info.completeBaseName().toStdString();
_suffix = info.suffix().toStdString();
_suffixComplete = info.completeSuffix().toStdString();
_filename = info.fileName().toStdString();
_absoluteFilePath = info.absoluteFilePath().toStdString();
_absolutePath = info.absolutePath().toStdString();
_isAbsolutePath = info.isAbsolute();
_lastFile = _file;
}
SetTempVarValue("basename", _basename);
SetTempVarValue("basenameComplete", _basenameComplete);
SetTempVarValue("suffix", _suffix);
SetTempVarValue("suffixComplete", _suffixComplete);
SetTempVarValue("filename", _filename);
SetTempVarValue("absoluteFilePath", _absoluteFilePath);
SetTempVarValue("absolutePath", _absolutePath);
SetTempVarValue("isAbsolutePath", _isAbsolutePath);
if (GetVariableValue().empty()) {
SetVariableValue(ret ? "true" : "false");
}
@ -237,6 +310,12 @@ static void populateConditions(QComboBox *list)
"AdvSceneSwitcher.condition.file.type.contentChange"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.condition.file.type.dateChange"));
list->addItem(
obs_module_text("AdvSceneSwitcher.condition.file.type.exists"));
list->addItem(
obs_module_text("AdvSceneSwitcher.condition.file.type.isFile"));
list->addItem(obs_module_text(
"AdvSceneSwitcher.condition.file.type.isFolder"));
}
MacroConditionFileEdit::MacroConditionFileEdit(

View File

@ -35,6 +35,9 @@ public:
MATCH,
CONTENT_CHANGE,
DATE_CHANGE,
EXISTS,
IS_FILE,
IS_FOLDER,
};
void SetCondition(Condition condition);
Condition GetCondition() const { return _condition; }
@ -59,6 +62,15 @@ private:
Condition _condition = Condition::MATCH;
QDateTime _lastMod;
size_t _lastHash = 0;
std::string _lastFile;
std::string _basename;
std::string _basenameComplete;
std::string _suffix;
std::string _suffixComplete;
std::string _filename;
std::string _absoluteFilePath;
std::string _absolutePath;
bool _isAbsolutePath = false;
static bool _registered;
static const std::string id;
};