]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/wx-console/wxbrestorepanel.cpp
- wxbRestorePanel : implemented restore before=<Date> parameter.
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.cpp
index 1783446fc8de3a2e6a150a975cd0b625257263b3..2d4e9ed35779447e89154cdc001bdc6e22805300 100644 (file)
@@ -4,6 +4,7 @@
  *
  *    Nicolas Boichat, April-July 2004
  *
+ *    Version $Id$
  */
 /*
    Copyright (C) 2004 Kern Sibbald and John Walker
@@ -585,12 +586,17 @@ void wxbRestorePanel::CmdStart() {
       
       SetStatus(choosing);
       
-      wxbUtils::WaitForPrompt(wxString("restore") <<
+      wxbTableParser* tableparser = new wxbTableParser();
+      wxbDataTokenizer* dt = new wxbDataTokenizer(true);
+      
+      wxbMainFrame::GetInstance()->Send(wxString("restore") <<
          " client=\"" << configPanel->GetRowString("Client") <<
          "\" fileset=\"" << configPanel->GetRowString("Fileset") <<
          "\" pool=\"" << configPanel->GetRowString("Pool") <<
-         "\" storage=\"" << configPanel->GetRowString("Storage") << "\"\n");
-      wxbUtils::WaitForPrompt("6\n");
+         "\" storage=\"" << configPanel->GetRowString("Storage") <<
+         "\" before=\"" << configPanel->GetRowString("Before") <<
+         "\" select\n");
+      //wxbUtils::WaitForPrompt("6\n");
       //WaitForEnd();
       /*wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxString() << configPanel->GetRowString("Before") << "\n", true);
       int client = pp->getChoices()->Index(configPanel->GetRowString("Client"));
@@ -600,10 +606,7 @@ void wxbRestorePanel::CmdStart() {
       }
       delete pp;*/
       
-      wxbTableParser* tableparser = new wxbTableParser();
-      wxbDataTokenizer* dt = new wxbDataTokenizer(true);
-      
-      wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString("Before") << "\n");
+      //wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString("Before") << "\n");
    
       while (!tableparser->hasFinished() && !dt->hasFinished()) {
          wxTheApp->Yield(true);
@@ -650,14 +653,16 @@ void wxbRestorePanel::CmdStart() {
       
       int var = 0;
       
-      while (!dt->hasFinished()) {
+      int i1, i2;
+      
+      while (true) {
          newdate = wxDateTime::Now();
          if (newdate.Subtract(base).GetMilliseconds() > 10 ) {
             base = newdate;
             for (; lastindex < dt->GetCount(); lastindex++) {
-               if (((*dt)[lastindex].Find("Building directory tree for JobId ") == 0) && 
-                     ((i = (*dt)[lastindex].Find(" ...")) > 0)) {
-                  str = (*dt)[lastindex].Mid(34, i-34);
+               if (((i1 = (*dt)[lastindex].Find("Building directory tree for JobId ")) >= 0) && 
+                     ((i2 = (*dt)[lastindex].Find(" ...")) > 0)) {
+                  str = (*dt)[lastindex].Mid(i1+34, i2-(i1+34));
                   for (i = 0; i < tableparser->GetCount(); i++) {
                      if (str == (*tableparser)[i][0]) {
                         str = (*tableparser)[i][2];
@@ -686,6 +691,10 @@ void wxbRestorePanel::CmdStart() {
             
             gauge->SetValue(gauge->GetValue()+var);
             
+            if (dt->hasFinished()) {
+               break;
+            }
+            
             /*wxbMainFrame::GetInstance()->Print(
                wxString("[") << gauge->GetValue() << "/" << done
                   << "-" << willdo << "]", CS_DEBUG);*/
@@ -814,20 +823,27 @@ void wxbRestorePanel::CmdStart() {
          
          wxDateTime jobtime;
          
-         if (jobname == (*tableparser)[tableparser->GetCount()-1][1]) {
-            wxStringTokenizer jtkz((*tableparser)[tableparser->GetCount()-1][2], " ", wxTOKEN_STRTOK);
-            if ((jobtime.ParseDate(jtkz.GetNextToken()) != NULL) && // Date
-                  (jobtime.ParseTime(jtkz.GetNextToken()) != NULL)) { // Time
-               if (jobtime.IsLaterThan(currenttime)) {
-                  jobid = (*tableparser)[tableparser->GetCount()-1][0];
-                  cmd << jobid << "\n";
-                  delete tableparser;
-                  cancel->Enable(true);
-                  break;
+         for (i = 0; i < tableparser->GetCount(); i++) {
+            if (jobname == (*tableparser)[i][1]) {
+               wxStringTokenizer jtkz((*tableparser)[i][2], " ", wxTOKEN_STRTOK);
+               if ((jobtime.ParseDate(jtkz.GetNextToken()) != NULL) && // Date
+                     (jobtime.ParseTime(jtkz.GetNextToken()) != NULL)) { // Time
+                  if (jobtime.IsLaterThan(currenttime)) {
+                     jobid = (*tableparser)[i][0];
+                     cmd << jobid << "\n";
+                     delete tableparser;
+                     tableparser = NULL;
+                     cancel->Enable(true);
+                     break;
+                  }
                }
             }
          }
    
+         if (tableparser == NULL) { //The job was found
+            break;
+         }
+         
          delete tableparser;
          
          wxStopWatch sw2;
@@ -1114,8 +1130,8 @@ void wxbRestorePanel::CmdListJobs() {
       wxbDataTokenizer* dt = wxbUtils::WaitForEnd(configPanel->GetRowString("Client") + "\n", true);
 
       if (!tableparser->hasFinished()) {
-         for (int i = 0; i < dt->Count(); i++) {
-            if ((*dt)[i].Index("No results to list.") == 0) {
+         for (unsigned int i = 0; i < dt->Count(); i++) {
+            if ((*dt)[i].Find("No results to list.") == 0) {
                configPanel->AddRowChoice("Before", "No backup found for this client.");
                configPanel->SetRowSelection("Before", 0);
                configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
@@ -1123,7 +1139,7 @@ void wxbRestorePanel::CmdListJobs() {
                delete dt;
                return;
             }
-            else if (((*dt)[i].Index("ERROR") > -1) || ((*dt)[i].Index("Query failed") > -1)) {
+            else if (((*dt)[i].Find("ERROR") > -1) || ((*dt)[i].Find("Query failed") > -1)) {
                configPanel->AddRowChoice("Before", "Cannot get previous backups list, see console.");
                configPanel->SetRowSelection("Before", 0);
                configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
@@ -2290,4 +2306,3 @@ void wxbRestorePanel::OnConfigCancel(wxCommandEvent& WXUNUSED(event)) {
    CmdConfigCancel();
    SetWorking(false);
 }
-