Skip to content

Commit

Permalink
fixed: automatic update via web-interface may not work (Windows only)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugbug committed Mar 24, 2015
1 parent ff8c6b1 commit 36c8758
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 84 deletions.
11 changes: 11 additions & 0 deletions daemon/main/Maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ bool Maintenance::StartUpdate(EBranch eBranch)
return false;
}

#ifdef WIN32
// make absolute path
if (!(strlen(m_szUpdateScript) > 2 && m_szUpdateScript[1] == ':') && m_szUpdateScript[0] != '\\')
{
char szFilename[MAX_PATH + 100];
snprintf(szFilename, sizeof(szFilename), "%s\\%s", g_pOptions->GetAppDir(), m_szUpdateScript);
free(m_szUpdateScript);
m_szUpdateScript = strdup(szFilename);
}
#endif

m_Messages.Clear();

m_UpdateScriptController = new UpdateScriptController();
Expand Down
113 changes: 57 additions & 56 deletions daemon/main/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,15 @@ Options::Script* Options::Scripts::Find(const char* szName)
}


Options::Options(int argc, char* argv[])
Options::Options()
{
m_bConfigErrors = false;
m_iConfigLine = 0;

// initialize options with default values
m_bConfigInitialized = false;
m_szConfigFilename = NULL;
m_szAppDir = NULL;
m_szDestDir = NULL;
m_szInterDir = NULL;
m_szTempDir = NULL;
Expand Down Expand Up @@ -618,7 +619,60 @@ Options::Options(int argc, char* argv[])
m_iPropagationDelay = 0;
m_iArticleCache = 0;
m_iEventInterval = 0;
}

Options::~Options()
{
free(m_szConfigFilename);
free(m_szAppDir);
free(m_szDestDir);
free(m_szInterDir);
free(m_szTempDir);
free(m_szQueueDir);
free(m_szNzbDir);
free(m_szWebDir);
free(m_szConfigTemplate);
free(m_szScriptDir);
free(m_szArgFilename);
free(m_szAddCategory);
free(m_szEditQueueText);
free(m_szLastArg);
free(m_szControlIP);
free(m_szControlUsername);
free(m_szControlPassword);
free(m_szRestrictedUsername);
free(m_szRestrictedPassword);
free(m_szAddUsername);
free(m_szAddPassword);
free(m_szSecureCert);
free(m_szSecureKey);
free(m_szAuthorizedIP);
free(m_szLogFile);
free(m_szLockFile);
free(m_szDaemonUsername);
free(m_szScriptOrder);
free(m_szPostScript);
free(m_szScanScript);
free(m_szQueueScript);
free(m_pEditQueueIDList);
free(m_szAddNZBFilename);
free(m_szAddDupeKey);
free(m_szUnrarCmd);
free(m_szSevenZipCmd);
free(m_szUnpackPassFile);
free(m_szExtCleanupDisk);
free(m_szParIgnoreExt);
free(m_szWebGetFilename);

for (NameList::iterator it = m_EditQueueNameList.begin(); it != m_EditQueueNameList.end(); it++)
{
free(*it);
}
m_EditQueueNameList.clear();
}

void Options::Init(int argc, char* argv[])
{
// Option "ConfigFile" will be initialized later, but we want
// to see it at the top of option list, so we add it first
SetOption(OPTION_CONFIGFILE, "");
Expand All @@ -634,6 +688,7 @@ Options::Options(int argc, char* argv[])
char* end = strrchr(szFilename, PATH_SEPARATOR);
if (end) *end = '\0';
SetOption(OPTION_APPDIR, szFilename);
m_szAppDir = strdup(szFilename);

SetOption(OPTION_VERSION, Util::VersionRevision());

Expand Down Expand Up @@ -698,55 +753,6 @@ Options::Options(int argc, char* argv[])
}
}

