--- Vago/trunk/Vago/mainwindow.cpp 2016/12/09 19:04:18 1061 +++ s10k/Vago/mainwindow.cpp 2017/12/30 13:57:32 1093 @@ -7,22 +7,26 @@ MainWindow::MainWindow(QWidget *parent) QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); + // We use this appender because it is the native way to have \r\n in windows in plog library + // example: https://github.com/SergiusTheBest/plog/blob/master/samples/NativeEOL/Main.cpp + static plog::RollingFileAppender> fileAppender + (QSTR_TO_CSTR(Util::FileSystem::getAppPath() + "/" + GlobalVars::AppLogName), 1024*5 /* 5 Mb max log size */, 3); + plog::init(plog::info, &fileAppender); - this->myLogger = new Logger(UtilVago::getAppPath(), GlobalVars::AppLogName); //start logger + ui->setupUi(this); - this->myLogger->writeString("Detected AppDir: "+UtilVago::getAppPath()); - this->myLogger->writeString("True app dir: "+QDir::currentPath()); + LOG_INFO << "Detected AppDir: " + UtilVago::getAppPath(); + LOG_INFO << "True app dir: "+QDir::currentPath(); setVagoWindowTitle(); if(!QFile::exists(UtilVago::getOniSplitExecutableAbsolutePath())){ - UtilVago::showAndLogErrorPopUp(this->myLogger, "OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); + UtilVago::showAndLogErrorPopUp("OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } if(!QFile::exists(UtilVago::getXmlToolsExecutableAbsolutePath())){ - UtilVago::showAndLogErrorPopUp(this->myLogger, "XmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); + UtilVago::showAndLogErrorPopUp("XmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } @@ -40,16 +44,16 @@ MainWindow::MainWindow(QWidget *parent) } if(!this->vagoSettings->contains("AeFolder")){ - Util::showPopUp("Seems it's the first time you are executing Vago. \n\nPlease input your Anniversary Edition (AE) Folder."); - QString aefolder=Util::normalizePath(QFileDialog::getExistingDirectory(this,"Choose Anniversary Edition (AE) folder...")); + Util::Dialogs::showInfo("Seems it's the first time you are executing Vago. \n\nPlease input your Anniversary Edition (AE) Folder."); + QString aefolder=Util::FileSystem::normalizePath(QFileDialog::getExistingDirectory(this,"Choose Anniversary Edition (AE) folder...")); if(aefolder.isEmpty()){ - UtilVago::showAndLogErrorPopUp(this->myLogger, "AE folder is mandatory. Application will now exit."); + UtilVago::showAndLogErrorPopUp("AE folder is mandatory. Application will now exit."); exit(1); } if(!aefolder.endsWith("AE")){ - Util::showWarningPopUp("Seems the folder you selected isn't called 'AE'. \n\nIf you run in any problems you can always change it in Vago preferences window."); + Util::Dialogs::showWarning("Seems the folder you selected isn't called 'AE'. \n\nIf you run in any problems you can always change it in Vago preferences window."); } this->vagoSettings->setValue("AeFolder", aefolder); @@ -176,7 +180,7 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { delete ui; - this->myLogger->writeString("Application Exited."); + LOG_INFO << "Application Exited."; } @@ -206,21 +210,21 @@ void MainWindow::applicationWasLoaded(){ this->win7TaskBarProgress = this->win7TaskBarButton->progress(); //Create a thread for do the conversion in background - this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess, this->win7TaskBarProgress); + this->myConverter = new Converter(UtilVago::getAppPath(), &this->listToProccess, this->win7TaskBarProgress); #else - this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess); + this->myConverter = new Converter(UtilVago::getAppPath(), &this->listToProccess); #endif connectSlots(); - this->myLogger->writeString("Application started."); + LOG_INFO << "Application started."; this->applicationIsFullyLoaded = true; QString lastSavedProject = this->vagoSettings->value("RecentProject1").toString(); if(!lastSavedProject.isEmpty() && this->vagoSettings->value("AskToOpenLastProject").toBool()){ - if(Util::showQuestionPopUp(this,"Do you want to load latest project?\n\nLatest project was '" + Util::cutNameWithoutBackSlash(lastSavedProject) + "'.")){ + if(Util::Dialogs::showQuestion(this,"Do you want to load latest project?\n\nLatest project was '" + Util::FileSystem::cutNameWithoutBackSlash(lastSavedProject) + "'.")){ loadProjectState(lastSavedProject); } } @@ -242,25 +246,25 @@ void MainWindow::on_actionAbout_triggere void MainWindow::on_actionAE_Package_Creator_triggered() { // it deletes itself once closed - WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings); } void MainWindow::on_actionSound_Wizard_triggered() { // it deletes itself once closed - WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger, &this->commandMap); + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, &this->commandMap); } void MainWindow::on_actionBackground_Image_Wizard_triggered() { // it deletes itself once closed - WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings); } void MainWindow::on_actionWindow_Messages_Wizard_triggered() { // it deletes itself once closed - WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings); } void MainWindow::on_tbOni_clicked() @@ -279,7 +283,7 @@ void MainWindow::on_tbOni_clicked() arguments << "-debugfiles"; if(!QProcess::startDetached(this->AeLocation+"/"+GlobalVars::OniExe,arguments,this->AeLocation)){ - showErrStatusMessage("Oni could not be started!"); + Util::StatusBar::showError(ui->statusBar, "Oni could not be started!"); } } @@ -288,7 +292,7 @@ void MainWindow::on_tbAE_clicked() // If the app turn out someday to a native app use QProcess::startDetached instead... if(!QDesktopServices::openUrl("file:///"+this->AeLocation+"/AEInstaller/bin/AEInstaller2.jar")){ - showErrStatusMessage("Could not start AE Installer!"); + Util::StatusBar::showError(ui->statusBar, "Could not start AE Installer!"); } } @@ -302,13 +306,13 @@ void MainWindow::on_tbXmlToolsInterface_ { //We pass no parent because we want to have an independent window for XmlToolsInterface, //so we can minimize it or maximize indepently from the MainWindow - XmlToolsInterface *xmlToolsWindow = new XmlToolsInterface(this->myLogger); + XmlToolsInterface *xmlToolsWindow = new XmlToolsInterface(); xmlToolsWindow->show(); //it destroys itself when finished. } void MainWindow::on_tbAbortConversion_clicked() { - if(Util::showQuestionPopUp(this,"Are you sure you want to abort the current conversion?")){ + if(Util::Dialogs::showQuestion(this,"Are you sure you want to abort the current conversion?")){ emit terminateCurrProcess(); } } @@ -323,14 +327,14 @@ void MainWindow::on_cbTexture_toggled(bo ui->leTextureName->setEnabled(checked); } -void MainWindow::on_cbWithAnimation_toggled(bool checked) +void MainWindow::on_cbSpecificFilesLevels_toggled(bool checked) { - ui->leAnimationName->setEnabled(checked); + ui->leSpecificFilesLevels->setEnabled(checked); } -void MainWindow::on_cbSpecificFilesLevels_toggled(bool checked) +void MainWindow::on_cbWithAnimation_toggled(bool checked) { - ui->leSpecificFilesLevels->setEnabled(checked); + ui->leAnimationName->setEnabled(checked); } void MainWindow::on_actionCheck_For_Updates_triggered() @@ -356,15 +360,15 @@ void MainWindow::checkVagoLastVersion(QN QString newVersion = sc.property("field_version").toObject().property("und").toObject().property("0").toObject().property("value").toString(); if(newVersion!=GlobalVars::AppVersion){ - Util::showRichPopUp("There's a new version of Vago! (v"+newVersion+")

