|
16 | 16 |
|
17 | 17 | namespace
|
18 | 18 | {
|
19 |
| - |
20 |
| - struct MatchPathSeparator |
21 |
| - { |
22 |
| - bool operator()(char ch) const { return ch == '\\' || ch == '/'; } |
23 |
| - }; |
24 |
| - |
25 |
| - std::string getBasename(std::string const& pathname) |
26 |
| - { |
27 |
| - return std::string( |
28 |
| - std::find_if(pathname.rbegin(), pathname.rend(), MatchPathSeparator()).base(), pathname.end()); |
29 |
| - } |
30 |
| - |
31 |
| -} |
32 |
| - |
33 |
| -bool changeExtension(std::string& path, std::string_view ext) |
34 |
| -{ |
35 |
| - std::string::size_type pos = path.rfind('.'); |
36 |
| - if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0) |
| 19 | + bool changeExtension(std::string& path, std::string_view ext) |
37 | 20 | {
|
38 |
| - path.replace(pos, path.length(), ext); |
39 |
| - return true; |
| 21 | + std::string::size_type pos = path.rfind('.'); |
| 22 | + if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0) |
| 23 | + { |
| 24 | + path.replace(pos, path.length(), ext); |
| 25 | + return true; |
| 26 | + } |
| 27 | + return false; |
40 | 28 | }
|
41 |
| - return false; |
42 | 29 | }
|
43 | 30 |
|
44 | 31 | bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path)
|
@@ -106,15 +93,16 @@ std::string Misc::ResourceHelpers::correctResourcePath(
|
106 | 93 | // fall back to a resource in the top level directory if it exists
|
107 | 94 | std::string fallback{ topLevelDirectories.front() };
|
108 | 95 | fallback += '\\';
|
109 |
| - fallback += getBasename(correctedPath); |
| 96 | + fallback += Misc::getFileName(correctedPath); |
| 97 | + |
110 | 98 | if (vfs->exists(fallback))
|
111 | 99 | return fallback;
|
112 | 100 |
|
113 | 101 | if (changedToDds)
|
114 | 102 | {
|
115 | 103 | fallback = topLevelDirectories.front();
|
116 | 104 | fallback += '\\';
|
117 |
| - fallback += getBasename(origExt); |
| 105 | + fallback += Misc::getFileName(origExt); |
118 | 106 | if (vfs->exists(fallback))
|
119 | 107 | return fallback;
|
120 | 108 | }
|
@@ -154,22 +142,23 @@ std::string Misc::ResourceHelpers::correctBookartPath(
|
154 | 142 | return image;
|
155 | 143 | }
|
156 | 144 |
|
157 |
| -std::string Misc::ResourceHelpers::correctActorModelPath(std::string_view resPath, const VFS::Manager* vfs) |
| 145 | +VFS::Path::Normalized Misc::ResourceHelpers::correctActorModelPath( |
| 146 | + VFS::Path::NormalizedView resPath, const VFS::Manager* vfs) |
158 | 147 | {
|
159 |
| - std::string mdlname(resPath); |
160 |
| - std::string::size_type p = mdlname.find_last_of("/\\"); |
| 148 | + std::string mdlname(resPath.value()); |
| 149 | + std::string::size_type p = mdlname.find_last_of('/'); |
161 | 150 | if (p != std::string::npos)
|
162 |
| - mdlname.insert(mdlname.begin() + p + 1, 'x'); |
| 151 | + mdlname.insert(mdlname.begin() + static_cast<std::string::difference_type>(p) + 1, 'x'); |
163 | 152 | else
|
164 | 153 | mdlname.insert(mdlname.begin(), 'x');
|
165 |
| - std::string kfname = mdlname; |
166 |
| - if (Misc::StringUtils::ciEndsWith(kfname, ".nif")) |
167 |
| - kfname.replace(kfname.size() - 4, 4, ".kf"); |
| 154 | + |
| 155 | + VFS::Path::Normalized kfname(mdlname); |
| 156 | + if (Misc::getFileExtension(mdlname) == "nif") |
| 157 | + kfname.changeExtension("kf"); |
168 | 158 |
|
169 | 159 | if (!vfs->exists(kfname))
|
170 |
| - { |
171 |
| - return std::string(resPath); |
172 |
| - } |
| 160 | + return VFS::Path::Normalized(resPath); |
| 161 | + |
173 | 162 | return mdlname;
|
174 | 163 | }
|
175 | 164 |
|
|
0 commit comments