00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "restore.h"
00011
00012
00013 Restore::Restore( QWidget* parent, const char* name, WFlags fl )
00014 : restoreDlg( parent, name, fl )
00015 {
00016 mainWin = parent;
00017 dir = new QDir();
00018 partitionTableFile = new QFile();
00019
00020 proc = new QProcess();
00021
00022
00023 output = new RestoreOutput(this,"Restore Output",TRUE);
00024
00025 strcpy(pathRev,RevPathMount().ascii());
00026 strcpy(deviceHDDestination,HDDevice().ascii());
00027 strcpy(swapPartition,SystemSwapPartition().ascii());
00028
00029 strcpy(pathServer,ServerPathMount().ascii());
00030 strcpy(addressServer,ServerAddress().ascii());
00031
00032
00033 connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
00034 connect( proc, SIGNAL(readyReadStderr()), this, SLOT(readFromStderr()) );
00035 }
00036
00037
00038 Restore::~Restore()
00039 {
00040 delete dir;
00041 dir = NULL;
00042 delete partitionTableFile;
00043 partitionTableFile = NULL;
00044 delete proc;
00045 proc = NULL;
00046 delete output;
00047 output = NULL;
00048 }
00049
00050
00051 void Restore::Init(bool *mountedRev, bool *mountedServer)
00052 {
00053 revMounted = mountedRev;
00054 foundedRev = FALSE;
00055 if (*revMounted == TRUE)
00056 {
00057 radRev->setEnabled(TRUE);
00058 ledRevStatus->setColor(Qt::green);
00059
00060 if (radRev->isChecked())
00061 {
00062
00063 dir->cd(pathRev,TRUE);
00064 machineList = dir->entryList(QDir::Dirs,QDir::Name);
00065
00066 cmbSerial->clear();
00067
00068
00069 for ( QStringList::Iterator it = machineList.begin(); it != machineList.end(); ++it )
00070 {
00071 if ((*it != ".") && (*it != "..") && (*it != "lost+found"))
00072 cmbSerial->insertItem(*it);
00073 }
00074
00075 if (cmbSerial->count() > 0)
00076 foundedRev = TRUE;
00077 else
00078 foundedRev = FALSE;
00079
00080 this->cmbSerial_activated(cmbSerial->currentText());
00081 }
00082 }
00083 else
00084 {
00085 radRev->setEnabled(FALSE);
00086 ledRevStatus->setColor(Qt::red);
00087 radServer->setChecked(TRUE);
00088 }
00089
00090 serverMounted = mountedServer;
00091 foundedServer = FALSE;
00092 if (*serverMounted == TRUE)
00093 {
00094 radServer->setEnabled(TRUE);
00095 ledServerStatus->setColor(Qt::green);
00096
00097 if (radServer->isChecked())
00098 {
00099
00100 dir->cd(pathServer,TRUE);
00101 machineList = dir->entryList(QDir::Dirs,QDir::Name);
00102
00103 cmbSerial->clear();
00104
00105
00106 for ( QStringList::Iterator it = machineList.begin(); it != machineList.end(); ++it )
00107 {
00108 if ((*it != ".") && (*it != "..") && (*it != "lost+found"))
00109 cmbSerial->insertItem(*it);
00110 }
00111
00112 if (cmbSerial->count() > 0)
00113 foundedServer = TRUE;
00114 else
00115 foundedServer = FALSE;
00116
00117 this->cmbSerial_activated(cmbSerial->currentText());
00118 }
00119 }
00120 else
00121 {
00122 radServer->setEnabled(FALSE);
00123 ledServerStatus->setColor(Qt::red);
00124 radRev->setChecked(TRUE);
00125 }
00126
00127
00128 if ((!foundedRev) && (!foundedServer))
00129 {
00130 cmbSerial->clear();
00131 cmbDate->clear();
00132 lstPartitions->clear();
00133 radRev->setChecked(TRUE);
00134 }
00135 }
00136
00137
00138 void Restore::btnCancelRestore_clicked()
00139 {
00140 this->Close();
00141 }
00142
00143
00144 void Restore::cmbSerial_activated(const QString& string)
00145 {
00146 if ((!foundedRev) && (!foundedServer))
00147 return;
00148
00149 dir->cd(string,TRUE);
00150
00151
00152
00153
00154 dateList = dir->entryList(QDir::Dirs,QDir::Name | QDir::Reversed);
00155
00156 cmbDate->clear();
00157
00158
00159 for ( QStringList::Iterator it = dateList.begin(); it != dateList.end(); ++it )
00160 {
00161 if ((*it != ".") && (*it != "..") && (*it != "lost+found"))
00162 cmbDate->insertItem(*it);
00163 }
00164
00165 dir->cd("..",TRUE);
00166
00167 if (cmbDate->count() > 0)
00168 {
00169 if (radRev->isChecked() == TRUE)
00170 foundedRev = TRUE;
00171 else
00172 foundedServer = TRUE;
00173 }
00174 else
00175 {
00176 if (radRev->isChecked() == TRUE)
00177 foundedRev = FALSE;
00178 else
00179 foundedServer = FALSE;
00180 }
00181
00182 this->cmbDate_activated(cmbDate->currentText());
00183 }
00184
00185
00186 void Restore::cmbDate_activated(const QString& string)
00187 {
00188 QString fileName;
00189 QString currentPath;
00190 QStringList fileList;
00191 QStringList::iterator it;
00192 char workingPath[20];
00193
00194 if ((!foundedRev) && (!foundedServer))
00195 return;
00196
00197 if (radRev->isChecked() == TRUE)
00198 strcpy(workingPath,pathRev);
00199 else
00200 strcpy(workingPath,pathServer);
00201
00202
00203 lstPartitions->clear();
00204
00205
00206 currentPath = dir->path();
00207 dir->cd(workingPath + cmbSerial->currentText() + "/" + string,TRUE);
00208 fileList = dir->entryList("*.sf",QDir::Files,QDir::Name);
00209 it = fileList.begin();
00210 fileName = *it;
00211 dir->cd(currentPath);
00212
00213 strcpy(deviceHDSource,FindHDSource(fileName).ascii());
00214
00215
00216 partitionTableFile->setName(workingPath + cmbSerial->currentText() + "/" + string + "/" + fileName);
00217
00218 if (partitionTableFile->open(IO_ReadOnly))
00219 {
00220 QTextStream stream(partitionTableFile);
00221
00222 vecPartitions.clear();
00223
00224 while (!stream.atEnd())
00225 {
00226 QCheckListItem *q;
00227 partitionData p;
00228
00229 this->ParsePartitionLine(stream.readLine(),p);
00230
00231 if ((p.name != "") && (p.size.toULong() > 0))
00232 {
00233
00234 q = new QCheckListItem(lstPartitions,p.name,QCheckListItem::CheckBox);
00235 q->setOpen(TRUE);
00236
00237 if (p.id == "82")
00238 {
00239
00240 q->setEnabled(FALSE);
00241 p.id = "Swap";
00242 vecPartitions.push_back(p);
00243 }
00244 else if ((p.id == " f") || (p.id == " 5"))
00245 {
00246
00247 q->setEnabled(FALSE);
00248 p.id = "Extended";
00249 }
00250 else
00251 {
00252 vecPartitions.push_back(p);
00253 q->setOn(TRUE);
00254 }
00255
00256
00257 if (p.bootable)
00258 {
00259 new QListViewItem(lstPartitions->lastItem(),"Details:",p.start,p.size,p.id,"YES");
00260 }
00261 else
00262 {
00263 new QListViewItem(lstPartitions->lastItem(),"Details:",p.start,p.size,p.id,"NO");
00264 }
00265 }
00266 }
00267 partitionTableFile->close();
00268
00269 if (radRev->isChecked() == TRUE)
00270 foundedRev = TRUE;
00271 else
00272 foundedServer = TRUE;
00273
00274 }
00275 else
00276 {
00277 QMessageBox::critical(this,"Error","Can't find partition table file!",
00278 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00279
00280 if (radRev->isChecked() == TRUE)
00281 foundedRev = FALSE;
00282 else
00283 foundedServer = FALSE;
00284 }
00285 }
00286
00287
00288 void Restore::ParsePartitionLine(QString line, partitionData& p)
00289 {
00290 if (line.at(0) == '/' )
00291 {
00292 QString s;
00293
00294
00295 s = line.section(" : ",0,0);
00296 p.name = s.remove(0,5);
00297
00298 line = line.section(" : ",1,1);
00299
00300
00301 s = line.section(",",0,0);
00302 p.start = s.section("= ",1,1);
00303
00304
00305 s = line.section(",",1,1);
00306 p.size = s.section("= ",1,1);
00307
00308
00309 s = line.section(",",2,2);
00310 p.id = s.section("=",1,1);
00311
00312
00313 s = line.section(",",3,3);
00314 if (s == " bootable")
00315 p.bootable = TRUE;
00316 else
00317 p.bootable = FALSE;
00318 }
00319 }
00320
00321
00322 QString Restore::FindHDSource(QString fileName)
00323 {
00324 QString s;
00325
00326 s = fileName.section("_",2,2);
00327 return s.section(".",0,0);
00328 }
00329
00330
00331 void Restore::btnStartRestore_clicked()
00332 {
00333 char workingPath[20];
00334
00335 if (radRev->isChecked() == TRUE)
00336 strcpy(workingPath,pathRev);
00337 else
00338 strcpy(workingPath,pathServer);
00339
00340 if ( ((radRev->isChecked() == TRUE) && (foundedRev == TRUE)) ||
00341 ((radServer->isChecked() == TRUE) && (foundedServer == TRUE)) )
00342 {
00343 QString s;
00344
00345 CenterWindow(this,output);
00346 this->setEnabled(FALSE);
00347 this->hide();
00348 output->setEnabled(TRUE);
00349 output->show();
00350
00351
00352 proc->setWorkingDirectory(workingPath + cmbSerial->currentText() + "/" + cmbDate->currentText() + "/");
00353
00354 proc->clearArguments();
00355
00356
00357 proc->addArgument("swapoff");
00358 proc->addArgument("-a");
00359 proc->start();
00360
00361 proc->clearArguments();
00362
00363
00364 proc->addArgument("swapon");
00365 proc->addArgument(swapPartition);
00366 proc->start();
00367
00368 proc->clearArguments();
00369
00370
00371 proc->addArgument("dd");
00372 proc->addArgument("if=" + cmbSerial->currentText() + "_" + cmbDate->currentText() + "_" + deviceHDSource +
00373 ".mbr");
00374 s = "of=/dev/";
00375 proc->addArgument(s + deviceHDDestination);
00376
00377
00378 QStringList sl = proc->arguments();
00379 s = "";
00380 for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it )
00381 {
00382 s += *it + " ";
00383 }
00384 output->appendCommand(s + "\n");
00385
00386 proc->start();
00387
00388 while (proc->isRunning())
00389 {
00390 qApp->processEvents();
00391 }
00392
00393 output->appendCommand("\n");
00394
00395 proc->clearArguments();
00396
00397
00398
00399 proc->addArgument("ds4RestorePT");
00400 proc->addArgument(deviceHDDestination);
00401
00402 proc->addArgument(cmbSerial->currentText() + "_" + cmbDate->currentText() + "_" + deviceHDSource + ".sf");
00403
00404
00405 sl = proc->arguments();
00406 s = "";
00407 for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it )
00408 {
00409 s += *it + " ";
00410 }
00411 output->appendCommand(s + "\n");
00412
00413 proc->start();
00414
00415 while (proc->isRunning())
00416 {
00417 qApp->processEvents();
00418 }
00419
00420 output->appendCommand("\n");
00421
00422
00423 QListViewItemIterator it(lstPartitions);
00424 while (it.current())
00425 {
00426 QListViewItem *item = it.current();
00427
00428 if (((QCheckListItem*)it.current())->isOn())
00429 {
00430 proc->clearArguments();
00431
00432
00433 proc->addArgument("ds4PartimageRestore");
00434 proc->addArgument(workingPath + cmbSerial->currentText() + "/" + cmbDate->currentText());
00435 proc->addArgument(Src2Dest(item->text(0)));
00436 proc->addArgument(cmbSerial->currentText() + "_" + cmbDate->currentText() + "_" + item->text(0) + ".bz2");
00437
00438
00439 sl = proc->arguments();
00440 s = "";
00441 for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it )
00442 {
00443 s += *it + " ";
00444 }
00445 output->appendCommand(s + "\n");
00446
00447 proc->start();
00448
00449 while (proc->isRunning())
00450 {
00451 qApp->processEvents();
00452 }
00453
00454 output->appendCommand("\n");
00455 }
00456 it+=2;
00457 }
00458
00459 output->appendCommand("\n");
00460
00461
00462 if (chkSwap->isChecked())
00463 {
00464 for(vector<partitionData>::iterator itP = vecPartitions.begin();
00465 itP != vecPartitions.end();
00466 itP++)
00467 {
00468 if ((*itP).id == "Swap")
00469 {
00470 proc->clearArguments();
00471
00472
00473 proc->addArgument("mkswap");
00474 proc->addArgument("-c");
00475 proc->addArgument("/dev/" + Src2Dest((*itP).name));
00476
00477
00478 QStringList sl = proc->arguments();
00479 s = "";
00480 for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it )
00481 {
00482 s += *it + " ";
00483 }
00484 output->appendCommand(s + "\n");
00485
00486 proc->start();
00487
00488 while (proc->isRunning())
00489 {
00490 qApp->processEvents();
00491 }
00492
00493 output->appendCommand("\n");
00494 }
00495 }
00496 }
00497
00498
00499 if (chkGrub->isChecked())
00500 {
00501 proc->clearArguments();
00502
00503
00504 proc->addArgument("ds4RestoreGrub");
00505 proc->addArgument(deviceHDDestination);
00506
00507
00508 QStringList sl = proc->arguments();
00509 s = "";
00510 for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it )
00511 {
00512 s += *it + " ";
00513 }
00514 output->appendCommand(s + "\n");
00515
00516 proc->start();
00517
00518 while (proc->isRunning())
00519 {
00520 qApp->processEvents();
00521 }
00522
00523 output->appendCommand("\n");
00524 }
00525
00526 QMessageBox::information(this,"Finish","Restore finished successfully!",
00527 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00528
00529 output->CloseEnabled();
00530 }
00531 else
00532 {
00533
00534 if (radRev->isChecked() == TRUE)
00535 QMessageBox::critical(this,"Error","There aren't images on Rev!",
00536 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00537 else
00538 QMessageBox::critical(this,"Error","There aren't images on Server!",
00539 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00540 }
00541
00542 }
00543
00544 QString Restore::Src2Dest(QString source)
00545 {
00546 QString dest;
00547 bool isNumber = false;
00548
00549 dest = source.right(1);
00550 dest.toUInt(&isNumber,10);
00551 if (isNumber == TRUE)
00552 return (deviceHDDestination + dest);
00553 return "";
00554 }
00555
00556 void Restore::readFromStdout()
00557 {
00558 output->appendOutput(proc->readStdout());
00559 }
00560
00561
00562 void Restore::readFromStderr()
00563 {
00564 output->appendError(proc->readStderr());
00565 }
00566
00567
00568 void Restore::closeEvent (QCloseEvent *e)
00569 {
00570 e->accept();
00571 this->Close();
00572 }
00573
00574
00575 void Restore::Close()
00576 {
00577 this->hide();
00578 mainWin->setEnabled(TRUE);
00579 }
00580
00581
00582 void Restore::btnMountRev_clicked()
00583 {
00584 if (*revMounted == TRUE)
00585 {
00586 if (UmountRev() == TRUE)
00587 {
00588 EjectRev();
00589 *revMounted = FALSE;
00590 radRev->setEnabled(FALSE);
00591 ledRevStatus->setColor(Qt::red);
00592 }
00593 else
00594 {
00595
00596 QMessageBox::critical(this,"Error","Unable to umount Rev!",
00597 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00598 }
00599 }
00600 else
00601 {
00602 if (MountRev() == TRUE)
00603 {
00604 *revMounted = TRUE;
00605 ledRevStatus->setColor(Qt::green);
00606 radRev->setEnabled(TRUE);
00607 radRev->setChecked(TRUE);
00608 }
00609 else
00610 {
00611
00612 QMessageBox::critical(this,"Error","Unable to mount Rev!",
00613 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00614 }
00615 }
00616 this->Init(revMounted,serverMounted);
00617 }
00618
00619
00620 void Restore::btnMountServer_clicked()
00621 {
00622 if (*serverMounted == TRUE)
00623 {
00624 if (UmountServer() == TRUE)
00625 {
00626 *serverMounted = FALSE;
00627 radServer->setEnabled(FALSE);
00628 ledServerStatus->setColor(Qt::red);
00629 radRev->setChecked(TRUE);
00630 }
00631 else
00632 {
00633
00634 QMessageBox::critical(this,"Error","Unable to umount shared directory!",
00635 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00636 }
00637 }
00638 else
00639 {
00640 if (MountServer() == TRUE)
00641 {
00642 *serverMounted = TRUE;
00643 ledServerStatus->setColor(Qt::green);
00644 radServer->setEnabled(TRUE);
00645 radServer->setChecked(TRUE);
00646 }
00647 else
00648 {
00649
00650 QMessageBox::critical(this,"Error","Unable to mount shared directory!",
00651 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00652 }
00653 }
00654 this->Init(revMounted,serverMounted);
00655 }
00656
00657 void Restore::radRev_clicked()
00658 {
00659 this->Init(revMounted,serverMounted);
00660 }
00661
00662 void Restore::radServer_clicked()
00663 {
00664 this->Init(revMounted,serverMounted);
00665 }
00666
00667
00668
00669
00670
00671
00672 #include "restore.moc"