Subversion Repositories WoWGM

Rev

Rev 3 | Rev 21 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 11
Line 55... Line 55...
55
}
55
}
56
 
56
 
57
//===========================================================================
57
//===========================================================================
58
BOOL CreateWTFFilePath (char* filePath, unsigned int size)
58
BOOL CreateWTFFilePath (char* filePath, unsigned int size)
59
{
59
{
60
	char buffer[260] = {};
60
	char buffer[FILENAME_MAX] = {};
61
 
61
 
62
	if (filePath && *filePath && size != 0) {
62
	if (filePath && *filePath && size != 0) {
63
		strncpy_s(buffer,"WTF\\",260u);
63
		SStrCopy(buffer,"WTF\\",FILENAME_MAX);
64
		strncat_s(buffer,filePath,260u);
64
		strncat_s(buffer,filePath,FILENAME_MAX);
65
 
65
 
66
		char* extension = strrchr(filePath,'.');
66
		char* extension = strrchr(filePath,'.');
67
		if (extension && *extension) {
67
		if (extension && *extension) {
68
			if (_strcmpi(extension,".wtf")) {
68
			if (_strcmpi(extension,".wtf")) {
69
				ConsoleWrite("File must have '.wtf' extension",ERROR_COLOR);
69
				ConsoleWrite("File must have '.wtf' extension",ERROR_COLOR);
70
				return FALSE;
70
				return FALSE;
71
			}
71
			}
72
		}
72
		}
73
		else {
73
		else {
74
			strncat_s(buffer,".wtf",260u);
74
			strncat_s(buffer,".wtf",FILENAME_MAX);
75
		}
75
		}
76
		strncpy_s(filePath,260u,buffer,260u);
76
		SStrCopy(filePath,buffer,FILENAME_MAX);
77
		return TRUE;
77
		return TRUE;
78
	}
78
	}
79
	return FALSE;
79
	return FALSE;
80
}
80
}
81
 
81
 
