Prechádzať zdrojové kódy

don't stop data conversion on error, log error and carry on

Paul 11 rokov pred
rodič
commit
5eb905aff9

+ 1 - 1
dependencies/SUDM

@@ -1 +1 @@
-Subproject commit dc3caf09dc381d0e843af6b4d77ec5807a887339
+Subproject commit 51955525428107d1b146244fd4be40c195e1594f

+ 60 - 24
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -32,13 +32,15 @@
 #include <QDir>
 #include "common/make_unique.h"
 
-FF7DataInstaller::FF7DataInstaller(std::string inputDir, std::string outputDir)
+FF7DataInstaller::FF7DataInstaller(std::string inputDir, std::string outputDir, std::function<void(std::string)> fnWriteOutputLine)
 #ifdef _DEBUG
     : mApp("plugins_d.cfg", "resources_d.cfg", "install_d.log"),
 #else
     : mApp("plugins.cfg", "resources.cfg", "install.log"),
 #endif
-    mInputDir(inputDir), mOutputDir(outputDir)
+    mInputDir(inputDir),
+    mOutputDir(outputDir),
+    mfnWriteOutputLine(fnWriteOutputLine)
 {
     if (!mApp.initOgre(true))
     {
@@ -65,12 +67,14 @@ int FF7DataInstaller::Progress()
     switch (mState)
     {
     case eIdle:
+        mfnWriteOutputLine("Loading flevel.lgp");
         mProgressStepNumElements = 1;
         mIteratorCounter = 0;
         mFieldsLgp = std::make_unique<ScopedLgp>(mApp.getRoot(), mInputDir + "field/flevel.lgp", "LGP", "FFVIIFields");
         mState = eInitCollectFieldSpawnPointsAndScaleFactors;
         return CalcProgress();
     case eInitCollectFieldSpawnPointsAndScaleFactors:
+        mfnWriteOutputLine("Collecting spawn points and scale factors");
         InitCollectSpawnAndScaleFactors();
         return CalcProgress();
     case eCollectFieldSpawnPointsAndScaleFactors:
@@ -80,6 +84,7 @@ int FF7DataInstaller::Progress()
         ConvertFieldsIteration();
         return CalcProgress();
     case eWriteMapListOfConvertedFieldsStart:
+        mfnWriteOutputLine("Write fields");
         WriteMapsXmlBegin();
         return CalcProgress();
     case eWriteMapListOfConvertedFieldsIteration:
@@ -89,6 +94,7 @@ int FF7DataInstaller::Progress()
         EndWriteMapsXml();
         return CalcProgress();
     case eConvertFieldModelsBegin:
+        mfnWriteOutputLine("Converting field models");
         ConvertFieldModelsBegin();
         return CalcProgress();
     case eConvertFieldModelsIteration:
@@ -358,7 +364,8 @@ static void FF7PcFieldToQGearsField(
     FieldSpawnPointsMap& spawnMap,
     const FieldScaleFactorMap& scaleFactorMap,
     ModelsAndAnimationsDb& modelAnimationDb,
-    MapCollection& maps)
+    MapCollection& maps,
+    std::function<void(std::string)> fnWriteOutputLine)
 {
     // Generate triggers script to insert into main decompiled FF7 field -> LUA script
     std::string gatewayScriptData;
@@ -392,11 +399,13 @@ static void FF7PcFieldToQGearsField(
         }
         else
         {
+            fnWriteOutputLine("[ERROR] Failed to open script file for writing");
             std::cerr << "Failed to open script file for writing" << std::endl;
         }
     }
     catch (const ::InternalDecompilerError& ex)
-    {
+    { 
+        fnWriteOutputLine("[ERROR] internal decompiler error");
         std::cerr << "InternalDecompilerError: " << ex.what() << std::endl;
     }
 
@@ -900,17 +909,20 @@ void FF7DataInstaller::CollectionFieldSpawnAndScaleFactors()
             if (mConversionStep == 1)
             {
                 mField = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
+                mfnWriteOutputLine("Load field " + resourceName);
                 return;
             }
 
             if (mConversionStep == 2)
             {
+                mfnWriteOutputLine("Read spawn points from scripts");
                 CollectSpawnPoints(mField, mMapList, mCollectedSpawnPoints);
                 return;
             }
            
             if (mConversionStep == 3)
             {
+                mfnWriteOutputLine("Read scale factor");
                 CollectFieldScaleFactors(mField, mCollectedScaleFactors, mMapList);
                 mConversionStep = 0;
                 mIteratorCounter++;
@@ -946,14 +958,16 @@ void FF7DataInstaller::ConvertFieldsIteration()
             if (/*IsTestField(resourceName) &&*/
                 !WillCrash(resourceName))
             {
+                mfnWriteOutputLine("Converting field " + resourceName);
                 std::cout << "Converting: " << resourceName << std::endl;
                 CreateDir(FieldMapDir() + "/" + resourceName);
 
                 QGears::FLevelFilePtr field = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
-                FF7PcFieldToQGearsField(field, mOutputDir, mMapList, mCollectedSpawnPoints, mCollectedScaleFactors, mModelsAndAnimationsUsedByConvertedFields, mConvertedMapList);
+                FF7PcFieldToQGearsField(field, mOutputDir, mMapList, mCollectedSpawnPoints, mCollectedScaleFactors, mModelsAndAnimationsUsedByConvertedFields, mConvertedMapList, mfnWriteOutputLine);
             }
             else
             {
+                mfnWriteOutputLine("[ERROR] Skip field " + resourceName + " due to crash or hang issue");
                 std::cout << "Skip: " << resourceName << " as it has a crash or hang issue" << std::endl;
             }
         }
@@ -988,6 +1002,8 @@ void FF7DataInstaller::WriteMapsXmlIteration()
     if (mConvertedMapListIt != mConvertedMapList.end())
     {
         auto map = *mConvertedMapListIt;
+
+        mfnWriteOutputLine("Writing field " + FieldName(map));
         std::unique_ptr<TiXmlElement> xmlElement(new TiXmlElement("map"));
         xmlElement->SetAttribute("name", FieldName(map));
         xmlElement->SetAttribute("file_name", FieldMapDir() + "/" + map + "/map.xml");
@@ -1019,6 +1035,7 @@ void FF7DataInstaller::ConvertFieldModelsBegin()
     mIteratorCounter = 0;
     mState = eConvertFieldModelsIteration;
     mIteratorCounter = 0;
+    mConversionStep = 0;
     mModelAnimationMapIterator = mModelsAndAnimationsUsedByConvertedFields.mMap.begin();
 }
 
@@ -1027,31 +1044,50 @@ void FF7DataInstaller::ConvertFieldModelsIteration()
     mProgressStepNumElements = mModelsAndAnimationsUsedByConvertedFields.mMap.size();
     if (mModelAnimationMapIterator != mModelsAndAnimationsUsedByConvertedFields.mMap.end())
     {
-        Ogre::ResourcePtr hrc = QGears::HRCFileManager::getSingleton().load(mModelAnimationMapIterator->first, "FFVII");
-
-        Ogre::String baseName;
-        QGears::StringUtil::splitBase(mModelAnimationMapIterator->first, baseName);
+        if (mConversionStep == 0)
+        {
+            mfnWriteOutputLine("Converting model " + mModelAnimationMapIterator->first);
+            mConversionStep++;
+        }
+        else
+        {
+            try
+            {
+                Ogre::ResourcePtr hrc = QGears::HRCFileManager::getSingleton().load(mModelAnimationMapIterator->first, "FFVII");
 
-        auto meshName = QGears::FF7::NameLookup::model(baseName) + ".mesh";
+                Ogre::String baseName;
+                QGears::StringUtil::splitBase(mModelAnimationMapIterator->first, baseName);
 
-        Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(meshName, "FFVII"));
-        Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
+                auto meshName = QGears::FF7::NameLookup::model(baseName) + ".mesh";
 
-        for (auto& anim : mModelAnimationMapIterator->second)
-        {
-            QGears::AFileManager       &afl_mgr(QGears::AFileManager::getSingleton());
-            QGears::AFilePtr  a = afl_mgr.load(anim, "FFVII").staticCast<QGears::AFile>();
+                Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(meshName, "FFVII"));
+                Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
 
-            // Convert the FF7 name to a more readable name set in the meta data
-            Ogre::String baseName;
-            QGears::StringUtil::splitBase(anim, baseName);
-            a->addTo(skeleton, QGears::FF7::NameLookup::animation(baseName));
-        }
+                for (auto& anim : mModelAnimationMapIterator->second)
+                {
+                    QGears::AFileManager       &afl_mgr(QGears::AFileManager::getSingleton());
+                    QGears::AFilePtr  a = afl_mgr.load(anim, "FFVII").staticCast<QGears::AFile>();
 
-        exportMesh(mOutputDir + "/" + FieldModelDir() + "/", mesh);
+                    // Convert the FF7 name to a more readable name set in the meta data
+                    Ogre::String baseName;
+                    QGears::StringUtil::splitBase(anim, baseName);
+                    a->addTo(skeleton, QGears::FF7::NameLookup::animation(baseName));
+                }
 
-        mIteratorCounter++;
-        mModelAnimationMapIterator++;
+                exportMesh(mOutputDir + "/" + FieldModelDir() + "/", mesh);
+            }
+            catch (const Ogre::Exception& ex)
+            {
+                mfnWriteOutputLine("[ERROR] converting model " + mModelAnimationMapIterator->first + " msg: " + ex.what());
+            }
+            catch (const std::exception& ex)
+            {
+                mfnWriteOutputLine("[ERROR] converting model " + mModelAnimationMapIterator->first + " msg: " + ex.what());
+            }
+            mIteratorCounter++;
+            mModelAnimationMapIterator++;
+            mConversionStep = 0;
+        }
     }
     else
     {

+ 3 - 1
utilities/q-gears-launcher/src/ff7DataInstaller.h

@@ -109,7 +109,7 @@ public:
 class FF7DataInstaller
 {
 public:
-    FF7DataInstaller(std::string inputDir, std::string outputDir);
+    FF7DataInstaller(std::string inputDir, std::string outputDir, std::function<void(std::string)> fnWriteOutputLine);
     ~FF7DataInstaller();
     int Progress();
 private:
@@ -167,4 +167,6 @@ private:
     std::unique_ptr<TiXmlElement> mElement;
 
     ModelAnimationMap::iterator mModelAnimationMapIterator;
+
+    std::function<void(std::string)> mfnWriteOutputLine;
 };

+ 7 - 1
utilities/q-gears-launcher/src/mainwindow.cpp

@@ -181,7 +181,13 @@ void MainWindow::on_btnGO_clicked()
         try
         {
             installerCreated = true;
-            mInstaller = std::make_unique<FF7DataInstaller>(QDir::toNativeSeparators(input).toStdString(), QDir::toNativeSeparators(output).toStdString());
+            mInstaller = std::make_unique<FF7DataInstaller>(
+                QDir::toNativeSeparators(input).toStdString(), 
+                QDir::toNativeSeparators(output).toStdString(),
+                [this](std::string outputLine)
+                {
+                mUi->txtOutput->append(outputLine.c_str());
+                } );
             OnInstallStarted();
         }
         catch (const std::exception&)

+ 20 - 3
utilities/q-gears-launcher/src/mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>734</width>
-    <height>217</height>
+    <width>720</width>
+    <height>375</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -169,6 +169,23 @@
           </property>
          </widget>
         </item>
+        <item>
+         <widget class="QLabel" name="label_5">
+          <property name="text">
+           <string>Output</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QTextEdit" name="txtOutput">
+          <property name="undoRedoEnabled">
+           <bool>false</bool>
+          </property>
+          <property name="readOnly">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
         <item>
          <widget class="QPushButton" name="btnGO">
           <property name="text">
@@ -187,7 +204,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>734</width>
+     <width>720</width>
      <height>21</height>
     </rect>
    </property>