void Scanner::InitPPParameters(const char* szCategory, NZBParameterList* pParameters, bool bReset) { bool bUnpack = g_pOptions->GetUnpack(); const char* szPostScript = g_pOptions->GetPostScript(); if (!Util::EmptyStr(szCategory)) { Options::Category* pCategory = g_pOptions->FindCategory(szCategory, false); if (pCategory) { bUnpack = pCategory->GetUnpack(); if (!Util::EmptyStr(pCategory->GetPostScript())) { szPostScript = pCategory->GetPostScript(); } } } if (bReset) { for (Options::Scripts::iterator it = g_pOptions->GetScripts()->begin(); it != g_pOptions->GetScripts()->end(); it++) { Options::Script* pScript = *it; char szParam[1024]; snprintf(szParam, 1024, "%s:", pScript->GetName()); szParam[1024-1] = '\0'; pParameters->SetParameter(szParam, NULL); } } pParameters->SetParameter("*Unpack:", bUnpack ? "yes" : "no"); if (!Util::EmptyStr(szPostScript)) { // split szPostScript into tokens and create pp-parameter for each token Tokenizer tok(szPostScript, ",;"); while (const char* szScriptName = tok.Next()) { char szParam[1024]; snprintf(szParam, 1024, "%s:", szScriptName); szParam[1024-1] = '\0'; pParameters->SetParameter(szParam, "yes"); } } }
bool QueueScriptCoordinator::UsableScript(ScriptConfig::Script& script, NzbInfo* nzbInfo, EEvent event) { if (!script.GetQueueScript()) { return false; } if (!Util::EmptyStr(script.GetQueueEvents()) && !strstr(script.GetQueueEvents(), QUEUE_EVENT_NAMES[event])) { return false; } // check queue-scripts const char* queueScript = g_Options->GetQueueScript(); if (!Util::EmptyStr(queueScript)) { Tokenizer tok(queueScript, ",;"); while (const char* scriptName = tok.Next()) { if (FileSystem::SameFilename(scriptName, script.GetName())) { return true; } } } // check post-processing-scripts assigned for that nzb for (NzbParameter& parameter : nzbInfo->GetParameters()) { const char* varname = parameter.GetName(); if (strlen(varname) > 0 && varname[0] != '*' && varname[strlen(varname)-1] == ':' && (!strcasecmp(parameter.GetValue(), "yes") || !strcasecmp(parameter.GetValue(), "on") || !strcasecmp(parameter.GetValue(), "1"))) { BString<1024> scriptName = varname; scriptName[strlen(scriptName)-1] = '\0'; // remove trailing ':' if (FileSystem::SameFilename(scriptName, script.GetName())) { return true; } } } // for URL-events the post-processing scripts are not assigned yet; // instead we take the default post-processing scripts for the category (or global) if (event == qeUrlCompleted) { const char* postScript = g_Options->GetPostScript(); if (!Util::EmptyStr(nzbInfo->GetCategory())) { Options::Category* categoryObj = g_Options->FindCategory(nzbInfo->GetCategory(), false); if (categoryObj && !Util::EmptyStr(categoryObj->GetPostScript())) { postScript = categoryObj->GetPostScript(); } } if (!Util::EmptyStr(postScript)) { Tokenizer tok(postScript, ",;"); while (const char* scriptName = tok.Next()) { if (FileSystem::SameFilename(scriptName, script.GetName())) { return true; } } } } return false; }
void QueueEditor::SetNzbCategory(NzbInfo* nzbInfo, const char* category, bool applyParams) { debug("QueueEditor: setting category '%s' for '%s'", category, nzbInfo->GetName()); bool oldUnpack = g_Options->GetUnpack(); const char* oldPostScript = g_Options->GetPostScript(); if (applyParams && !Util::EmptyStr(nzbInfo->GetCategory())) { Options::Category* categoryObj = g_Options->FindCategory(nzbInfo->GetCategory(), false); if (categoryObj) { oldUnpack = categoryObj->GetUnpack(); if (!Util::EmptyStr(categoryObj->GetPostScript())) { oldPostScript = categoryObj->GetPostScript(); } } } g_QueueCoordinator->SetQueueEntryCategory(m_downloadQueue, nzbInfo, category); if (!applyParams) { return; } bool newUnpack = g_Options->GetUnpack(); const char* newPostScript = g_Options->GetPostScript(); if (!Util::EmptyStr(nzbInfo->GetCategory())) { Options::Category* categoryObj = g_Options->FindCategory(nzbInfo->GetCategory(), false); if (categoryObj) { newUnpack = categoryObj->GetUnpack(); if (!Util::EmptyStr(categoryObj->GetPostScript())) { newPostScript = categoryObj->GetPostScript(); } } } if (oldUnpack != newUnpack) { nzbInfo->GetParameters()->SetParameter("*Unpack:", newUnpack ? "yes" : "no"); } if (strcasecmp(oldPostScript, newPostScript)) { // add new params not existed in old category Tokenizer tokNew(newPostScript, ",;"); while (const char* newScriptName = tokNew.Next()) { bool found = false; const char* oldScriptName; Tokenizer tokOld(oldPostScript, ",;"); while ((oldScriptName = tokOld.Next()) && !found) { found = !strcasecmp(newScriptName, oldScriptName); } if (!found) { nzbInfo->GetParameters()->SetParameter(BString<1024>("%s:", newScriptName), "yes"); } } // remove old params not existed in new category Tokenizer tokOld(oldPostScript, ",;"); while (const char* oldScriptName = tokOld.Next()) { bool found = false; const char* newScriptName; Tokenizer tokNew(newPostScript, ",;"); while ((newScriptName = tokNew.Next()) && !found) { found = !strcasecmp(newScriptName, oldScriptName); } if (!found) { nzbInfo->GetParameters()->SetParameter(BString<1024>("%s:", oldScriptName), "no"); } } } }