diff --git a/BinRpc.cpp b/BinRpc.cpp index 089781f7..896c48ef 100644 --- a/BinRpc.cpp +++ b/BinRpc.cpp @@ -299,7 +299,7 @@ void VersionBinCommand::Execute() return; } - SendBoolResponse(true, VERSION); + SendBoolResponse(true, Util::VersionRevision()); } void DownloadBinCommand::Execute() diff --git a/Makefile.am b/Makefile.am index 8a676030..7a87fe28 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ nzbget_SOURCES = ArticleDownloader.cpp ArticleDownloader.h BinRpc.cpp BinRpc.h \ QueueCoordinator.h QueueEditor.cpp QueueEditor.h RemoteClient.cpp RemoteClient.h \ RemoteServer.cpp RemoteServer.h Scheduler.cpp Scheduler.h ScriptController.cpp \ ScriptController.h ServerPool.cpp ServerPool.h TLS.cpp TLS.h Thread.cpp Thread.h Util.cpp \ - Util.h XmlRpc.cpp XmlRpc.h nzbget.cpp nzbget.h + Util.h XmlRpc.cpp XmlRpc.h nzbget.cpp nzbget.h svn_version.cpp EXTRA_DIST = nzbget.conf.example postprocess-example.sh \ win32.h NTService.cpp NTService.h \ @@ -18,4 +18,41 @@ EXTRA_DIST = nzbget.conf.example postprocess-example.sh \ libpar2-0.2-MSVC8.patch libsigc++-2.0.18-MSVC8.patch \ Makefile.cvs nzbget.kdevelop nzbget.sln nzbget.vcproj +# Determining subversion revision: +# 1) If directory ".svn" exists we take revision from it using program svnversion (part of subversion package) +# File is recreated only if revision number was changed. +# 2) If directory ".svn" doesn't exists we keep and reuse file "svn_version.cpp", +# which was possibly created early. +# 3) If neither directory ".svn" nor file "svn_version.cpp" are available +# we create new file "svn_version.c" with empty revision number. +svn_version.cpp: FORCE + @ if test -d ./.svn ; then \ + V="$(shell svnversion -n .)"; \ + H="$(shell test -f ./svn_version.cpp && head -n 1 svn_version.cpp)"; \ + if test "/* $$V */" != "$$H" ; then \ + ( \ + echo "/* $$V */" ;\ + echo "/* This file is automatically regenerated on each build. Do not edit it. */" ;\ + echo "const char* svn_version(void)" ;\ + echo "{" ;\ + echo " const char* SVN_Version = \"$$V\";" ;\ + echo " return SVN_Version;" ;\ + echo "}" ;\ + ) > svn_version.cpp ; \ + fi \ + elif test -f ./svn_version.cpp ; then \ + test "ok, reuse existing file"; \ + else \ + ( \ + echo "/* */" ;\ + echo "/* This file is automatically regenerated on each build. Do not edit it. */" ;\ + echo "const char* svn_version(void)" ;\ + echo "{" ;\ + echo " const char* SVN_Version = \"\";" ;\ + echo " return SVN_Version;" ;\ + echo "}" ;\ + ) > svn_version.cpp ; \ + fi +FORCE: + clean-bak: rm *~ diff --git a/Makefile.in b/Makefile.in index 1572b363..a74f8ef7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -66,7 +66,7 @@ am_nzbget_OBJECTS = ArticleDownloader.$(OBJEXT) BinRpc.$(OBJEXT) \ RemoteServer.$(OBJEXT) Scheduler.$(OBJEXT) \ ScriptController.$(OBJEXT) ServerPool.$(OBJEXT) TLS.$(OBJEXT) \ Thread.$(OBJEXT) Util.$(OBJEXT) XmlRpc.$(OBJEXT) \ - nzbget.$(OBJEXT) + nzbget.$(OBJEXT) svn_version.$(OBJEXT) nzbget_OBJECTS = $(am_nzbget_OBJECTS) nzbget_LDADD = $(LDADD) DEFAULT_INCLUDES = -I. -I$(srcdir) -I. @@ -209,7 +209,7 @@ nzbget_SOURCES = ArticleDownloader.cpp ArticleDownloader.h BinRpc.cpp BinRpc.h \ QueueCoordinator.h QueueEditor.cpp QueueEditor.h RemoteClient.cpp RemoteClient.h \ RemoteServer.cpp RemoteServer.h Scheduler.cpp Scheduler.h ScriptController.cpp \ ScriptController.h ServerPool.cpp ServerPool.h TLS.cpp TLS.h Thread.cpp Thread.h Util.cpp \ - Util.h XmlRpc.cpp XmlRpc.h nzbget.cpp nzbget.h + Util.h XmlRpc.cpp XmlRpc.h nzbget.cpp nzbget.h svn_version.cpp EXTRA_DIST = nzbget.conf.example postprocess-example.sh \ win32.h NTService.cpp NTService.h \ @@ -336,6 +336,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlRpc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nzbget.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/svn_version.Po@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -624,6 +625,43 @@ uninstall-am: uninstall-binPROGRAMS uninstall-info-am uninstall-info-am +# Determining subversion revision: +# 1) If directory ".svn" exists we take revision from it using program svnversion (part of subversion package) +# File is recreated only if revision number was changed. +# 2) If directory ".svn" doesn't exists we keep and reuse file "svn_version.cpp", +# which was possibly created early. +# 3) If neither directory ".svn" nor file "svn_version.cpp" are available +# we create new file "svn_version.c" with empty revision number. +svn_version.cpp: FORCE + @ if test -d ./.svn ; then \ + V="$(shell svnversion -n .)"; \ + H="$(shell test -f ./svn_version.cpp && head -n 1 svn_version.cpp)"; \ + if test "/* $$V */" != "$$H" ; then \ + ( \ + echo "/* $$V */" ;\ + echo "/* This file is automatically regenerated on each build. Do not edit it. */" ;\ + echo "const char* svn_version(void)" ;\ + echo "{" ;\ + echo " const char* SVN_Version = \"$$V\";" ;\ + echo " return SVN_Version;" ;\ + echo "}" ;\ + ) > svn_version.cpp ; \ + fi \ + elif test -f ./svn_version.cpp ; then \ + test "ok, reuse existing file"; \ + else \ + ( \ + echo "/* */" ;\ + echo "/* This file is automatically regenerated on each build. Do not edit it. */" ;\ + echo "const char* svn_version(void)" ;\ + echo "{" ;\ + echo " const char* SVN_Version = \"\";" ;\ + echo " return SVN_Version;" ;\ + echo "}" ;\ + ) > svn_version.cpp ; \ + fi +FORCE: + clean-bak: rm *~ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/Options.cpp b/Options.cpp index c972080f..b3e97291 100644 --- a/Options.cpp +++ b/Options.cpp @@ -773,7 +773,7 @@ void Options::InitCommandLine(int argc, char* argv[]) exit(0); break; case 'v': - printf("nzbget version: %s\n", VERSION); + printf("nzbget version: %s\n", Util::VersionRevision()); exit(1); break; case 'p': diff --git a/Util.cpp b/Util.cpp index 9518a4ca..cda53863 100644 --- a/Util.cpp +++ b/Util.cpp @@ -47,6 +47,11 @@ #include "nzbget.h" #include "Util.h" +#ifndef WIN32 +// function "svn_version" is automatically generated in file "svn_version.cpp" on each build +const char* svn_version(void); +#endif + #ifdef WIN32 // getopt for WIN32: @@ -199,6 +204,8 @@ const char* DirBrowser::Next() #endif +char Util::VersionRevisionBuf[40]; + char* Util::BaseFileName(const char* filename) { char* p = (char*)strrchr(filename, PATH_SEPARATOR); @@ -1131,3 +1138,17 @@ void Util::FormatFileSize(char * szBuffer, int iBufLen, long long lFileSize) } szBuffer[iBufLen - 1] = '\0'; } + +void Util::InitVersionRevision() +{ +#ifndef WIN32 + if ((strlen(svn_version()) > 0) && strstr(VERSION, "testing")) + { + snprintf(VersionRevisionBuf, sizeof(VersionRevisionBuf), "%s-r%s", VERSION, svn_version()); + } + else +#endif + { + snprintf(VersionRevisionBuf, sizeof(VersionRevisionBuf), "%s", VERSION); + } +} diff --git a/Util.h b/Util.h index 5187f26b..12ba1a0c 100644 --- a/Util.h +++ b/Util.h @@ -143,6 +143,21 @@ public: * The returned pointer points to the part of source-string, no additional strings are allocated. */ static const char* JsonNextValue(const char* szJsonText, int* pValueLength); + + /* + * Returns program version and revision number as string formatted like "0.7.0-r295". + * If revision number is not available only version is returned ("0.7.0"). + */ + static const char* VersionRevision() { return VersionRevisionBuf; }; + + /* + * Initialize buffer for program version and revision number. + * This function must be called during program initialization before any + * call to "VersionRevision()". + */ + static void InitVersionRevision(); + + static char VersionRevisionBuf[40]; }; #endif diff --git a/XmlRpc.cpp b/XmlRpc.cpp index dafbb510..fa855340 100644 --- a/XmlRpc.cpp +++ b/XmlRpc.cpp @@ -373,7 +373,7 @@ void XmlRpcProcessor::SendResponse(const char* szResponse, bool bFault) char szResponseHeader[1024]; int iBodyLen = iResponseLen + iHeaderLen + iFooterLen + iOpenTagLen + iCloseTagLen; - snprintf(szResponseHeader, 1024, bXmlRpc ? XML_RESPONSE_HEADER : JSON_RESPONSE_HEADER, iBodyLen, VERSION); + snprintf(szResponseHeader, 1024, bXmlRpc ? XML_RESPONSE_HEADER : JSON_RESPONSE_HEADER, iBodyLen, Util::VersionRevision()); // Send the request answer m_pConnection->Send(szResponseHeader, strlen(szResponseHeader)); @@ -729,8 +729,7 @@ void VersionXmlCommand::Execute() const char* JSON_RESPONSE_STRING_BODY = "\"%s\""; char szContent[1024]; - snprintf(szContent, 1024, IsJson() ? JSON_RESPONSE_STRING_BODY : XML_RESPONSE_STRING_BODY, - VERSION); + snprintf(szContent, 1024, IsJson() ? JSON_RESPONSE_STRING_BODY : XML_RESPONSE_STRING_BODY, Util::VersionRevision()); szContent[1024-1] = '\0'; AppendResponse(szContent); diff --git a/nzbget.cpp b/nzbget.cpp index 961d3f3d..ff2927af 100644 --- a/nzbget.cpp +++ b/nzbget.cpp @@ -73,6 +73,7 @@ #include "PrePostProcessor.h" #include "ParChecker.h" #include "Scheduler.h" +#include "Util.h" #ifdef WIN32 #include "NTService.h" #endif @@ -128,6 +129,8 @@ int main(int argc, char *argv[], char *argp[]) #endif #endif + Util::InitVersionRevision(); + #ifdef WIN32 _set_fmode(_O_BINARY); InstallUninstallServiceCheck(argc, argv); @@ -163,21 +166,21 @@ int main(int argc, char *argv[], char *argp[]) if (g_pOptions->GetDaemonMode()) { #ifdef WIN32 - info("nzbget %s service-mode", VERSION); + info("nzbget %s service-mode", Util::VersionRevision()); StartService(Run); return 0; #else Daemonize(); - info("nzbget %s daemon-mode", VERSION); + info("nzbget %s daemon-mode", Util::VersionRevision()); #endif } else if (g_pOptions->GetServerMode()) { - info("nzbget %s server-mode", VERSION); + info("nzbget %s server-mode", Util::VersionRevision()); } else if (g_pOptions->GetRemoteClientMode()) { - info("nzbget %s remote-mode", VERSION); + info("nzbget %s remote-mode", Util::VersionRevision()); } if (!g_pOptions->GetRemoteClientMode())