mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-30 20:52:11 +01:00
[util] Handle upper-case file extensions correctly
This commit is contained in:
parent
f4cbc9ae9d
commit
fe00919d5f
@ -985,12 +985,7 @@ namespace dxvk {
|
|||||||
if (!path.empty() && *path.rbegin() != '/')
|
if (!path.empty() && *path.rbegin() != '/')
|
||||||
path += '/';
|
path += '/';
|
||||||
|
|
||||||
std::string exeName = env::getExeName();
|
std::string exeName = env::getExeBaseName();
|
||||||
auto extp = exeName.find_last_of('.');
|
|
||||||
|
|
||||||
if (extp != std::string::npos && exeName.substr(extp + 1) == "exe")
|
|
||||||
exeName.erase(extp);
|
|
||||||
|
|
||||||
path += exeName + ".dxvk-cache";
|
path += exeName + ".dxvk-cache";
|
||||||
return str::tows(path.c_str());
|
return str::tows(path.c_str());
|
||||||
}
|
}
|
||||||
|
@ -100,12 +100,7 @@ namespace dxvk {
|
|||||||
if (!path.empty() && *path.rbegin() != '/')
|
if (!path.empty() && *path.rbegin() != '/')
|
||||||
path += '/';
|
path += '/';
|
||||||
|
|
||||||
std::string exeName = env::getExeName();
|
std::string exeName = env::getExeBaseName();
|
||||||
auto extp = exeName.find_last_of('.');
|
|
||||||
|
|
||||||
if (extp != std::string::npos && exeName.substr(extp + 1) == "exe")
|
|
||||||
exeName.erase(extp);
|
|
||||||
|
|
||||||
path += exeName + "_" + base;
|
path += exeName + "_" + base;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <numeric>
|
||||||
|
|
||||||
#include "util_env.h"
|
#include "util_env.h"
|
||||||
|
|
||||||
#include "./com/com_include.h"
|
#include "./com/com_include.h"
|
||||||
@ -15,6 +17,23 @@ namespace dxvk::env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t matchFileExtension(const std::string& name, const char* ext) {
|
||||||
|
auto pos = name.find_last_of('.');
|
||||||
|
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
return pos;
|
||||||
|
|
||||||
|
bool matches = std::accumulate(name.begin() + pos + 1, name.end(), true,
|
||||||
|
[&ext] (bool current, char a) {
|
||||||
|
if (a >= 'A' && a <= 'Z')
|
||||||
|
a += 'a' - 'A';
|
||||||
|
return current && *ext && a == *(ext++);
|
||||||
|
});
|
||||||
|
|
||||||
|
return matches ? pos : std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getExeName() {
|
std::string getExeName() {
|
||||||
std::string fullPath = getExePath();
|
std::string fullPath = getExePath();
|
||||||
auto n = fullPath.find_last_of('\\');
|
auto n = fullPath.find_last_of('\\');
|
||||||
@ -25,6 +44,17 @@ namespace dxvk::env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string getExeBaseName() {
|
||||||
|
auto exeName = getExeName();
|
||||||
|
auto extp = matchFileExtension(exeName, "exe");
|
||||||
|
|
||||||
|
if (extp != std::string::npos)
|
||||||
|
exeName.erase(extp);
|
||||||
|
|
||||||
|
return exeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getExePath() {
|
std::string getExePath() {
|
||||||
std::vector<WCHAR> exePath;
|
std::vector<WCHAR> exePath;
|
||||||
exePath.resize(MAX_PATH + 1);
|
exePath.resize(MAX_PATH + 1);
|
||||||
|
@ -15,6 +15,16 @@ namespace dxvk::env {
|
|||||||
*/
|
*/
|
||||||
std::string getEnvVar(const char* name);
|
std::string getEnvVar(const char* name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Checks whether a file name has a given extension
|
||||||
|
*
|
||||||
|
* \param [in] name File name
|
||||||
|
* \param [in] ext Extension to match, in lowercase letters
|
||||||
|
* \returns Position of the extension within the file name, or
|
||||||
|
* \c std::string::npos if the file has a different extension
|
||||||
|
*/
|
||||||
|
size_t matchFileExtension(const std::string& name, const char* ext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Gets the executable name
|
* \brief Gets the executable name
|
||||||
*
|
*
|
||||||
@ -25,6 +35,14 @@ namespace dxvk::env {
|
|||||||
*/
|
*/
|
||||||
std::string getExeName();
|
std::string getExeName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Gets the executable name without extension
|
||||||
|
*
|
||||||
|
* Same as \ref getExeName but without the file extension.
|
||||||
|
* \returns Executable name
|
||||||
|
*/
|
||||||
|
std::string getExeBaseName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Gets full path to executable
|
* \brief Gets full path to executable
|
||||||
* \returns Path to executable
|
* \returns Path to executable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user