diff options
author | George Hazan <ghazan@miranda.im> | 2022-03-15 21:38:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-03-15 21:38:40 +0300 |
commit | f6eec51f101fffaa1809dcd92727e46ee38a1a12 (patch) | |
tree | e20d3cdd0bf9c0865396ec8aca6e83ea26ff857b /src/mir_core | |
parent | 25e7342fbc71b4cd2f31432cac614150d2ceb076 (diff) |
file iterators implementation for Windows API + major code cleaning in Profile Manager window
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/mir_core.vcxproj | 3 | ||||
-rw-r--r-- | src/mir_core/mir_core.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/mir_core/src/Windows/fileutil.cpp | 78 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 18 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 18 |
5 files changed, 120 insertions, 0 deletions
diff --git a/src/mir_core/mir_core.vcxproj b/src/mir_core/mir_core.vcxproj index f0466fabab..c748d431ce 100644 --- a/src/mir_core/mir_core.vcxproj +++ b/src/mir_core/mir_core.vcxproj @@ -140,6 +140,9 @@ <ClCompile Include="src\Windows\CTimer.cpp">
<PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
</ClCompile>
+ <ClCompile Include="src\Windows\fileutil.cpp">
+ <PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
+ </ClCompile>
<ClCompile Include="src\Windows\hyperlink.cpp">
<PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
</ClCompile>
diff --git a/src/mir_core/mir_core.vcxproj.filters b/src/mir_core/mir_core.vcxproj.filters index 92df544754..c6fbd4c6a1 100644 --- a/src/mir_core/mir_core.vcxproj.filters +++ b/src/mir_core/mir_core.vcxproj.filters @@ -176,6 +176,9 @@ <ClCompile Include="src\Windows\winver.cpp">
<Filter>Source Files\Windows</Filter>
</ClCompile>
+ <ClCompile Include="src\Windows\fileutil.cpp">
+ <Filter>Source Files\Windows</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\miranda.h">
diff --git a/src/mir_core/src/Windows/fileutil.cpp b/src/mir_core/src/Windows/fileutil.cpp new file mode 100644 index 0000000000..2522cc7cbe --- /dev/null +++ b/src/mir_core/src/Windows/fileutil.cpp @@ -0,0 +1,78 @@ +/* +Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../stdafx.h" + +///////////////////////////////////////////////////////////////////////////////////////// + +MFilePath::MFileIterator::iterator MFilePath::MFileIterator::iterator::operator++() +{ + if (ptr != nullptr) { + if (::FindNextFileW(ptr->m_hFind, &ptr->m_data) == 0) { + ::FindClose(ptr->m_hFind); ptr->m_hFind = INVALID_HANDLE_VALUE; + ptr = nullptr; + } + } + return *this; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MFilePath::MFileIterator::MFileIterator(const wchar_t *pwszPath) +{ + if (pwszPath != nullptr) + m_hFind = ::FindFirstFileW(pwszPath, &m_data); +} + +MFilePath::MFileIterator::~MFileIterator() +{ + if (m_hFind != INVALID_HANDLE_VALUE) + ::FindClose(m_hFind); +} + +MFilePath::MFileIterator::iterator MFilePath::MFileIterator::begin() +{ + if (m_hFind == INVALID_HANDLE_VALUE) + return MFilePath::MFileIterator::iterator(nullptr); + + return MFilePath::MFileIterator::iterator(this); +} + +bool MFilePath::MFileIterator::isDir() const +{ + if (m_hFind == INVALID_HANDLE_VALUE) + return false; + + return (m_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +bool MFilePath::isExist() const +{ + return _waccess(c_str(), 0) == 0; +} + +bool MFilePath::move(const wchar_t *pwszDest) +{ + return MoveFileW(c_str(), pwszDest) != 0; +} + +MFilePath::MFileIterator MFilePath::search() +{ + return MFileIterator(c_str()); +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 021c8d309b..aff924ba4a 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1515,3 +1515,21 @@ db_copy_module @1736 ?db_is_module_empty@@YG_NIPBD@Z @1737 NONAME
?AddOption@CCtrlTreeOpts@@QAEXPB_W0AA_N@Z @1738 NONAME
?AddOption@CCtrlTreeOpts@@QAEXPB_W0AAII@Z @1739 NONAME
+??0MFileIterator@MFilePath@@QAE@PB_W@Z @1740 NONAME
+??0MFilePath@@QAE@$$QAV0@@Z @1741 NONAME
+??0MFilePath@@QAE@ABV0@@Z @1742 NONAME
+??0MFilePath@@QAE@PB_W@Z @1743 NONAME
+??0MFilePath@@QAE@XZ @1744 NONAME
+??1MFileIterator@MFilePath@@QAE@XZ @1745 NONAME
+??1MFilePath@@QAE@XZ @1746 NONAME
+??4MFileIterator@MFilePath@@QAEAAV01@ABV01@@Z @1747 NONAME
+??4MFilePath@@QAEAAV0@$$QAV0@@Z @1748 NONAME
+??4MFilePath@@QAEAAV0@ABV0@@Z @1749 NONAME
+?begin@MFileIterator@MFilePath@@QAE?AViterator@12@XZ @1750 NONAME
+?end@MFileIterator@MFilePath@@QAE?AViterator@12@XZ @1751 NONAME
+?getPath@MFileIterator@MFilePath@@QBEPB_WXZ @1752 NONAME
+?isDir@MFileIterator@MFilePath@@QBE_NXZ @1753 NONAME
+?isExist@MFilePath@@QBE_NXZ @1754 NONAME
+?move@MFilePath@@QAE_NPB_W@Z @1755 NONAME
+?search@MFilePath@@QAE?AVMFileIterator@1@XZ @1756 NONAME
+??Eiterator@MFileIterator@MFilePath@@QAE?AV012@XZ @1757 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 7a4fc63354..fb1e14fda7 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1515,3 +1515,21 @@ db_copy_module @1736 ?db_is_module_empty@@YA_NIPEBD@Z @1737 NONAME
?AddOption@CCtrlTreeOpts@@QEAAXPEB_W0AEA_N@Z @1738 NONAME
?AddOption@CCtrlTreeOpts@@QEAAXPEB_W0AEAII@Z @1739 NONAME
+??0MFileIterator@MFilePath@@QEAA@PEB_W@Z @1740 NONAME
+??0MFilePath@@QEAA@$$QEAV0@@Z @1741 NONAME
+??0MFilePath@@QEAA@AEBV0@@Z @1742 NONAME
+??0MFilePath@@QEAA@PEB_W@Z @1743 NONAME
+??0MFilePath@@QEAA@XZ @1744 NONAME
+??1MFileIterator@MFilePath@@QEAA@XZ @1745 NONAME
+??1MFilePath@@QEAA@XZ @1746 NONAME
+??4MFileIterator@MFilePath@@QEAAAEAV01@AEBV01@@Z @1747 NONAME
+??4MFilePath@@QEAAAEAV0@$$QEAV0@@Z @1748 NONAME
+??4MFilePath@@QEAAAEAV0@AEBV0@@Z @1749 NONAME
+?begin@MFileIterator@MFilePath@@QEAA?AViterator@12@XZ @1750 NONAME
+?end@MFileIterator@MFilePath@@QEAA?AViterator@12@XZ @1751 NONAME
+?getPath@MFileIterator@MFilePath@@QEBAPEB_WXZ @1752 NONAME
+?isDir@MFileIterator@MFilePath@@QEBA_NXZ @1753 NONAME
+?isExist@MFilePath@@QEBA_NXZ @1754 NONAME
+?move@MFilePath@@QEAA_NPEB_W@Z @1755 NONAME
+?search@MFilePath@@QEAA?AVMFileIterator@1@XZ @1756 NONAME
+??Eiterator@MFileIterator@MFilePath@@QEAA?AV012@XZ @1757 NONAME
|