Example #1
0
bool NpcEdit::loadFile(const QString &fileName, NPCConfigFile FileData)
{
    QFile file(fileName);
    NpcData = FileData;
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Load file error"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return false;
    }

    QFileInfo fileI(fileName);

    //Get NPC-ID from FileName
    npc_id = FileName_to_npcID(fileI.baseName());
    setDefaultData(npc_id);
    ui->CurrentNPCID->setText( QString::number(npc_id) );

    StartNPCData = NpcData; //Save current history for made reset
    setDataBoxes();

    setCurrentFile(fileName);
    documentNotModified();

    loadPreview();
    on_DirectLeft_clicked();

    return true;
}
Example #2
0
bool NpcEdit::saveFile(const QString &fileName, const bool addToRecent)
{
    QApplication::setOverrideCursor(Qt::WaitCursor);
    if(!FileFormats::WriteNPCTxtFileF(fileName, NpcData))
    {
        QApplication::restoreOverrideCursor();
        QMessageBox::warning(this, tr("File save error"),
                             tr("Cannot save file %1:\n%2.")
                             .arg(fileName)
                             .arg(FileFormats::errorString));
        return false;
    }
    GlobalSettings::savePath_npctxt = QFileInfo(fileName).path();

    QFileInfo fileI(fileName);
    unsigned int old_npc_id = npc_id;
    npc_id = FileName_to_npcID(fileI.baseName());
    setDefaultData(npc_id);
    ui->CurrentNPCID->setText( QString::number(npc_id) );

    QApplication::restoreOverrideCursor();
    setCurrentFile(fileName);

    documentNotModified();

    if(old_npc_id == npc_id)
    {
        refreshImageFile();
        updatePreview();
    }
    else
    {
        loadPreview();
    }

    if(addToRecent)
    {
        MainWinConnect::pMainWin->AddToRecentFiles(fileName);
        MainWinConnect::pMainWin->SyncRecentFiles();
    }
    return true;
}
Example #3
0
bool npcedit::loadFile(const QString &fileName, NPCConfigFile FileData)
{
    QFile file(fileName);
    NpcData = FileData;
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Load file error"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return false;
    }

    QFileInfo fileI(fileName);

    //Get NPC-ID from FileName
    QStringList tmp = fileI.baseName().split(QChar('-'));
    if(tmp.size()==2)
        if(!SMBX64::Int(tmp[1]))
        {
            npc_id = tmp[1].toInt();
            setDefaultData( tmp[1].toInt() );
            ui->CurrentNPCID->setText( tmp[1] );
        }
        else
            setDefaultData(0);
    else
        setDefaultData(0);

    StartNPCData = NpcData; //Save current history for made reset
    setDataBoxes();

    setCurrentFile(fileName);
    documentNotModified();

    loadPreview();
    on_DirectLeft_clicked();

    return true;
}
Example #4
0
  static void run(const Input& input) {
    if ( input.ErrorCheck() ) {
      typedef Ext::UserError UE;
      typedef std::ifstream* StreamPtr;
      typedef Bed::bed_check_iterator<BedType1*> IterType1;
      typedef Bed::bed_check_iterator<BedType2*> IterType2;
      typedef BedReader<IterType1> BedReaderType1;
      typedef BedReader<IterType2> BedReaderType2;
  
      StreamPtr refFilePtr = static_cast<StreamPtr>(0);
      StreamPtr nonRefFilePtr = static_cast<StreamPtr>(0);
      BedReaderType1* refFile = static_cast<BedReaderType1*>(0);
      BedReaderType2* nonRefFile = static_cast<BedReaderType2*>(0);
  
      bool isStdin = (input.GetReferenceFileName() == "-");
      refFilePtr = new std::ifstream(input.GetReferenceFileName().c_str());
      if ( isStdin ) {
        IterType1 fileI(std::cin, "stdin", input.Chrome());
        refFile = new BedReaderType1(fileI);
      } else {
        if ( !refFilePtr || !(*refFilePtr) )
          throw(UE("Unable to find file: " + input.GetReferenceFileName()));
        IterType1 fileI(*refFilePtr, input.GetReferenceFileName(), input.Chrome());
        refFile = new BedReaderType1(fileI);
      }
  
      isStdin = (input.GetNonReferenceFileName() == "-");
      nonRefFilePtr = new std::ifstream(input.GetNonReferenceFileName().c_str());
      if ( isStdin ) {
        IterType2 fileJ(std::cin, input.GetNonReferenceFileName(), input.Chrome());
        nonRefFile = new BedReaderType2(fileJ);
      } else {
        if ( !nonRefFilePtr || !(*nonRefFilePtr) )
          throw(UE("Unable to find file: " + input.GetNonReferenceFileName()));
        IterType2 fileJ(*nonRefFilePtr, input.GetNonReferenceFileName(), input.Chrome());
        nonRefFile = new BedReaderType2(fileJ);
      }

      runDistances(*refFile, *nonRefFile, input);

      if ( refFile ) {
        refFile->CleanAll(); // read file all the way through for error-checking
        delete refFile;
      }
      if ( nonRefFile ) {
        nonRefFile->CleanAll(); // read file all the way through for error-checking
        delete nonRefFile;
      }
      if ( refFilePtr )
        delete refFilePtr;
      if ( nonRefFilePtr )
        delete nonRefFilePtr;
  
    } else { // fast-mode
      typedef Ext::FPWrap<Ext::InvalidFile> FPType;
      typedef Bed::allocate_iterator_starch_bed<BedType1*> IterType1;
      typedef Bed::allocate_iterator_starch_bed<BedType2*> IterType2;
      typedef BedReader<IterType1> BedReaderType1;
      typedef BedReader<IterType2> BedReaderType2;
  
      FPType* refFilePtr = static_cast<FPType*>(0);
      FPType* nonRefFilePtr = static_cast<FPType*>(0);
      BedReaderType1* refFile = static_cast<BedReaderType1*>(0);
      BedReaderType2* nonRefFile = static_cast<BedReaderType2*>(0);
  
      refFilePtr = new FPType(input.GetReferenceFileName());
      refFile = new BedReaderType1(IterType1(*refFilePtr, input.Chrome()));
  
      nonRefFilePtr = new FPType(input.GetNonReferenceFileName());
      nonRefFile = new BedReaderType2(IterType2(*nonRefFilePtr, input.Chrome()));

      runDistances(*refFile, *nonRefFile, input);

      if ( refFile )
        delete refFile;
      if ( nonRefFile )
        delete nonRefFile;
      if ( refFilePtr )
        delete refFilePtr;
      if ( nonRefFilePtr )
        delete nonRefFilePtr;
    }
  }