diff --git a/Tools/UnitTests/Source/TKernel/TCString_Tests.cpp b/Tools/UnitTests/Source/TKernel/TCString_Tests.cpp index 13d0a52..7e9f428 100644 --- a/Tools/UnitTests/Source/TKernel/TCString_Tests.cpp +++ b/Tools/UnitTests/Source/TKernel/TCString_Tests.cpp @@ -7,4 +7,12 @@ TEST_CASE("Constructor", "[TCString]") { TCString string("ABCD"); REQUIRE(string == "ABCD"); +} + +TEST_CASE("Concat Strings", "[TCString]") +{ + TCString string("ABCD"); + TCString string2("EFGH"); + string += string2; + REQUIRE(string == "ABCDEFGH"); } \ No newline at end of file diff --git a/Toshi/Include/TKernel/TCString.h b/Toshi/Include/TKernel/TCString.h index dbdf553..3cfa3af 100644 --- a/Toshi/Include/TKernel/TCString.h +++ b/Toshi/Include/TKernel/TCString.h @@ -39,6 +39,7 @@ class TOSHI_EXPORT TCString FreeBuffer(); } + TCString& Concat(TCString const& a_rString, TINT a_iLength = -1); TINT Compare(TPCCHAR a_pcString, int a_iLength = -1) const; void Copy(const TCString& a_rOther, TINT a_iLength = -1); @@ -47,6 +48,8 @@ class TOSHI_EXPORT TCString TCString& __cdecl Format(TPCCHAR a_pcFormat, ...); TINT Find(char a_cFind, TINT a_iIndex = 0) const; + void Truncate(TINT a_iLength); + TBOOL IsIndexValid(TINT a_iIndex = 0) const { return a_iIndex <= m_iStrLen && a_iIndex >= 0; @@ -99,6 +102,12 @@ class TOSHI_EXPORT TCString return *this; } + TCString& operator+=(TCString const& a_rString) + { + Concat(a_rString); + return *this; + } + TCCHAR& operator[](TINT a_iIndex) const { TASSERT((a_iIndex>=0) && (a_iIndex<=(TINT)m_iStrLen)); diff --git a/Toshi/Include/TKernel/TFile.h b/Toshi/Include/TKernel/TFile.h index 8474311..70cf8ad 100644 --- a/Toshi/Include/TKernel/TFile.h +++ b/Toshi/Include/TKernel/TFile.h @@ -111,12 +111,15 @@ class TOSHI_EXPORT TFileManager void MountFileSystem(TFileSystem* a_pFileSystem); void UnmountFileSystem(TFileSystem* a_pFileSystem); + TCString MakeAbsolutePath(TCString const& a_rPath); + static TFileManager* __stdcall GetFileManager() { return s_pFileManager; } void SetSystemPath(TCString const& a_rSysPath) { m_pcSystemPath = a_rSysPath; InvalidateSystemPath(); } + TCString const& GetWorkingDirectory() const { return m_pcWorkingDirectory; } private: void ValidateSystemPath(); @@ -175,6 +178,7 @@ class TOSHI_EXPORT TFile static TFile* Create(const TCString& a_sName, TUINT a_uiMode); static void Destroy(TFile* a_pFile); static void PrintFileAccess(TBOOL a_bFileAccess) {} + static TCString __stdcall ConcatPath(TCString const& a_rPath1, TCString const& a_rPath2); void Destroy(); TFileSystem* GetFileSystem() const { return m_pFileSystem; } diff --git a/Toshi/Include/TKernel/TSystem.h b/Toshi/Include/TKernel/TSystemTools.h similarity index 80% rename from Toshi/Include/TKernel/TSystem.h rename to Toshi/Include/TKernel/TSystemTools.h index 9dcc8f6..92bd629 100644 --- a/Toshi/Include/TKernel/TSystem.h +++ b/Toshi/Include/TKernel/TSystemTools.h @@ -9,6 +9,7 @@ class TOSHI_EXPORT TSystem static TINT __stdcall StringLength(TPCCHAR a_String); static TINT __stdcall StringCompareNoCase(TPCCHAR a_String1, TPCCHAR a_String2, TINT a_uiSize); + static TCHAR const* __stdcall StringCopy(TPCHAR a_DestinationString, TCHAR const* a_SourceString, TINT a_iCount); static TPVOID __stdcall MemCopy(TPVOID a_dest, TPCVOID a_src, TUINT a_iSize); static TPBYTE GetScratchMem() { return ms_aScratchMem; } diff --git a/Toshi/Include/TKernel/Win/TNativeFileWin.h b/Toshi/Include/TKernel/Win/TNativeFileWin.h index 6b0ff03..1ea1248 100644 --- a/Toshi/Include/TKernel/Win/TNativeFileWin.h +++ b/Toshi/Include/TKernel/Win/TNativeFileWin.h @@ -13,7 +13,7 @@ class TOSHI_EXPORT TNativeFileSystem : public TFileSystem virtual TFile* CreateFile(Toshi::TCString const& a_rFilename, TUINT a_uiMode) override; virtual void DestroyFile(TFile* a_pFile) override; virtual TBOOL RemoveFile(TCString const& a_rFilename) override; - virtual TCString MakeInternalPath(const TCString& a_rsPath) override; + virtual TCString MakeInternalPath(TCString const& a_rsPath) override; private: HANDLE m_hFileSystem; // 0x1C diff --git a/Toshi/Source/TKernel/TCString.cpp b/Toshi/Source/TKernel/TCString.cpp index 828b103..50c3bc7 100644 --- a/Toshi/Source/TKernel/TCString.cpp +++ b/Toshi/Source/TKernel/TCString.cpp @@ -1,6 +1,7 @@ #include "TCString.h" -#include "TSystem.h" +#include "TSystemTools.h" #include +#include TOSHI_NAMESPACE_USING @@ -36,10 +37,30 @@ TBOOL TCString::AllocBuffer(TINT a_iLength, TBOOL a_bClear) } m_iStrLen = a_iLength; } - if (a_bClear) m_pBuffer[0] = 0; + if (a_bClear) m_pBuffer[0] = '\0'; return hasChanged; } +TCString& TCString::Concat(TCString const& a_rString, TINT a_iLength) +{ + TINT len = a_rString.Length(); + if (len < a_iLength || a_iLength == -1) { + a_iLength = len; + } + TPCHAR pBuffer = m_pBuffer; + len = Length(); + TBOOL ret = AllocBuffer(len + a_iLength, TFALSE); + if (ret) { + TSystem::StringCopy(m_pBuffer, pBuffer, -1); + } + TSystem::StringCopy(m_pBuffer + len, a_rString.m_pBuffer, a_iLength); + m_pBuffer[len + a_iLength] = '\0'; + if (ret && len != 0) { + tfree(pBuffer); + } + return *this; +} + TINT TCString::Compare(TPCCHAR a_pcString, int a_iLength) const { TASSERT(a_pcString!=TNULL); @@ -91,3 +112,20 @@ TINT TCString::Find(char a_cFind, TINT a_iIndex) const return foundAt - GetString(); } + +void TCString::Truncate(TINT a_iLength) +{ + TINT len = Length(); + if (len < a_iLength) { + a_iLength = len; + } + TPCHAR pBuffer = m_pBuffer; + TBOOL ret = AllocBuffer(a_iLength, TFALSE); + if (ret) { + TSystem::StringCopy(m_pBuffer, pBuffer, a_iLength); + } + m_pBuffer[a_iLength] = '\0'; + if (ret && len != 0) { + tfree(pBuffer); + } +} diff --git a/Toshi/Source/TKernel/TDebug.cpp b/Toshi/Source/TKernel/TDebug.cpp index 8877f24..af785f7 100644 --- a/Toshi/Source/TKernel/TDebug.cpp +++ b/Toshi/Source/TKernel/TDebug.cpp @@ -1,7 +1,7 @@ #include "TDebug.h" #include #include -#include "TSystem.h" +#include "TSystemTools.h" #ifdef TOSHI_NOTFINAL diff --git a/Toshi/Source/TKernel/TFile.cpp b/Toshi/Source/TKernel/TFile.cpp index cf14276..f7d2716 100644 --- a/Toshi/Source/TKernel/TFile.cpp +++ b/Toshi/Source/TKernel/TFile.cpp @@ -18,6 +18,13 @@ void TFile::Destroy(TFile* a_pFile) } } +TCString __stdcall TFile::ConcatPath(TCString const& a_rPath1, TCString const& a_rPath2) +{ + TCString str = TCString(); + + return TCString(); +} + void TFile::Destroy() { Destroy(this); @@ -89,6 +96,11 @@ void TFileManager::UnmountFileSystem(TFileSystem* a_pFileSystem) InvalidateSystemPath(); } +TCString TFileManager::MakeAbsolutePath(TCString const& a_rPath) +{ + return TFile::ConcatPath(a_rPath, GetWorkingDirectory()); +} + TFileSystem* __stdcall TFileManager::FindFileSystem(TDList& a_rFileSystems, const TCString& a_rFileSysName) { for (auto pNode = a_rFileSystems.Begin(); pNode != a_rFileSystems.End(); pNode++) { diff --git a/Toshi/Source/TKernel/TObject.cpp b/Toshi/Source/TKernel/TObject.cpp index 8152d5f..cdb3f13 100644 --- a/Toshi/Source/TKernel/TObject.cpp +++ b/Toshi/Source/TKernel/TObject.cpp @@ -1,5 +1,5 @@ #include "TObject.h" -#include "TSystem.h" +#include "TSystemTools.h" TOSHI_NAMESPACE_USING diff --git a/Toshi/Source/TKernel/TSystem.cpp b/Toshi/Source/TKernel/TSystemTools.cpp similarity index 62% rename from Toshi/Source/TKernel/TSystem.cpp rename to Toshi/Source/TKernel/TSystemTools.cpp index 39738d8..7dd81e9 100644 --- a/Toshi/Source/TKernel/TSystem.cpp +++ b/Toshi/Source/TKernel/TSystemTools.cpp @@ -1,4 +1,4 @@ -#include "TSystem.h" +#include "TSystemTools.h" #include "TDebug.h" #include @@ -18,6 +18,19 @@ TINT __stdcall TSystem::StringCompareNoCase(TPCCHAR a_String1, TPCCHAR a_String2 return a_uiSize != -1 ? _strnicmp(a_String1, a_String2, a_uiSize) : _stricmp(a_String1, a_String2); } +TCHAR const* __stdcall TSystem::StringCopy(TPCHAR a_DestinationString, TCHAR const* a_SourceString, TINT a_iCount) +{ + TASSERT((a_DestinationString!=TNULL) && (a_SourceString!=TNULL)); + if (a_iCount != -1) { + return strncpy(a_DestinationString, a_SourceString, a_iCount); + } + TPCHAR d = a_DestinationString; + TCHAR const* s = a_SourceString; + while (*s != '\0') + *d++ = *s++; + return a_DestinationString; +} + TPVOID __stdcall TSystem::MemCopy(TPVOID a_dest, TPCVOID a_src, TUINT a_iSize) { // Note: Idk if they used gcclib's memcpy() or their own diff --git a/Toshi/Source/TKernel/Win/TNativeFileWin.cpp b/Toshi/Source/TKernel/Win/TNativeFileWin.cpp index 0b769bf..b44de96 100644 --- a/Toshi/Source/TKernel/Win/TNativeFileWin.cpp +++ b/Toshi/Source/TKernel/Win/TNativeFileWin.cpp @@ -37,8 +37,21 @@ TBOOL TNativeFileSystem::RemoveFile(TCString const& a_rFilename) return DeleteFile(a_rFilename.GetString()); } -TCString TNativeFileSystem::MakeInternalPath(const TCString& a_rsPath) +TCString TNativeFileSystem::MakeInternalPath(TCString const& a_rsPath) { + TCString prefix = GetPrefix(); + if (prefix.Length() > 0) { + if (prefix[prefix.Length() - 1] == '/' || prefix[prefix.Length() - 1] == '\\') { + prefix.Truncate(prefix.Length() - 1); + } + } + TFileManager *pFileManager = TFileManager::GetFileManager(); + TVALIDADDRESS(pFileManager); + { + TCString empty; + pFileManager->MakeAbsolutePath(empty); + prefix += empty; + } return TCString(); }