コード例 #1
0
ファイル: loaderwindow.cpp プロジェクト: als5ev/updater
bool LoaderWindow::openFile(QString pfilename)
{
  fileNew();

  QFileInfo fi(pfilename);
  if (fi.filePath().isEmpty())
    return false;
    
  QByteArray data = gunzipFile(fi.filePath());
  if(data.isEmpty())
  {
    _p->handler->message(QtFatalMsg,
                         tr("<p>The file %1 appears to be empty or it is not "
                            "compressed in the expected format.")
                         .arg(fi.filePath()));
    return false;
  }

  _files = new TarFile(data);
  if(!_files->isValid())
  {
    _p->handler->message(QtFatalMsg,
                         tr("<p>The file %1 does not appear to contain a valid "
                            "update package (not a valid TAR file?).")
                         .arg(fi.filePath()));
    delete _files;
    _files = 0;
    return false;
  }

  // find the content file
  QStringList list = _files->_list.keys();
  QString contentFile = QString::null;
  QStringList contentsnames;
  contentsnames << "package.xml" << "contents.xml";
  for (int i = 0; i < contentsnames.size() && contentFile.isNull(); i++)
  {
    foreach (QString mit, list)
    {
      QFileInfo fi(mit);
      if(fi.fileName() == contentsnames.at(i))
      {
        if(!contentFile.isNull())
        {
          _p->handler->message(QtFatalMsg,
                               tr("<p>Multiple %1 files found in %2. "
                                  "Currently only packages containing a single "
                                  "content.xml file are supported.")
                               .arg(contentsnames.at(i)).arg(fi.filePath()));
          delete _files;
          _files = 0;
          return false;
        }
        contentFile = mit;
      }
    }
  }
コード例 #2
0
ファイル: logdatasource.cpp プロジェクト: pballok/analog
void cLogDataSource::prepareFiles()
        throw()
{
    cTracer  obTracer( &g_obLogger, "cLogDataSource::prepareFiles" );

    for( int i = 0; i < m_slOrigFiles.size(); i++ )
    {
        try
        {
            QString qsFileName = m_slOrigFiles.at( i );
            if( qsFileName.indexOf( ".zip", qsFileName.size() - 4, Qt::CaseInsensitive ) != -1 )
            {
                m_slTempFiles.push_back( unzipFile( qsFileName ) );
                continue;
            }

            if( qsFileName.indexOf( ".gz", qsFileName.size() - 3, Qt::CaseInsensitive ) != -1 )
            {
                m_slTempFiles.push_back( gunzipFile( qsFileName ) );
                continue;
            }

            if( qsFileName.indexOf( "sysError" ) != -1 )
            {
                m_slTempFiles.push_back( decodeFile( qsFileName ) );
                continue;
            }

            m_slTempFiles.push_back( copyFile( qsFileName ) );
        }
        catch( cSevException &e )
        {
            g_obLogger << e;
        }
    }
}
コード例 #3
0
void dictionaries::finished(QNetworkReply * nwrep)
{
  if(nwrep->header(QNetworkRequest::LocationHeader).isValid())
  {
    QNetworkReply * newrep = nwam->get(QNetworkRequest(QUrl(nwrep->header(QNetworkRequest::LocationHeader).toString())));
    connect(newrep, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
    _nwrep = newrep;
  }
  else
  {
    if(nwrep->error() == QNetworkReply::NoError)
    {
      QByteArray ba = nwrep->readAll();
      if(!ba.isEmpty())
      {
        QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
        if(!dir.exists())
          dir.mkpath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
        QFile file(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/spell." + langext + ".tar.gz");
        if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
          file.write(ba);
          file.close();
          QByteArray data = gunzipFile(file.fileName());
          if(!data.isEmpty())
          {
            TarFile *_files = new TarFile(data);
            if(_files->isValid())
            {
              bool error = false;
              QMapIterator<QString, QByteArray> i(_files->_list);
              while (i.hasNext())
              {
                i.next();
                //cout << i.key() << ": " << i.value() << endl;
                QFile ff(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + i.key());
                if(ff.open(QIODevice::WriteOnly | QIODevice::Truncate))
                {
                  ff.write(i.value());
                  ff.close();
                }
                else
                {
                  error = true;
                }
              }
              if(error)
              {
                _label->setText(tr("Could not save one or more files."));
              }
              else
              {
                _label->setText(tr("Dictionaries downloaded."));
                xtHelp::reload();
              }
            }
            else
            {
              _label->setText(tr("Could not read archive format."));
            }
            delete _files;
          }
          else
          {
            _label->setText(tr("Could not uncompress file."));
          }
        }
        else
        {
          _label->setText(tr("Could not save file."));
        }
      }
      else
      {
        _label->setText(tr("No dictionary is currently available."));
      }
    }
    else
    {
      qDebug() << "Error: " << nwrep->error();
      _label->setText(tr("Could not retrieve dictionaries at this time."));
    }
    _progress->setRange(0, 100);
    _progress->setValue(100);
    _button->setText(tr("Start"));
    _state = Idle;
  }
  if(nwrep == _nwrep)
    _nwrep = 0;
  nwrep->deleteLater();
}
コード例 #4
0
void LoaderWindow::fileOpen()
{
    fileNew();

    QSettings settings("xTuple.com", "Updater");
    QString path = settings.value("LastDirectory").toString();

    QFileInfo fi(QFileDialog::getOpenFileName(this,tr("Open Package"), path,
                 tr("Package Files (*.gz);;All Files (*.*)")));
    if(fi.filePath().isEmpty())
        return;

    settings.setValue("LastDirectory", fi.path());

    QByteArray data = gunzipFile(fi.filePath());
    if(data.isEmpty())
    {
        QMessageBox::warning(this, tr("Error Opening File"),
                             tr("<p>The file %1 appears to be empty or it is not "
                                "compressed in the expected format.")
                             .arg(fi.filePath()));
        return;
    }

    _files = new TarFile(data);
    if(!_files->isValid())
    {
        QMessageBox::warning(this, tr("Error Opening file"),
                             tr("<p>The file %1 does not appear to contain a valid "
                                "update package (not a valid TAR file?).")
                             .arg(fi.filePath()));
        delete _files;
        _files = 0;
        return;
    }

    // find the content file
    QStringList list = _files->_list.keys();
    QString contentFile = QString::null;
    QStringList contentsnames;
    contentsnames << "package.xml" << "contents.xml";
    for (int i = 0; i < contentsnames.size() && contentFile.isNull(); i++)
    {
        QRegExp re(".*" + contentsnames.at(i) + "$");
        for(QStringList::Iterator mit = list.begin(); mit != list.end(); ++mit)
        {
            if(re.exactMatch(*mit))
            {
                if(!contentFile.isNull())
                {
                    QMessageBox::warning(this, tr("Error Opening file"),
                                         tr("<p>Multiple %1 files found in %2. "
                                            "Currently only packages containing a single "
                                            "content.xml file are supported.")
                                         .arg(contentsnames.at(i)).arg(fi.filePath()));
                    delete _files;
                    _files = 0;
                    return;
                }
                contentFile = *mit;
            }
        }
    }

    QStringList msgList;
    QList<bool> fatalList;

    if(contentFile.isNull())
    {
        QMessageBox::warning(this, tr("Error Opening file"),
                             tr("<p>No %1 file was found in package %2.")
                             .arg(contentsnames.join(" or ")).arg(fi.filePath()));
        delete _files;
        _files = 0;
        return;
    }
    else if (! contentFile.endsWith(contentsnames.at(0)))
    {
        qDebug("Deprecated Package Format: Packages for this version of "
               "the Updater should have their contents described by a file "
               "named %s. The current package being loaded uses an outdated "
               "file name %s.",
               qPrintable(contentsnames.at(0)), qPrintable(contentFile));
    }

    QByteArray docData = _files->_list[contentFile];
    QDomDocument doc;
    QString errMsg;
    int errLine, errCol;
    if(!doc.setContent(docData, &errMsg, &errLine, &errCol))
    {
        QMessageBox::warning(this, tr("Error Opening file"),
                             tr("<p>There was a problem reading the %1 file in "
                                "this package.<br>%2<br>Line %3, Column %4")
                             .arg(contentFile).arg(errMsg)
                             .arg(errLine).arg(errCol));
        delete _files;
        _files = 0;
        return;
    }

    _text->clear();
    _text->setEnabled(true);

    QString delayedWarning;
    _package = new Package(doc.documentElement(), msgList, fatalList);
    if (msgList.size() > 0)
    {
        bool fatal = false;
        if (DEBUG)
            qDebug("LoaderWindow::fileOpen()  i fatal msg");
        for (int i = 0; i < msgList.size(); i++)
        {
            _text->append(QString("<br><font color=\"%1\">%2</font>")
                          .arg(fatalList.at(i) ? "red" : "orange")
                          .arg(msgList.at(i)));
            fatal = fatal || fatalList.at(i);
            if (DEBUG)
                qDebug("LoaderWindow::fileOpen() %2d %5d %s",
                       i, fatalList.at(i), qPrintable(msgList.at(i)));
        }
        if (fatal)
        {
            _text->append(tr("<p><font color=\"red\">The %1 file appears "
                             "to be invalid.</font></p>").arg(contentFile));
            return;
        }
        else
            delayedWarning = tr("<p><font color=\"orange\">The %1 file "
                                "seems to have problems. You should contact %2 "
                                "before proceeding.</font></p>")
                             .arg(contentFile)
                             .arg(_package->developer().isEmpty() ?
                                  tr("the package developer") : _package->developer());
    }

    _pkgname->setText(tr("Package %1 (%2)").arg(_package->id()).arg(fi.filePath()));

    _progress->setValue(0);
    _progress->setMaximum(_files->_list.count() - 1);
    _progress->setEnabled(true);
    if (DEBUG)
        qDebug("LoaderWindow::fileOpen() progress initialized to max %d",
               _progress->maximum());

    _status->setEnabled(true);
    _status->setText(tr("<p><b>Checking Prerequisites!</b></p>"));
    _text->append("<p><b>Prerequisites</b>:<br/>");
    bool allOk = true;
    // check prereqs
    QString str;
    QStringList strlist;
    QStringList::Iterator slit;
    XSqlQuery qry;
    for(QList<Prerequisite>::iterator i = _package->_prerequisites.begin();
            i != _package->_prerequisites.end(); ++i)
    {
        _status->setText(tr("<p><b>Checking Prerequisites!</b></p><p>%1...</p>")
                         .arg((*i).name()));
        _text->append(tr("%1").arg((*i).name()));
        if (! (*i).met(errMsg))
        {
            allOk = false;
            str = QString("<blockquote><font size=\"+1\" color=\"red\"><b>%1</b></font></blockquote>").arg(tr("Failed"));
            if (! errMsg.isEmpty())
                str += tr("<p>%1</p>").arg(errMsg);

            strlist = (*i).providerList();
            if(strlist.count() > 0)
            {
                str += tr("<b>Requires:</b><br />");
                str += tr("<ul>");
                for(slit = strlist.begin(); slit != strlist.end(); ++slit)
                    str += tr("<li>%1: %2</li>").arg((*i).provider(*slit).package()).arg((*i).provider(*slit).info());
                str += tr("</ul>");
            }

            str += tr("</blockquote>");
            _text->append(str);
            if (DEBUG)
                qDebug("%s", qPrintable(str));
        }
    }

    if(!allOk)
    {
        _status->setText(tr("<p><b>Checking Prerequisites!</b></p><p>One or more prerequisites <b>FAILED</b>. These prerequisites must be satisified before continuing.</p>"));
        return;
    }

    _status->setText(tr("<p><b>Checking Prerequisites!</b></p><p>Check completed.</p>"));
    if (delayedWarning.isEmpty())
        _text->append(tr("<p><b><font color=\"green\">Ready to Start update!</font></b></p>"));
    else
    {
        _text->append(tr("<p><b>Ready to Start update!</b></p>"));
        _text->append(delayedWarning);
    }
    _text->append(tr("<p><b>NOTE</b>: Have you backed up your database? If not, you should "
                     "backup your database now. It is good practice to backup a database "
                     "before updating it.</p>"));

    /*
    single vs multiple transaction functionality was added at around the same
    time as OpenMFG/PostBooks 2.3.0 was being developed. before 2.3.0, update
    scripts from xTuple (OpenMFG, LLC) assumed multiple transactions (one per
    file within the package). take advantage of the update package naming
    conventions to see if we've been given a pre-2.3.0 file and *need* to use
    multiple transactions.
    */
    _premultitransfile = false;
    QString destver = fi.filePath();
    // if follows OpenMFG/xTuple naming convention
    if (destver.contains(QRegExp(".*/?[12][0123][0-9]((alpha|beta|rc)[1-9])?"
                                 "to"
                                 "[1-9][0-9][0-9]((alpha|beta|rc)[1-9])?.gz$")))
    {
        if (DEBUG)
            qDebug("%s", destver.toAscii().data());
        destver.remove(QRegExp(".*/?[12][0123][0-9]((alpha|beta|rc)[1-9])?to"));
        if (DEBUG)
            qDebug("%s", destver.toAscii().data());
        destver.remove(QRegExp("((alpha|beta|rc)[1-9])?.gz$"));
        if (DEBUG)
            qDebug("%s", destver.toAscii().data());
        // now destver is just the destination release #
        if (destver.toInt() < 230)
            _premultitransfile = true;
    }
    else
    {
        if (DEBUG)
            qDebug("not one of our old files");
    }

    _start->setEnabled(true);
}
コード例 #5
0
void helpDownload::finished(QNetworkReply * nwrep)
{
  if(nwrep->header(QNetworkRequest::LocationHeader).isValid())
  {
    if(nwrep->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301)
    {
      qDebug() << "301 Not found";
      _progress->setRange(0, 100);
      _progress->setValue(100);
      _label->setText("No documentation is currently available.");
      _button->setText(tr("Start"));
      _state = Idle;
    }
    else
    {
      QNetworkReply * newrep = nwam->get(QNetworkRequest(QUrl(nwrep->header(QNetworkRequest::LocationHeader).toString())));
      connect(newrep, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
      _nwrep = newrep;
    }
  }
  else
  {
    if(nwrep->error() == QNetworkReply::NoError)
    {
      QByteArray ba = nwrep->readAll();
      if(!ba.isEmpty())
      {
        if(ba[0] == '<')
        {
          QRegExp re("<a href=\"([^\"]+)\" class=\"direct-download\">");
          QString html(ba);
          re.indexIn(html);
          QStringList list = re.capturedTexts();
          if(list.size() > 1)
          {
            QString url = list.at(1);
            url = url.replace("&amp;", "&");
            qDebug() << "Redirecting to " << url;
            QNetworkReply * newrep = nwam->get(QNetworkRequest(QUrl(url)));
            connect(newrep, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
            _nwrep = newrep;
          }
          else
          {
            _label->setText(tr("Received unknown response from server."));
          }
        }        
        else
        {
          #if QT_VERSION >= 0x050000
          QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
          if(!dir.exists())
            dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
          QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/helpXTupleGUIClient-" + ver + ".tar.gz");
          #else
          QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
          if(!dir.exists())
             dir.mkpath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
          QFile file(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/helpXTupleGUIClient-" + ver + ".tar.gz");
          #endif
          if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
          {
            file.write(ba);
            file.close();
            QByteArray data = gunzipFile(file.fileName());
            if(!data.isEmpty())
            {
              TarFile *_files = new TarFile(data);
              if(_files->isValid())
              {
                bool error = false;
                QMapIterator<QString, QByteArray> i(_files->_list);
                while (i.hasNext())
                {
                  i.next();
                  //cout << i.key() << ": " << i.value() << endl;
                  #if QT_VERSION >= 0x050000
                  QFile ff(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + i.key());
                  #else
                  QFile ff(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + i.key());
                  #endif
                  if(ff.open(QIODevice::WriteOnly | QIODevice::Truncate))
                  {
                    ff.write(i.value());
                    ff.close();
                  }
                  else
                  {
                    error = true;
                  }
                }
                if(error)
                {
                  _label->setText(tr("Could not save one or more files."));
                }
                else
                {
                  _label->setText(tr("Documentation downloaded."));
                  xtHelp::reload();
                }
              }
              else
              {
                _label->setText(tr("Could not read archive format."));
              }
              delete _files;
            }
            else
            {
              _label->setText(tr("Could not uncompress file."));
            }
          }
          else
          {
            _label->setText(tr("Could not save file."));
          }
        }
      }
      else
      {
        _label->setText(tr("No documentation is currently available."));
      }
    }
    else
    {
      qDebug() << "Error: " << nwrep->error();
      _label->setText(tr("Could not retrieve documentation at this time."));
    }
    _progress->setRange(0, 100);
    _progress->setValue(100);
    _button->setText(tr("Start"));
    _state = Idle;
  }
  if(nwrep == _nwrep)
    _nwrep = 0;
  nwrep->deleteLater();
}