From 2a962e1cf6f8a0a5889b72c9b31a2c85b51f46bf Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Mon, 15 Nov 2004 16:49:53 +0000 Subject: [PATCH] Add -w parameter to wx-console to change the temporary directory. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1697 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/wx-console/TODO | 3 +++ bacula/src/wx-console/console_thread.cpp | 20 ++++++++++++---- bacula/src/wx-console/console_thread.h | 3 +++ bacula/src/wx-console/wxbmainframe.cpp | 29 ++++++++++++++++++------ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/bacula/src/wx-console/TODO b/bacula/src/wx-console/TODO index 8839f14d80..a877a4ea28 100644 --- a/bacula/src/wx-console/TODO +++ b/bacula/src/wx-console/TODO @@ -1,3 +1,6 @@ +console_thread: Find an alternate way to get error messages, without using + a temporary file. (See Kern's mail 15.11.04 - 17:32) + general : Show nice messages boxes when errors occurs. general : Bug reported by Kern: diff --git a/bacula/src/wx-console/console_thread.cpp b/bacula/src/wx-console/console_thread.cpp index d27b6e2810..ba51097f30 100644 --- a/bacula/src/wx-console/console_thread.cpp +++ b/bacula/src/wx-console/console_thread.cpp @@ -51,6 +51,16 @@ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); bool console_thread::inited = false; bool console_thread::configloaded = false; +wxString console_thread::working_dir = "."; + +void console_thread::SetWorkingDirectory(wxString w_dir) { + if ((w_dir.Last() == '/') || (w_dir.Last() == '\\')) { + console_thread::working_dir = w_dir.Mid(0, w_dir.Length()-1); + } + else { + console_thread::working_dir = w_dir; + } +} void console_thread::InitLib() { if (WSA_Init() != 0) { @@ -62,7 +72,7 @@ void console_thread::InitLib() { init_stack_dump(); my_name_is(0, NULL, "wx-console"); //textdomain("bacula-console"); - working_directory = "."; + working_directory = console_thread::working_dir; inited = true; } @@ -95,11 +105,11 @@ wxString console_thread::LoadConfig(wxString configfile) { } init_msg(NULL, msgs); - init_console_msg("."); + init_console_msg(console_thread::working_dir); if (!parse_config(configfile.c_str(), 0)) { configloaded = false; - wxFile file("./wx-console.conmsg"); + wxFile file(console_thread::working_dir + "/wx-console.conmsg"); if (!file.IsOpened()) return "Unable to retrieve error message."; wxString err = ""; @@ -113,12 +123,12 @@ wxString console_thread::LoadConfig(wxString configfile) { } file.Close(); term_msg(); - wxRemoveFile("./wx-console.conmsg"); + wxRemoveFile(console_thread::working_dir + "/wx-console.conmsg"); return err; } term_msg(); - wxRemoveFile("./wx-console.conmsg"); + wxRemoveFile(console_thread::working_dir + "/wx-console.conmsg"); init_msg(NULL, NULL); configloaded = true; diff --git a/bacula/src/wx-console/console_thread.h b/bacula/src/wx-console/console_thread.h index 2f50be2226..ff126d3d76 100644 --- a/bacula/src/wx-console/console_thread.h +++ b/bacula/src/wx-console/console_thread.h @@ -51,12 +51,15 @@ class console_thread : public wxThread static void InitLib(); static void FreeLib(); static wxString LoadConfig(wxString configfile); + static void SetWorkingDirectory(wxString w_dir); private: static bool inited; static bool configloaded; bool choosingdirector; + static wxString working_dir; + int directorchoosen; BSOCK* UA_sock; diff --git a/bacula/src/wx-console/wxbmainframe.cpp b/bacula/src/wx-console/wxbmainframe.cpp index bd95f2c305..15b6e85e93 100644 --- a/bacula/src/wx-console/wxbmainframe.cpp +++ b/bacula/src/wx-console/wxbmainframe.cpp @@ -339,11 +339,30 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) { promptparser = new wxbPromptParser(); } - if (config == "") { - if ((wxTheApp->argc == 3) && (wxString(wxTheApp->argv[1]) == "-c")) { - configfile = wxTheApp->argv[2]; + if (config == "") { + configfile = ""; + + if (((wxTheApp->argc % 2) != 1)) { + Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG); + Print("Usage: wx-console [-c configfile] [-w tmp]\n", CS_DEBUG); } else { + for (int c = 1; c < wxTheApp->argc; c += 2) { + if ((wxTheApp->argc >= c+2) && (wxString(wxTheApp->argv[c]) == "-c")) { + configfile = wxTheApp->argv[c+1]; + } + if ((wxTheApp->argc >= c+2) && (wxString(wxTheApp->argv[c]) == "-w")) { + console_thread::SetWorkingDirectory(wxTheApp->argv[c+1]); + } + if (wxTheApp->argv[c][0] != '-') { + Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG); + Print("Usage: wx-console [-c configfile] [-w tmp]\n", CS_DEBUG); + break; + } + } + } + + if (configfile == "") { wxConfig::Set(new wxConfig("wx-console", "bacula")); if (!wxConfig::Get()->Read("/ConfigFile", &configfile)) { #ifdef HAVE_MACOSX @@ -362,10 +381,6 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) { #endif //HAVE_WIN32 #endif //HAVE_MACOSX wxConfig::Get()->Write("/ConfigFile", configfile); - if (wxTheApp->argc > 1) { - Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG); - Print("Usage: wx-console [-c configfile]\n", CS_DEBUG); - } int answer = wxMessageBox( wxString("It seems that it is the first time you run wx-console.\n") << -- 2.39.5