Skip to content

Commit

Permalink
Fixed limitation to _MAX_PATH for long path names.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimoga committed Oct 16, 2024
1 parent 588cfdc commit 056491b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions DemoApp/DemoApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

const DWORD nLength = _MAX_PATH;
const DWORD nLength = 0x1000 /* _MAX_PATH */;
TCHAR lpszFilePath[nLength] = { 0, };
GetModuleFileName(nullptr, lpszFilePath, nLength);
WriteConfigFile(lpszFilePath, _T("https://www.moga.doctor/freeware/IntelliEditSetup.msi"));
Expand Down Expand Up @@ -264,14 +264,14 @@ DWORD WINAPI UpdateThreadProc(LPVOID lpParam)
UNREFERENCED_PARAMETER(lpParam);

g_bThreadRunning = true;
const DWORD nLength = _MAX_PATH;
const DWORD nLength = 0x1000 /* _MAX_PATH */;
TCHAR lpszFilePath[nLength] = { 0, };
GetModuleFileName(nullptr, lpszFilePath, nLength);
g_bNewUpdateFound = CheckForUpdates(lpszFilePath, _T("https://www.moga.doctor/freeware/genUp4win.xml"), UI_Callback);
g_bThreadRunning = false;

::ExitThread(0);
return 0;
// return 0;
}

DWORD m_nUpdateThreadID = 0;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Second step is to generate the configuration file, using the `WriteConfigFile` f

The C++ code to generate the configuration file is:
```cpp
const DWORD nLength = _MAX_PATH;
const DWORD nLength = 0x1000 /* _MAX_PATH */;
TCHAR lpszFilePath[nLength] = { 0, };
GetModuleFileName(nullptr, lpszFilePath, nLength);
WriteConfigFile(lpszFilePath, MSI_OR_EXE_INSTALLATION_FILE);
Expand All @@ -30,7 +30,7 @@ Third step is to check for updates, using the `CheckForUpdates` function.
The C++ code to check for updates is:
```cpp
const DWORD nLength = _MAX_PATH;
const DWORD nLength = 0x1000 /* _MAX_PATH */;
TCHAR lpszFilePath[nLength] = { 0, };
GetModuleFileName(nullptr, lpszFilePath, nLength);
g_bNewUpdateFound = CheckForUpdates(lpszFilePath, XML_CONFIGURATION_FILE);
Expand Down
22 changes: 12 additions & 10 deletions genUp4win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const std::wstring GetAppSettingsFilePath(const std::wstring& strFilePath, const
TCHAR lpszDirectory[_MAX_DIR] = { 0, };
TCHAR lpszFilename[_MAX_FNAME] = { 0, };
TCHAR lpszExtension[_MAX_EXT] = { 0, };
TCHAR lpszFullPath[_MAX_PATH] = { 0, };
TCHAR lpszFullPath[0x1000 /* _MAX_PATH */] = { 0, };

WCHAR* lpszSpecialFolderPath = nullptr;
if ((SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &lpszSpecialFolderPath)) == S_OK)
Expand All @@ -55,7 +55,7 @@ const std::wstring GetAppSettingsFilePath(const std::wstring& strFilePath, const
}

_tsplitpath_s(strFilePath.c_str(), lpszDrive, _MAX_DRIVE, lpszDirectory, _MAX_DIR, lpszFilename, _MAX_FNAME, lpszExtension, _MAX_EXT);
_tmakepath_s(lpszFullPath, _MAX_PATH, lpszDrive, lpszDirectory, strProductName.c_str(), _T(".xml"));
_tmakepath_s(lpszFullPath, 0x1000 /* _MAX_PATH */, lpszDrive, lpszDirectory, strProductName.c_str(), _T(".xml"));
OutputDebugString(lpszFullPath);
return lpszFullPath;
}
Expand All @@ -68,7 +68,8 @@ bool WriteConfigFile(const std::wstring& strFilePath, const std::wstring& strDow
if (pVersionInfo.Load(strFilePath.c_str()))
{
const std::wstring& strProductName = pVersionInfo.GetProductName();
try {
try
{
const HRESULT hr{ CoInitialize(nullptr) };
if (FAILED(hr))
{
Expand Down Expand Up @@ -99,11 +100,11 @@ bool ReadConfigFile(const std::wstring& strConfigURL, const std::wstring& strPro
CString strStatusMessage;
HRESULT hResult = S_OK;
bool retVal = false;
TCHAR lpszTempPath[_MAX_PATH] = { 0 };
DWORD nLength = GetTempPath(_MAX_PATH, lpszTempPath);
TCHAR lpszTempPath[0x1000 /* _MAX_PATH */] = { 0, };
DWORD nLength = GetTempPath(0x1000 /* _MAX_PATH */, lpszTempPath);
if (nLength > 0)
{
TCHAR lpszFilePath[_MAX_PATH] = { 0 };
TCHAR lpszFilePath[0x1000 /* _MAX_PATH */] = { 0, };
nLength = GetTempFileName(lpszTempPath, nullptr, 0, lpszFilePath);
if (nLength > 0)
{
Expand All @@ -115,7 +116,8 @@ bool ReadConfigFile(const std::wstring& strConfigURL, const std::wstring& strPro
}
if ((hResult = URLDownloadToFile(nullptr, strConfigURL.c_str(), strFileName, 0, nullptr)) == S_OK)
{
try {
try
{
const HRESULT hr{ CoInitialize(nullptr) };
if (FAILED(hr))
{
Expand Down Expand Up @@ -166,11 +168,11 @@ bool CheckForUpdates(const std::wstring& strFilePath, const std::wstring& strCon
bool bNewUpdateFound = (strLatestVersion.compare(pVersionInfo.GetProductVersionAsString()) != 0);
if (bNewUpdateFound)
{
TCHAR lpszTempPath[_MAX_PATH] = { 0 };
DWORD nLength = GetTempPath(_MAX_PATH, lpszTempPath);
TCHAR lpszTempPath[0x1000 /* _MAX_PATH */] = { 0, };
DWORD nLength = GetTempPath(0x1000 /* _MAX_PATH */, lpszTempPath);
if (nLength > 0)
{
TCHAR lpszFilePath[_MAX_PATH] = { 0 };
TCHAR lpszFilePath[0x1000 /* _MAX_PATH */] = { 0, };
nLength = GetTempFileName(lpszTempPath, nullptr, 0, lpszFilePath);
if (nLength > 0)
{
Expand Down
Binary file modified genUp4win.rc
Binary file not shown.
Binary file modified x64/Release/DemoApp.exe
Binary file not shown.
Binary file modified x64/Release/genUp4win.dll
Binary file not shown.

0 comments on commit 056491b

Please sign in to comment.