summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_utils.h4
-rwxr-xr-xplugins/Msg_Export/src/utils.cpp2
-rw-r--r--plugins/PluginUpdater/pu_stub/pu_stub.cpp8
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp2
-rw-r--r--plugins/PluginUpdater/src/stdafx.h2
-rw-r--r--src/mir_app/src/database.cpp9
-rw-r--r--src/mir_app/src/profilemanager.cpp9
-rw-r--r--src/mir_core/src/path.cpp32
8 files changed, 35 insertions, 33 deletions
diff --git a/include/m_utils.h b/include/m_utils.h
index f7bf4cb80d..6da1d844b7 100644
--- a/include/m_utils.h
+++ b/include/m_utils.h
@@ -291,8 +291,8 @@ EXTERN_C MIR_CORE_DLL(int) CreateDirectoryTreeW(const wchar_t *pwszDir);
// Creates all subdirectories required to create a file with the file name given
// Returns 0 on success or an error code otherwise
-EXTERN_C MIR_CORE_DLL(void) CreatePathToFile(char *wszFilePath);
-EXTERN_C MIR_CORE_DLL(void) CreatePathToFileW(wchar_t *wszFilePath);
+EXTERN_C MIR_CORE_DLL(int) CreatePathToFile(const char *wszFilePath);
+EXTERN_C MIR_CORE_DLL(int) CreatePathToFileW(const wchar_t *wszFilePath);
/////////////////////////////////////////////////////////////////////////////////////////
// Checks if a file name is absolute or not
diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp
index 87e4f7b980..27b12dd673 100755
--- a/plugins/Msg_Export/src/utils.cpp
+++ b/plugins/Msg_Export/src/utils.cpp
@@ -1053,7 +1053,7 @@ HANDLE openCreateFile(wstring sFilePath)
if (hFile == INVALID_HANDLE_VALUE) {
// this might be because the path isent created
// so we will try to create it
- if (!CreateDirectoryTreeW(sFilePath.c_str()))
+ if (!CreatePathToFileW(sFilePath.c_str()))
hFile = CreateFile(sFilePath.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
}
diff --git a/plugins/PluginUpdater/pu_stub/pu_stub.cpp b/plugins/PluginUpdater/pu_stub/pu_stub.cpp
index 2a42d51c4c..fb4cd24462 100644
--- a/plugins/PluginUpdater/pu_stub/pu_stub.cpp
+++ b/plugins/PluginUpdater/pu_stub/pu_stub.cpp
@@ -28,7 +28,7 @@ void log(const wchar_t *tszFormat, ...)
#endif
}
-int CreateDirectoryTreeW(const WCHAR* szDir)
+int CreateDirectoryTreeW(const wchar_t* szDir)
{
wchar_t szTestDir[MAX_PATH];
lstrcpynW(szTestDir, szDir, MAX_PATH);
@@ -37,7 +37,7 @@ int CreateDirectoryTreeW(const WCHAR* szDir)
if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
return 0;
- WCHAR *pszLastBackslash = wcsrchr(szTestDir, '\\');
+ wchar_t *pszLastBackslash = wcsrchr(szTestDir, '\\');
if (pszLastBackslash == nullptr)
return 0;
@@ -47,9 +47,9 @@ int CreateDirectoryTreeW(const WCHAR* szDir)
return (CreateDirectoryW(szTestDir, nullptr) == 0) ? GetLastError() : 0;
}
-void CreatePathToFileW(WCHAR* wszFilePath)
+void CreatePathToFileW(wchar_t *wszFilePath)
{
- WCHAR* pszLastBackslash = wcsrchr(wszFilePath, '\\');
+ wchar_t* pszLastBackslash = wcsrchr(wszFilePath, '\\');
if (pszLastBackslash == nullptr)
return;
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp
index bf96b77579..e0c47e2680 100644
--- a/plugins/PluginUpdater/src/Utils.cpp
+++ b/plugins/PluginUpdater/src/Utils.cpp
@@ -583,7 +583,7 @@ int SafeCreateDirectory(const wchar_t *pFolder)
return TransactPipe(4, pFolder, nullptr);
}
-int SafeCreateFilePath(wchar_t *pFolder)
+int SafeCreateFilePath(const wchar_t *pFolder)
{
if (hPipe == nullptr) {
CreatePathToFileW(pFolder);
diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h
index 8e59245d55..b05403facf 100644
--- a/plugins/PluginUpdater/src/stdafx.h
+++ b/plugins/PluginUpdater/src/stdafx.h
@@ -249,6 +249,6 @@ int SafeCreateDirectory(const wchar_t *ptszDirName);
int SafeCopyFile(const wchar_t *ptszSrc, const wchar_t *ptszDst);
int SafeMoveFile(const wchar_t *ptszSrc, const wchar_t *ptszDst);
int SafeDeleteFile(const wchar_t *ptszSrc);
-int SafeCreateFilePath(wchar_t *pFolder);
+int SafeCreateFilePath(const wchar_t *pFolder);
char *StrToLower(char *str);
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)