00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "clone.h"
00011
00012
00013 Clone::Clone(QWidget* parent, const char* name, WFlags fl)
00014 : cloneDlg(parent,name,fl)
00015 {
00016 mainWin = parent;
00017
00018 proc = new QProcess();
00019
00020 strcpy(pathRev,RevPathMount().ascii());
00021 strcpy(deviceHDSource,HDDevice().ascii());
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 }
00035
00036 Clone::~Clone()
00037 {
00038 delete proc;
00039 proc = NULL;
00040 }
00041
00042 void Clone::Init(bool *mounted)
00043 {
00044 QDate date;
00045
00046 date = QDate::currentDate();
00047 edtDate->setText(date.toString("yyyyMMdd"));
00048
00049 revMounted = mounted;
00050 if (*revMounted == TRUE)
00051 {
00052 ledRevStatus->setColor(Qt::green);
00053 }
00054 else
00055 {
00056 ledRevStatus->setColor(Qt::red);
00057 }
00058 }
00059
00060 void Clone::btnCancel_clicked()
00061 {
00062 this->Close();
00063 }
00064
00065 void Clone::closeEvent (QCloseEvent *e)
00066 {
00067 e->accept();
00068 this->Close();
00069 }
00070
00071 void Clone::Close()
00072 {
00073 this->hide();
00074 mainWin->setEnabled(TRUE);
00075 }
00076
00077 void Clone::btnClone_clicked()
00078 {
00079 if (*revMounted == TRUE)
00080 {
00081 if (edtSerial->text() == "")
00082 {
00083
00084 QMessageBox::critical(this,"Error","Machine serial number cannot be empty!",
00085 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00086 }
00087 else if (edtSerial->text() != edtSerialAgain->text())
00088 {
00089
00090 QMessageBox::critical(this,"Error","Machine serial numbers are not equal!",
00091 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00092 }
00093 else
00094 {
00095 QString s;
00096 QStringList listPartitions;
00097 QFile partitionTableFile;
00098
00099 this->setEnabled(FALSE);
00100 this->hide();
00101
00102 proc->clearArguments();
00103
00104
00105 proc->addArgument("mkdir");
00106 proc->addArgument("-p");
00107 proc->addArgument( + edtSerial->text());
00108
00109 proc->start();
00110
00111 while (proc->isRunning())
00112 {
00113 qApp->processEvents();
00114 }
00115
00116 proc->clearArguments();
00117
00118
00119 proc->addArgument("mkdir");
00120 proc->addArgument("-p");
00121 proc->addArgument(pathRev + edtSerial->text() + "/" + edtDate->text());
00122
00123 proc->start();
00124
00125 while (proc->isRunning())
00126 {
00127 qApp->processEvents();
00128 }
00129
00130 proc->clearArguments();
00131
00132
00133 proc->addArgument("dd");
00134 s = "if=/dev/";
00135 s += deviceHDSource;
00136 proc->addArgument(s);
00137 s = "of=";
00138 s += pathRev + edtSerial->text() + "/" + edtDate->text() + "/" + edtSerial->text() + "_" +
00139 edtDate->text() + "_";
00140 s += deviceHDSource;
00141 s += ".mbr";
00142 proc->addArgument(s);
00143 proc->addArgument("count=1");
00144 proc->addArgument("bs=512");
00145
00146 proc->start();
00147
00148 while (proc->isRunning())
00149 {
00150 qApp->processEvents();
00151 }
00152
00153 proc->clearArguments();
00154
00155
00156
00157 proc->addArgument("ds4ClonePT");
00158 proc->addArgument(deviceHDSource);
00159 s = pathRev + edtSerial->text() + "/" + edtDate->text() + "/" + edtSerial->text() + "_" +
00160 edtDate->text() + "_";
00161 s += deviceHDSource;
00162 s += ".sf";
00163 proc->addArgument(s);
00164
00165 proc->start();
00166
00167 while (proc->isRunning())
00168 {
00169 qApp->processEvents();
00170 }
00171
00172
00173 s = pathRev + edtSerial->text() + "/" + edtDate->text() + "/" + edtSerial->text() + "_" +
00174 edtDate->text() + "_";
00175 s += deviceHDSource;
00176 s += ".sf";
00177 partitionTableFile.setName(s);
00178
00179 if (partitionTableFile.open(IO_ReadOnly))
00180 {
00181 QTextStream stream(&partitionTableFile);
00182
00183 listPartitions.clear();
00184
00185
00186 while (!stream.atEnd())
00187 {
00188 ParsePartitionLine(stream.readLine(),listPartitions);
00189 }
00190
00191 partitionTableFile.close();
00192 }
00193
00194
00195 for ( QStringList::Iterator it = listPartitions.begin(); it != listPartitions.end(); it++ )
00196 {
00197 proc->clearArguments();
00198
00199
00200 proc->addArgument("ds4PartimageClone");
00201 proc->addArgument(pathRev + edtSerial->text() + "/" + edtDate->text());
00202 proc->addArgument(*it);
00203 proc->addArgument(edtSerial->text() + "_" + edtDate->text() + "_" + *it + ".bz2");
00204
00205 proc->start();
00206
00207 while (proc->isRunning())
00208 {
00209 qApp->processEvents();
00210 }
00211 }
00212
00213 this->setEnabled(TRUE);
00214
00215 QMessageBox::information(this,"Finish","Clone finished successfully!",
00216 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00217
00218 this->Close();
00219 }
00220 }
00221 else
00222 {
00223
00224 QMessageBox::critical(this,"Error","Rev is not mounted!",
00225 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00226 }
00227 }
00228
00229 void Clone::ParsePartitionLine(QString line, QStringList& l)
00230 {
00231 if (line.at(0) == '/' )
00232 {
00233 QString s,name,id;
00234
00235
00236 s = line.section(" : ",0,0);
00237 name = s.remove(0,5);
00238
00239 line = line.section(" : ",1,1);
00240
00241
00242 s = line.section(",",2,2);
00243 id = s.section("=",1,1);
00244
00245 if (id != "82")
00246 {
00247 l += name;
00248 }
00249 }
00250 }
00251
00252 void Clone::btnMount_clicked()
00253 {
00254 if (*revMounted == TRUE)
00255 {
00256 if (UmountRev() == TRUE)
00257 {
00258 EjectRev();
00259 *revMounted = FALSE;
00260 ledRevStatus->setColor(Qt::red);
00261 }
00262 else
00263 {
00264
00265 QMessageBox::critical(this,"Error","Unable to umount Rev!",
00266 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00267 }
00268 }
00269 else
00270 {
00271 if (MountRev() == TRUE)
00272 {
00273 *revMounted = TRUE;
00274 ledRevStatus->setColor(Qt::green);
00275 }
00276 else
00277 {
00278
00279 QMessageBox::critical(this,"Error","Unable to mount Rev!",
00280 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00281 }
00282 }
00283 }
00284
00285
00286 #include "clone.moc"
00287