Пример #1
0
BOOL
TSHPath::RenameExtension(LPTSTR pszPath, LPCTSTR pszExt)
{
  static TModuleProc2<BOOL,LPTSTR,LPCTSTR>
         renameExtension(GetModule(), RenameExtensionStr);
  return renameExtension(pszPath, pszExt);
}
Пример #2
0
bool EpisodeConverterWorker::runJob()
{
    m_jobRunning = true;
    m_isFine = false;

    QString BackupDirectory = QString("pge_maintainer_backup-%1-%2-%3_%4-%5-%6")
            .arg(QDate().currentDate().year())
            .arg(QDate().currentDate().month())
            .arg(QDate().currentDate().day())
            .arg(QTime().currentTime().hour())
            .arg(QTime().currentTime().minute())
            .arg(QTime().currentTime().second());
    m_currentValue = 0;

    try
    {
        for(int i=0; i<m_episodeBox.d.size(); i++)
        {
            EpisodeBox_level& lvl = m_episodeBox.d[i];
            QString relDirPath;
            QString oldPath = lvl.fPath;
            if(preparePath(m_episode, relDirPath, lvl.fPath, BackupDirectory, m_doBackup))
                continue;
            switch(m_targetFormat)
            {
            case 0://PGE-X
                qDebug() << "Make LVLX";
                lvl.ftype = EpisodeBox_level::F_LVLX;
                renameExtension(lvl.fPath, ".lvlx");
                if(!FileFormats::SaveLevelFile(lvl.d, lvl.fPath, FileFormats::LVL_PGEX))
                    throw(FileFormats::errorString);
                break;
            case 1://SMBX 1...64
                qDebug() << "Make LVL SMBX" << lvl.ftypeVer;
                lvl.ftype = EpisodeBox_level::F_LVL;
                lvl.ftypeVer = m_targetFormatVer;
                renameExtension(lvl.fPath, ".lvl");
                if(!FileFormats::SaveLevelFile(lvl.d, lvl.fPath, FileFormats::LVL_SMBX64, m_targetFormatVer))
                    throw(FileFormats::errorString);
                break;
            case 2://SMBX-38A
                qDebug() << "Make LVL SMBX-38a";
                lvl.ftype = EpisodeBox_level::F_LVL38A;
                renameExtension(lvl.fPath, ".lvl");
                if(!FileFormats::SaveLevelFile(lvl.d, lvl.fPath, FileFormats::LVL_SMBX38A))
                    throw(FileFormats::errorString);
                break;
            }

            if(oldPath != lvl.fPath)
            {
                m_episodeBox.renameLevel(oldPath, lvl.fPath);
                QFile::remove(oldPath);
            }
            qDebug() << "Successfully!";
            m_currentValue++;
        }

        for(int i=0; i<m_episodeBox.dw.size(); i++)
        {
            EpisodeBox_world& wld = m_episodeBox.dw[i];
            qDebug() << "Open world map" << wld.fPath;
            QString relDirPath;
            if(preparePath(m_episode, relDirPath, wld.fPath, BackupDirectory, m_doBackup))
                continue;

            qDebug() << "Will be processed";

            if(m_doBackup)
            {
                qDebug() << "Make backup";
                QFileInfo oldFile(wld.fPath);
                m_episode.mkpath(BackupDirectory + "/" + relDirPath);
                QFile::copy(wld.fPath, BackupDirectory+"/" + relDirPath + "/" + oldFile.fileName() );
            }
            QString oldPath = wld.fPath;

            switch(m_targetFormat)
            {
            case 0://PGE-X
                qDebug() << "Make WLDX";
                wld.ftype = EpisodeBox_world::F_WLDX;
                renameExtension(wld.fPath, ".wldx");
                if(!FileFormats::SaveWorldFile(wld.d, wld.fPath, FileFormats::WLD_PGEX))
                    throw(FileFormats::errorString);
                break;
            case 1://SMBX 1...64
                qDebug() << "Make WLD SMBX "<<wld.ftypeVer;
                wld.ftype = EpisodeBox_world::F_WLD;
                wld.ftypeVer = m_targetFormatVer;
                renameExtension(wld.fPath, ".wld");
                if(!FileFormats::SaveWorldFile(wld.d, wld.fPath, FileFormats::WLD_SMBX64, m_targetFormatVer))
                    throw(FileFormats::errorString);
                break;
            case 2://SMBX-38A
                qDebug() << "Make WLD SMBX-38a";
                wld.ftype = EpisodeBox_world::F_WLD38A;
                renameExtension(wld.fPath, ".wld");
                if(!FileFormats::SaveWorldFile(wld.d, wld.fPath, FileFormats::WLD_SMBX38A))
                    throw(FileFormats::errorString);
                break;
            }

            if(oldPath != wld.fPath)
            {
                qDebug() << "Delete old file";
                //m_episodeBox.renameLevel(oldPath, wld.fPath);
                QFile::remove(oldPath);
            }
            qDebug() << "Successfully!";
            m_currentValue++;
        }

        m_isFine=true;
    }
    catch(QString err)
    {
        m_errorString = "Error ocouped while conversion process: " + err;
        emit workFinished(false);
        m_isFine = false;
    }
    m_jobRunning = false;

    qDebug() << "Work done, exiting";
    emit workFinished(true);
    return m_isFine;
}