2008-02-19 22:06:10 +03:00
|
|
|
#include "QMacInstallDialog.h"
|
2008-04-05 00:02:50 +04:00
|
|
|
#include <QMessageBox>
|
2008-02-19 22:06:10 +03:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include "ui_MacInstallDialog.h"
|
|
|
|
|
|
|
|
class QMacInstallDialog::QMacInstallDialogInternals : public Ui::Dialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
QMacInstallDialog::QMacInstallDialog(QWidget*w)
|
|
|
|
:QDialog(w)
|
|
|
|
{
|
|
|
|
this->Internals = new QMacInstallDialogInternals;
|
|
|
|
this->Internals->setupUi(this);
|
|
|
|
QObject::connect(this->Internals->choosePathButton, SIGNAL(pressed()),
|
|
|
|
this, SLOT(ShowBrowser()));
|
|
|
|
QObject::connect(this->Internals->skipInstallButton, SIGNAL(pressed()),
|
|
|
|
this, SLOT(SkipInstall()));
|
|
|
|
QObject::connect(this->Internals->doInstallButton, SIGNAL(pressed()),
|
|
|
|
this, SLOT(DoInstall()));
|
|
|
|
this->Internals->InstallPrefix->setText("/usr/bin/");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QMacInstallDialog::~QMacInstallDialog()
|
|
|
|
{
|
|
|
|
delete this->Internals;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMacInstallDialog::DoInstall()
|
|
|
|
{
|
|
|
|
QDir installDir(this->Internals->InstallPrefix->text());
|
2009-11-24 01:30:00 +03:00
|
|
|
QString installTo = installDir.path();
|
2012-07-06 23:26:39 +04:00
|
|
|
if(!cmSystemTools::FileExists(installTo.toLocal8Bit().data()))
|
2008-04-05 00:02:50 +04:00
|
|
|
{
|
|
|
|
QString message = tr("Build install does not exist, "
|
2012-07-06 23:26:39 +04:00
|
|
|
"should I create it?\n\n"
|
|
|
|
"Directory: ");
|
2008-04-05 00:02:50 +04:00
|
|
|
message += installDir.path();
|
|
|
|
QString title = tr("Create Directory");
|
|
|
|
QMessageBox::StandardButton btn;
|
|
|
|
btn = QMessageBox::information(this, title, message,
|
|
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
|
|
if(btn == QMessageBox::Yes)
|
|
|
|
{
|
2012-07-06 23:26:39 +04:00
|
|
|
cmSystemTools::MakeDirectory(installTo.toLocal8Bit().data());
|
2008-04-05 00:02:50 +04:00
|
|
|
}
|
|
|
|
}
|
2008-02-19 22:06:10 +03:00
|
|
|
QDir cmExecDir(QApplication::applicationDirPath());
|
|
|
|
cmExecDir.cd("../bin");
|
|
|
|
QFileInfoList list = cmExecDir.entryInfoList();
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
QFileInfo fileInfo = list.at(i);
|
2009-11-24 01:30:00 +03:00
|
|
|
QString filename = fileInfo.fileName();
|
2008-04-04 01:02:26 +04:00
|
|
|
if(filename.size() && filename[0] == '.')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-11-24 01:30:00 +03:00
|
|
|
QString file = fileInfo.absoluteFilePath();
|
|
|
|
QString newName = installTo;
|
2008-02-19 22:06:10 +03:00
|
|
|
newName += "/";
|
|
|
|
newName += filename;
|
2008-04-04 00:18:37 +04:00
|
|
|
// Remove the old files
|
2012-07-06 23:26:39 +04:00
|
|
|
if(cmSystemTools::FileExists(newName.toLocal8Bit().data()))
|
2008-04-04 00:18:37 +04:00
|
|
|
{
|
2012-07-06 23:26:39 +04:00
|
|
|
std::cout << "rm [" << newName.toLocal8Bit().data() << "]\n";
|
|
|
|
if(!cmSystemTools::RemoveFile(newName.toLocal8Bit().data()))
|
2008-04-23 17:58:18 +04:00
|
|
|
{
|
|
|
|
QString message = tr("Failed to remove file "
|
|
|
|
"installation may be incomplete: ");
|
2012-07-06 23:26:39 +04:00
|
|
|
message += newName;
|
2008-04-23 17:58:18 +04:00
|
|
|
QString title = tr("Error Removing file");
|
|
|
|
QMessageBox::StandardButton btn =
|
|
|
|
QMessageBox::critical(this, title, message,
|
|
|
|
QMessageBox::Ok|QMessageBox::Abort);
|
|
|
|
if(btn == QMessageBox::Abort)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-04-04 00:18:37 +04:00
|
|
|
}
|
2012-07-06 23:26:39 +04:00
|
|
|
std::cout << "ln -s [" << file.toLocal8Bit().data() << "] [";
|
|
|
|
std::cout << newName.toLocal8Bit().data() << "]\n";
|
|
|
|
if(!cmSystemTools::CreateSymlink(file.toLocal8Bit().data(),
|
|
|
|
newName.toLocal8Bit().data()))
|
2008-04-23 17:58:18 +04:00
|
|
|
{
|
|
|
|
QString message = tr("Failed create symlink "
|
|
|
|
"installation may be incomplete: ");
|
2012-07-06 23:26:39 +04:00
|
|
|
message += newName;
|
2008-04-23 17:58:18 +04:00
|
|
|
QString title = tr("Error Creating Symlink");
|
|
|
|
QMessageBox::StandardButton btn =
|
|
|
|
QMessageBox::critical(this, title, message,
|
|
|
|
QMessageBox::Ok|QMessageBox::Abort);
|
|
|
|
if(btn == QMessageBox::Abort)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-19 22:06:10 +03:00
|
|
|
}
|
|
|
|
this->done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMacInstallDialog::SkipInstall()
|
|
|
|
{
|
|
|
|
this->done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMacInstallDialog::ShowBrowser()
|
|
|
|
{
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(this,
|
|
|
|
tr("Enter Install Prefix"), this->Internals->InstallPrefix->text());
|
|
|
|
if(!dir.isEmpty())
|
|
|
|
{
|
|
|
|
this->Internals->InstallPrefix->setText(dir);
|
|
|
|
}
|
|
|
|
}
|