"+ - "You can download it here."); + Util::Dialogs::showRichInfo("There's a new version of Vago! (v"+newVersion+")

"+ + "You can download it here."); } else{ - Util::showPopUp("You are using last version."); + Util::Dialogs::showInfo("You are using last version."); } } else{ - UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred checking last version:\n\n"+result->errorString()); + UtilVago::showAndLogErrorPopUp("An error occurred checking last version:\n\n"+result->errorString()); } result->deleteLater(); } @@ -392,7 +396,7 @@ void MainWindow::on_pbAddSourceCharacter void MainWindow::on_pbAddSourceLevels_clicked() { if(QString::compare(ui->cbFromLevels->currentText(),"ONI FILES",Qt::CaseSensitive)==0 && QString::compare(ui->cbToLevels->currentText(),"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster) - addFilesSource(ui->twSourcesLevels,Util::multipleDirDialog("Choose folders with ONIs...")); + addFilesSource(ui->twSourcesLevels,Util::Dialogs::multipleDirSelection("Choose folders with ONIs...")); } else{ addFilesSource(ui->twSourcesLevels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); @@ -414,7 +418,7 @@ QString MainWindow::getFileOutputFolder( myOutputFolder+="/"+ui->tabWidget->tabText(ui->tabWidget->currentIndex()); myOutputFolder+="/"+QString(fromTo).replace(" / ","_").replace(" > "," - "); } - return Util::insertQuotes(myOutputFolder+"/"); + return Util::String::insertQuotes(myOutputFolder+"/"); } void MainWindow::addFilesSource(DropTableWidget *myTable, QStringList files){ @@ -427,22 +431,80 @@ void MainWindow::addFilesSource(DropTabl from = QString(fromTo).remove(fromTo.indexOf(" >"),fromTo.size()-1); //parse the string to get the from, only 1 time parsed by each group of files = very fast to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> " - //Pre-processing (check if the files/folders received are valid), e.g. check for ONI->DAT if are only given folders and not files + //Pre-processing (check if the files/folders received are valid), e.g. check for ONI FILES->DAT if are only given folders and not files if(from=="ONI FILES" && to=="DAT"){ //check if it's a folder - foreach(QString myFile, files){ + for(const QString &myFile : files){ if(!QDir(myFile).exists()){ - showErrStatusMessage("Only folders are allowed for this operation."); + Util::StatusBar::showError(ui->statusBar, "Only folders are allowed for this operation."); return; } } } else{ - foreach(QString myFile, files){ + for(const QString &myFile : files){ + //check if it's a file if(QDir(myFile).exists()){ - showErrStatusMessage("Only files are allowed for this operation."); + Util::StatusBar::showError(ui->statusBar, "Only files are allowed for this operation."); + return; + } + + // Check if the given files have the expected extensions + QFileInfo fileInfo(myFile); + + QStringList expectedExtensions; + + bool extensionIsValid = false; + + if( + from == "DAT / TXMP ONI" || + from == "DAT / SNDD ONI" || + from == "DAT / SUBT ONI" + ){ + expectedExtensions << "DAT" << "ONI"; + } + else if(from == "TGA / DDS / PNG / JPG"){ + expectedExtensions << "TGA" << "DDS" << "PNG" << "JPG"; + } + else if( + from == "TRAM ONI" || + from == "TRBS / ONCC ONI" || + from == "M3GM ONI" || + from == "ONWC ONI" || + from == "OBAN ONI (cam)" || + from == "AKEV ONI" + ){ + expectedExtensions << "ONI"; + } + else if(from == "TRBS XML" || from == "MASTER XML"){ + expectedExtensions << "XML"; + } + else if(from == "TRBS DAE"){ + expectedExtensions << "DAE"; + } + else if(from == "FILM DAT"){ + expectedExtensions << "DAT"; + } + else if(from == "WAV / AIF"){ + expectedExtensions << "WAV" << "AIF"; + } + else{ + expectedExtensions << from; + } + + for(const QString &currExpectedExtension : expectedExtensions){ + if(fileInfo.suffix().toUpper() == currExpectedExtension){ + extensionIsValid = true; + break; + } + } + + if(!extensionIsValid){ + QString errorMsg = "Can't add the file '" + fileInfo.fileName() + "'. It isn't a " + expectedExtensions.join(" or ") + " file."; + Util::Dialogs::showError(errorMsg); + Util::StatusBar::showError(ui->statusBar, errorMsg); return; } } @@ -454,9 +516,9 @@ void MainWindow::addFilesSource(DropTabl QString myOutputFolder=getFileOutputFolder(fromTo); //if folder doesn't exist onisplit will create it for us :) - foreach(QString currentFile, files){ + for(QString currentFile : files){ - currentFile=Util::normalizeAndQuote(currentFile); //insert quotes ("") in file + currentFile=Util::FileSystem::normalizeAndQuote(currentFile); //insert quotes ("") in file if(lastFileName.isEmpty()){ //Optimization: all commands are the same for each file, just replace the filename @@ -465,10 +527,10 @@ void MainWindow::addFilesSource(DropTabl if(command.isEmpty()){ //something wrong was happening (not inputted a texture name?) return; //stop adding files } - currentFile=Util::cutName(currentFile); + currentFile=Util::FileSystem::cutName(currentFile); }else{ //one parsing was already made just replace the filename by the old one in the command - currentFile=Util::cutName(currentFile); + currentFile=Util::FileSystem::cutName(currentFile); command.replace(lastFileName,currentFile,Qt::CaseSensitive); //case sentive is faster } @@ -502,27 +564,27 @@ QString MainWindow::fileParsingTextures( if(ui->gbTextures->isEnabled()){ //faster than compare strings (if is DAT/ONI) - if(ui->cbMipMapsTextures->isChecked()){ + if(ui->cbMipMapsTextures->isEnabled() && ui->cbMipMapsTextures->isChecked()){ command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbMipMapsTextures->text()); } - if(ui->cbNoUwrap->isChecked()){ + if(ui->cbNoUwrap->isEnabled() && ui->cbNoUwrap->isChecked()){ command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNoUwrap->text()); } - if(ui->cbNoVwrap->isChecked()){ + if(ui->cbNoVwrap->isEnabled() && ui->cbNoVwrap->isChecked()){ command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNoVwrap->text()); } - if(ui->cbLarge->isChecked()){ + if(ui->cbLarge->isEnabled() && ui->cbLarge->isChecked()){ command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbLarge->text()); } command+=" "+this->commandMap.value(tabTitle+"->"+getTextureRBCheckedTypeTexture()->text()); - if(ui->cbEnvMap->isChecked()){ + if(ui->cbEnvMap->isEnabled() && ui->cbEnvMap->isChecked()){ if(ui->leEnvMapTexture->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbEnvMap->text()+"' is selected. The name texture name cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbEnvMap->text()+"' is selected. The name texture name cannot be empty."); return ""; } command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbEnvMap->text()) + ui->leEnvMapTexture->text().remove(".oni",Qt::CaseInsensitive); @@ -534,24 +596,28 @@ QString MainWindow::fileParsingTextures( QString MainWindow::fileParsingCharacters(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ - QString command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder + " " + file ; + QString command=this->commandMap.value(tabTitle + "->" + from + "->" + to) + " " + myOutputFolder + " " + file ; - if(ui->cbCellShading->isChecked()){ - command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbCellShading->text()); + if(ui->cbCellShading->isEnabled() && ui->cbCellShading->isChecked()){ + command+=" "+this->commandMap.value(tabTitle + "->" + ui->cbCellShading->text()); + } + + if(ui->cbNormals->isEnabled() && ui->cbNormals->isChecked()){ + command+=" "+this->commandMap.value(tabTitle + "->" + ui->cbNormals->text()); } - if(ui->cbNormals->isChecked()){ - command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNormals->text()); + if(ui->cbStandingPose->isEnabled() && ui->cbStandingPose->isChecked()){ + command+=" "+this->commandMap.value(tabTitle + "->" + ui->cbStandingPose->text()); } - if(ui->cbWithTRBS_ONCC->isChecked()){ + if(ui->cbWithTRBS_ONCC->isEnabled() && ui->cbWithTRBS_ONCC->isChecked()){ if(ui->leTRBS_ONCC->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbWithTRBS_ONCC->text()+"' is selected. The name cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '" + ui->cbWithTRBS_ONCC->text() + "' is selected. The name cannot be empty."); return ""; } - command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbWithTRBS_ONCC->text())+Util::normalizeAndQuote(ui->leTRBS_ONCC->text()); + command+= " " + this->commandMap.value(tabTitle + "->" + ui->cbWithTRBS_ONCC->text()) + Util::FileSystem::normalizeAndQuote(ui->leTRBS_ONCC->text()); } return command; @@ -562,19 +628,19 @@ QString MainWindow::fileParsingObjects(Q QString command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder; - if(ui->cbTexture->isChecked()){ + if(ui->cbTexture->isEnabled() && ui->cbTexture->isChecked()){ if(ui->leTextureName->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbTexture->text()+"' is selected. The file source cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbTexture->text()+"' is selected. The file source cannot be empty."); return ""; } command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbTexture->text()) + ui->leTextureName->text(); } - else if(ui->cbWithAnimation->isChecked()){ + else if(ui->cbWithAnimation->isEnabled() && ui->cbWithAnimation->isChecked()){ if(ui->leAnimationName->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbWithAnimation->text()+"' is selected. The file source cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbWithAnimation->text()+"' is selected. The file source cannot be empty."); return ""; } - command+=" "+Util::normalizeAndQuote(ui->leAnimationName->text()) + " " + this->commandMap.value(tabTitle+"->"+ui->cbWithAnimation->text()) + file; + command+=" "+Util::FileSystem::normalizeAndQuote(ui->leAnimationName->text()) + " " + this->commandMap.value(tabTitle+"->"+ui->cbWithAnimation->text()) + file; return command; } @@ -593,10 +659,10 @@ QString MainWindow::fileParsingLevels(QS command=this->commandMap.value(tabTitle+"->"+from+"->"+to); - if(ui->cbSpecificFilesLevels->isChecked()){ + if(ui->cbSpecificFilesLevels->isEnabled() && ui->cbSpecificFilesLevels->isChecked()){ if(ui->leSpecificFilesLevels->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbSpecificFilesLevels->text()+"' is selected. The files pattern cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbSpecificFilesLevels->text()+"' is selected. The files pattern cannot be empty."); return ""; } @@ -604,7 +670,7 @@ QString MainWindow::fileParsingLevels(QS } if(from=="DAT" && to=="ONI FILES"){ // extract files to a subdir with the files name ex: level0_Final - command += " " + myOutputFolder.insert(myOutputFolder.size()-2,QString(Util::cutName(file)).replace(".dat","")) + " " + file; + command += " " + myOutputFolder.insert(myOutputFolder.size()-2,QString(Util::FileSystem::cutName(file)).replace(".dat","")) + " " + file; } else{ command+=" "+myOutputFolder+" "+file; @@ -619,9 +685,9 @@ QString MainWindow::fileParsingLevels(QS command+=GlobalVars::OniSplitProcSeparator; //insert mark so we know this action will take 2 commands } - if(ui->cbDatLevels->isChecked()){ + if(ui->cbDatLevels->isEnabled() && ui->cbDatLevels->isChecked()){ if(ui->leTargetDatLevels->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbDatLevels->text()+"' is selected. The name cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbDatLevels->text()+"' is selected. The name cannot be empty."); return ""; } datName+=QString(myOutputFolder).insert(myOutputFolder.size()-1,ui->leTargetDatLevels->text()); //set name inputted by user @@ -631,14 +697,14 @@ QString MainWindow::fileParsingLevels(QS } else{ if(from=="ONI FILES"){ - datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/")+".dat"); //if none iputted set the same name of input file + datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::FileSystem::cutName(file).remove("/")+".dat"); //if none iputted set the same name of input file } else if(from=="MASTER XML"){ - datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/").replace(".xml",".dat",Qt::CaseInsensitive)); //if none iputted set the same name of input file + datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::FileSystem::cutName(file).remove("/").replace(".xml",".dat",Qt::CaseInsensitive)); //if none iputted set the same name of input file } } if(from=="ONI FILES"){ - if(ui->actionWindows->isChecked()){ //is target plataform select windows? + if(ui->actionWindows->isEnabled() && ui->actionWindows->isChecked()){ //is target plataform select windows? return command=this->commandMap.value(tabTitle+"->"+from+"->"+to+"(PC)")+" "+ file + " "+datName; } else{ @@ -646,7 +712,7 @@ QString MainWindow::fileParsingLevels(QS } } else if(from=="MASTER XML"){ - if(ui->actionWindows->isChecked()){ //is target plataform select windows? + if(ui->actionWindows->isEnabled() && ui->actionWindows->isChecked()){ //is target plataform select windows? command+=this->commandMap.value(tabTitle+"->ONI FILES->"+to+"(PC)")+" "+myOutputFolder+" "+datName; //add second command } else{ @@ -655,19 +721,19 @@ QString MainWindow::fileParsingLevels(QS } } - if(ui->cbBnvLevels->isChecked()){ + if(ui->cbBnvLevels->isEnabled() && ui->cbBnvLevels->isChecked()){ - if(ui->leBnvLevels->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbBnvLevels->text()+"' is selected. The BNV file cannot be empty."); + if(ui->leBnvLevels->isEnabled() && ui->leBnvLevels->text().isEmpty()){ + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbBnvLevels->text()+"' is selected. The BNV file cannot be empty."); return ""; } - command+=" "+Util::normalizeAndQuote(ui->leBnvLevels->text()); + command+=" "+Util::FileSystem::normalizeAndQuote(ui->leBnvLevels->text()); } - if(ui->cbAdditionalSourcesLevels->isChecked()){ + if(ui->cbAdditionalSourcesLevels->isEnabled() && ui->cbAdditionalSourcesLevels->isChecked()){ if(ui->leAdditSourcesLevels->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbAdditionalSourcesLevels->text()+"' is selected. The source files cannot be empty."); + Util::StatusBar::showError(ui->statusBar, "Checkbox '"+ui->cbAdditionalSourcesLevels->text()+"' is selected. The source files cannot be empty."); return ""; } @@ -679,7 +745,7 @@ QString MainWindow::fileParsingLevels(QS while(true){ nextIndex=additionalFiles.indexOf(";",currentIndex+1); - command += " "+Util::normalizeAndQuote(additionalFiles.mid(currentIndex,(nextIndex-currentIndex))); + command += " "+Util::FileSystem::normalizeAndQuote(additionalFiles.mid(currentIndex,(nextIndex-currentIndex))); if(nextIndex==-1){ //we got to the end, stop parsing break; @@ -688,8 +754,8 @@ QString MainWindow::fileParsingLevels(QS } } - if(ui->cbGridsLevels->isChecked()){ - command+=GlobalVars::OniSplitProcSeparator+this->commandMap.value(tabTitle+"->"+ui->cbGridsLevels->text())+" "+Util::normalizeAndQuote(ui->leBnvLevels->text())+" "+file+" -out:"+myOutputFolder; + if(ui->cbGridsLevels->isEnabled() && ui->cbGridsLevels->isChecked()){ + command+=GlobalVars::OniSplitProcSeparator+this->commandMap.value(tabTitle+"->"+ui->cbGridsLevels->text())+" "+Util::FileSystem::normalizeAndQuote(ui->leBnvLevels->text())+" "+file+" -out:"+myOutputFolder; } return command; @@ -742,12 +808,12 @@ void MainWindow::startConversion(){ } if(!ready){ - showErrStatusMessage("Please add sources to convert first."); + Util::StatusBar::showError(ui->statusBar, "Please add sources to convert first."); return; } if(this->myBar->isVisible()){ - Util::showErrorPopUp("Another conversion is progress. Please wait until it finishes."); + Util::Dialogs::showError("Another conversion is progress. Please wait until it finishes."); return; } @@ -781,15 +847,15 @@ void MainWindow::TresultConversion(QStri QString sNumErrors=QString::number(numErrors); if(numErrors>1){ UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" errors."); - showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" errors)."); + Util::StatusBar::showError(ui->statusBar, "Something gone wrong. Check log file ("+sNumErrors+" errors)."); } else{ UtilVago::showErrorPopUpLogButton(result); - showErrStatusMessage("Something gone wrong. Check log file."); + Util::StatusBar::showError(ui->statusBar, "Something gone wrong. Check log file."); } } else{ - showSuccessStatusMessage("Everything went well!"); + Util::StatusBar::showSuccess(ui->statusBar, "Everything went well!"); } } @@ -797,25 +863,7 @@ void MainWindow::TconversionAborted(){ this->myBar->hide(); ui->tbAbortConversion->hide(); - showErrStatusMessage("Conversion was aborted."); -} - -void MainWindow::showErrStatusMessage(QString message){ - - QPalette myPalete = QPalette(); - myPalete.setColor( QPalette::WindowText, QColor(255,0,0)); - statusBar()->setPalette( myPalete ); - ui->statusBar->showMessage(message,10000); //display by 10 seconds - -} - -void MainWindow::showSuccessStatusMessage(QString message){ - - QPalette myPalete = QPalette(); - myPalete.setColor( QPalette::WindowText, QColor(0,150,0)); - statusBar()->setPalette( myPalete ); - ui->statusBar->showMessage(message,10000); //display by 10 seconds - + Util::StatusBar::showError(ui->statusBar, "Conversion was aborted."); } void MainWindow::mapCommands(){ @@ -864,6 +912,7 @@ void MainWindow::mapCommands(){ this->commandMap.insert("characters->"+ui->cbWithTRBS_ONCC->text(),"-anim-body:"); this->commandMap.insert("characters->"+ui->cbCellShading->text(),"-cel"); this->commandMap.insert("characters->"+ui->cbNormals->text(),"-normals"); + this->commandMap.insert("characters->"+ui->cbStandingPose->text(),"-noanim"); //Possible Combinations this->commandMap.insertMulti("characters->TRAM ONI","XML / XML & DAE"); this->commandMap.insertMulti("characters->TRBS / ONCC ONI","DAE"); @@ -879,7 +928,7 @@ void MainWindow::mapCommands(){ this->commandMap.insert("objects->ONWC ONI->DAE","-extract:dae"); this->commandMap.insert("objects->OBAN ONI (cam)->DAE","-extract:dae"); this->commandMap.insert("objects->OBJ->M3GM ONI","-create:m3gm"); - //######################Characters Options + //######################Objects Options this->commandMap.insert("objects->"+ui->cbTexture->text(),"-tex:"); this->commandMap.insert("objects->"+ui->cbWithAnimation->text(),"-geom:"); //Possible Combinations @@ -966,71 +1015,81 @@ void MainWindow::updateComboBox(const QS else if(comboBox == ui->cbToTextures){ identifier = ui->tabWidget->tabText(TexturesTabIndex); - //Options are only used for DAT/ONI -> Image - if(QString::compare(arg1,"DAT / ONI",Qt::CaseSensitive)==0){ //case sensitive is faster + //Options are only used for DAT/TXMP ONI -> Image + if(QString::compare(arg1,"DAT / TXMP ONI",Qt::CaseSensitive)==0){ //case sensitive is faster ui->gbTextures->setEnabled(false); } else{ ui->gbTextures->setEnabled(true); + ui->leEnvMapTexture->setEnabled(ui->cbEnvMap->isChecked()); } } else if(comboBox == ui->cbToCharacters){ identifier = ui->tabWidget->tabText(CharactersTabIndex); ui->cbWithTRBS_ONCC->setEnabled(false); - ui->cbWithTRBS_ONCC->setChecked(false); ui->cbCellShading->setEnabled(false); - ui->cbCellShading->setChecked(false); ui->cbNormals->setEnabled(false); - ui->cbNormals->setChecked(false); -//#error add drag and drop to Extract TRAM with TRBS/ONCC + ui->cbStandingPose->setEnabled(false); + ui->leTRBS_ONCC->setEnabled(false); + + //#error add drag and drop to Extract TRAM with TRBS/ONCC if(QString::compare(arg1,"TRAM ONI",Qt::CaseSensitive)==0){ //case sensitive is faster ui->cbWithTRBS_ONCC->setEnabled(true); + ui->leTRBS_ONCC->setEnabled(ui->cbWithTRBS_ONCC->isChecked()); } else if(QString::compare(arg1,"TRBS DAE",Qt::CaseSensitive)==0){ ui->cbNormals->setEnabled(true); ui->cbCellShading->setEnabled(true); } + else if(QString::compare(arg1,"TRBS / ONCC ONI",Qt::CaseSensitive)==0){ + ui->cbStandingPose->setEnabled(true); + } } else if(comboBox == ui->cbToObjects){ identifier = ui->tabWidget->tabText(ObjectsTabIndex); ui->cbTexture->setEnabled(false); - ui->cbTexture->setChecked(false); + ui->leTextureName->setEnabled(false); ui->cbWithAnimation->setEnabled(false); - ui->cbWithAnimation->setChecked(false); + ui->leAnimationName->setEnabled(false); if(QString::compare(arg1,"M3GM ONI",Qt::CaseSensitive)==0){ //case sensitive is faster ui->cbWithAnimation->setEnabled(true); + ui->leAnimationName->setEnabled(ui->cbWithAnimation->isChecked()); } else if(QString::compare(arg1,"OBJ",Qt::CaseSensitive)==0){ ui->cbTexture->setEnabled(true); + ui->leTextureName->setEnabled(ui->cbTexture->isChecked()); } } else if(comboBox == ui->cbToLevels){ identifier = ui->tabWidget->tabText(LevelsTabIndex); ui->cbSpecificFilesLevels->setEnabled(false); - ui->cbSpecificFilesLevels->setChecked(false); + ui->leSpecificFilesLevels->setEnabled(false); ui->cbDatLevels->setEnabled(false); - ui->cbDatLevels->setChecked(false); + ui->leTargetDatLevels->setEnabled(false); ui->cbBnvLevels->setEnabled(false); - ui->cbBnvLevels->setChecked(false); + ui->leBnvLevels->setEnabled(false); ui->cbAdditionalSourcesLevels->setEnabled(false); - ui->cbAdditionalSourcesLevels->setChecked(false); + ui->leAdditSourcesLevels->setEnabled(false); ui->cbGridsLevels->setEnabled(false); - ui->cbGridsLevels->setChecked(false); if(arg1=="DAT"){ //case sensitive is faster ui->cbSpecificFilesLevels->setEnabled(true); + ui->leSpecificFilesLevels->setEnabled( ui->cbSpecificFilesLevels->isChecked()); } else if(arg1=="ONI FILES"){ //case sensitive is faster ui->cbDatLevels->setEnabled(true); + ui->leTargetDatLevels->setEnabled(ui->cbDatLevels->isChecked()); } else if(arg1=="DAE"){ ui->cbBnvLevels->setEnabled(true); + ui->leBnvLevels->setEnabled(ui->cbBnvLevels->isChecked()); ui->cbAdditionalSourcesLevels->setEnabled(true); + ui->leAdditSourcesLevels->setEnabled(ui->cbAdditionalSourcesLevels->isChecked()); } } else{ // Misc @@ -1131,7 +1190,7 @@ void MainWindow::removeTableContents(Dro QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os if(size==0){ - Util::showPopUp("Select a row first."); + Util::Dialogs::showInfo("Select a row first."); return; } @@ -1145,7 +1204,7 @@ void MainWindow::removeTableContents(Dro #endif - if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?",defaultButton)){ + if(Util::Dialogs::showQuestion(this,"Are you sure you want to delete the selected rows?",defaultButton)){ for(int i=0; iremoveRow(myTable->selectedItems().at(size-i-1)->row()); myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row()); @@ -1160,7 +1219,7 @@ void MainWindow::clearTableContents(Drop QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os if(myTable->rowCount()==0){ - Util::showPopUp("Nothing to clear."); + Util::Dialogs::showInfo("Nothing to clear."); return; } @@ -1173,7 +1232,7 @@ void MainWindow::clearTableContents(Drop } #endif - if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){ + if(Util::Dialogs::showQuestion(this,"Are you sure you want to clear the content?",defaultButton)){ clearTableNoPrompt(myTable); updateItemsLoaded(myTable); rowsWereChangedInDropTableWidget(); @@ -1209,7 +1268,7 @@ void MainWindow::closeEvent(QCloseEvent QMessageBox::StandardButton MainWindow::askToSaveCurrentProject(){ QMessageBox::StandardButton result = - Util::showQuestionPopUpWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes); + Util::Dialogs::showQuestionWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes); if(result == QMessageBox::StandardButton::Yes){ on_actionSave_triggered(); @@ -1283,7 +1342,7 @@ void MainWindow::on_actionCheck_OniSplit QString result=myProcess.readAllStandardOutput(); - Util::showPopUp("This Vago version was built with base in OniSplit version "+GlobalVars::BuiltOniSplitVersion+"\n\nCurrent version is:\n"+result.trimmed()); + Util::Dialogs::showInfo("This Vago version was built with base in OniSplit version "+GlobalVars::BuiltOniSplitVersion+"\n\nCurrent version is:\n"+result.trimmed()); } void MainWindow::on_actionCheck_xmlTools_version_triggered() @@ -1294,7 +1353,7 @@ void MainWindow::on_actionCheck_xmlTools myProcess.waitForFinished(); QString result=myProcess.readLine(); - Util::showPopUp("This Vago version was built with base in XmlTools version "+GlobalVars::BuiltXmlToolsVersion+"\n\nCurrent version is:\n"+result.trimmed()); + Util::Dialogs::showInfo("This Vago version was built with base in XmlTools version "+GlobalVars::BuiltXmlToolsVersion+"\n\nCurrent version is:\n"+result.trimmed()); } /** @@ -1334,13 +1393,13 @@ void MainWindow::on_actionWorkspace_trig ui->actionOther->setChecked(false); this->outputFolder=this->workspaceLocation; ui->tbOpenFolder->setToolTip("Open Vago workspace"); - showSuccessStatusMessage("Vago is now outputting the NEW items for Vago workspace."); + Util::StatusBar::showSuccess(ui->statusBar, "Vago is now outputting the NEW items for Vago workspace."); } void MainWindow::on_actionOther_triggered() { QString newDir=QFileDialog::getExistingDirectory(this,"Choose the folder for output NEW files directly...",this->AeLocation+"/GameDataFolder"); - newDir=Util::normalizePath(newDir); + newDir=Util::FileSystem::normalizePath(newDir); if(newDir.isEmpty()){ ui->actionOther->setChecked(false); @@ -1357,9 +1416,9 @@ void MainWindow::on_actionOther_triggere this->outputFolder=newDir; - QString newDirName=Util::cutName(newDir); + QString newDirName=Util::FileSystem::cutName(newDir); ui->tbOpenFolder->setToolTip("Open "+newDirName+" output folder"); - showSuccessStatusMessage("Vago is now outputting the NEW items for "+newDirName+"."); + Util::StatusBar::showSuccess(ui->statusBar, "Vago is now outputting the NEW items for "+newDirName+"."); } void MainWindow::on_actionView_log_triggered() @@ -1498,7 +1557,7 @@ void MainWindow::dtContextMenu(DropTable QList selectedRows = QList(); - foreach(QModelIndex rowItem, myTable->selectionModel()->selectedRows()){ + for(const QModelIndex &rowItem : myTable->selectionModel()->selectedRows()){ selectedRows << rowItem.row(); } @@ -1536,7 +1595,7 @@ void MainWindow::dtContextMenu(DropTable //Can we change the settings? (the conversion must be the same) QString currentSettings = (getTypeConversion(myTable)); //call function at the mainWindow with a signal (different threads?) - foreach(int row, selectedRows){ + for(const int row : selectedRows){ if( myTable->item(row,1)->text() != currentSettings){ //If we find out any of the selected items can't be convert disable operation changeOptions->setEnabled(false); break; @@ -1566,7 +1625,7 @@ void MainWindow::dtContextMenu(DropTable } QApplication::clipboard()->setText(toCopy); - showSuccessStatusMessage(QString::number(size) + (size==1?" item ":" items ")+ "copied to the clipboard"); + Util::StatusBar::showSuccess(ui->statusBar, QString::number(size) + (size==1?" item ":" items ")+ "copied to the clipboard"); } else if(selectedOption==moveUp.get()){ qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it @@ -1590,7 +1649,7 @@ void MainWindow::dtContextMenu(DropTable else if(selectedOption==outOther.get()){ QString newDir=QFileDialog::getExistingDirectory(this,"Choose the folder for the output of the files selected...",this->AeLocation+"/GameDataFolder"); - newDir=Util::normalizePath(newDir); + newDir=Util::FileSystem::normalizePath(newDir); if(newDir.isEmpty()){ return; //do nothing @@ -1636,7 +1695,7 @@ void MainWindow::dtContextMenu(DropTable } rowsWereChangedInDropTableWidget(); - showSuccessStatusMessage(result); + Util::StatusBar::showSuccess(ui->statusBar, result); } } @@ -1649,8 +1708,7 @@ void MainWindow::changeToCurrentSettings QString command; - foreach(int row, rows){ - + for(int row : rows){ command=getCommand(myTable,getFileOutputFolder(fromTo,myTable->getOutputAbsolute(row)),from,to,myTable->getFileAbsolute(row)); if(command.isEmpty()){ //something wrong was happening (not inputted a texture name?) @@ -1662,14 +1720,14 @@ void MainWindow::changeToCurrentSettings } rowsWereChangedInDropTableWidget(); - showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings"); + Util::StatusBar::showSuccess(ui->statusBar, QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings"); } void MainWindow::changeItemsOutput(DropTableWidget* myTable, QList rows, QString newOutput){ QString command, currentAbsoluteFile, fromTo, from, to; - foreach(int row, rows){ //No optimization possible here, commands may be different + for(const int row : rows){ //No optimization possible here, commands may be different fromTo=myTable->item(row,1)->text(); from = QString(fromTo).remove(fromTo.indexOf(" >"),fromTo.size()-1); //parse the string to get the from to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> " @@ -1686,7 +1744,7 @@ void MainWindow::changeItemsOutput(DropT } rowsWereChangedInDropTableWidget(); - showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace")); + Util::StatusBar::showSuccess(ui->statusBar, QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::FileSystem::cutName(newOutput):"Vago workspace")); } QString MainWindow::getCommand(DropTableWidget* myTable, QString myOutputFolder, QString from, QString to , QString file){ @@ -1770,121 +1828,100 @@ void MainWindow::connectSlots(){ void MainWindow::saveProjectState(const QString &filePath) { + try{ + ProjectFileVago::saveProjectDataToFile(filePath, fetchCurrentProjectData()); - QList tableWidgets = getAllTableWidgets(); + this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); - pugi::xml_document doc; + this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; - pugi::xml_node rootNode = doc.append_child("VagoProject"); - rootNode.append_attribute("vagoVersion").set_value(GlobalVars::LastCompatibleVersion.toUtf8().constData()); + addNewRecentProject(filePath); - foreach(DropTableWidget* const &myTable, tableWidgets){ - saveProjectWidget(rootNode, myTable); - } + setVagoWindowTitle(); - if(!doc.save_file(filePath.toUtf8().constData(), PUGIXML_TEXT("\t"), pugi::format_default | pugi::format_write_bom, pugi::xml_encoding::encoding_utf8)){ - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error ocurred while trying to save the project file. Please try another path."); - return; + Util::StatusBar::showSuccess(ui->statusBar, "Project saved sucessfully."); } + catch(const std::exception& e){ + QString errorMessage = "An error ocurred while trying to save the project file. Please try another path."; + UtilVago::showAndLogErrorPopUpLogButton(errorMessage); + Util::StatusBar::showError(ui->statusBar, "Couldn't save project file."); + } +} - this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); +ProjectFileVago::ProjectData MainWindow::fetchCurrentProjectData(){ - this->lastProjectFilePath = filePath; - this->unsavedChangesExist = false; + ProjectFileVago::ProjectData currentProjectData; - addNewRecentProject(filePath); + auto fFetchTabGenericData = + [](ProjectFileVago::ProjectTable &projectTable, + const QComboBox * const cbFrom, + const QComboBox * const cbTo, + DropTableWidget const * const table) ->void{ - setVagoWindowTitle(); + projectTable.from = cbFrom->currentText(); + projectTable.to = cbTo->currentText(); - showSuccessStatusMessage("Project saved sucessfully."); -} + for(int i=0; irowCount(); i++){ -void MainWindow::saveProjectWidget(pugi::xml_node &rootNode, DropTableWidget* table) -{ - QString from; - QString to; - QString tabName = getTabNameByTableWidget(table); - - pugi::xml_node currentNodeTable = rootNode.append_child("tempName"); - pugi::xml_node options; - - if(table==ui->twSourcesXML){ //So we only need to parse one command. - from = ui->cbFromXML->currentText().toUtf8().constData(); - to = ui->cbToXML->currentText().toUtf8().constData(); - } - else if(table==ui->twSourcesTextures){ - from = ui->cbFromTextures->currentText().toUtf8().constData(); - to = ui->cbToTextures->currentText().toUtf8().constData(); - options = currentNodeTable.append_child("Options"); - options.append_attribute("type").set_value(Util::qStrToCstr(getTextureRBCheckedTypeTexture()->text())); - options.append_attribute("genMipMaps").set_value(Util::boolToCstr(ui->cbMipMapsTextures->isChecked())); - options.append_attribute("noUwrap").set_value(Util::boolToCstr(ui->cbNoUwrap->isChecked())); - options.append_attribute("noVwrap").set_value(Util::boolToCstr(ui->cbNoVwrap->isChecked())); - options.append_attribute("large").set_value(Util::boolToCstr(ui->cbLarge->isChecked())); - options.append_attribute("envMap").set_value(Util::boolToCstr(ui->cbEnvMap->isChecked())); - options.append_attribute("envMapValue").set_value(Util::qStrToCstr(ui->leEnvMapTexture->text())); - } - else if(table==ui->twSourcesCharacters){ - from = ui->cbFromCharacters->currentText().toUtf8().constData(); - to = ui->cbToCharacters->currentText().toUtf8().constData(); - options = currentNodeTable.append_child("Options"); - options.append_attribute("cellShading").set_value(Util::boolToCstr(ui->cbCellShading->isChecked())); - options.append_attribute("normals").set_value(Util::boolToCstr(ui->cbNormals->isChecked())); - options.append_attribute("extractTRBSONCC").set_value(Util::boolToCstr(ui->cbWithTRBS_ONCC->isChecked())); - options.append_attribute("extractTRBSONCCValue").set_value(Util::qStrToCstr(ui->leTRBS_ONCC->text())); - } - else if(table==ui->twSourcesObjects){ - from = ui->cbFromObjects->currentText().toUtf8().constData(); - to = ui->cbToObjects->currentText().toUtf8().constData(); - options = currentNodeTable.append_child("Options"); - options.append_attribute("texture").set_value(Util::boolToCstr(ui->cbTexture->isChecked())); - options.append_attribute("textureValue").set_value(Util::qStrToCstr(ui->leTextureName->text())); - options.append_attribute("withAnimation").set_value(Util::boolToCstr(ui->cbWithAnimation->isChecked())); - options.append_attribute("withAnimationValue").set_value(Util::qStrToCstr(ui->leAnimationName->text())); - } - else if(table==ui->twSourcesLevels){ - from = ui->cbFromLevels->currentText().toUtf8().constData(); - to = ui->cbToLevels->currentText().toUtf8().constData(); - options = currentNodeTable.append_child("Options"); - options.append_attribute("extractWithFiles").set_value(Util::boolToCstr(ui->cbSpecificFilesLevels->isChecked())); - options.append_attribute("extractWithFilesValue").set_value(Util::qStrToCstr(ui->leSpecificFilesLevels->text())); - options.append_attribute("datFilename").set_value(Util::boolToCstr(ui->cbDatLevels->isChecked())); - options.append_attribute("datFilenameValue").set_value(Util::qStrToCstr(ui->leTargetDatLevels->text())); - options.append_attribute("bnvSource").set_value(Util::boolToCstr(ui->cbBnvLevels->isChecked())); - options.append_attribute("bnvSourceValue").set_value(Util::qStrToCstr(ui->leBnvLevels->text())); - options.append_attribute("generateGrids").set_value(Util::boolToCstr(ui->cbGridsLevels->isChecked())); - options.append_attribute("additionalSources").set_value(Util::boolToCstr(ui->cbAdditionalSourcesLevels->isChecked())); - options.append_attribute("additionalSourcesValue").set_value(Util::qStrToCstr(ui->leAdditSourcesLevels->text())); - } - else{ - from = ui->cbFromMisc->currentText().toUtf8().constData(); - to = ui->cbToMisc->currentText().toUtf8().constData(); - } - - currentNodeTable.set_name(tabName.toUtf8().constData()); + ProjectFileVago::ProjectTableRow currentRow; - currentNodeTable.append_attribute("from").set_value(from.toUtf8().constData()); - currentNodeTable.append_attribute("to").set_value(to.toUtf8().constData()); + currentRow.fileFolder = table->item(i,0)->text(); + currentRow.fromTo = table->item(i,1)->text(); + currentRow.command= table->item(i,2)->text(); + if(table->item(i,2)->background()==table->disabledBackStyle){ + currentRow.isDisabled = true; + } - for(int i=0; irowCount(); i++){ - - QString currFileFolder = table->item(i,0)->text(); - QString currFromTo = table->item(i,1)->text(); - QString currCommand = table->item(i,2)->text(); - - pugi::xml_node currentRow = currentNodeTable.append_child("Row"); + projectTable.rows.append(currentRow); + } + }; + // XML tab + fFetchTabGenericData(currentProjectData.xmlTable, ui->cbFromXML, ui->cbToXML, ui->twSourcesXML); - currentRow.append_attribute("fileFolder").set_value(Util::qStrToCstr(currFileFolder)); - currentRow.append_attribute("fromTo").set_value(Util::qStrToCstr(currFromTo)); - currentRow.append_attribute("command").set_value(Util::qStrToCstr(currCommand)); + // Textures tab + fFetchTabGenericData(currentProjectData.texturesTable, ui->cbFromTextures, ui->cbToTextures, ui->twSourcesTextures); + currentProjectData.texturesTable.rbTexturesType = getTextureRBCheckedTypeTexture()->text(); + currentProjectData.texturesTable.cbGenMipMaps = ui->cbMipMapsTextures->isChecked(); + currentProjectData.texturesTable.cbNoUwrap = ui->cbNoUwrap->isChecked(); + currentProjectData.texturesTable.cbNoVwrap = ui->cbNoVwrap->isChecked(); + currentProjectData.texturesTable.cbLarge = ui->cbLarge->isChecked(); + currentProjectData.texturesTable.cbEnvMap = ui->cbEnvMap->isChecked(); + currentProjectData.texturesTable.leEnvMapTexture = ui->leEnvMapTexture->text(); + + // Characters tab + fFetchTabGenericData(currentProjectData.charactersTable, ui->cbFromCharacters, ui->cbToCharacters, ui->twSourcesCharacters); + currentProjectData.charactersTable.cbCellShading = ui->cbCellShading->isChecked(); + currentProjectData.charactersTable.cbNormals = ui->cbNormals->isChecked(); + currentProjectData.charactersTable.cbStandingPose = ui->cbStandingPose->isChecked(); + currentProjectData.charactersTable.cbWithTRBS_ONCC = ui->cbWithTRBS_ONCC->isChecked(); + currentProjectData.charactersTable.leTRBS_ONCC = ui->leTRBS_ONCC->text(); + + // Objects tab + fFetchTabGenericData(currentProjectData.objectsTable, ui->cbFromObjects, ui->cbToObjects, ui->twSourcesObjects); + currentProjectData.objectsTable.cbTexture = ui->cbTexture->isChecked(); + currentProjectData.objectsTable.leTextureName = ui->leTextureName->text(); + currentProjectData.objectsTable.cbWithAnimation = ui->cbWithAnimation->isChecked(); + currentProjectData.objectsTable.leAnimationName = ui->leAnimationName->text(); + + // Levels tab + fFetchTabGenericData(currentProjectData.levelsTable, ui->cbFromLevels, ui->cbToLevels, ui->twSourcesLevels); + currentProjectData.levelsTable.cbSpecificFilesLevels = ui->cbSpecificFilesLevels->isChecked(); + currentProjectData.levelsTable.leSpecificFilesLevels = ui->leSpecificFilesLevels->text(); + currentProjectData.levelsTable.cbDatLevels = ui->cbDatLevels->isChecked(); + currentProjectData.levelsTable.leTargetDatLevels = ui->leTargetDatLevels->text(); + currentProjectData.levelsTable.cbBnvLevels = ui->cbBnvLevels->isChecked(); + currentProjectData.levelsTable.leBnvLevels = ui->leBnvLevels->text(); + currentProjectData.levelsTable.cbGridsLevels = ui->cbGridsLevels->isChecked(); + currentProjectData.levelsTable.cbAdditionalSourcesLevels = ui->cbAdditionalSourcesLevels->isChecked(); + currentProjectData.levelsTable.leAdditSourcesLevels = ui->leAdditSourcesLevels->text(); - if(table->item(i,2)->background()==table->disabledBackStyle){ - currentRow.append_attribute("disabled").set_value(true); - } + // Misc tab + fFetchTabGenericData(currentProjectData.miscTable, ui->cbFromMisc, ui->cbToMisc, ui->twSourcesMisc); - } + return currentProjectData; } QRadioButton* MainWindow::getTextureRBCheckedTypeTexture() @@ -1940,7 +1977,7 @@ void MainWindow::setVagoWindowTitle(){ vagoTitle += "Untitled"; } else{ - vagoTitle += Util::cutNameWithoutBackSlash(this->lastProjectFilePath); + vagoTitle += Util::FileSystem::cutNameWithoutBackSlash(this->lastProjectFilePath); } if(this->unsavedChangesExist){ @@ -2019,6 +2056,23 @@ QList MainWindow::getA void MainWindow::loadProjectState(const QString &filePath) { + auto fLoadTabGenericData = + [this]( // we are capturing this only to call the addRowTable function... + const ProjectFileVago::ProjectTable &tableData, + DropTableWidget * const table, + QComboBox * const cbFrom, + QComboBox * const cbTo) -> void{ + + cbFrom->setCurrentText(tableData.from); + cbTo->setCurrentText(tableData.to); + + // Add rows + for(const ProjectFileVago::ProjectTableRow ¤tRow : tableData.rows){ + addRowTable(table,currentRow.fileFolder,currentRow.fromTo,currentRow.command, currentRow.isDisabled); + } + + }; + this->projectIsLoading = true; if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ @@ -2029,160 +2083,76 @@ void MainWindow::loadProjectState(const } } - QString statusError = "Couldn't load project."; + try{ + ProjectFileVago::ProjectData projectData = ProjectFileVago::readProjectDataFromFile(filePath); - pugi::xml_document doc; + // XML tab + fLoadTabGenericData(projectData.xmlTable, ui->twSourcesXML, ui->cbFromXML, ui->cbToXML); - pugi::xml_parse_result result = doc.load_file(Util::qStrToCstr(filePath)); + // Textures tab + fLoadTabGenericData(projectData.texturesTable, ui->twSourcesTextures, ui->cbFromTextures, ui->cbToTextures); + getTextureRBTypeTextureByName(projectData.texturesTable.rbTexturesType)->setChecked(true); + ui->cbMipMapsTextures->setChecked(projectData.texturesTable.cbGenMipMaps); + ui->cbNoUwrap->setChecked(projectData.texturesTable.cbNoUwrap); + ui->cbNoVwrap->setChecked(projectData.texturesTable.cbNoVwrap); + ui->cbLarge->setChecked(projectData.texturesTable.cbLarge); + ui->cbEnvMap->setChecked(projectData.texturesTable.cbEnvMap); + ui->leEnvMapTexture->setText(projectData.texturesTable.leEnvMapTexture); + + // Characters tab + fLoadTabGenericData(projectData.charactersTable, ui->twSourcesCharacters, ui->cbFromCharacters, ui->cbToCharacters); + + ui->cbCellShading->setChecked(projectData.charactersTable.cbCellShading); + ui->cbNormals->setChecked(projectData.charactersTable.cbNormals); + ui->cbStandingPose->setChecked(projectData.charactersTable.cbStandingPose); + ui->cbWithTRBS_ONCC->setChecked(projectData.charactersTable.cbWithTRBS_ONCC); + ui->leTRBS_ONCC->setText(projectData.charactersTable.leTRBS_ONCC); + + // Objects tab + fLoadTabGenericData(projectData.objectsTable, ui->twSourcesObjects, ui->cbFromObjects, ui->cbToObjects); + + ui->cbTexture->setChecked(projectData.objectsTable.cbTexture); + ui->leTextureName->setText(projectData.objectsTable.leTextureName); + ui->cbWithAnimation->setChecked(projectData.objectsTable.cbWithAnimation); + ui->leAnimationName->setText(projectData.objectsTable.leAnimationName); + + // Levels tab + fLoadTabGenericData(projectData.levelsTable, ui->twSourcesLevels, ui->cbFromLevels, ui->cbToLevels); + + ui->cbSpecificFilesLevels->setChecked(projectData.levelsTable.cbSpecificFilesLevels); + ui->leSpecificFilesLevels->setText(projectData.levelsTable.leSpecificFilesLevels); + ui->cbDatLevels->setChecked(projectData.levelsTable.cbDatLevels); + ui->leTargetDatLevels->setText(projectData.levelsTable.leTargetDatLevels); + ui->cbBnvLevels->setChecked(projectData.levelsTable.cbBnvLevels); + ui->leBnvLevels->setText(projectData.levelsTable.leBnvLevels); + ui->cbGridsLevels->setChecked(projectData.levelsTable.cbGridsLevels); + ui->cbAdditionalSourcesLevels->setChecked(projectData.levelsTable.cbAdditionalSourcesLevels); + ui->leAdditSourcesLevels->setText(projectData.levelsTable.leAdditSourcesLevels); + + // Misc tab + fLoadTabGenericData(projectData.miscTable, ui->twSourcesMisc, ui->cbFromMisc, ui->cbToMisc); - if(result.status!=pugi::status_ok){ - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error ocurred while loading project file.\n" + QString(result.description())); - showErrStatusMessage(statusError); - this->projectIsLoading = false; - return; - } + this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); + this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; - if(QString(doc.root().first_child().name()) != "VagoProject"){ - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, QString(doc.root().name()) + "The file opened is not a valid VagoProject file. Load aborted."); - showErrStatusMessage(statusError); - this->projectIsLoading = false; - return; - } + addNewRecentProject(filePath); - QString projVagoVersion; + setVagoWindowTitle(); - try{ - projVagoVersion = QString(doc.select_node("/VagoProject/@vagoVersion").attribute().value()); - } - catch (const pugi::xpath_exception& e) - { - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't find the vagoVersion of the current project. Load aborted.\n" + QString(e.what())); - showErrStatusMessage(statusError); this->projectIsLoading = false; - return; - } - if(!projVagoVersion.startsWith(GlobalVars::LastCompatibleVersion)){ - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "The project that you are trying to load seems it is not compatible with your Vago Version. Please update Vago and try again."); - showErrStatusMessage(statusError); - this->projectIsLoading = false; - return; - } - - // After the initial validations begin loading the project data - - QList tableWidgets = getAllTableWidgets(); - - try{ - foreach(DropTableWidget* const &myTable, tableWidgets){ - loadProjectWidget(doc, myTable); - } + Util::StatusBar::showSuccess(ui->statusBar, "Project loaded sucessfully."); } catch(const std::exception& e){ - UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't load the vago project. Error: " + QString(e.what())); - showErrStatusMessage(statusError); this->projectIsLoading = false; - return; + QString errorMessage = "Couldn't load the Vago project. Error: " + QString(e.what()); + LOG_ERROR << errorMessage; + Util::Dialogs::showError(errorMessage); + Util::StatusBar::showError(ui->statusBar, "Couldn't load project."); } - this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); - - this->lastProjectFilePath = filePath; - this->unsavedChangesExist = false; - - addNewRecentProject(filePath); - - setVagoWindowTitle(); - - this->projectIsLoading = false; - - showSuccessStatusMessage("Project loaded sucessfully."); -} - - -void MainWindow::loadProjectWidget(pugi::xml_document &doc, DropTableWidget* table) -{ - QString tabName = getTabNameByTableWidget(table); - QString from (doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/@from")).attribute().value()); - QString to (doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/@to")).attribute().value()); - - if(table==ui->twSourcesXML){ - ui->cbFromXML->setCurrentText(from); - on_cbFromXML_currentIndexChanged(from); - ui->cbToXML->setCurrentText(to); - } - else if(table==ui->twSourcesTextures){ - //ui->cbFromTextures->setCurrentText(from); - on_cbFromTextures_currentIndexChanged(from); - ui->cbToTextures->setCurrentText(to); - - getTextureRBTypeTextureByName((doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@type")).attribute().value()))->setChecked(true); - ui->cbMipMapsTextures->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@genMipMaps")).attribute().as_bool()); - ui->cbNoUwrap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@noUwrap")).attribute().as_bool()); - ui->cbNoVwrap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@noVwrap")).attribute().as_bool()); - ui->cbLarge->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@large")).attribute().as_bool()); - ui->cbEnvMap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@envMap")).attribute().as_bool()); - ui->leEnvMapTexture->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@envMapValue")).attribute().value())); - } - else if(table==ui->twSourcesCharacters){ - ui->cbFromCharacters->setCurrentText(from); - on_cbFromCharacters_currentIndexChanged(from); - ui->cbToCharacters->setCurrentText(to); - - - ui->cbCellShading->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@cellShading")).attribute().as_bool()); - ui->cbNormals->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@normals")).attribute().as_bool()); - ui->cbWithTRBS_ONCC->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractTRBSONCC")).attribute().as_bool()); - ui->leTRBS_ONCC->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractTRBSONCCValue")).attribute().value())); - } - else if(table==ui->twSourcesObjects){ - ui->cbFromObjects->setCurrentText(from); - on_cbFromObjects_currentIndexChanged(from); - ui->cbToObjects->setCurrentText(to); - - ui->cbTexture->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@texture")).attribute().as_bool()); - ui->leTextureName->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@textureValue")).attribute().value())); - ui->cbWithAnimation->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@withAnimation")).attribute().as_bool()); - ui->leAnimationName->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@withAnimationValue")).attribute().value())); - } - else if(table==ui->twSourcesLevels){ - ui->cbFromLevels->setCurrentText(from); - on_cbFromLevels_currentIndexChanged(from); - ui->cbToLevels->setCurrentText(to); - - ui->cbSpecificFilesLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractWithFiles")).attribute().as_bool()); - ui->leSpecificFilesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractWithFilesValue")).attribute().value())); - ui->cbDatLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@datFilename")).attribute().as_bool()); - ui->leTargetDatLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@datFilenameValue")).attribute().value())); - ui->cbBnvLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSource")).attribute().as_bool()); - ui->leBnvLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSourceValue")).attribute().value())); - ui->cbGridsLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@generateGrids")).attribute().as_bool()); - ui->cbAdditionalSourcesLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSources")).attribute().as_bool()); - ui->leAdditSourcesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSourcesValue")).attribute().value())); - } - else{ - ui->cbFromMisc->setCurrentText(from); - on_cbFromMisc_currentIndexChanged(from); - ui->cbToMisc->setCurrentText(to); - } - - // Clean previous rows - clearTableNoPrompt(table); - - for(const pugi::xpath_node &xPathNode : doc.select_nodes(Util::qStrToCstr("/VagoProject/"+tabName+"/Row"))){ - pugi::xml_node currNode = xPathNode.node(); - - QString currFileFolder = currNode.attribute("fileFolder").value(); - QString currFromTo = currNode.attribute("fromTo").value(); - QString currCommand = currNode.attribute("command").value(); - - bool isToDisable = false; - pugi::xml_attribute disabledAttr = currNode.attribute("disabled"); - isToDisable = disabledAttr.empty() ? false : disabledAttr.as_bool(); - - addRowTable(table,currFileFolder,currFromTo,currCommand, isToDisable); - } } void MainWindow::saveRecentProjects(){