mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Use proper path for autoupdater on *nix
This commit is contained in:
parent
bccc94193e
commit
d835826461
|
@ -70,7 +70,7 @@ void CAutoUpdate::FetchFile(const char *pFile, const char *pDestPath)
|
||||||
if(!pDestPath)
|
if(!pDestPath)
|
||||||
pDestPath = pFile;
|
pDestPath = pFile;
|
||||||
CFetchTask *Task = new CFetchTask;
|
CFetchTask *Task = new CFetchTask;
|
||||||
m_pFetcher->QueueAdd(Task, aBuf, pDestPath, 2, this, &CAutoUpdate::CompletionCallback, &CAutoUpdate::ProgressCallback);
|
m_pFetcher->QueueAdd(Task, aBuf, pDestPath, -2, this, &CAutoUpdate::CompletionCallback, &CAutoUpdate::ProgressCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAutoUpdate::Update()
|
void CAutoUpdate::Update()
|
||||||
|
@ -113,11 +113,15 @@ void CAutoUpdate::ReplaceClient()
|
||||||
dbg_msg("autoupdate", "Replacing " PLAT_CLIENT_EXEC);
|
dbg_msg("autoupdate", "Replacing " PLAT_CLIENT_EXEC);
|
||||||
|
|
||||||
//Replace running executable by renaming twice...
|
//Replace running executable by renaming twice...
|
||||||
m_pStorage->RemoveFile("DDNet.old", 2);
|
m_pStorage->RemoveBinaryFile("DDNet.old");
|
||||||
m_pStorage->RenameFile(PLAT_CLIENT_EXEC, "DDNet.old", 2);
|
m_pStorage->RenameBinaryFile(PLAT_CLIENT_EXEC, "DDNet.old");
|
||||||
m_pStorage->RenameFile("DDNet.tmp", PLAT_CLIENT_EXEC, 2);
|
m_pStorage->RenameBinaryFile("DDNet.tmp", PLAT_CLIENT_EXEC);
|
||||||
#if !defined(CONF_FAMILY_WINDOWS)
|
#if !defined(CONF_FAMILY_WINDOWS)
|
||||||
if (system("chmod +x " PLAT_CLIENT_EXEC))
|
char aPath[512];
|
||||||
|
m_pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aPath, sizeof aPath);
|
||||||
|
char aBuf[512];
|
||||||
|
str_format(aBuf, sizeof aBuf, "chmod +x %s", aPath);
|
||||||
|
if (system(aBuf))
|
||||||
dbg_msg("autoupdate", "Error setting client executable bit");
|
dbg_msg("autoupdate", "Error setting client executable bit");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -127,18 +131,23 @@ void CAutoUpdate::ReplaceServer()
|
||||||
dbg_msg("autoupdate", "Replacing " PLAT_SERVER_EXEC);
|
dbg_msg("autoupdate", "Replacing " PLAT_SERVER_EXEC);
|
||||||
|
|
||||||
//Replace running executable by renaming twice...
|
//Replace running executable by renaming twice...
|
||||||
m_pStorage->RemoveFile("DDNet-Server.old", 2);
|
m_pStorage->RemoveBinaryFile("DDNet-Server.old");
|
||||||
m_pStorage->RenameFile(PLAT_SERVER_EXEC, "DDNet-Server.old", 2);
|
m_pStorage->RenameBinaryFile(PLAT_SERVER_EXEC, "DDNet-Server.old");
|
||||||
m_pStorage->RenameFile("DDNet-Server.tmp", PLAT_SERVER_EXEC, 2);
|
m_pStorage->RenameBinaryFile("DDNet-Server.tmp", PLAT_SERVER_EXEC);
|
||||||
#if !defined(CONF_FAMILY_WINDOWS)
|
#if !defined(CONF_FAMILY_WINDOWS)
|
||||||
if (system("chmod +x " PLAT_SERVER_EXEC))
|
char aPath[512];
|
||||||
|
m_pStorage->GetBinaryPath(PLAT_SERVER_EXEC, aPath, sizeof aPath);
|
||||||
|
char aBuf[512];
|
||||||
|
str_format(aBuf, sizeof aBuf, "chmod +x %s", aPath);
|
||||||
|
if (system(aBuf))
|
||||||
dbg_msg("autoupdate", "Error setting server executable bit");
|
dbg_msg("autoupdate", "Error setting server executable bit");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAutoUpdate::ParseUpdate()
|
void CAutoUpdate::ParseUpdate()
|
||||||
{
|
{
|
||||||
IOHANDLE File = m_pStorage->OpenFile("update.json", IOFLAG_READ, IStorage::TYPE_ALL);
|
char aPath[512];
|
||||||
|
IOHANDLE File = m_pStorage->OpenFile(m_pStorage->GetBinaryPath("update.json", aPath, sizeof aPath), IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
if(File)
|
if(File)
|
||||||
{
|
{
|
||||||
char aBuf[4096*4];
|
char aBuf[4096*4];
|
||||||
|
@ -208,7 +217,7 @@ void CAutoUpdate::PerformUpdate()
|
||||||
}
|
}
|
||||||
while(!m_RemovedFiles.empty())
|
while(!m_RemovedFiles.empty())
|
||||||
{
|
{
|
||||||
m_pStorage->RemoveFile(m_RemovedFiles.back().c_str(), IStorage::TYPE_SAVE);
|
m_pStorage->RemoveBinaryFile(m_RemovedFiles.back().c_str());
|
||||||
m_RemovedFiles.pop_back();
|
m_RemovedFiles.pop_back();
|
||||||
}
|
}
|
||||||
if(m_ServerUpdate)
|
if(m_ServerUpdate)
|
||||||
|
|
|
@ -1032,8 +1032,7 @@ void CClient::DebugRender()
|
||||||
void CClient::Restart()
|
void CClient::Restart()
|
||||||
{
|
{
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
Storage()->GetCompletePath(2, PLAT_CLIENT_EXEC, aBuf, sizeof aBuf);
|
shell_execute(Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
||||||
shell_execute(aBuf);
|
|
||||||
Quit();
|
Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,20 +93,15 @@ void CFetcher::FetcherThread(void *pUser)
|
||||||
|
|
||||||
void CFetcher::FetchFile(CFetchTask *pTask)
|
void CFetcher::FetchFile(CFetchTask *pTask)
|
||||||
{
|
{
|
||||||
for(int i = 0; pTask->m_pDest[i] != '\0'; i++)
|
char aPath[512];
|
||||||
{
|
if(pTask->m_StorageType == -2)
|
||||||
if(pTask->m_pDest[i] == '/')
|
m_pStorage->GetBinaryPath(pTask->m_pDest, aPath, sizeof(aPath));
|
||||||
{
|
else
|
||||||
pTask->m_pDest[i] = '\0';
|
m_pStorage->GetCompletePath(pTask->m_StorageType, pTask->m_pDest, aPath, sizeof(aPath));
|
||||||
m_pStorage->CreateFolder(pTask->m_pDest, pTask->m_StorageType);
|
|
||||||
pTask->m_pDest[i] = '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char aPath[256];
|
|
||||||
m_pStorage->GetCompletePath(pTask->m_StorageType, pTask->m_pDest, aPath, sizeof(aPath));
|
|
||||||
IOHANDLE File = io_open(aPath, IOFLAG_WRITE);
|
IOHANDLE File = io_open(aPath, IOFLAG_WRITE);
|
||||||
|
|
||||||
|
char aCAFile[512];
|
||||||
|
m_pStorage->GetBinaryPath("data/ca-ddnet.pem", aCAFile, sizeof aCAFile);
|
||||||
|
|
||||||
char aErr[CURL_ERROR_SIZE];
|
char aErr[CURL_ERROR_SIZE];
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_ERRORBUFFER, aErr);
|
curl_easy_setopt(m_pHandle, CURLOPT_ERRORBUFFER, aErr);
|
||||||
|
@ -115,7 +110,7 @@ void CFetcher::FetchFile(CFetchTask *pTask)
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(m_pHandle, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_MAXREDIRS, 4L);
|
curl_easy_setopt(m_pHandle, CURLOPT_MAXREDIRS, 4L);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_FAILONERROR, 1L);
|
curl_easy_setopt(m_pHandle, CURLOPT_FAILONERROR, 1L);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_CAINFO, "data/ca-ddnet.pem");
|
curl_easy_setopt(m_pHandle, CURLOPT_CAINFO, aCAFile);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_URL, pTask->m_pUrl);
|
curl_easy_setopt(m_pHandle, CURLOPT_URL, pTask->m_pUrl);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_WRITEDATA, File);
|
curl_easy_setopt(m_pHandle, CURLOPT_WRITEDATA, File);
|
||||||
curl_easy_setopt(m_pHandle, CURLOPT_WRITEFUNCTION, &CFetcher::WriteToFile);
|
curl_easy_setopt(m_pHandle, CURLOPT_WRITEFUNCTION, &CFetcher::WriteToFile);
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
virtual bool Init();
|
virtual bool Init();
|
||||||
~CFetcher();
|
~CFetcher();
|
||||||
|
|
||||||
virtual void QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest, int StorageType = 2, void *pUser = 0, COMPFUNC pfnCompCb = 0, PROGFUNC pfnProgCb = 0);
|
virtual void QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest, int StorageType = -2, void *pUser = 0, COMPFUNC pfnCompCb = 0, PROGFUNC pfnProgCb = 0);
|
||||||
virtual void Escape(char *pBud, size_t size, const char *pStr);
|
virtual void Escape(char *pBud, size_t size, const char *pStr);
|
||||||
static void FetcherThread(void *pUser);
|
static void FetcherThread(void *pUser);
|
||||||
void FetchFile(CFetchTask *pTask);
|
void FetchFile(CFetchTask *pTask);
|
||||||
|
|
|
@ -17,7 +17,6 @@ class CFetchTask
|
||||||
|
|
||||||
char m_pUrl[256];
|
char m_pUrl[256];
|
||||||
char m_pDest[128];
|
char m_pDest[128];
|
||||||
int m_StorageType;
|
|
||||||
PROGFUNC m_pfnProgressCallback;
|
PROGFUNC m_pfnProgressCallback;
|
||||||
COMPFUNC m_pfnCompCallback;
|
COMPFUNC m_pfnCompCallback;
|
||||||
void *m_pUser;
|
void *m_pUser;
|
||||||
|
@ -27,6 +26,7 @@ class CFetchTask
|
||||||
int m_Progress;
|
int m_Progress;
|
||||||
int m_State;
|
int m_State;
|
||||||
bool m_Abort;
|
bool m_Abort;
|
||||||
|
int m_StorageType;
|
||||||
public:
|
public:
|
||||||
CFetchTask();
|
CFetchTask();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class IFetcher : public IInterface
|
||||||
MACRO_INTERFACE("fetcher", 0)
|
MACRO_INTERFACE("fetcher", 0)
|
||||||
public:
|
public:
|
||||||
virtual bool Init() = 0;
|
virtual bool Init() = 0;
|
||||||
virtual void QueueAdd(CFetchTask *pTask,const char *pUrl, const char *pDest, int StorageType = 2, void *pUser = 0, COMPFUNC pfnCompCb = 0, PROGFUNC pfnProgCb = 0) = 0;
|
virtual void QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest, int StorageType = -2, void *pUser = 0, COMPFUNC pfnCompCb = 0, PROGFUNC pfnProgCb = 0) = 0;
|
||||||
virtual void Escape(char *pBud, size_t size, const char *pStr) = 0;
|
virtual void Escape(char *pBud, size_t size, const char *pStr) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
char m_aDatadir[MAX_PATH_LENGTH];
|
char m_aDatadir[MAX_PATH_LENGTH];
|
||||||
char m_aUserdir[MAX_PATH_LENGTH];
|
char m_aUserdir[MAX_PATH_LENGTH];
|
||||||
char m_aCurrentdir[MAX_PATH_LENGTH];
|
char m_aCurrentdir[MAX_PATH_LENGTH];
|
||||||
|
char m_aBinarydir[MAX_PATH_LENGTH];
|
||||||
|
|
||||||
CStorage()
|
CStorage()
|
||||||
{
|
{
|
||||||
|
@ -163,6 +164,7 @@ public:
|
||||||
if(fs_is_dir("data/mapres"))
|
if(fs_is_dir("data/mapres"))
|
||||||
{
|
{
|
||||||
str_copy(m_aDatadir, "data", sizeof(m_aDatadir));
|
str_copy(m_aDatadir, "data", sizeof(m_aDatadir));
|
||||||
|
str_copy(m_aBinarydir, "", sizeof(m_aBinarydir));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +172,7 @@ public:
|
||||||
if(fs_is_dir(DATA_DIR "/mapres"))
|
if(fs_is_dir(DATA_DIR "/mapres"))
|
||||||
{
|
{
|
||||||
str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
|
str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
|
||||||
|
str_copy(m_aBinarydir, "", sizeof(m_aBinarydir));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +187,7 @@ public:
|
||||||
{
|
{
|
||||||
char aBaseDir[MAX_PATH_LENGTH];
|
char aBaseDir[MAX_PATH_LENGTH];
|
||||||
str_copy(aBaseDir, pArgv0, Pos+1);
|
str_copy(aBaseDir, pArgv0, Pos+1);
|
||||||
|
str_copy(m_aBinarydir, aBaseDir, sizeof(m_aBinarydir));
|
||||||
str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aBaseDir);
|
str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aBaseDir);
|
||||||
str_append(aBaseDir, "/data/mapres", sizeof(aBaseDir));
|
str_append(aBaseDir, "/data/mapres", sizeof(aBaseDir));
|
||||||
|
|
||||||
|
@ -213,6 +217,7 @@ public:
|
||||||
str_format(aBuf, sizeof(aBuf), "%s/mapres", aDirs[i]);
|
str_format(aBuf, sizeof(aBuf), "%s/mapres", aDirs[i]);
|
||||||
if(fs_is_dir(aBuf))
|
if(fs_is_dir(aBuf))
|
||||||
{
|
{
|
||||||
|
str_copy(m_aBinarydir, aDirs[i], sizeof(aDirs[i])-5);
|
||||||
str_copy(m_aDatadir, aDirs[i], sizeof(m_aDatadir));
|
str_copy(m_aDatadir, aDirs[i], sizeof(m_aDatadir));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +245,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetPath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)
|
virtual const char *GetPath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)
|
||||||
{
|
{
|
||||||
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
|
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
|
||||||
return pBuffer;
|
return pBuffer;
|
||||||
|
@ -364,6 +369,12 @@ public:
|
||||||
return !fs_remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer)));
|
return !fs_remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool RemoveBinaryFile(const char *pFilename)
|
||||||
|
{
|
||||||
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
|
return !fs_remove(GetBinaryPath(pFilename, aBuffer, sizeof(aBuffer)));
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool RenameFile(const char* pOldFilename, const char* pNewFilename, int Type)
|
virtual bool RenameFile(const char* pOldFilename, const char* pNewFilename, int Type)
|
||||||
{
|
{
|
||||||
if(Type < 0 || Type >= m_NumPaths)
|
if(Type < 0 || Type >= m_NumPaths)
|
||||||
|
@ -373,6 +384,13 @@ public:
|
||||||
return !fs_rename(GetPath(Type, pOldFilename, aOldBuffer, sizeof(aOldBuffer)), GetPath(Type, pNewFilename, aNewBuffer, sizeof (aNewBuffer)));
|
return !fs_rename(GetPath(Type, pOldFilename, aOldBuffer, sizeof(aOldBuffer)), GetPath(Type, pNewFilename, aNewBuffer, sizeof (aNewBuffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool RenameBinaryFile(const char* pOldFilename, const char* pNewFilename)
|
||||||
|
{
|
||||||
|
char aOldBuffer[MAX_PATH_LENGTH];
|
||||||
|
char aNewBuffer[MAX_PATH_LENGTH];
|
||||||
|
return !fs_rename(GetBinaryPath(pOldFilename, aOldBuffer, sizeof(aOldBuffer)), GetBinaryPath(pNewFilename, aNewBuffer, sizeof (aNewBuffer)));
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool CreateFolder(const char *pFoldername, int Type)
|
virtual bool CreateFolder(const char *pFoldername, int Type)
|
||||||
{
|
{
|
||||||
if(Type < 0 || Type >= m_NumPaths)
|
if(Type < 0 || Type >= m_NumPaths)
|
||||||
|
@ -394,6 +412,12 @@ public:
|
||||||
GetPath(Type, pDir, pBuffer, BufferSize);
|
GetPath(Type, pDir, pBuffer, BufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const char* GetBinaryPath(const char *pDir, char *pBuffer, unsigned BufferSize)
|
||||||
|
{
|
||||||
|
str_format(pBuffer, BufferSize, "%s%s%s", m_aBinarydir, !m_aBinarydir[0] ? "" : "/", pDir);
|
||||||
|
return pBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
static IStorage *Create(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments)
|
static IStorage *Create(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments)
|
||||||
{
|
{
|
||||||
CStorage *p = new CStorage();
|
CStorage *p = new CStorage();
|
||||||
|
|
|
@ -26,6 +26,10 @@ public:
|
||||||
virtual bool RenameFile(const char* pOldFilename, const char* pNewFilename, int Type) = 0;
|
virtual bool RenameFile(const char* pOldFilename, const char* pNewFilename, int Type) = 0;
|
||||||
virtual bool CreateFolder(const char *pFoldername, int Type) = 0;
|
virtual bool CreateFolder(const char *pFoldername, int Type) = 0;
|
||||||
virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
|
virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
|
||||||
|
|
||||||
|
virtual bool RemoveBinaryFile(const char *pFilename) = 0;
|
||||||
|
virtual bool RenameBinaryFile(const char* pOldFilename, const char* pNewFilename) = 0;
|
||||||
|
virtual const char* GetBinaryPath(const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern IStorage *CreateStorage(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments);
|
extern IStorage *CreateStorage(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments);
|
||||||
|
|
Loading…
Reference in a new issue