Пример #1
0
 /// <summary>
 /// Search for model file, first in user's FM folder, then in any of the CRF files. Extract if necessary, then return location.
 /// </summary>
 /// <param name="userModelName">Text the user has entered in the ComboBox.</param>
 /// <param name="subFolderName">obj or mesh.</param>
 /// <param name="shortName">Filename with extension.</param>
 /// <returns></returns>
 private string findModelFile(string userModelName, string subFolderName, string shortName)
 {
     if (File.Exists(userModelName))
     {
         return(userModelName); //no need to extract if file is already in place
     }
     else //model name and/or file in CRF
     {
         if (userModelName.StartsWith(modelNamePrefix))                                             //model name
         {
             string userGameDirObjectPath = Path.Combine(cbGameDir.Text, subFolderName, shortName); //try the users FM obj dir
             if (File.Exists(userGameDirObjectPath))                                                //object FM obj dir
             {
                 return(userGameDirObjectPath);
             }
             else
             {
                 if (!chkNoResMods.Checked && ZipFileTools.FindFile(epCRF, shortName, true)) //Found in resource mod
                 {
                     ZipFileTools.ExtractFile(shortName, epCRF, userTempDir, true, true, out modelExtracted);
                     return(Path.Combine(userTempDir, shortName)); //prepare to extract to %temp%
                 }
                 else
                 {
                     if (rootCRF != null)
                     {
                         if (ZipFileTools.FindFile(rootCRF, shortName, false)) //found in Thief2\obj.crf - 1.18 patch
                         {
                             ZipFileTools.ExtractFile(shortName, rootCRF, userTempDir, true, false, out modelExtracted);
                             return(Path.Combine(userTempDir, shortName)); //prepare to extract to %temp%
                         }
                     }
                     if (resCRF != null)
                     {
                         if (ZipFileTools.FindFile(resCRF, shortName, false)) //found in Thief2\RES\obj.crf
                         {
                             ZipFileTools.ExtractFile(shortName, resCRF, userTempDir, true, false, out modelExtracted);
                             return(Path.Combine(userTempDir, shortName)); //prepare to extract to %temp%
                         }
                     }
                 }
             }
         }
         return(""); //default if file not found
     }
 }
Пример #2
0
        /// <summary>
        /// For each object texture found, return its location (either permanent file in \txt(16) or texture library, or temp file) and whether or not it can be deleted after conversion.
        /// </summary>
        /// <param name="simpleTextureNames"></param>
        /// <returns></returns>
        private List <TextureFoundInfo> findOrExtractTextures(List <string> simpleTextureNames, string modelFolder)
        {
            List <TextureFoundInfo> sourceTextures = new List <TextureFoundInfo>(); //Lists found/extracted texture locations

            string txt16 = Path.Combine(cbGameDir.Text, modelFolder, "txt16");
            string txt   = Path.Combine(cbGameDir.Text, modelFolder, "txt");

            string[]  folderLocations = { txt16, txt };
            ZipFile[] crfFiles        = { epCRF, rootCRF, resCRF };

            //search priority is location, then extension. e.g. a gif in the fm folder overrides a png in ep2.crf
            foreach (string texture in simpleTextureNames)
            {
                bool found = false;
                // look in /txt16 and then .dds, then .png etc, then txt
                foreach (string texFolder in folderLocations) //if found in txt16 or txt
                {
                    foreach (string extension in tExtensions)
                    {
                        string testFile = Path.Combine(texFolder, texture + extension);
                        if (File.Exists(testFile))
                        {
                            TextureFoundInfo foundTexture = new TextureFoundInfo();
                            foundTexture.FullPath  = testFile;
                            foundTexture.CanDelete = false;
                            sourceTextures.Add(foundTexture);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (found)
                {
                    continue;        //stop searching for texture
                }
                //look in each crf file, starting with ep2.crf (unless user isn't using it)
                foreach (ZipFile crf in crfFiles)
                {
                    foreach (string extension in tExtensions)
                    {
                        if (chkNoResMods.Checked && crf == epCRF) //don't look in ep crf if user is ignoring it
                        {
                            continue;
                        }

                        if (crf != null && ZipFileTools.FindTextureEP(crf, modelFolder, texture + extension))
                        {
                            ZipFileTools.ExtractTextureEP(crf, modelFolder, texture + extension, userTempDir, true);

                            TextureFoundInfo info = new TextureFoundInfo();
                            info.FullPath  = Path.Combine(userTempDir, texture + extension);
                            info.CanDelete = true;

                            sourceTextures.Add(info);
                            found = true;
                            break;
                        }
                        else if (crf != null && ZipFileTools.FindTexture(crf, texture + extension))
                        {
                            ZipFileTools.ExtractTexture(crf, texture + extension, userTempDir, true);

                            TextureFoundInfo info = new TextureFoundInfo();
                            info.FullPath  = Path.Combine(userTempDir, texture + extension);
                            info.CanDelete = true;

                            sourceTextures.Add(info);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;        //stop looking in crf files
                    }
                }
            }

            return(sourceTextures);
        }