#351: refactor: moved changeable state into new Unit "WorkState.cpp"

from Unit “Options.cpp”. The latter now contains only program options
(which cannot be changed without reload).
This commit is contained in:
Andrey Prygunkov
2019-01-22 21:57:00 +01:00
parent bb1cb68653
commit e3bd94189a
26 changed files with 235 additions and 146 deletions

View File

@@ -1,7 +1,7 @@
#
# This file is part of nzbget. See <http://nzbget.net>.
#
# Copyright (C) 2008-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2008-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -68,6 +68,8 @@ nzbget_SOURCES = \
daemon/main/nzbget.h \
daemon/main/Options.cpp \
daemon/main/Options.h \
daemon/main/WorkState.cpp \
daemon/main/WorkState.h \
daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h \
daemon/main/StackTrace.cpp \

14
Makefile.in vendored
View File

@@ -17,7 +17,7 @@
#
# This file is part of nzbget. See <http://nzbget.net>.
#
# Copyright (C) 2008-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2008-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -232,7 +232,8 @@ am__nzbget_SOURCES_DIST = daemon/connect/Connection.cpp \
daemon/main/DiskService.h daemon/main/Maintenance.cpp \
daemon/main/Maintenance.h daemon/main/nzbget.cpp \
daemon/main/nzbget.h daemon/main/Options.cpp \
daemon/main/Options.h daemon/main/Scheduler.cpp \
daemon/main/Options.h daemon/main/WorkState.cpp \
daemon/main/WorkState.h daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h daemon/main/StackTrace.cpp \
daemon/main/StackTrace.h daemon/nntp/ArticleDownloader.cpp \
daemon/nntp/ArticleDownloader.h daemon/nntp/ArticleWriter.cpp \
@@ -387,7 +388,8 @@ am_nzbget_OBJECTS = daemon/connect/Connection.$(OBJEXT) \
daemon/main/CommandLineParser.$(OBJEXT) \
daemon/main/DiskService.$(OBJEXT) \
daemon/main/Maintenance.$(OBJEXT) daemon/main/nzbget.$(OBJEXT) \
daemon/main/Options.$(OBJEXT) daemon/main/Scheduler.$(OBJEXT) \
daemon/main/Options.$(OBJEXT) daemon/main/WorkState.$(OBJEXT) \
daemon/main/Scheduler.$(OBJEXT) \
daemon/main/StackTrace.$(OBJEXT) \
daemon/nntp/ArticleDownloader.$(OBJEXT) \
daemon/nntp/ArticleWriter.$(OBJEXT) \
@@ -720,7 +722,8 @@ nzbget_SOURCES = daemon/connect/Connection.cpp \
daemon/main/DiskService.h daemon/main/Maintenance.cpp \
daemon/main/Maintenance.h daemon/main/nzbget.cpp \
daemon/main/nzbget.h daemon/main/Options.cpp \
daemon/main/Options.h daemon/main/Scheduler.cpp \
daemon/main/Options.h daemon/main/WorkState.cpp \
daemon/main/WorkState.h daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h daemon/main/StackTrace.cpp \
daemon/main/StackTrace.h daemon/nntp/ArticleDownloader.cpp \
daemon/nntp/ArticleDownloader.h daemon/nntp/ArticleWriter.cpp \
@@ -1158,6 +1161,8 @@ daemon/main/nzbget.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/Options.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/WorkState.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/Scheduler.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/StackTrace.$(OBJEXT): daemon/main/$(am__dirstamp) \
@@ -1553,6 +1558,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/Options.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/Scheduler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/StackTrace.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/WorkState.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/nzbget.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/nntp/$(DEPDIR)/ArticleDownloader.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/nntp/$(DEPDIR)/ArticleWriter.Po@am__quote@

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2012-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2012-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include "WebDownloader.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "Util.h"
#include "FileSystem.h"
@@ -72,19 +73,19 @@ void WebDownloader::Run()
if ((((Status == adFailed) && (remainedDownloadRetries > 1)) ||
((Status == adConnectError) && (remainedConnectRetries > 1)))
&& !IsStopped() && !(!m_force && g_Options->GetPauseDownload()))
&& !IsStopped() && !(!m_force && g_WorkState->GetPauseDownload()))
{
detail("Waiting %i sec to retry", g_Options->GetUrlInterval());
int msec = 0;
while (!IsStopped() && (msec < g_Options->GetUrlInterval() * 1000) &&
!(!m_force && g_Options->GetPauseDownload()))
!(!m_force && g_WorkState->GetPauseDownload()))
{
usleep(100 * 1000);
msec += 100;
}
}
if (IsStopped() || (!m_force && g_Options->GetPauseDownload()))
if (IsStopped() || (!m_force && g_WorkState->GetPauseDownload()))
{
Status = adRetry;
break;

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
#include "Log.h"
#include "Util.h"
#include "Options.h"
#include "WorkState.h"
static const int POSTPROCESS_PARCHECK = 92;
static const int POSTPROCESS_SUCCESS = 93;
@@ -272,14 +273,14 @@ void PostScriptController::AddMessage(Message::EKind kind, const char* text)
m_postInfo->SetProgressLabel(text);
}
if (g_Options->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority())
if (g_WorkState->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority())
{
time_t stageTime = m_postInfo->GetStageTime();
time_t startTime = m_postInfo->GetStartTime();
time_t waitTime = Util::CurrentTime();
// wait until Post-processor is unpaused
while (g_Options->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
while (g_WorkState->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
{
usleep(100 * 1000);

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "FeedCoordinator.h"
#include "Options.h"
#include "WorkState.h"
#include "WebDownloader.h"
#include "Util.h"
#include "FileSystem.h"
@@ -98,7 +99,7 @@ void FeedCoordinator::Run()
while (!IsStopped())
{
// this code should not be called too often, once per second is OK
if (!g_Options->GetPauseDownload() || m_force || g_Options->GetUrlForce())
if (!g_WorkState->GetPauseDownload() || m_force || g_Options->GetUrlForce())
{
Guard guard(m_downloadsMutex);

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "Options.h"
#include "WorkState.h"
#include "Frontend.h"
#include "Log.h"
#include "Connection.h"
@@ -57,8 +58,8 @@ bool Frontend::PrepareData()
if (m_summary)
{
m_currentDownloadSpeed = g_StatMeter->CalcCurrentDownloadSpeed();
m_pauseDownload = g_Options->GetPauseDownload();
m_downloadLimit = g_Options->GetDownloadRate();
m_pauseDownload = g_WorkState->GetPauseDownload();
m_downloadLimit = g_WorkState->GetSpeedLimit();
m_threadCount = Thread::GetThreadCount();
g_StatMeter->CalcTotalStat(&m_upTimeSec, &m_dnTimeSec, &m_allBytes, &m_standBy);
@@ -108,8 +109,8 @@ void Frontend::ServerPauseUnpause(bool pause)
}
else
{
g_Options->SetResumeTime(0);
g_Options->SetPauseDownload(pause);
g_WorkState->SetResumeTime(0);
g_WorkState->SetPauseDownload(pause);
}
}
@@ -121,7 +122,7 @@ void Frontend::ServerSetDownloadRate(int rate)
}
else
{
g_Options->SetDownloadRate(rate);
g_WorkState->SetSpeedLimit(rate);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "DiskService.h"
#include "Options.h"
#include "WorkState.h"
#include "StatMeter.h"
#include "Log.h"
#include "Util.h"
@@ -38,7 +39,7 @@ void DiskService::ServiceWork()
{
debug("Disk service work");
if (!g_Options->GetPauseDownload() &&
if (!g_WorkState->GetPauseDownload() &&
g_Options->GetDiskSpace() > 0 && !g_StatMeter->GetStandBy())
{
// check free disk space every 1 second
@@ -59,7 +60,7 @@ void DiskService::CheckDiskSpace()
if (freeSpace > -1 && freeSpace / 1024 / 1024 < g_Options->GetDiskSpace())
{
warn("Low disk space on %s. Pausing download", g_Options->GetDestDir());
g_Options->SetPauseDownload(true);
g_WorkState->SetPauseDownload(true);
}
if (!Util::EmptyStr(g_Options->GetInterDir()))
@@ -68,7 +69,7 @@ void DiskService::CheckDiskSpace()
if (freeSpace > -1 && freeSpace / 1024 / 1024 < g_Options->GetDiskSpace())
{
warn("Low disk space on %s. Pausing download", g_Options->GetInterDir());
g_Options->SetPauseDownload(true);
g_WorkState->SetPauseDownload(true);
}
}
}
@@ -106,7 +107,7 @@ void DiskService::CheckRequiredDir()
info("All required directories available");
}
g_Options->SetTempPauseDownload(false);
g_Options->SetTempPausePostprocess(false);
g_WorkState->SetTempPauseDownload(false);
g_WorkState->SetTempPausePostprocess(false);
m_waitingRequiredDir = false;
}

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -300,6 +300,7 @@ public:
bool GetDirectRename() { return m_directRename; }
bool GetReorderFiles() { return m_reorderFiles; }
EFileNaming GetFileNaming() { return m_fileNaming; }
int GetDownloadRate() const { return m_downloadRate; }
Categories* GetCategories() { return &m_categories; }
Category* FindCategory(const char* name, bool searchAliases) { return m_categories.FindCategory(name, searchAliases); }
@@ -311,24 +312,6 @@ public:
bool GetDaemonMode() { return m_daemonMode; }
void SetRemoteClientMode(bool remoteClientMode) { m_remoteClientMode = remoteClientMode; }
bool GetRemoteClientMode() { return m_remoteClientMode; }
void SetPauseDownload(bool pauseDownload) { m_pauseDownload = pauseDownload; }
bool GetPauseDownload() const { return m_pauseDownload; }
void SetPausePostProcess(bool pausePostProcess) { m_pausePostProcess = pausePostProcess; }
bool GetPausePostProcess() const { return m_pausePostProcess; }
void SetPauseScan(bool pauseScan) { m_pauseScan = pauseScan; }
bool GetPauseScan() const { return m_pauseScan; }
void SetTempPauseDownload(bool tempPauseDownload) { m_tempPauseDownload = tempPauseDownload; }
bool GetTempPauseDownload() const { return m_tempPauseDownload; }
bool GetTempPausePostprocess() const { return m_tempPausePostprocess; }
void SetTempPausePostprocess(bool tempPausePostprocess) { m_tempPausePostprocess = tempPausePostprocess; }
void SetDownloadRate(int rate) { m_downloadRate = rate; }
int GetDownloadRate() const { return m_downloadRate; }
void SetResumeTime(time_t resumeTime) { m_resumeTime = resumeTime; }
time_t GetResumeTime() const { return m_resumeTime; }
void SetLocalTimeOffset(int localTimeOffset) { m_localTimeOffset = localTimeOffset; }
int GetLocalTimeOffset() { return m_localTimeOffset; }
void SetQuotaReached(bool quotaReached) { m_quotaReached = quotaReached; }
bool GetQuotaReached() { return m_quotaReached; }
private:
OptEntries m_optEntries;
@@ -450,20 +433,12 @@ private:
int m_dailyQuota = 0;
bool m_reorderFiles = false;
EFileNaming m_fileNaming = nfArticle;
int m_downloadRate = 0;
// Current state
// Application mode
bool m_serverMode = false;
bool m_daemonMode = false;
bool m_remoteClientMode = false;
bool m_pauseDownload = false;
bool m_pausePostProcess = false;
bool m_pauseScan = false;
bool m_tempPauseDownload = true;
bool m_tempPausePostprocess = true;
int m_downloadRate = 0;
time_t m_resumeTime = 0;
int m_localTimeOffset = 0;
bool m_quotaReached = false;
void Init(const char* exeName, const char* configFilename, bool noConfig,
CmdOptList* commandLineOptions, bool noDiskAccess, Extender* extender);

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "Scheduler.h"
#include "Options.h"
#include "WorkState.h"
#include "Log.h"
#include "NewsServer.h"
#include "ServerPool.h"
@@ -121,8 +122,8 @@ void Scheduler::CheckTasks()
}
}
time_t localCurrent = current + g_Options->GetLocalTimeOffset();
time_t localLastCheck = m_lastCheck + g_Options->GetLocalTimeOffset();
time_t localCurrent = current + g_WorkState->GetLocalTimeOffset();
time_t localLastCheck = m_lastCheck + g_WorkState->GetLocalTimeOffset();
tm tmCurrent;
gmtime_r(&localCurrent, &tmCurrent);
@@ -194,26 +195,26 @@ void Scheduler::ExecuteTask(Task* task)
case scDownloadRate:
if (!task->m_param.Empty())
{
g_Options->SetDownloadRate(atoi(task->m_param) * 1024);
g_WorkState->SetSpeedLimit(atoi(task->m_param) * 1024);
m_downloadRateChanged = true;
}
break;
case scPauseDownload:
case scUnpauseDownload:
g_Options->SetPauseDownload(task->m_command == scPauseDownload);
g_WorkState->SetPauseDownload(task->m_command == scPauseDownload);
m_pauseDownloadChanged = true;
break;
case scPausePostProcess:
case scUnpausePostProcess:
g_Options->SetPausePostProcess(task->m_command == scPausePostProcess);
g_WorkState->SetPausePostProcess(task->m_command == scPausePostProcess);
m_pausePostProcessChanged = true;
break;
case scPauseScan:
case scUnpauseScan:
g_Options->SetPauseScan(task->m_command == scPauseScan);
g_WorkState->SetPauseScan(task->m_command == scPauseScan);
m_pauseScanChanged = true;
break;
@@ -252,19 +253,19 @@ void Scheduler::PrintLog()
{
if (m_downloadRateChanged)
{
info("Scheduler: setting download rate to %i KB/s", g_Options->GetDownloadRate() / 1024);
info("Scheduler: setting download rate to %i KB/s", g_WorkState->GetSpeedLimit() / 1024);
}
if (m_pauseDownloadChanged)
{
info("Scheduler: %s download", g_Options->GetPauseDownload() ? "pausing" : "unpausing");
info("Scheduler: %s download", g_WorkState->GetPauseDownload() ? "pausing" : "unpausing");
}
if (m_pausePostProcessChanged)
{
info("Scheduler: %s post-processing", g_Options->GetPausePostProcess() ? "pausing" : "unpausing");
info("Scheduler: %s post-processing", g_WorkState->GetPausePostProcess() ? "pausing" : "unpausing");
}
if (m_pauseScanChanged)
{
info("Scheduler: %s scan", g_Options->GetPauseScan() ? "pausing" : "unpausing");
info("Scheduler: %s scan", g_WorkState->GetPauseScan() ? "pausing" : "unpausing");
}
if (m_serverChanged)
{
@@ -331,14 +332,14 @@ void Scheduler::FetchFeed(const char* feedList)
void Scheduler::CheckScheduledResume()
{
time_t resumeTime = g_Options->GetResumeTime();
time_t resumeTime = g_WorkState->GetResumeTime();
time_t currentTime = Util::CurrentTime();
if (resumeTime > 0 && currentTime >= resumeTime)
{
info("Autoresume");
g_Options->SetResumeTime(0);
g_Options->SetPauseDownload(false);
g_Options->SetPausePostProcess(false);
g_Options->SetPauseScan(false);
g_WorkState->SetResumeTime(0);
g_WorkState->SetPauseDownload(false);
g_WorkState->SetPausePostProcess(false);
g_WorkState->SetPauseScan(false);
}
}

23
daemon/main/WorkState.cpp Normal file
View File

@@ -0,0 +1,23 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nzbget.h"
#include "WorkState.h"

61
daemon/main/WorkState.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WORKSTATE_H
#define WORKSTATE_H
class WorkState
{
public:
void SetPauseDownload(bool pauseDownload) { m_pauseDownload = pauseDownload; }
bool GetPauseDownload() const { return m_pauseDownload; }
void SetPausePostProcess(bool pausePostProcess) { m_pausePostProcess = pausePostProcess; }
bool GetPausePostProcess() const { return m_pausePostProcess; }
void SetPauseScan(bool pauseScan) { m_pauseScan = pauseScan; }
bool GetPauseScan() const { return m_pauseScan; }
void SetTempPauseDownload(bool tempPauseDownload) { m_tempPauseDownload = tempPauseDownload; }
bool GetTempPauseDownload() const { return m_tempPauseDownload; }
bool GetTempPausePostprocess() const { return m_tempPausePostprocess; }
void SetTempPausePostprocess(bool tempPausePostprocess) { m_tempPausePostprocess = tempPausePostprocess; }
void SetSpeedLimit(int speedLimit) { m_speedLimit = speedLimit; }
int GetSpeedLimit() const { return m_speedLimit; }
void SetResumeTime(time_t resumeTime) { m_resumeTime = resumeTime; }
time_t GetResumeTime() const { return m_resumeTime; }
void SetLocalTimeOffset(int localTimeOffset) { m_localTimeOffset = localTimeOffset; }
int GetLocalTimeOffset() { return m_localTimeOffset; }
void SetQuotaReached(bool quotaReached) { m_quotaReached = quotaReached; }
bool GetQuotaReached() { return m_quotaReached; }
private:
bool m_pauseDownload = false;
bool m_pausePostProcess = false;
bool m_pauseScan = false;
bool m_tempPauseDownload = true;
bool m_tempPausePostprocess = true;
int m_downloadRate = 0;
time_t m_resumeTime = 0;
int m_localTimeOffset = 0;
bool m_quotaReached = false;
int m_speedLimit = 0;
};
extern WorkState* g_WorkState;
#endif

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
#include "Log.h"
#include "NzbFile.h"
#include "Options.h"
#include "WorkState.h"
#include "CommandLineParser.h"
#include "ScriptConfig.h"
#include "Thread.h"
@@ -71,6 +72,7 @@ void RunMain();
// Globals
Log* g_Log;
Options* g_Options;
WorkState* g_WorkState;
ServerPool* g_ServerPool;
QueueCoordinator* g_QueueCoordinator;
UrlCoordinator* g_UrlCoordinator;
@@ -193,6 +195,7 @@ private:
// globals
std::unique_ptr<Log> m_log;
std::unique_ptr<Options> m_options;
std::unique_ptr<WorkState> m_workState;
std::unique_ptr<ServerPool> m_serverPool;
std::unique_ptr<QueueCoordinator> m_queueCoordinator;
std::unique_ptr<UrlCoordinator> m_urlCoordinator;
@@ -390,6 +393,9 @@ void NZBGet::CreateGlobals()
m_commandScriptLog = std::make_unique<CommandScriptLog>();
g_CommandScriptLog = m_commandScriptLog.get();
m_workState = std::make_unique<WorkState>();
g_WorkState = m_workState.get();
m_scheduler = std::make_unique<Scheduler>();
m_diskService = std::make_unique<DiskService>();
@@ -415,7 +421,8 @@ void NZBGet::BootConfig()
m_commandLineParser->GetNoConfig(), (Options::CmdOptList*)m_commandLineParser->GetOptionList(), this);
m_options->SetRemoteClientMode(m_commandLineParser->GetRemoteClientMode());
m_options->SetServerMode(m_commandLineParser->GetServerMode());
m_options->SetPauseDownload(m_commandLineParser->GetPauseDownload());
m_workState->SetPauseDownload(m_commandLineParser->GetPauseDownload());
m_workState->SetSpeedLimit(g_Options->GetDownloadRate());
m_log->InitOptions();
@@ -427,9 +434,9 @@ void NZBGet::BootConfig()
m_commandLineParser->GetClientOperation() == CommandLineParser::opClientNoOperation)
{
info("Pausing all activities due to errors in configuration");
m_options->SetPauseDownload(true);
m_options->SetPausePostProcess(true);
m_options->SetPauseScan(true);
m_workState->SetPauseDownload(true);
m_workState->SetPausePostProcess(true);
m_workState->SetPauseScan(true);
}
m_serverPool->SetTimeout(m_options->GetArticleTimeout());

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
#include "Decoder.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "ServerPool.h"
#include "StatMeter.h"
#include "Util.h"
@@ -102,8 +103,8 @@ void ArticleDownloader::Run()
SetLastUpdateTimeNow();
SetStatus(adRunning);
if (IsStopped() || ((g_Options->GetPauseDownload() || g_Options->GetQuotaReached()) && !force) ||
(g_Options->GetTempPauseDownload() && !m_fileInfo->GetExtraPriority()) ||
if (IsStopped() || ((g_WorkState->GetPauseDownload() || g_WorkState->GetQuotaReached()) && !force) ||
(g_WorkState->GetTempPauseDownload() && !m_fileInfo->GetExtraPriority()) ||
serverConfigGeneration != g_ServerPool->GetGeneration())
{
status = adRetry;
@@ -194,8 +195,8 @@ void ArticleDownloader::Run()
break;
}
if (IsStopped() || ((g_Options->GetPauseDownload() || g_Options->GetQuotaReached()) && !force) ||
(g_Options->GetTempPauseDownload() && !m_fileInfo->GetExtraPriority()) ||
if (IsStopped() || ((g_WorkState->GetPauseDownload() || g_WorkState->GetQuotaReached()) && !force) ||
(g_WorkState->GetTempPauseDownload() && !m_fileInfo->GetExtraPriority()) ||
serverConfigGeneration != g_ServerPool->GetGeneration())
{
status = adRetry;
@@ -339,9 +340,9 @@ ArticleDownloader::EStatus ArticleDownloader::Download()
while (!IsStopped() && !m_decoder.GetEof())
{
// throttle the bandwidth
while (!IsStopped() && (g_Options->GetDownloadRate() > 0.0f) &&
(g_StatMeter->CalcCurrentDownloadSpeed() > g_Options->GetDownloadRate() ||
g_StatMeter->CalcMomentaryDownloadSpeed() > g_Options->GetDownloadRate()))
while (!IsStopped() && (g_WorkState->GetSpeedLimit() > 0.0f) &&
(g_StatMeter->CalcCurrentDownloadSpeed() > g_WorkState->GetSpeedLimit() ||
g_StatMeter->CalcMomentaryDownloadSpeed() > g_WorkState->GetSpeedLimit()))
{
SetLastUpdateTimeNow();
usleep(10 * 1000);

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2014-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2014-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "StatMeter.h"
#include "Options.h"
#include "WorkState.h"
#include "ServerPool.h"
#include "DiskState.h"
#include "Util.h"
@@ -57,8 +58,8 @@ void ServerVolume::CalcSlots(time_t locCurTime)
void ServerVolume::AddData(int bytes)
{
time_t curTime = Util::CurrentTime();
time_t locCurTime = curTime + g_Options->GetLocalTimeOffset();
time_t locDataTime = m_dataTime + g_Options->GetLocalTimeOffset();
time_t locCurTime = curTime + g_WorkState->GetLocalTimeOffset();
time_t locDataTime = m_dataTime + g_WorkState->GetLocalTimeOffset();
int lastMinSlot = m_minSlot;
int lastHourSlot = m_hourSlot;
@@ -188,10 +189,10 @@ void StatMeter::AdjustTimeOffset()
tmSplittedTime.tm_isdst = -1;
time_t locTime = mktime(&tmSplittedTime);
time_t localTimeDelta = utcTime - locTime;
g_Options->SetLocalTimeOffset((int)localTimeDelta + g_Options->GetTimeCorrection());
g_WorkState->SetLocalTimeOffset((int)localTimeDelta + g_Options->GetTimeCorrection());
m_lastTimeOffset = utcTime;
debug("UTC delta: %i (%i+%i)", g_Options->GetLocalTimeOffset(), (int)localTimeDelta, g_Options->GetTimeCorrection());
debug("UTC delta: %i (%i+%i)", g_WorkState->GetLocalTimeOffset(), (int)localTimeDelta, g_Options->GetTimeCorrection());
}
/*
@@ -446,7 +447,7 @@ bool StatMeter::Load(bool* perfectServerMatch)
for (ServerVolume& serverVolume : m_serverVolumes)
{
serverVolume.CalcSlots(serverVolume.GetDataTime() + g_Options->GetLocalTimeOffset());
serverVolume.CalcSlots(serverVolume.GetDataTime() + g_WorkState->GetLocalTimeOffset());
}
return ok;
@@ -465,20 +466,20 @@ void StatMeter::CheckQuota()
bool monthlyQuotaReached = g_Options->GetMonthlyQuota() > 0 && monthBytes >= (int64)g_Options->GetMonthlyQuota() * 1024 * 1024;
bool dailyQuotaReached = g_Options->GetDailyQuota() > 0 && dayBytes >= (int64)g_Options->GetDailyQuota() * 1024 * 1024;
if (monthlyQuotaReached && !g_Options->GetQuotaReached())
if (monthlyQuotaReached && !g_WorkState->GetQuotaReached())
{
warn("Monthly quota reached at %s", *Util::FormatSize(monthBytes));
}
else if (dailyQuotaReached && !g_Options->GetQuotaReached())
else if (dailyQuotaReached && !g_WorkState->GetQuotaReached())
{
warn("Daily quota reached at %s", *Util::FormatSize(dayBytes));
}
else if (!monthlyQuotaReached && !dailyQuotaReached && g_Options->GetQuotaReached())
else if (!monthlyQuotaReached && !dailyQuotaReached && g_WorkState->GetQuotaReached())
{
info("Quota lifted");
}
g_Options->SetQuotaReached(monthlyQuotaReached || dailyQuotaReached);
g_WorkState->SetQuotaReached(monthlyQuotaReached || dailyQuotaReached);
}
void StatMeter::CalcQuotaUsage(int64& monthBytes, int64& dayBytes)
@@ -487,7 +488,7 @@ void StatMeter::CalcQuotaUsage(int64& monthBytes, int64& dayBytes)
ServerVolume totalVolume = m_serverVolumes[0];
time_t locTime = Util::CurrentTime() + g_Options->GetLocalTimeOffset();
time_t locTime = Util::CurrentTime() + g_WorkState->GetLocalTimeOffset();
int daySlot = (int)(locTime / 86400) - totalVolume.GetFirstDay();
dayBytes = 0;
@@ -515,7 +516,7 @@ int StatMeter::CalcMonthSlots(ServerVolume& volume)
{
int elapsedDays;
time_t locCurTime = Util::CurrentTime() + g_Options->GetLocalTimeOffset();
time_t locCurTime = Util::CurrentTime() + g_WorkState->GetLocalTimeOffset();
tm dayparts;
gmtime_r(&locCurTime, &dayparts);

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "PrePostProcessor.h"
#include "Options.h"
#include "WorkState.h"
#include "Log.h"
#include "HistoryCoordinator.h"
#include "DupeCoordinator.h"
@@ -59,7 +60,7 @@ void PrePostProcessor::Run()
while (!IsStopped())
{
if (g_Options->GetTempPausePostprocess())
if (g_WorkState->GetTempPausePostprocess())
{
// Postprocess is paused: just wait and loop
usleep(200 * 1000);
@@ -610,7 +611,7 @@ NzbInfo* PrePostProcessor::PickNextJob(DownloadQueue* downloadQueue, bool allowP
!g_QueueScriptCoordinator->HasJob(nzbInfo1->GetId(), nullptr) &&
nzbInfo1->GetDirectUnpackStatus() != NzbInfo::nsRunning &&
(!nzbInfo || nzbInfo1->GetPriority() > nzbInfo->GetPriority()) &&
(!g_Options->GetPausePostProcess() || nzbInfo1->GetForcePriority()) &&
(!g_WorkState->GetPausePostProcess() || nzbInfo1->GetForcePriority()) &&
(allowPar || !nzbInfo1->GetPostInfo()->GetNeedParCheck()) &&
(std::find(m_activeJobs.begin(), m_activeJobs.end(), nzbInfo1) == m_activeJobs.end()) &&
nzbInfo1->IsDownloadCompleted(true))
@@ -644,7 +645,7 @@ void PrePostProcessor::CheckPostQueue()
PostInfo* postInfo = postJob->GetPostInfo();
if (postInfo->GetStage() == PostInfo::ptQueued &&
(!g_Options->GetPausePostProcess() || postInfo->GetNzbInfo()->GetForcePriority()))
(!g_WorkState->GetPausePostProcess() || postInfo->GetNzbInfo()->GetForcePriority()))
{
StartJob(downloadQueue, postInfo, allowPar);
CheckRequestPar(downloadQueue);
@@ -892,16 +893,16 @@ void PrePostProcessor::UpdatePauseState()
}
}
if (needPause && !g_Options->GetTempPauseDownload())
if (needPause && !g_WorkState->GetTempPauseDownload())
{
info("Pausing download before post-processing");
}
else if (!needPause && g_Options->GetTempPauseDownload())
else if (!needPause && g_WorkState->GetTempPauseDownload())
{
info("Unpausing download after post-processing");
}
g_Options->SetTempPauseDownload(needPause);
g_WorkState->SetTempPauseDownload(needPause);
}
bool PrePostProcessor::EditList(DownloadQueue* downloadQueue, IdList* idList,

View File

@@ -23,6 +23,7 @@
#include "DupeCoordinator.h"
#include "ParParser.h"
#include "Options.h"
#include "WorkState.h"
#include "DiskState.h"
#include "Log.h"
#include "FileSystem.h"
@@ -532,7 +533,7 @@ void RepairController::UpdateParCheckProgress()
void RepairController::CheckPauseState(PostInfo* postInfo)
{
if (g_Options->GetPausePostProcess() && !postInfo->GetNzbInfo()->GetForcePriority())
if (g_WorkState->GetPausePostProcess() && !postInfo->GetNzbInfo()->GetForcePriority())
{
time_t stageTime = postInfo->GetStageTime();
time_t startTime = postInfo->GetStartTime();
@@ -541,7 +542,7 @@ void RepairController::CheckPauseState(PostInfo* postInfo)
time_t waitTime = Util::CurrentTime();
// wait until Post-processor is unpaused
while (g_Options->GetPausePostProcess() && !postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
while (g_WorkState->GetPausePostProcess() && !postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
{
usleep(50 * 1000);

View File

@@ -22,6 +22,7 @@
#include "nzbget.h"
#include "QueueCoordinator.h"
#include "Options.h"
#include "WorkState.h"
#include "ServerPool.h"
#include "ArticleDownloader.h"
#include "ArticleWriter.h"
@@ -211,7 +212,7 @@ void QueueCoordinator::Run()
downloadsChecked = true;
m_hasMoreJobs = hasMoreArticles || articeDownloadsRunning;
if (hasMoreArticles && !IsStopped() && (int)m_activeDownloads.size() < m_downloadsLimit &&
(!g_Options->GetTempPauseDownload() || fileInfo->GetExtraPriority()))
(!g_WorkState->GetTempPauseDownload() || fileInfo->GetExtraPriority()))
{
StartArticleDownload(fileInfo, articleInfo, connection);
articeDownloadsRunning = true;
@@ -526,7 +527,7 @@ bool QueueCoordinator::GetNextArticle(DownloadQueue* downloadQueue, FileInfo* &f
bool nzbPaused = nzbInfo->GetFileList()->size() - nzbInfo->GetPausedFileCount() <= 0;
if ((!fileInfo || nzbHigherPriority) && !nzbPaused &&
(!(g_Options->GetPauseDownload() || g_Options->GetQuotaReached()) || nzbInfo->GetForcePriority()))
(!(g_WorkState->GetPauseDownload() || g_WorkState->GetQuotaReached()) || nzbInfo->GetForcePriority()))
{
for (FileInfo* fileInfo1 : nzbInfo->GetFileList())
{
@@ -1022,9 +1023,9 @@ void QueueCoordinator::LogDebugInfo()
downloadQueue->CalcRemainingSize(&remaining, &remainingForced);
info(" Remaining: %.1f MB, Forced: %.1f MB", remaining / 1024.0 / 1024.0, remainingForced / 1024.0 / 1024.0);
info(" Download: %s, Post-process: %s, Scan: %s",
(g_Options->GetPauseDownload() ? "paused" : g_Options->GetTempPauseDownload() ? "temp-paused" : "active"),
(g_Options->GetPausePostProcess() ? "paused" : "active"),
(g_Options->GetPauseScan() ? "paused" : "active"));
(g_WorkState->GetPauseDownload() ? "paused" : g_WorkState->GetTempPauseDownload() ? "temp-paused" : "active"),
(g_WorkState->GetPausePostProcess() ? "paused" : "active"),
(g_WorkState->GetPauseScan() ? "paused" : "active"));
info(" ---------- QueueCoordinator");
info(" Active Downloads: %i, Limit: %i", (int)m_activeDownloads.size(), m_downloadsLimit);

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "Scanner.h"
#include "Options.h"
#include "WorkState.h"
#include "Log.h"
#include "QueueCoordinator.h"
#include "HistoryCoordinator.h"
@@ -96,7 +97,7 @@ void Scanner::ServiceWork()
m_nzbDirInterval = g_Options->GetNzbDirInterval();
if (g_Options->GetPauseScan() && !m_requestedNzbDirScan)
if (g_WorkState->GetPauseScan() && !m_requestedNzbDirScan)
{
return;
}

View File

@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "UrlCoordinator.h"
#include "Options.h"
#include "WorkState.h"
#include "WebDownloader.h"
#include "Util.h"
#include "FileSystem.h"
@@ -99,7 +100,7 @@ void UrlCoordinator::Run()
if ((int)m_activeDownloads.size() < g_Options->GetUrlConnections())
{
nzbInfo = GetNextUrl(downloadQueue);
if (nzbInfo && (!g_Options->GetPauseDownload() || g_Options->GetUrlForce()))
if (nzbInfo && (!g_WorkState->GetPauseDownload() || g_Options->GetUrlForce()))
{
StartUrlDownload(nzbInfo);
downloadStarted = true;

View File

@@ -2,7 +2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2005 Bo Cordes Petersen <placebodk@sourceforge.net>
* Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
#include "BinRpc.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "QueueEditor.h"
#include "Util.h"
#include "FileSystem.h"
@@ -313,20 +314,20 @@ void PauseUnpauseBinCommand::Execute()
return;
}
g_Options->SetResumeTime(0);
g_WorkState->SetResumeTime(0);
switch (ntohl(PauseUnpauseRequest.m_action))
{
case rpDownload:
g_Options->SetPauseDownload(ntohl(PauseUnpauseRequest.m_pause));
g_WorkState->SetPauseDownload(ntohl(PauseUnpauseRequest.m_pause));
break;
case rpPostProcess:
g_Options->SetPausePostProcess(ntohl(PauseUnpauseRequest.m_pause));
g_WorkState->SetPausePostProcess(ntohl(PauseUnpauseRequest.m_pause));
break;
case rpScan:
g_Options->SetPauseScan(ntohl(PauseUnpauseRequest.m_pause));
g_WorkState->SetPauseScan(ntohl(PauseUnpauseRequest.m_pause));
break;
}
@@ -341,7 +342,7 @@ void SetDownloadRateBinCommand::Execute()
return;
}
g_Options->SetDownloadRate(ntohl(SetDownloadRequest.m_downloadRate));
g_WorkState->SetSpeedLimit(ntohl(SetDownloadRequest.m_downloadRate));
SendBoolResponse(true, "Rate-Command completed successfully");
}
@@ -674,10 +675,10 @@ void ListBinCommand::Execute()
Util::SplitInt64(remainingSize, &sizeHi, &sizeLo);
ListResponse.m_remainingSizeHi = htonl(sizeHi);
ListResponse.m_remainingSizeLo = htonl(sizeLo);
ListResponse.m_downloadLimit = htonl(g_Options->GetDownloadRate());
ListResponse.m_downloadPaused = htonl(g_Options->GetPauseDownload());
ListResponse.m_postPaused = htonl(g_Options->GetPausePostProcess());
ListResponse.m_scanPaused = htonl(g_Options->GetPauseScan());
ListResponse.m_downloadRate = htonl(g_WorkState->GetSpeedLimit());
ListResponse.m_downloadPaused = htonl(g_WorkState->GetPauseDownload());
ListResponse.m_postPaused = htonl(g_WorkState->GetPausePostProcess());
ListResponse.m_scanPaused = htonl(g_WorkState->GetPauseScan());
ListResponse.m_threadCount = htonl(Thread::GetThreadCount() - 1); // not counting itself
ListResponse.m_postJobCount = htonl(postJobCount);

View File

@@ -541,9 +541,9 @@ bool RemoteClient::RequestServerList(bool files, bool groups, const char* patter
int averageSpeed = (int)(ntohl(ListResponse.m_downloadTimeSec) > 0 ? allBytes / ntohl(ListResponse.m_downloadTimeSec) : 0);
printf("Session download rate: %s\n", *Util::FormatSpeed(averageSpeed));
if (ntohl(ListResponse.m_downloadLimit) > 0)
if (ntohl(ListResponse.m_downloadRate) > 0)
{
printf("Speed limit: %s\n", *Util::FormatSpeed(ntohl(ListResponse.m_downloadLimit)));
printf("Speed limit: %s\n", *Util::FormatSpeed(ntohl(ListResponse.m_downloadRate)));
}
int sec = ntohl(ListResponse.m_upTimeSec);

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include "XmlRpc.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "Scanner.h"
#include "FeedCoordinator.h"
#include "ServerPool.h"
@@ -1102,20 +1103,20 @@ void PauseUnpauseXmlCommand::Execute()
{
bool ok = true;
g_Options->SetResumeTime(0);
g_WorkState->SetResumeTime(0);
switch (m_pauseAction)
{
case paDownload:
g_Options->SetPauseDownload(m_pause);
g_WorkState->SetPauseDownload(m_pause);
break;
case paPostProcess:
g_Options->SetPausePostProcess(m_pause);
g_WorkState->SetPausePostProcess(m_pause);
break;
case paScan:
g_Options->SetPauseScan(m_pause);
g_WorkState->SetPauseScan(m_pause);
break;
default:
@@ -1137,7 +1138,7 @@ void ScheduleResumeXmlCommand::Execute()
time_t curTime = Util::CurrentTime();
g_Options->SetResumeTime(curTime + seconds);
g_WorkState->SetResumeTime(curTime + seconds);
BuildBoolResponse(true);
}
@@ -1179,7 +1180,7 @@ void SetDownloadRateXmlCommand::Execute()
return;
}
g_Options->SetDownloadRate(rate * 1024);
g_WorkState->SetSpeedLimit(rate * 1024);
BuildBoolResponse(true);
}
@@ -1322,11 +1323,11 @@ void StatusXmlCommand::Execute()
int articleCacheMBytes = (int)(articleCache / 1024 / 1024);
int downloadRate = (int)(g_StatMeter->CalcCurrentDownloadSpeed());
int downloadLimit = (int)(g_Options->GetDownloadRate());
bool downloadPaused = g_Options->GetPauseDownload();
bool postPaused = g_Options->GetPausePostProcess();
bool scanPaused = g_Options->GetPauseScan();
bool quotaReached = g_Options->GetQuotaReached();
int downloadLimit = (int)(g_WorkState->GetSpeedLimit());
bool downloadPaused = g_WorkState->GetPauseDownload();
bool postPaused = g_WorkState->GetPausePostProcess();
bool scanPaused = g_WorkState->GetPauseScan();
bool quotaReached = g_WorkState->GetQuotaReached();
int threadCount = Thread::GetThreadCount() - 1; // not counting itself
uint32 downloadedSizeHi, downloadedSizeLo;
@@ -1354,7 +1355,7 @@ void StatusXmlCommand::Execute()
int freeDiskSpaceMB = (int)(freeDiskSpace / 1024 / 1024);
int serverTime = (int)Util::CurrentTime();
int resumeTime = (int)g_Options->GetResumeTime();
int resumeTime = (int)g_WorkState->GetResumeTime();
bool feedActive = g_FeedCoordinator->HasActiveDownloads();
int queuedScripts = g_QueueScriptCoordinator->GetQueueSize();

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2014-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2014-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
#include "nzbget.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "FeedCoordinator.h"
#include "StatMeter.h"
#include "WinConsole.h"
@@ -29,14 +30,11 @@
#include "Util.h"
#include "resource.h"
extern Options* g_Options;
extern char* (*g_Arguments)[];
extern int g_ArgumentCount;
extern void ExitProc();
extern void Reload();
extern WinConsole* g_WinConsole;
extern FeedCoordinator* g_FeedCoordinator;
extern StatMeter* g_StatMeter;
#define UM_TRAYICON (WM_USER + 1)
#define UM_QUIT (WM_USER + 2)
@@ -290,10 +288,10 @@ LRESULT WinConsole::TrayWndProc(HWND hwndWin, UINT uMsg, WPARAM wParam, LPARAM l
case UM_TRAYICON:
if (lParam == WM_LBUTTONUP && !m_doubleClick)
{
g_Options->SetPauseDownload(!g_Options->GetPauseDownload());
g_Options->SetPausePostProcess(g_Options->GetPauseDownload());
g_Options->SetPauseScan(g_Options->GetPauseDownload());
g_Options->SetResumeTime(0);
g_WorkState->SetPauseDownload(!g_WorkState->GetPauseDownload());
g_WorkState->SetPausePostProcess(g_WorkState->GetPauseDownload());
g_WorkState->SetPauseScan(g_WorkState->GetPauseDownload());
g_WorkState->SetResumeTime(0);
UpdateTrayIcon();
}
else if (lParam == WM_LBUTTONDBLCLK && m_doubleClick)
@@ -761,7 +759,7 @@ void WinConsole::UpdateTrayIcon()
strncpy(oldTip, m_iconData->szTip, sizeof(m_iconData->szTip));
oldTip[200-1] = '\0';
if (g_Options->GetPauseDownload())
if (g_WorkState->GetPauseDownload())
{
m_iconData->hIcon = m_pausedIcon;
strncpy(m_iconData->szTip, "NZBGet - paused", sizeof(m_iconData->szTip));
@@ -956,8 +954,8 @@ void WinConsole::ResetFactoryDefaults()
BString<1024> path;
CString errmsg;
g_Options->SetPauseDownload(true);
g_Options->SetPausePostProcess(true);
g_WorkState->SetPauseDownload(true);
g_WorkState->SetPausePostProcess(true);
char commonAppDataPath[MAX_PATH];
SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, commonAppDataPath);

View File

@@ -203,6 +203,7 @@
<ClCompile Include="daemon\main\Maintenance.cpp" />
<ClCompile Include="daemon\main\nzbget.cpp" />
<ClCompile Include="daemon\main\Options.cpp" />
<ClCompile Include="daemon\main\WorkState.cpp" />
<ClCompile Include="daemon\main\Scheduler.cpp" />
<ClCompile Include="daemon\main\StackTrace.cpp" />
<ClCompile Include="daemon\nntp\ArticleDownloader.cpp" />
@@ -308,6 +309,7 @@
<ClInclude Include="daemon\main\Maintenance.h" />
<ClInclude Include="daemon\main\nzbget.h" />
<ClInclude Include="daemon\main\Options.h" />
<ClInclude Include="daemon\main\WorkState.h" />
<ClInclude Include="daemon\main\Scheduler.h" />
<ClInclude Include="daemon\main\StackTrace.h" />
<ClInclude Include="daemon\nntp\ArticleDownloader.h" />