Options::~Options()
{
free(m_szConfigFilename);
free(m_szDestDir);
free(m_szInterDir);
free(m_szTempDir);
free(m_szQueueDir);
free(m_szNzbDir);
free(m_szWebDir);
free(m_szConfigTemplate);
free(m_szScriptDir);
free(m_szArgFilename);
free(m_szAddCategory);
free(m_szEditQueueText);
free(m_szLastArg);
free(m_szControlIP);
free(m_szControlUsername);
free(m_szControlPassword);
free(m_szRestrictedUsername);
free(m_szRestrictedPassword);
free(m_szAddUsername);
free(m_szAddPassword);
free(m_szSecureCert);
free(m_szSecureKey);
free(m_szAuthorizedIP);
free(m_szLogFile);
free(m_szLockFile);
free(m_szDaemonUsername);
free(m_szScriptOrder);
free(m_szPostScript);
free(m_szScanScript);
free(m_szQueueScript);
free(m_pEditQueueIDList);
free(m_szAddNZBFilename);
free(m_szAddDupeKey);
free(m_szUnrarCmd);
free(m_szSevenZipCmd);
free(m_szUnpackPassFile);
free(m_szExtCleanupDisk);
free(m_szParIgnoreExt);
free(m_szWebGetFilename);

for (NameList::iterator it = m_EditQueueNameList.begin(); it != m_EditQueueNameList.end(); it++)
{
free(*it);
}
m_EditQueueNameList.clear();
}

