texturev: Added Linux file association.
This commit is contained in:
parent
1872250574
commit
8cf12291f4
@ -444,20 +444,6 @@ void help(const char* _error = NULL)
|
||||
);
|
||||
}
|
||||
|
||||
std::string replaceAll(const std::string& _str, const char* _from, const char* _to)
|
||||
{
|
||||
std::string str = _str;
|
||||
size_t startPos = 0;
|
||||
const size_t fromLen = strlen(_from);
|
||||
const size_t toLen = strlen(_to);
|
||||
while ( (startPos = str.find(_from, startPos) ) != std::string::npos)
|
||||
{
|
||||
str.replace(startPos, fromLen, _to);
|
||||
startPos += toLen;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void associate()
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
@ -466,7 +452,7 @@ void associate()
|
||||
char exec[MAX_PATH];
|
||||
GetModuleFileNameA(GetModuleHandleA(NULL), exec, MAX_PATH);
|
||||
|
||||
std::string strExec = replaceAll(exec, "\\", "\\\\");
|
||||
std::string strExec = bx::replaceAll(exec, "\\", "\\\\");
|
||||
|
||||
std::string value;
|
||||
bx::stringPrintf(value, "@=\"\\\"%s\\\" \\\"%%1\\\"\"\r\n\r\n", strExec.c_str() );
|
||||
@ -513,6 +499,34 @@ void associate()
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif BX_PLATFORM_LINUX
|
||||
std::string str;
|
||||
str += "#/bin/bash\n\n";
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
|
||||
{
|
||||
const char* ext = s_supportedExt[ii];
|
||||
bx::stringPrintf(str, "xdg-mime default texturev.desktop image/%s\n", ext);
|
||||
}
|
||||
|
||||
str += "\n";
|
||||
|
||||
bx::CrtFileWriter writer;
|
||||
bx::Error err;
|
||||
if (bx::open(&writer, "/tmp/texturev.sh", false, &err) )
|
||||
{
|
||||
bx::write(&writer, str.c_str(), str.length(), &err);
|
||||
bx::close(&writer);
|
||||
|
||||
if (err.isOk() )
|
||||
{
|
||||
bx::ProcessReader reader;
|
||||
if (bx::open(&reader, "/bin/bash /tmp/texturev.sh", &err) )
|
||||
{
|
||||
bx::close(&reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user