From 2dc271fd939bb4ad06e27dd405d5eab9ba116a10 Mon Sep 17 00:00:00 2001
From: Tazpn <tazpn@users.sourceforge.net>
Date: Sat, 14 Jul 2007 16:27:04 +0000
Subject: [PATCH] Miscellaneous fixes w.r.t texture search paths.

---
 MaxNifTools.ini       | 42 ++++++++++++++++++++++++++----------------
 NifCommon/niutils.cpp | 12 +++++++++---
 2 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/MaxNifTools.ini b/MaxNifTools.ini
index 659e70e..a9223ae 100644
--- a/MaxNifTools.ini
+++ b/MaxNifTools.ini
@@ -8,13 +8,13 @@ MaxSDKVersion=0
 ShortDescription=Netimmerse/Gamebryo
 ; KnownApplications - Used to indicate which sections in the ini file point 
 ;    to "Applications" which have their own settings in a section below.
-KnownApplications=Oblivion;Morrowind;Civilization 4;Dark Age of Camelot;Freedom Force;Freedom Force vs. the 3rd Reich;Star Trek: Bridge Commander;User
+KnownApplications=Oblivion;Morrowind;Civilization 4;Dark Age of Camelot;Freedom Force;Freedom Force vs. the 3rd Reich;Star Trek: Bridge Commander;Loki;User
 ; Reparse the Applications (and therefore Texture directory cache) on every import/export
 Reparse=0
 ; Website - Primary website
-Website=http://www.niftools.org
+Website=http://niftools.sourceforge.net
 ; Wiki - Documentation website
-Wiki=http://www.niftools.org/wiki/index.php/3ds_Max
+Wiki=http://niftools.sourceforge.net/wiki/index.php/3ds_Max
 ; Force Plugcfg directory (Default=1) dont use the "recommended directory by max"
 ForcePlugcfg=1
 
@@ -214,11 +214,11 @@ NiVersion=4.0.0.2
 NiUserVersion=0
 InstallPath=[HKLM\SOFTWARE\Bethesda Softworks\Morrowind]=@"Installed Path"
 RootPath=${InstallPath}\Data Files
-ExtractFolder=E:\Nifs\Morrowind\Data Files
-RootPaths=${RootPath};${ExtractFolder}
-TextureRootPaths=${RootPath}\Textures;${ExtractFolder}\Textures
+ExtractFolder=
+RootPaths=${RootPath};${MeshRootPath};${ExtractFolder}
+TextureRootPaths=${RootPath}\Textures;${TextureRootPath}\Textures;${ExtractFolder}\Textures
 TextureExtensions=.tga;
-TextureSearchPaths=${RootPath}\Textures
+TextureSearchPaths=${RootPath}\Textures;${TextureRootPath}\Textures
 GoToSkeletonBindPosition=1
 SupportPrnStrings=1
 Rotate90Degrees=Bip?? Head
@@ -240,10 +240,9 @@ TextureUseFullPath=1
 NiVersion=10.1.0.0
 NiUserVersion=0
 Isles_InstallPath=[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Dark Age of Camelot - Shrouded Isles_is1]=@"InstallLocation"
-RootPath=
 ExtractFolder=
-RootPaths=${Isles_InstallPath};${ExtractFolder}
-TextureRootPaths=$(ExtractFolder)
+RootPaths=${Isles_InstallPath};${MeshRootPath};${ExtractFolder}
+TextureRootPaths=${TextureRootPath};
 TextureExtensions=.dds;.bmp;.tga
 TextureSearchPaths=
 
@@ -253,8 +252,8 @@ NiUserVersion=0
 InstallPath=
 RootPath=
 ExtractFolder=
-RootPaths=${InstallPath};${ExtractFolder}
-TextureRootPaths=$(ExtractFolder)
+RootPaths=${RootPath};${MeshRootPath};${ExtractFolder}
+TextureRootPaths=${RootPath};${TextureRootPath};${ExtractFolder}
 TextureExtensions=.dds;.bmp;.tga
 TextureSearchPaths=
 
@@ -264,8 +263,8 @@ NiUserVersion=0
 InstallPath=
 RootPath=
 ExtractFolder=
-RootPaths=${InstallPath};${ExtractFolder}
-TextureRootPaths=$(ExtractFolder)
+RootPaths=${RootPath};${MeshRootPath};${ExtractFolder}
+TextureRootPaths=${RootPath};${TextureRootPath};${ExtractFolder}
 TextureExtensions=.tga
 TextureSearchPaths=
 
@@ -275,13 +274,24 @@ NiUserVersion=0
 InstallPath=
 RootPath=
 ExtractFolder=
-RootPaths=${InstallPath};${ExtractFolder}
-TextureRootPaths=$(ExtractFolder)
+RootPaths=${RootPath};${MeshRootPath};${ExtractFolder}
+TextureRootPaths=${RootPath};${TextureRootPath};${ExtractFolder}
 TextureExtensions=.tga
 TextureSearchPaths=${RootPath}
 DoNotReuseExistingBones=1
 TextureUseFullPath=-1
 
+[Loki]
+NiVersion=10.2.0.0
+NiUserVersion=0
+InstallPath=[HKLM\SOFTWARE\Cyanide\Loki]=@"GameDir"
+DemoPath=[HKLM\SOFTWARE\Cyanide\Loki - Demo]=@"GameDir"
+RootPaths=${InstallPath};${DemoPath};${MeshRootPath}
+TextureRootPaths=${InstallPath}\Data;${DemoPath}\Data;${TextureRootPath}
+TextureExtensions=.tga;.dds
+TextureSearchPaths=${TextureRootPaths}
+TextureUseFullPath=-1
+
 [User]
 NiVersion=20.0.0.5
 NiUserVersion=0
diff --git a/NifCommon/niutils.cpp b/NifCommon/niutils.cpp
index f1f6362..889e17f 100644
--- a/NifCommon/niutils.cpp
+++ b/NifCommon/niutils.cpp
@@ -661,9 +661,15 @@ void BuildFileNameMap(NameValueCollection & collection, const TCHAR *root, const
                   PathCombine(buffer, path, FindFileData.cFileName);
                   GetLongPathName(buffer, buffer, MAX_PATH);
                   PathRemoveExtension(FindFileData.cFileName);
-                  PathRelativePathTo(buffer2, root, FILE_ATTRIBUTE_DIRECTORY, buffer, FILE_ATTRIBUTE_NORMAL);
-                  TCHAR *p = buffer2; while (*p == '\\') ++p;
-                  collection.insert(KeyValuePair(FindFileData.cFileName, p));					
+                  if (PathRelativePathTo(buffer2, root, FILE_ATTRIBUTE_DIRECTORY, buffer, FILE_ATTRIBUTE_NORMAL))
+				  {
+					  TCHAR *p = buffer2; while (*p == '\\') ++p;
+					  collection.insert(KeyValuePair(FindFileData.cFileName, p));					
+				  }
+				  else
+				  {
+					  collection.insert(KeyValuePair(FindFileData.cFileName, buffer));
+				  }
                }
             }
          }
-- 
GitLab