Applied MAX_PATH everywhere

Also used strrchr instead of hand-rolled search for the last backslash
This commit is contained in:
PatrickvL 2016-12-11 17:50:38 +01:00
parent d9040173ec
commit bb3087932d
6 changed files with 75 additions and 86 deletions

View File

@ -44,7 +44,7 @@
// construct via Xbe file
Xbe::Xbe(const char *x_szFilename)
{
char szBuffer[260];
char szBuffer[MAX_PATH];
ConstructorInit();
@ -849,7 +849,7 @@ void Xbe::Export(const char *x_szXbeFilename)
if(GetError() != 0)
return;
char szBuffer[260];
char szBuffer[MAX_PATH];
printf("Xbe::Export: Writing Xbe file...");

View File

@ -38,6 +38,11 @@
#include <cstdio>
//#include <windef.h> // For MAX_PATH
// The above leads to 55 compile errors, so until we've sorted out why that happens, declare MAX_PATH ourselves for now :
#define MAX_PATH 260
// Xbe (Xbox Executable) file object
class Xbe : public Error
{
@ -214,7 +219,7 @@ class Xbe : public Error
uint08 **m_bzSection;
// Xbe original path
char m_szPath[260];
char m_szPath[MAX_PATH];
// Xbe ascii title, translated from certificate title
char m_szAsciiTitle[40];

View File

@ -58,11 +58,11 @@ WndMain::WndMain(HINSTANCE x_hInstance) : Wnd(x_hInstance), m_bCreated(false), m
m_w = 640;
m_h = 480;
m_ExeFilename = (char*)calloc(1, 260);
m_XbeFilename = (char*)calloc(1, 260);
m_ExeFilename = (char*)calloc(1, MAX_PATH);
m_XbeFilename = (char*)calloc(1, MAX_PATH);
m_CxbxDebugFilename = (char*)calloc(1, 260);
m_KrnlDebugFilename = (char*)calloc(1, 260);
m_CxbxDebugFilename = (char*)calloc(1, MAX_PATH);
m_KrnlDebugFilename = (char*)calloc(1, MAX_PATH);
int v=0;
@ -105,10 +105,10 @@ WndMain::WndMain(HINSTANCE x_hInstance) : Wnd(x_hInstance), m_bCreated(false), m
dwType = REG_DWORD; dwSize = sizeof(DWORD);
RegQueryValueEx(hKey, "AutoConvertToExe", NULL, &dwType, (PBYTE)&m_AutoConvertToExe, &dwSize);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegQueryValueEx(hKey, "CxbxDebugFilename", NULL, &dwType, (PBYTE)m_CxbxDebugFilename, &dwSize);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegQueryValueEx(hKey, "KrnlDebugFilename", NULL, &dwType, (PBYTE)m_KrnlDebugFilename, &dwSize);
int v=0;
@ -119,9 +119,9 @@ WndMain::WndMain(HINSTANCE x_hInstance) : Wnd(x_hInstance), m_bCreated(false), m
sprintf(buffer, "RecentXbe%d", v);
m_szRecentXbe[v] = (char*)calloc(1, 260);
m_szRecentXbe[v] = (char*)calloc(1, MAX_PATH);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegQueryValueEx(hKey, buffer, NULL, &dwType, (PBYTE)m_szRecentXbe[v], &dwSize);
}
@ -131,9 +131,9 @@ WndMain::WndMain(HINSTANCE x_hInstance) : Wnd(x_hInstance), m_bCreated(false), m
sprintf(buffer, "RecentExe%d", v);
m_szRecentExe[v] = (char*)calloc(1, 260);
m_szRecentExe[v] = (char*)calloc(1, MAX_PATH);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegQueryValueEx(hKey, buffer, NULL, &dwType, (PBYTE)m_szRecentExe[v], &dwSize);
}
@ -161,7 +161,7 @@ WndMain::~WndMain()
sprintf(buffer, "RecentXbe%d", v);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegSetValueEx(hKey, buffer, 0, dwType, (PBYTE)m_szRecentXbe[v], dwSize);
@ -174,7 +174,7 @@ WndMain::~WndMain()
sprintf(buffer, "RecentExe%d", v);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegSetValueEx(hKey, buffer, 0, dwType, (PBYTE)m_szRecentExe[v], dwSize);
@ -196,10 +196,10 @@ WndMain::~WndMain()
dwType = REG_DWORD; dwSize = sizeof(DWORD);
RegSetValueEx(hKey, "AutoConvertToExe", 0, dwType, (PBYTE)&m_AutoConvertToExe, dwSize);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegSetValueEx(hKey, "CxbxDebugFilename", 0, dwType, (PBYTE)m_CxbxDebugFilename, dwSize);
dwType = REG_SZ; dwSize = 260;
dwType = REG_SZ; dwSize = MAX_PATH;
RegSetValueEx(hKey, "KrnlDebugFilename", 0, dwType, (PBYTE)m_KrnlDebugFilename, dwSize);
}
}
@ -446,13 +446,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = {0};
char filename[MAX_PATH] = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Xbox Executables (*.xbe)\0*.xbe\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -495,13 +495,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
OPENFILENAME ofn = {0};
char filename[260] = {0};
char filename[MAX_PATH] = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Windows Executables (*.exe)\0*.exe\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -595,13 +595,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = "logo.bmp";
char filename[MAX_PATH] = "logo.bmp";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Bitmap Image Files (*.bmp)\0*.bmp\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -706,13 +706,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = "*.bmp";
char filename[MAX_PATH] = "*.bmp";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Bitmap Image Files (*.bmp)\0*.bmp\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -864,13 +864,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = "Xbe.txt";
char filename[MAX_PATH] = "Xbe.txt";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Text Documents (*.txt)\0*.txt\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -979,13 +979,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = "KrnlDebug.txt";
char filename[MAX_PATH] = "KrnlDebug.txt";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Text Documents (*.txt)\0*.txt\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -997,7 +997,7 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
MessageBox(m_hwnd, "This will not take effect until emulation is (re)started.\n", "Cxbx-Reloaded", MB_OK);
strncpy(m_KrnlDebugFilename, ofn.lpstrFile, 259);
strncpy(m_KrnlDebugFilename, ofn.lpstrFile, MAX_PATH-1);
m_bExeChanged = true;
@ -1038,13 +1038,13 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
OPENFILENAME ofn = {0};
char filename[260] = "CxbxDebug.txt";
char filename[MAX_PATH] = "CxbxDebug.txt";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Text Documents (*.txt)\0*.txt\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -1054,7 +1054,7 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
if(GetSaveFileName(&ofn) != FALSE)
{
strncpy(m_CxbxDebugFilename, ofn.lpstrFile, 259);
strncpy(m_CxbxDebugFilename, ofn.lpstrFile, MAX_PATH-1);
m_CxbxDebug = DM_FILE;
@ -1540,7 +1540,7 @@ void WndMain::OpenXbe(const char *x_filename)
}
else
{
strncpy(m_szRecentXbe[c], m_szRecentXbe[r], 259);
strncpy(m_szRecentXbe[c], m_szRecentXbe[r], MAX_PATH-1);
}
}
}
@ -1559,15 +1559,15 @@ void WndMain::OpenXbe(const char *x_filename)
else
{
if(m_szRecentXbe[v] == 0)
m_szRecentXbe[v] = (char*)calloc(1, 260);
strncpy(m_szRecentXbe[v], m_szRecentXbe[v-1], 259);
m_szRecentXbe[v] = (char*)calloc(1, MAX_PATH);
strncpy(m_szRecentXbe[v], m_szRecentXbe[v-1], MAX_PATH-1);
}
}
// add new item as first index
{
if(m_szRecentXbe[0] == 0)
m_szRecentXbe[0] = (char*)calloc(1, 260);
m_szRecentXbe[0] = (char*)calloc(1, MAX_PATH);
strcpy(m_szRecentXbe[0], m_XbeFilename);
}
@ -1656,7 +1656,7 @@ void WndMain::SaveXbeAs()
{
OPENFILENAME ofn = {0};
char filename[260] = "default.xbe";
char filename[MAX_PATH] = "default.xbe";
SuggestFilename(m_XbeFilename, filename, ".xbe");
@ -1664,7 +1664,7 @@ void WndMain::SaveXbeAs()
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Xbox Executables (*.xbe)\0*.xbe\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -1722,7 +1722,7 @@ void WndMain::ImportExe(const char *x_filename)
if(m_szRecentExe[r] == 0 || r > m_dwRecentExe - 1)
m_szRecentExe[c] = 0;
else
strncpy(m_szRecentExe[c], m_szRecentExe[r], 259);
strncpy(m_szRecentExe[c], m_szRecentExe[r], MAX_PATH-1);
}
}
@ -1737,15 +1737,15 @@ void WndMain::ImportExe(const char *x_filename)
else
{
if(m_szRecentExe[v] == 0)
m_szRecentExe[v] = (char*)calloc(1, 260);
strncpy(m_szRecentExe[v], m_szRecentExe[v-1], 259);
m_szRecentExe[v] = (char*)calloc(1, MAX_PATH);
strncpy(m_szRecentExe[v], m_szRecentExe[v-1], MAX_PATH-1);
}
}
// add new item as first index
{
if(m_szRecentExe[0] == 0)
m_szRecentExe[0] = (char*)calloc(1, 260);
m_szRecentExe[0] = (char*)calloc(1, MAX_PATH);
strcpy(m_szRecentExe[0], m_ExeFilename);
}
@ -1764,7 +1764,7 @@ void WndMain::ImportExe(const char *x_filename)
// convert to exe file
bool WndMain::ConvertToExe(const char *x_filename, bool x_bVerifyIfExists, HWND hwndParent)
{
char filename[260] = "default.exe";
char filename[MAX_PATH] = "default.exe";
if(x_filename == NULL)
{
@ -1776,7 +1776,7 @@ bool WndMain::ConvertToExe(const char *x_filename, bool x_bVerifyIfExists, HWND
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = "Windows Executables (*.exe)\0*.exe\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 260;
ofn.nMaxFile = MAX_PATH;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
@ -1831,26 +1831,18 @@ bool WndMain::ConvertToExe(const char *x_filename, bool x_bVerifyIfExists, HWND
// start emulation
void WndMain::StartEmulation(EnumAutoConvert x_AutoConvert, HWND hwndParent)
{
char szBuffer[260];
char szBuffer[MAX_PATH];
// register xbe path with CxbxKrnl.dll
g_EmuShared->SetXbePath(m_Xbe->m_szPath);
// shell exe
{
GetModuleFileName(NULL, szBuffer, 260);
GetModuleFileName(NULL, szBuffer, MAX_PATH);
sint32 spot=-1;
for(int v=0;v<260;v++)
{
if(szBuffer[v] == '\\')
spot = v;
else if(szBuffer[v] == '\0')
break;
}
if(spot != -1)
szBuffer[spot] = '\0';
char *spot = strrchr(szBuffer, '\\');
if (spot != NULL)
*spot = '\0';
char szExeFileName[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), szExeFileName, MAX_PATH);

View File

@ -363,7 +363,8 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
setlocale(LC_ALL, "English");
#ifdef _DEBUG
MessageBoxA(NULL, "Attach a Debugger", "DEBUG", 0);
// MessageBoxA(NULL, "Attach a Debugger", "DEBUG", 0);
// Debug child processes using https://marketplace.visualstudio.com/items?itemName=GreggMiskelly.MicrosoftChildProcessDebuggingPowerTool
#endif
// debug console allocation (if configured)
@ -457,7 +458,7 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
}
// Initialize devices :
char szBuffer[260];
char szBuffer[MAX_PATH];
SHGetSpecialFolderPath(NULL, szBuffer, CSIDL_APPDATA, TRUE);
strcat(szBuffer, "\\Cxbx-Reloaded\\");
@ -465,7 +466,7 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
CxbxBasePath = basePath + "\\EmuDisk\\";
// Determine XBE Path
memset(szBuffer, 0, 260);
memset(szBuffer, 0, MAX_PATH);
g_EmuShared->GetXbePath(szBuffer);
std::string xbePath(szBuffer);
PathRemoveFileSpec(szBuffer);
@ -473,7 +474,7 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
CxbxBasePathHandle = CreateFile(CxbxBasePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
memset(szBuffer, 0, 260);
memset(szBuffer, 0, MAX_PATH);
sprintf(szBuffer, "%08X", ((Xbe::Certificate*)pXbeHeader->dwCertificateAddr)->dwTitleId);
std::string titleId(szBuffer);

View File

@ -86,7 +86,7 @@ class EmuShared : public Mutex
// ******************************************************************
XBController m_XBController;
XBVideo m_XBVideo;
char m_XbePath[260];
char m_XbePath[MAX_PATH];
};
// ******************************************************************

View File

@ -65,7 +65,7 @@ void EmuHLEIntercept(Xbe::LibraryVersion *pLibraryVersion, Xbe::Header *pXbeHead
{
Xbe::Certificate *pCertificate = (Xbe::Certificate*)pXbeHeader->dwCertificateAddr;
char szCacheFileName[260];
char szCacheFileName[MAX_PATH];
DbgPrintf("\n");
DbgPrintf("*******************************************************************************\n");
@ -77,36 +77,27 @@ void EmuHLEIntercept(Xbe::LibraryVersion *pLibraryVersion, Xbe::Header *pXbeHead
// initialize HLE cache file
//
{
SHGetSpecialFolderPath(NULL, szCacheFileName, CSIDL_APPDATA, TRUE);
{
SHGetSpecialFolderPath(NULL, szCacheFileName, CSIDL_APPDATA, TRUE);
strcat(szCacheFileName, "\\Cxbx-Reloaded\\");
strcat(szCacheFileName, "\\Cxbx-Reloaded\\");
CreateDirectory(szCacheFileName, NULL);
CreateDirectory(szCacheFileName, NULL);
sint32 spot = -1;
char *spot = strrchr(szCacheFileName, '\\');
for(int v=0;v<260;v++)
{
if(szCacheFileName[v] == '\\') { spot = v; }
else if(szCacheFileName[v] == '\0') { break; }
}
//
// create HLECache directory
//
if(spot != -1) { szCacheFileName[spot] = '\0'; }
strcpy(spot, "\\HLECache");
//
// create HLECache directory
//
strcpy(&szCacheFileName[spot], "\\HLECache");
CreateDirectory(szCacheFileName, NULL);
//
CreateDirectory(szCacheFileName, NULL);
//
// open title's cache file
//
sprintf(&szCacheFileName[spot+9], "\\%08x.dat", pCertificate->dwTitleId);
sprintf(spot+9, "\\%08x.dat", pCertificate->dwTitleId);
FILE *pCacheFile = fopen(szCacheFileName, "rb");