From: <man...@us...> - 2013-11-08 13:18:48
|
Revision: 3126 http://sourceforge.net/p/modplug/code/3126 Author: manxorist Date: 2013-11-08 13:18:39 +0000 (Fri, 08 Nov 2013) Log Message: ----------- [Ref] Move _splitpath functionality into mpt::PathString. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/TrackerSettings.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-08 12:38:53 UTC (rev 3125) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-08 13:18:39 UTC (rev 3126) @@ -176,3 +176,51 @@ } } // namespace mpt::String + + +#if defined(MODPLUG_TRACKER) + +namespace mpt { + +void PathString::SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const +//------------------------------------------------------------------------------------------------------ +{ + wchar_t tempDrive[_MAX_DRIVE]; + wchar_t tempDir[_MAX_DIR]; + wchar_t tempFname[_MAX_FNAME]; + wchar_t tempExt[_MAX_EXT]; + _wsplitpath(path.c_str(), tempDrive, tempDir, tempFname, tempExt); + if(drive) *drive = mpt::PathString::FromNative(tempDrive); + if(dir) *dir = mpt::PathString::FromNative(tempDir); + if(fname) *fname = mpt::PathString::FromNative(tempFname); + if(ext) *ext = mpt::PathString::FromNative(tempExt); +} + +PathString PathString::GetDrive() const +{ + PathString drive; + SplitPath(&drive, nullptr, nullptr, nullptr); + return drive; +} +PathString PathString::GetDir() const +{ + PathString dir; + SplitPath(nullptr, &dir, nullptr, nullptr); + return dir; +} +PathString PathString::GetFileName() const +{ + PathString fname; + SplitPath(nullptr, nullptr, &fname, nullptr); + return fname; +} +PathString PathString::GetFileExt() const +{ + PathString ext; + SplitPath(nullptr, nullptr, nullptr, &ext); + return ext; +} + +} // namespace mpt + +#endif Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-08 12:38:53 UTC (rev 3125) +++ trunk/OpenMPT/common/mptString.h 2013-11-08 13:18:39 UTC (rev 3126) @@ -162,8 +162,10 @@ #if defined(WIN32) - typedef std::wstring RawPathString; +#else // !WIN32 +typedef std::string RawPathString; +#endif // WIN32 class PathString { @@ -216,7 +218,23 @@ return a.AsNative() != b.AsNative(); } bool empty() const { return path.empty(); } + public: + +#if defined(MODPLUG_TRACKER) + + void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; + PathString GetDrive() const; + PathString GetDir() const; + PathString GetFileName() const; + PathString GetFileExt() const; + +#endif + +public: + +#if defined(WIN32) + // conversions MPT_DEPRECATED std::string ToLocale() const { return mpt::String::Encode(path, mpt::CharsetLocale); } std::string ToUTF8() const { return mpt::String::Encode(path, mpt::CharsetUTF8); } @@ -245,64 +263,9 @@ #endif } #endif -}; #else // !WIN32 -typedef std::string RawPathString; - -class PathString -{ -private: - RawPathString path; -private: - PathString(const RawPathString & path) - : path(path) - { - return; - } -public: - PathString() - { - return; - } - PathString(const PathString & other) - : path(other.path) - { - return; - } - PathString & assign(const PathString & other) - { - path = other.path; - return *this; - } - PathString & operator = (const PathString & other) - { - return assign(other); - } - PathString & append(const PathString & other) - { - path.append(other.path); - return *this; - } - PathString & operator += (const PathString & other) - { - return append(other); - } - friend PathString operator + (const PathString & a, const PathString & b) - { - return PathString(a).append(b); - } - friend bool operator == (const PathString & a, const PathString & b) - { - return a.AsNative() == b.AsNative(); - } - friend bool operator != (const PathString & a, const PathString & b) - { - return a.AsNative() != b.AsNative(); - } - bool empty() const { return path.empty(); } -public: // conversions std::string ToLocale() const { return path; } std::string ToUTF8() const { return mpt::String::Convert(path, mpt::CharsetLocale, mpt::CharsetUTF8); } @@ -312,10 +275,10 @@ static PathString FromWide(const std::wstring &path) { return PathString(mpt::String::Encode(path, mpt::CharsetLocale)); } RawPathString AsNative() const { return path; } static PathString FromNative(const RawPathString &path) { return PathString(path); } -}; #endif // WIN32 +}; } // namespace mpt Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-08 12:38:53 UTC (rev 3125) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-08 13:18:39 UTC (rev 3126) @@ -697,11 +697,8 @@ if(GetModuleFileNameW(NULL, tempExePath, CountOf(tempExePath))) { mpt::String::SetNullTerminator(tempExePath); - wchar_t szDrive[_MAX_DRIVE] = L""; - wchar_t szDir[_MAX_PATH] = L""; - _wsplitpath(tempExePath, szDrive, szDir, NULL, NULL); - m_szExePath = mpt::PathString::FromNative(szDrive); - m_szExePath += mpt::PathString::FromNative(szDir); + m_szExePath = mpt::PathString::FromNative(tempExePath).GetDrive(); + m_szExePath += mpt::PathString::FromNative(tempExePath).GetDir(); WCHAR wcsDir[MAX_PATH]; GetFullPathNameW(m_szExePath.AsNative().c_str(), CountOf(wcsDir), wcsDir, NULL); Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-08 12:38:53 UTC (rev 3125) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-08 13:18:39 UTC (rev 3126) @@ -791,10 +791,7 @@ if(bStripFilename) { - wchar_t szPath[_MAX_PATH]; - wchar_t szDir[_MAX_DIR]; - _wsplitpath(szFilenameFrom.AsNative().c_str(), szPath, szDir, 0, 0); - path = mpt::PathString::FromNative(szPath) + mpt::PathString::FromNative(szDir); + path = szFilenameFrom.GetDrive() + szFilenameFrom.GetDir(); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |