summaryrefslogtreecommitdiff
path: root/plugins/Folders/src/folderItem.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-08-07 12:10:19 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-08-07 12:10:19 +0000
commit52a0c6e6efb7014b87552097c13ceea6175ce377 (patch)
treedc4d3e62d27d6538672c9e80166ed945cf659a2f /plugins/Folders/src/folderItem.cpp
parent97ecd2b560357a1c7756d7b93d0b820f63071080 (diff)
folders -> TCHAR
git-svn-id: http://svn.miranda-ng.org/main/trunk@1389 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Folders/src/folderItem.cpp')
-rw-r--r--plugins/Folders/src/folderItem.cpp227
1 files changed, 55 insertions, 172 deletions
diff --git a/plugins/Folders/src/folderItem.cpp b/plugins/Folders/src/folderItem.cpp
index cf58e5feac..fa40d855c9 100644
--- a/plugins/Folders/src/folderItem.cpp
+++ b/plugins/Folders/src/folderItem.cpp
@@ -22,78 +22,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
#include "services.h"
-CFolderItem::CFolderItem(const char *sectionName, const char *name, const char *format, const DWORD flags)
+CFolderItem::CFolderItem(const char *sectionName, const char *name, const TCHAR *format, const DWORD flags)
{
- strncpy(szSection, sectionName, sizeof(szSection));
- szFormat = NULL;
- szOldFormat = NULL;
- szFormatW = NULL;
- szOldFormatW = NULL;
- strncpy(szName, name, sizeof(szName));
- this->flags = flags;
+ m_szSection = mir_strdup(sectionName);
+ m_szName = mir_strdup(name);
+ m_tszFormat = NULL;
+ m_tszOldFormat = NULL;
+ m_flags = flags;
GetDataFromDatabase(format);
FolderCreateDirectory();
}
-void MyFree(void *data)
-{
- if (data)
- {
- free(data);
- }
-}
-
CFolderItem::~CFolderItem()
{
-// WriteDataToDatabase();
- if (IsUnicode())
- {
- MyFree(szFormatW);
- MyFree(szOldFormatW);
- }
- else{
- MyFree(szFormat);
- MyFree(szOldFormat);
- }
-}
-
-const char *CFolderItem::GetSection() const
-{
- return szSection;
-}
-
-const char *CFolderItem::GetName() const
-{
- return szName;
-}
-
-const char *CFolderItem::GetFormat() const
-{
- return szFormat;
-}
-
-const wchar_t *CFolderItem::GetFormatW() const
-{
- return szFormatW;
+ mir_free(m_szSection);
+ mir_free(m_szName);
+ mir_free(m_tszFormat);
+ mir_free(m_tszOldFormat);
}
-void CFolderItem::SetFormat(const char *newFormat)
+void CFolderItem::SetFormat(const TCHAR *newFormat)
{
- MyFree(szOldFormat);
- szOldFormat = szFormat;
- szFormat = _strdup((strlen(newFormat) > 0) ? newFormat : MIRANDA_PATH);
-}
-
-void CFolderItem::SetFormatW(const wchar_t *newFormat)
-{
- MyFree(szOldFormatW);
- szOldFormatW = szFormatW;
- szFormatW = _wcsdup((wcslen(newFormat) > 0) ? newFormat : MIRANDA_PATHW);
-}
-
-int CFolderItem::IsUnicode() const
-{
- return (flags & FF_UNICODE);
+ mir_free(m_tszOldFormat);
+ m_tszOldFormat = m_tszFormat;
+ m_tszFormat = mir_tstrdup( *newFormat ? newFormat : MIRANDA_PATHT);
}
int CFolderItem::IsEqual(const CFolderItem *other)
@@ -103,12 +55,12 @@ int CFolderItem::IsEqual(const CFolderItem *other)
int CFolderItem::IsEqual(const char *section, const char *name)
{
- return ((strcmp(szName, name) == 0) && (strcmp(szSection, section) == 0));
+ return ((strcmp(m_szName, name) == 0) && (strcmp(m_szSection, section) == 0));
}
int CFolderItem::IsEqualTranslated(const char *trSection, const char *trName)
{
- return ((strcmp(Translate(szName), trName) == 0) && (strcmp(Translate(szSection), trSection) == 0));
+ return ((strcmp(Translate(m_szName), trName) == 0) && (strcmp(Translate(m_szSection), trSection) == 0));
}
int CFolderItem::operator ==(const CFolderItem *other)
@@ -116,135 +68,66 @@ int CFolderItem::operator ==(const CFolderItem *other)
return IsEqual(other);
}
-void CFolderItem::Expand(char *buffer, int size)
+void CFolderItem::Expand(TCHAR *buffer, int size)
{
- if (IsUnicode())
- {
- ExpandPathW((wchar_t *) buffer, szFormatW, size);
- }
- else{
- ExpandPath(buffer, szFormat, size);
- }
+ ExpandPath(buffer, m_tszFormat, size);
}
void CFolderItem::Save()
{
- int res = FolderDeleteOldDirectory(FALSE);
- //FolderCreateDirectory(!res);
+ FolderDeleteOldDirectory(FALSE);
FolderCreateDirectory(FALSE);
WriteDataToDatabase();
}
int CFolderItem::FolderCreateDirectory(int showFolder)
{
- int res = FOLDER_SUCCESS;
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- if (szFormatW)
- {
- ExpandPathW(buffer, szFormatW, MAX_FOLDER_SIZE);
- CreateDirectories(buffer);
- if (showFolder)
- {
- ShellExecuteW(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
- }
- res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
- }
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- if (szFormat)
- {
- ExpandPath(buffer, szFormat, MAX_FOLDER_SIZE);
- CreateDirectories(buffer);
- if (showFolder)
- {
- ShellExecuteA(NULL, "explore", buffer, NULL, NULL, SW_SHOW);
- }
- res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
- }
- }
- return res;
+ if (m_tszFormat == NULL)
+ return FOLDER_SUCCESS;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ ExpandPath(buffer, m_tszFormat, SIZEOF(buffer));
+ CreateDirectoryTreeT(buffer);
+ if (showFolder)
+ ShellExecute(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
+
+ return (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
}
int CFolderItem::FolderDeleteOldDirectory(int showFolder)
{
- int res = FOLDER_SUCCESS;
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- if (szOldFormatW)
- {
- if (wcscmp(szFormatW, szOldFormatW) == 0) //format wasn't changed
- {
- return res;
- }
- ExpandPathW(buffer, szOldFormatW, MAX_FOLDER_SIZE);
- RemoveDirectories(buffer);
- res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
- if ((res == FOLDER_FAILURE) && (showFolder))
- {
- ShellExecuteW(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
- }
- }
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- if (szOldFormat)
- {
- if (strcmp(szFormat, szOldFormat) == 0) //format wasn't changed
- {
- return res;
- }
- ExpandPath(buffer, szOldFormat, MAX_FOLDER_SIZE);
- RemoveDirectories(buffer);
- res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
- if ((res == FOLDER_FAILURE) && (showFolder))
- {
- ShellExecuteA(NULL, "explore", buffer, NULL, NULL, SW_SHOW);
- }
- }
- }
+ if ( !m_tszOldFormat)
+ return FOLDER_SUCCESS;
+
+ if ( !_tcscmp(m_tszFormat, m_tszOldFormat)) //format wasn't changed
+ return FOLDER_SUCCESS;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ ExpandPath(buffer, m_tszOldFormat, SIZEOF(buffer));
+ RemoveDirectories(buffer);
+ int res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
+ if ((res == FOLDER_FAILURE) && (showFolder))
+ ShellExecute(NULL, _T("explore"), buffer, NULL, NULL, SW_SHOW);
return res;
}
-void CFolderItem::GetDataFromDatabase(const char *szNotFound)
+void CFolderItem::GetDataFromDatabase(const TCHAR *szNotFound)
{
char name[256];
- strcpy(name, szSection);
- strcat(name, szName);
-
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetStringFromDatabase(name, (const wchar_t *) szNotFound, buffer, MAX_FOLDER_SIZE);
- SetFormatW(buffer);
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- GetStringFromDatabase(name, szNotFound, buffer, MAX_FOLDER_SIZE);
- SetFormat(buffer);
- }
+ strcpy_s(name, sizeof(name), m_szSection);
+ strcat_s(name, sizeof(name), m_szName);
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetStringFromDatabase(name, szNotFound, buffer, SIZEOF(buffer));
+ SetFormat(buffer);
}
void CFolderItem::WriteDataToDatabase()
{
- char name[256];
- strcpy(name, szSection);
- strcat(name, szName);
-
- if (IsUnicode())
- {
- if (szFormatW)
- {
- WriteStringToDatabase(name, szFormatW);
- }
- }
- else{
- if (szFormat)
- {
- WriteStringToDatabase(name, szFormat);
- }
- }
-} \ No newline at end of file
+ char szSettingName[256];
+ strcpy_s(szSettingName, sizeof(szSettingName), m_szSection);
+ strcat_s(szSettingName, sizeof(szSettingName), m_szName);
+
+ if (m_tszFormat)
+ db_set_ts(NULL, ModuleName, szSettingName, m_tszFormat);
+}