void DialogMakeRom::on_buttonMake_clicked() { std::FILE *rom,*mapdata; rom=fopenQ(ui->editRom->text(),"rb+"); if(rom==0){ QMessageBox msgBox; msgBox.setText("Failed to open the ROM."); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } mapdata=fopenQ(ui->editSrcFile->text(),"rb"); if(mapdata==0){ QMessageBox msgBox; msgBox.setText("Failed to open the mapdata file."); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } u32 len; std::fseek(mapdata,0,SEEK_END); len=std::ftell(mapdata); std::fseek(mapdata,0,SEEK_SET); std::unique_ptr<u8[]> buf(new u8[len]); std::fread(buf.get(),len,1,mapdata); std::fclose(mapdata); u16 fileId=nitroGetSubFileId(rom,"rom/map01/mapdata"); assert(fileId!=0xFFFF); u32 dp,dl; dp=nitroGetSubFileOffset(rom,fileId,&dl); if(dl>=len){ std::fseek(rom,dp,SEEK_SET); std::fwrite(buf.get(),len,1,rom); }else{ ROM_HEADER rom_header; std::fseek(rom,0,SEEK_SET); std::fread(&rom_header,sizeof(rom_header),1,rom); dp=rom_header.ROMSize; rom_header.ROMSize+=len; rom_header.CRC16=nitroCrc16(&rom_header,offsetof(ROM_HEADER,headerCRC16)); std::fseek(rom,0,SEEK_SET); std::fwrite(&rom_header,sizeof(rom_header),1,rom); nitroSetSubFileOffset(rom,fileId,dp,len); std::fseek(rom,dp,SEEK_SET); std::fwrite(buf.get(),len,1,rom); } std::fclose(rom); QMessageBox msgBox; msgBox.setText("Success!"); msgBox.exec(); return; }
void MainWindow::on_actionExtract_triggered(){ QString fileName=QFileDialog::getOpenFileName(this, tr("Select ROM"), "", tr("ROM File(*.nds *.bin);;Any files(*.*)")); if(fileName==QString::null)return; std::FILE* rom=fopenQ(fileName,"rb"); if(rom==nullptr){ QMessageBox msgBox; msgBox.setText(tr("Failed to open the ROM.")); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } fileName=QFileDialog::getSaveFileName(this, tr("Save mapdata to..."), "", tr("mapdata File(*.bin)")); if(fileName==QString::null)return; std::FILE* mapdataFile=fopenQ(fileName,"wb"); if(mapdataFile==nullptr){ QMessageBox msgBox; msgBox.setText(tr("Failed to open mapdata file.")); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); std::fclose(rom); return; } u16 id=nitroGetSubFileId(rom,"rom/map01/mapdata"); u32 off,len; off=nitroGetSubFileOffset(rom,id,&len); std::unique_ptr<u8[]> buf(new u8[len]); std::fseek(rom,off,SEEK_SET); std::fread(buf.get(),len,1,rom); std::fwrite(buf.get(),len,1,mapdataFile); std::fclose(rom); std::fclose(mapdataFile); QMessageBox msgBox; msgBox.setText(tr("Succeeded to extract mapdata from ROM.")); msgBox.exec(); openMapdata(fileName); }
void MainWindow::on_actionSave_triggered() { if(currentFileName==QString::null)return; std::FILE* file=fopenQ(currentFileName,"wb"); if(file==nullptr){ QMessageBox msgBox; msgBox.setText(tr("Failed to open the file.")); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } if(map.isLoaded())saveCurrentRoom(); mapdata.toFile(file); std::fclose(file); }
void MainWindow::on_actionSaveAs_triggered(){ QString fileName=QFileDialog::getSaveFileName(this, tr("Save As ..."), "", tr("mapdata File(*.bin)")); if(fileName==QString::null)return; std::FILE* file=fopenQ(fileName,"wb"); if(file==nullptr){ QMessageBox msgBox; msgBox.setText(tr("Failed to open the file.")); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } if(map.isLoaded())saveCurrentRoom(); mapdata.toFile(file); std::fclose(file); currentFileName=fileName; }
void MainWindow::openMapdata(QString fileName){ std::FILE* file=fopenQ(fileName,"rb"); if(file==nullptr){ QMessageBox msgBox; msgBox.setText(tr("Failed to open the file.")); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.exec(); return; } mapdata.fromFile(file); std::fclose(file); currentFileName=fileName; mapUpdateTimer.stop(); map.unload(); ui->menuMap->setEnabled(true); ui->actionSave->setEnabled(true); ui->actionSaveAs->setEnabled(true); ui->actionMakeRom->setEnabled(true); clearOperationStack(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), itemTableModal(this), ui(new Ui::MainWindow), mapUpdateTimer(this) { ui->setupUi(this); ui->actionShowAnimation->setChecked(true); ui->mapView->pMainWindow=this; ui->mapView->pBlockStore=ui->blockStore; ui->blockStore->pMainWindow=this; ui->itemTable->setModel(&itemTableModal); ui->itemTable->setItemDelegate(new ItemTableDelegate(this)); ui->itemTable->resizeRowsToContents(); ui->itemTable->resizeColumnsToContents(); ui->splitterMain->setStretchFactor(1,1); ui->splitterRight->setStretchFactor(0,1); connect(ui->mapView,SIGNAL(showStatusTip(const QString&)), ui->statusBar,SLOT(showMessage(const QString&))); connect(ui->blockStore,SIGNAL(showStatusTip(const QString&)), ui->statusBar,SLOT(showMessage(const QString&))); connect(ui->mapView,SIGNAL(selectItem(int)), this,SLOT(onSelectItem(int))); connect(ui->mapView,SIGNAL(itemDragging(bool)), this,SLOT(onItemDragging(bool))); QToolButton* scrollAreaCornerResize=new QToolButton(this); scrollAreaCornerResize->setDefaultAction(ui->actionResizeMap); ui->mapViewScrollArea->setCornerWidget(scrollAreaCornerResize); MapOperation::pMap=↦ MapOperation::pMainWindow=this; connect(&mapUpdateTimer, SIGNAL(timeout()), this, SLOT(on_updateMap())); connect(ui->actionUndo, SIGNAL(triggered()), this, SLOT(undo())); connect(ui->actionRedo, SIGNAL(triggered()), this, SLOT(redo())); loadRoomList(); clearOperationStack(); //Open a file QString fileName=commandLineFile; std::FILE* file=fopenQ(fileName,"rb"); if(!file)return; mapdata.fromFile(file); std::fclose(file); currentFileName=fileName; ui->actionSave->setEnabled(true); ui->actionSaveAs->setEnabled(true); ui->actionMakeRom->setEnabled(true); }