void Options::Dump()
{
for (OptEntries::iterator it = m_OptEntries.begin(); it != m_OptEntries.end(); it++)
Expand Down Expand Up @@ -921,12 +927,7 @@ void Options::InitOptFile()
// search for config file in default locations
#ifdef WIN32
char szFilename[MAX_PATH + 20];
GetModuleFileName(NULL, szFilename, MAX_PATH + 1);
szFilename[MAX_PATH] = '\0';
Util::NormalizePathSeparators(szFilename);
char* end = strrchr(szFilename, PATH_SEPARATOR);
if (end) end[1] = '\0';
strcat(szFilename, "nzbget.conf");
snprintf(szFilename, sizeof(szFilename), "%s\\nzbget.conf", m_szAppDir);

if (!Util::FileExists(szFilename))
{
Expand Down
5 changes: 4 additions & 1 deletion daemon/main/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class Options
// Options
bool m_bConfigErrors;
int m_iConfigLine;
char* m_szAppDir;
char* m_szConfigFilename;
char* m_szDestDir;
char* m_szInterDir;
Expand Down Expand Up @@ -425,8 +426,9 @@ class Options
void LoadScripts(Scripts* pScripts);

public:
Options(int argc, char* argv[]);
Options();
~Options();
void Init(int argc, char* argv[]);

bool LoadConfig(OptEntries* pOptEntries);
bool SaveConfig(OptEntries* pOptEntries);
Expand All @@ -438,6 +440,7 @@ class Options
OptEntries* LockOptEntries();
void UnlockOptEntries();
const char* GetConfigFilename() { return m_szConfigFilename; }
const char* GetAppDir() { return m_szAppDir; }
const char* GetDestDir() { return m_szDestDir; }
const char* GetInterDir() { return m_szInterDir; }
const char* GetTempDir() { return m_szTempDir; }
Expand Down
3 changes: 2 additions & 1 deletion daemon/main/nzbget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ void Run(bool bReload)
g_pQueueScriptCoordinator = new QueueScriptCoordinator();

debug("Reading options");
g_pOptions = new Options(g_iArgumentCount, *g_szArguments);
g_pOptions = new Options();
g_pOptions->Init(g_iArgumentCount, *g_szArguments);

#ifndef WIN32
if (g_pOptions->GetUMask() < 01000)
Expand Down
26 changes: 3 additions & 23 deletions daemon/windows/WinConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,6 @@ void WinConsole::SetupConfigFile()
{
// create new config-file from config template

char szAppDir[MAX_PATH + 30];
GetModuleFileName(NULL, szAppDir, MAX_PATH + 1);
szAppDir[MAX_PATH] = '\0';
Util::NormalizePathSeparators(szAppDir);
char* end = strrchr(szAppDir, PATH_SEPARATOR);
if (end) *end = '\0';

char szFilename[MAX_PATH + 30];

char szCommonAppDataPath[MAX_PATH];
Expand All @@ -941,7 +934,7 @@ void WinConsole::SetupConfigFile()
Util::CreateDirectory(szAppDataPath);

char szConfTemplateFilename[MAX_PATH + 30];
snprintf(szConfTemplateFilename, sizeof(szConfTemplateFilename), "%s\\nzbget.conf.template", szAppDir);
snprintf(szConfTemplateFilename, sizeof(szConfTemplateFilename), "%s\\nzbget.conf.template", g_pOptions->GetAppDir());
szConfTemplateFilename[sizeof(szConfTemplateFilename)-1] = '\0';

CopyFile(szConfTemplateFilename, szFilename, FALSE);
Expand Down Expand Up @@ -982,20 +975,13 @@ void WinConsole::SetupScripts()
char szAppDataPath[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szAppDataPath);

char szAppDir[MAX_PATH + 30];
GetModuleFileName(NULL, szAppDir, MAX_PATH + 1);
szAppDir[MAX_PATH] = '\0';
Util::NormalizePathSeparators(szAppDir);
char* end = strrchr(szAppDir, PATH_SEPARATOR);
if (end) *end = '\0';

char szDestDir[MAX_PATH + 1];
snprintf(szDestDir, sizeof(szDestDir), "%s\\NZBGet\\scripts", szAppDataPath);
szDestDir[sizeof(szDestDir)-1] = '\0';
Util::CreateDirectory(szDestDir);

char szSrcDir[MAX_PATH + 30];
snprintf(szSrcDir, sizeof(szSrcDir), "%s\\scripts", szAppDir);
snprintf(szSrcDir, sizeof(szSrcDir), "%s\\scripts", g_pOptions->GetAppDir());
szSrcDir[sizeof(szSrcDir)-1] = '\0';

DirBrowser dir(szSrcDir);
Expand Down Expand Up @@ -1096,17 +1082,11 @@ void WinConsole::ResetFactoryDefaults()
}

// delete old config file in the program's directory
GetModuleFileName(NULL, szPath, MAX_PATH + 1);
szPath[MAX_PATH] = '\0';
Util::NormalizePathSeparators(szPath);
char* end = strrchr(szPath, PATH_SEPARATOR);
if (end) end[1] = '\0';
strcat(szPath, "nzbget.conf");
snprintf(szPath, sizeof(szPath), "%s\\nzbget.conf", g_pOptions->GetAppDir());

remove(szPath);
Util::GetLastErrorMessage(szErrBuf, sizeof(szErrBuf));


if (Util::FileExists(szPath))
{
snprintf(szMessage, 1024, "Could not delete file %s:\n%s.\nPlease delete the file manually and try again.", szPath, szErrBuf);
Expand Down
20 changes: 17 additions & 3 deletions windows/install-update.bat
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if x%NZBUP_BRANCH%==x (

rem extracting link to update-info-URL from "webui\package-info.json"
set UPDATE_INFO_LINK=
for /f "delims=" %%a in (%NZBOP_WEBDIR%\package-info.json) do (
for /f "delims=" %%a in ('type "%NZBOP_WEBDIR%\package-info.json"') do (
set line=%%a
set line=!line:update-info-link=!
if not %%a==!line! (
Expand All @@ -58,6 +58,14 @@ cd %NZBGET_DIR%

if "%1"=="/step2" goto STEP2

rem Determine if NZBGet is running as a service
set NZBGET_SERVICE=no
for /F "tokens=3 delims=: " %%H in ('sc query "NZBGet" ^| findstr " STATE"') do (
if /I "%%H" EQU "RUNNING" (
set NZBGET_SERVICE=yes
)
)

echo Downloading version information...
rem using special command "-B webget" NZBGet works like a simple wget
rem and fetches files from web-servers
Expand Down Expand Up @@ -102,7 +110,7 @@ rem In that case the command interpreter will go grazy because it doesn't like t
rem batch files being replaced during execution.
copy install-update.bat "%TEMP%\nzbget-update.bat" > nul
if errorlevel 1 goto COPYSCRIPT_FAILURE
start "Updating NZBGet" /I /MIN CALL "%TEMP%\nzbget-update.bat" /step2 "%NZBGET_DIR%" %SETUP_EXE%
start "Updating NZBGet" /I /MIN CALL "%TEMP%\nzbget-update.bat" /step2 "%NZBGET_DIR%" %SETUP_EXE% %NZBGET_SERVICE%

echo [NZB] QUIT

Expand All @@ -114,6 +122,7 @@ rem init from command line params
set NZBGET_DIR=%2
cd %NZBGET_DIR%
set SETUP_EXE=%3
set NZBGET_SERVICE=%4

rem check if nzbget.exe is running
echo Stopping NZBGet...
Expand Down Expand Up @@ -148,7 +157,12 @@ echo.
del %TEMP%\%SETUP_EXE%

echo Starting NZBGet...
start /MIN nzbget.exe -app -auto -s

if "%NZBGET_SERVICE%"=="yes" (
net start NZBGet
) else (
start /MIN nzbget.exe -app -auto -s
)
if errorlevel 1 goto START_FAILURE
ping 127.0.0.1 -n 2 -w 1000 > nul
exit
Expand Down

0 comments on commit 36c8758

Please sign in to comment.