[Box Backup-dev] COMMIT r522 - box/chris/general/bin/bbackupd

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sun, 26 Feb 2006 14:20:48 +0000 (GMT)


Author: chris
Date: 2006-02-26 14:20:45 +0000 (Sun, 26 Feb 2006)
New Revision: 522

Modified:
   box/chris/general/bin/bbackupd/Win32BackupService.cpp
   box/chris/general/bin/bbackupd/Win32BackupService.h
Log:
* Win32BackupService.cpp, Win32BackupService.h
- Accept configuration file name as parameter to RunService, and pass it
  to Win32BackupService::WinService()
- Cleaned up generation of default config file name in WinService


Modified: box/chris/general/bin/bbackupd/Win32BackupService.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32BackupService.cpp	2006-02-26 14:18:43 UTC (rev 521)
+++ box/chris/general/bin/bbackupd/Win32BackupService.cpp	2006-02-26 14:20:45 UTC (rev 522)
@@ -17,8 +17,8 @@
 
 unsigned int WINAPI RunService(LPVOID lpParameter)
 {
-	DWORD retVal = gpDaemonService->WinService();
-	SetEvent( gStopServiceEvent );
+	DWORD retVal = gpDaemonService->WinService((const char*) lpParameter);
+	SetEvent(gStopServiceEvent);
 	return retVal;
 }
 
@@ -27,25 +27,36 @@
 	gpDaemonService->SetTerminateWanted();
 }
 
-DWORD Win32BackupService::WinService(void)
+DWORD Win32BackupService::WinService(const char* pConfigFileName)
 {
-	int argc = 2;
-	//first off get the path name for the default 
-	char buf[MAX_PATH];
+	char exepath[MAX_PATH];
+	GetModuleFileName(NULL, exepath, sizeof(exepath));
+
+	std::string configfile;
 	
-	GetModuleFileName(NULL, buf, sizeof(buf));
-	std::string buffer(buf);
-	std::string conf( "-c");
-	std::string cfile(buffer.substr(0,(buffer.find("bbackupd.exe"))) 
-			+ "bbackupd.conf");
+	if (pConfigFileName != NULL)
+	{
+		configfile = pConfigFileName;
+	}
+	else
+	{
+		// make the default config file name,
+		// based on the program path
+		configfile = exepath;
+		configfile = configfile.substr(0,
+			configfile.rfind(DIRECTORY_SEPARATOR_ASCHAR));
+		configfile += DIRECTORY_SEPARATOR "bbackupd.conf";
+	}
 
-	const char *argv[] = {conf.c_str(), cfile.c_str()};
+	const char *argv[] = {exepath, "-c", configfile.c_str()};
+	int argc = sizeof(argv) / sizeof(*argv);
+	DWORD ret;
 
 	MAINHELPER_START
+	ret = this->Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);
+	MAINHELPER_END
 
-	return this->Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);
-
-	MAINHELPER_END
+	return ret;
 }
 
 #endif // WIN32

Modified: box/chris/general/bin/bbackupd/Win32BackupService.h
===================================================================
--- box/chris/general/bin/bbackupd/Win32BackupService.h	2006-02-26 14:18:43 UTC (rev 521)
+++ box/chris/general/bin/bbackupd/Win32BackupService.h	2006-02-26 14:20:45 UTC (rev 522)
@@ -12,7 +12,7 @@
 class Win32BackupService : public BackupDaemon
 {
 public:
-	DWORD WinService(void);
+	DWORD WinService(const char* pConfigFileName);
 };
 
 #endif // WIN32