Extract method IStorage::GetBinaryPathAbsolute

This commit is contained in:
Robert Müller 2023-01-02 15:22:27 +01:00
parent a0df1ebfc0
commit 6e28ca6fe4
3 changed files with 21 additions and 15 deletions

View file

@ -4906,22 +4906,8 @@ int CClient::UdpConnectivity(int NetType)
#if defined(CONF_FAMILY_WINDOWS)
void CClient::ShellRegister()
{
char aBinaryPath[IO_MAX_PATH_LENGTH];
Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBinaryPath, sizeof(aBinaryPath));
char aFullPath[IO_MAX_PATH_LENGTH];
if(fs_is_relative_path(aBinaryPath))
{
if(fs_getcwd(aFullPath, sizeof(aFullPath)))
{
str_append(aFullPath, "/", sizeof(aFullPath));
str_append(aFullPath, aBinaryPath, sizeof(aFullPath));
}
else
aFullPath[0] = '\0';
}
else
str_copy(aFullPath, aBinaryPath);
Storage()->GetBinaryPathAbsolute(PLAT_CLIENT_EXEC, aFullPath, sizeof(aFullPath));
if(!aFullPath[0])
{
dbg_msg("client", "Failed to register protocol and file extensions: could not determine absolute path");

View file

@ -677,6 +677,25 @@ public:
return pBuffer;
}
const char *GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize) override
{
char aBinaryPath[IO_MAX_PATH_LENGTH];
GetBinaryPath(PLAT_CLIENT_EXEC, aBinaryPath, sizeof(aBinaryPath));
if(fs_is_relative_path(aBinaryPath))
{
if(fs_getcwd(pBuffer, BufferSize))
{
str_append(pBuffer, "/", BufferSize);
str_append(pBuffer, aBinaryPath, BufferSize);
}
else
pBuffer[0] = '\0';
}
else
str_copy(pBuffer, aBinaryPath, BufferSize);
return pBuffer;
}
static IStorage *Create(int StorageType, int NumArgs, const char **ppArguments)
{
CStorage *pStorage = new CStorage();

View file

@ -57,6 +57,7 @@ public:
virtual bool RemoveBinaryFile(const char *pFilename) = 0;
virtual bool RenameBinaryFile(const char *pOldFilename, const char *pNewFilename) = 0;
virtual const char *GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
virtual const char *GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize);
static const char *FormatTmpPath(char *aBuf, unsigned BufSize, const char *pPath);