Line 89... Line 89...
89
//===========================================================================
89
//===========================================================================
90
int __cdecl ConsoleCommand_CreateExec (const char* cmd, const char* arguments)
90
int __cdecl ConsoleCommand_CreateExec (const char* cmd, const char* arguments)
91
{
91
{
92
	if (ValidateFileName(arguments))
92
	if (ValidateFileName(arguments))
93
	{
93
	{
94
		char folder[260] = {};
94
		char folder[FILENAME_MAX] = {};
95
		char filePath[260] = {};
95
		char filePath[FILENAME_MAX] = {};
96
 
96
 
97
		strncpy_s(s_fileName,arguments,260u);
97
		SStrCopy(s_fileName,arguments,FILENAME_MAX);
98
		strncpy_s(filePath,s_fileName,260u);
98
		SStrCopy(filePath,s_fileName,FILENAME_MAX);
99
 
99
 
100
		if (CreateWTFFilePath(filePath,260u)) {
100
		if (CreateWTFFilePath(filePath,FILENAME_MAX)) {
101
			if (OsFileExists(filePath)) {
101
			if (OsFileExists(filePath)) {
102
				ConsoleWrite("File exists are you sure you want to Overwrite Y / N ? ",WARNING_COLOR);
102
				ConsoleWrite("File exists are you sure you want to Overwrite Y / N ? ",WARNING_COLOR);
103
				g_ExecCreateMode = EM_PROMPTOVERWRITE;
103
				g_ExecCreateMode = EM_PROMPTOVERWRITE;
104
			}
104
			}
105
			else {
105
			else {
106
				strcpy_s(folder,filePath);
106
				SStrCopy(folder,filePath,FILENAME_MAX);
107
 
107
 
108
				char* dirName = strrchr(folder,'\\');
108
				char* dirName = strrchr(folder,'\\');
109
				if (dirName)
109
				if (dirName)
110
					*dirName = 0;
110
					*dirName = 0;
111
 
111
 
Line 132... Line 132...
132
		ConsoleWrite("You must type 'new' 'filename' to begin creating an Exec file",WARNING_COLOR);
132
		ConsoleWrite("You must type 'new' 'filename' to begin creating an Exec file",WARNING_COLOR);
133
		result = TRUE;
133
		result = TRUE;
134
	}
134
	}
135
	else
135
	else
136
	{
136
	{
137
		char filePath[260] = {};
137
		char filePath[FILENAME_MAX] = {};
138
		strncpy_s(filePath, s_fileName, 260u);
138
		SStrCopy(filePath, s_fileName, FILENAME_MAX);
139
 
139
 
140
		if (CreateWTFFilePath(filePath, 260u))
140
		if (CreateWTFFilePath(filePath, FILENAME_MAX))
141
		{
141
		{
142
			HANDLE hFile = OsCreateFile(filePath,FILE_ALL_ACCESS,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE)0x3F3F3F3F);
142
			HANDLE hFile = OsCreateFile(filePath,FILE_ALL_ACCESS,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE)0x3F3F3F3F);
143
			if (hFile == INVALID_HANDLE_VALUE)
143
			if (hFile == INVALID_HANDLE_VALUE)
144
			{
144
			{
145
				ConsoleWrite("Error trying to create the file.",ERROR_COLOR);
145
				ConsoleWrite("Error trying to create the file.",ERROR_COLOR);
Line 148... Line 148...
148
			{
148
			{
149
				if (g_ExecCreateMode == EM_APPEND)
149
				if (g_ExecCreateMode == EM_APPEND)
150
					OsSetFilePointer(hFile,CREATE_ALWAYS,0i64);
150
					OsSetFilePointer(hFile,CREATE_ALWAYS,0i64);
151
 
151
 
152
				DWORD count = 0;
152
				DWORD count = 0;
153
				size_t bufLen = strlen(g_ExecBuffer);
153
				DWORD bufLen = SStrLen(g_ExecBuffer);
154
				COLOR_T color;
154
				COLOR_T color;
155
				const char *str;
155
				const char *str;
156
				OsWriteFile(hFile,g_ExecBuffer,bufLen,&count);
156
				OsWriteFile(hFile,g_ExecBuffer,bufLen,&count);
157
				if (count)
157
				if (count)
158
				{
158
				{
Line 177... Line 177...
177
 
177
 
178
//===========================================================================
178
//===========================================================================
179
int __cdecl ConsoleCommand_RunExec(const char *command, const char *arguments)
179
int __cdecl ConsoleCommand_RunExec(const char *command, const char *arguments)
180
{
180
{
181
	int result = 0;
181
	int result = 0;
182
	char filename[260] = { '\0' };
182
	char filename[FILENAME_MAX] = { '\0' };
183
	char tmp[260] = { '\0' };
183
	char tmp[FILENAME_MAX] = { '\0' };
184
	char lineBuffer[128] = { '\0' };
184
	char lineBuffer[128] = { '\0' };
185
	char param1[32] = { '\0' };
185
	char param1[32] = { '\0' };
186
	DWORD bytes;
186
	DWORD bytes;
187
 
187
 
188
	int verbose = 0;
188
	int verbose = 0;
Line 217... Line 217...
217
					token = strtok_s(bufferPtr, "\r\n", &nextToken);
217
					token = strtok_s(bufferPtr, "\r\n", &nextToken);
218
					if (token)
218
					if (token)
219
					{
219
					{
220
						do
220
						do
221
						{
221
						{
222
							strncpy_s(lineBuffer, token, 128u);
222
							SStrCopy(lineBuffer, token, 128u);
223
							if (lineBuffer[0])
223
							if (lineBuffer[0])
224
							{
224
							{
225
								if (verbose)
225
								if (verbose)
226
								{
226
								{
227
									_snprintf(tmp, 260u, "Executing ->%s", lineBuffer);
227
									_snprintf(tmp, FILENAME_MAX, "Executing ->%s", lineBuffer);
228
									ConsoleWrite(tmp, ECHO_COLOR);
228
									ConsoleWrite(tmp, ECHO_COLOR);
229
								}
229
								}
230
								ConsoleCommandExecute(lineBuffer, 0);
230
								ConsoleCommandExecute(lineBuffer, 0);
231
							}
231
							}
232
							token = strtok_s(NULL, "\r\n", &nextToken);
232
							token = strtok_s(NULL, "\r\n", &nextToken);
Line 244... Line 244...
244
				}
244
				}
245
			}
245
			}
246
			else
246
			else
247
			{
247
			{
248
				if (*command)
248
				if (*command)
249
					_snprintf(tmp, 260u, "Unable to load file %s", filename);
249
					_snprintf(tmp, FILENAME_MAX, "Unable to load file %s", filename);
250
				else
250
				else
251
					_snprintf(tmp, 260u, "Unknown command: %s", arguments);
251
					_snprintf(tmp, FILENAME_MAX, "Unknown command: %s", arguments);
252
				ConsoleWrite(tmp, ERROR_COLOR);
252
				ConsoleWrite(tmp, ERROR_COLOR);
253
				result = 0;
253
				result = 0;
254
			}
254
			}
255
			OsCloseFile(hFile);
255
			OsCloseFile(hFile);
256
			free(readData);
256
			free(readData);