From 5004a5850ffc5157661b331abb4649237c31efdb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 14 Aug 2018 20:24:31 +0300 Subject: fix for CreatePathToFileW prototype (missing const specifier) --- src/mir_app/src/database.cpp | 9 ++++----- src/mir_app/src/profilemanager.cpp | 9 ++++++--- src/mir_core/src/path.cpp | 32 ++++++++++++++++---------------- 3 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp index 4c41fa8f4b..58e731c567 100644 --- a/src/mir_app/src/database.cpp +++ b/src/mir_app/src/database.cpp @@ -410,18 +410,17 @@ int tryOpenDatabase(const wchar_t *tszProfile) // enumerate all database plugins static int tryCreateDatabase(const wchar_t *ptszProfile) { - wchar_t *tszProfile = NEWWSTR_ALLOCA(ptszProfile); - CreatePathToFileW(tszProfile); + CreatePathToFileW(ptszProfile); for (auto &p : arDbPlugins) { - int err = p->makeDatabase(tszProfile); + int err = p->makeDatabase(ptszProfile); if (err == ERROR_SUCCESS) { g_bDbCreated = true; - MDatabaseCommon *pDb = p->Load(tszProfile, FALSE); + MDatabaseCommon *pDb = p->Load(ptszProfile, FALSE); if (pDb == nullptr) // driver was found but smth went wrong return EGROKPRF_CANTREAD; - fillProfileName(tszProfile); + fillProfileName(ptszProfile); currDblink = p; db_setCurrent(currDb = pDb); return 0; diff --git a/src/mir_app/src/profilemanager.cpp b/src/mir_app/src/profilemanager.cpp index c1d4b7e47c..8d287abc17 100644 --- a/src/mir_app/src/profilemanager.cpp +++ b/src/mir_app/src/profilemanager.cpp @@ -82,13 +82,16 @@ class CCreateProfileDlg : public CDlgBase CCtrlButton &m_btnOk; PROFILEMANAGERDATA *m_pd; - int CreateProfile(wchar_t *profile, DATABASELINK *link) + int CreateProfile(const wchar_t *profile, DATABASELINK *link) { wchar_t buf[256]; int err = 0; + // check if the file already exists - wchar_t *file = wcsrchr(profile, '\\'); - if (file) file++; + const wchar_t *file = wcsrchr(profile, '\\'); + if (file) + file++; + if (_waccess(profile, 0) == 0) { // file already exists! mir_snwprintf(buf, diff --git a/src/mir_core/src/path.cpp b/src/mir_core/src/path.cpp index b502cd3830..5809593ff9 100644 --- a/src/mir_core/src/path.cpp +++ b/src/mir_core/src/path.cpp @@ -81,18 +81,18 @@ MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, const char *base) return GetFullPathNameA(buf, _countof(buf), pOut, nullptr); } -MIR_CORE_DLL(void) CreatePathToFile(char *szFilePath) +MIR_CORE_DLL(int) CreatePathToFile(const char *szFilePath) { if (szFilePath == nullptr) - return; + return ERROR_INVALID_PARAMETER; - char *pszLastBackslash = strrchr(szFilePath, '\\'); - if (pszLastBackslash == nullptr) - return; + char *buf = NEWSTR_ALLOCA(szFilePath); + char *p = strrchr(buf, '\\'); + if (p == nullptr) + return 0; - *pszLastBackslash = '\0'; - CreateDirectoryTree(szFilePath); - *pszLastBackslash = '\\'; + *p = '\0'; + return CreateDirectoryTree(buf); } MIR_CORE_DLL(int) CreateDirectoryTree(const char *szDir) @@ -171,18 +171,18 @@ MIR_CORE_DLL(int) PathToAbsoluteW(const WCHAR *pSrc, WCHAR *pOut, const WCHAR *b return GetFullPathName(buf, MAX_PATH, pOut, nullptr); } -MIR_CORE_DLL(void) CreatePathToFileW(WCHAR *wszFilePath) +MIR_CORE_DLL(int) CreatePathToFileW(const wchar_t *wszFilePath) { if (wszFilePath == nullptr) - return; + return ERROR_INVALID_PARAMETER; - WCHAR *pszLastBackslash = wcsrchr(wszFilePath, '\\'); - if (pszLastBackslash == nullptr) - return; + wchar_t *buf = NEWWSTR_ALLOCA(wszFilePath); + wchar_t *p = wcsrchr(buf, '\\'); + if (p == nullptr) + return 0; - *pszLastBackslash = '\0'; - CreateDirectoryTreeW(wszFilePath); - *pszLastBackslash = '\\'; + *p = '\0'; + return CreateDirectoryTreeW(buf); } MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR *szDir) -- cgit v1.2.3