Allow for second private chat trigger (
bug 3667, r,a11=pred).
1 #include "InstallerUtil.h"
2 #include "InstallerMain.h"
6 int tstrcasecmp(const TCHAR *str1, const TCHAR *str2)
9 return _wcsicmp(str1, str2);
11 return _stricmp(str1, str2);
15 size_t AnsiToUnicode(const char *str, wchar_t *buffer, size_t maxchars)
23 (size_t)MultiByteToWideChar(CP_UTF8,
33 bool IsWhiteSpaceA(const char *stream)
42 return isspace(c) != 0;
46 int BreakStringA(const char *str, char *out, size_t maxchars)
48 const char *inptr = str;
49 while (*inptr != '\0' && IsWhiteSpaceA(inptr))
63 const char *start, *end = NULL;
65 bool quoted = (*inptr == '"');
70 /* Read input until we reach a quote. */
71 while (*inptr != '\0' && *inptr != '"')
73 /* Update the end point, increment the stream. */
76 /* Read one more token if we reached an end quote */
85 /* Read input until we reach a space */
86 while (*inptr != '\0' && !IsWhiteSpaceA(inptr))
88 /* Update the end point, increment the stream. */
93 /* Copy the string we found, if necessary */
105 for (const char *ptr=start;
106 (ptr <= end) && ((unsigned)(outptr - out) < (maxchars));
114 /* Consume more of the string until we reach non-whitespace */
115 while (*inptr != '\0' && IsWhiteSpaceA(inptr))
120 return (int)(inptr - str);
123 size_t UTIL_Format(TCHAR *buffer, size_t count, const TCHAR *fmt, ...)
129 len = UTIL_FormatArgs(buffer, count, fmt, ap);
141 size_t UTIL_FormatArgs(TCHAR *buffer, size_t count, const TCHAR *fmt, va_list ap)
143 size_t len = _vsntprintf(buffer, count, fmt, ap);
154 size_t UTIL_PathFormat(TCHAR *buffer, size_t count, const TCHAR *fmt, ...)
160 len = UTIL_FormatArgs(buffer, count, fmt, ap);
163 for (size_t i = 0; i < len; i++)
165 if (buffer[i] == '/')
174 const TCHAR *GetFileFromPath(const TCHAR *path)
176 size_t len = _tcslen(path);
178 for (size_t i = len - 1;
182 if (path[i] == '\\' || path[i] == '/')
191 void GenerateErrorMessage(DWORD err, TCHAR *buffer, size_t maxchars)
193 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
196 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
201 UTIL_Format(buffer, maxchars, _T("Unknown error"));
205 INT_PTR AskToExit(HWND hWnd)
207 TCHAR verify_exit[100];
209 if (LoadString(g_hInstance,
212 sizeof(verify_exit) / sizeof(TCHAR)
215 return (INT_PTR)FALSE;
218 int val = MessageBox(
220 _T("Are you sure you want to exit?"),
221 _T("SourceMod Installer"),
222 MB_YESNO|MB_ICONQUESTION);
224 if (val == 0 || val == IDYES)
226 UpdateGlobalPosition(hWnd);
227 EndDialog(hWnd, NULL);
228 return (INT_PTR)TRUE;
231 return (INT_PTR)FALSE;
234 size_t UTIL_GetFileSize(const TCHAR *file_path)
238 if ((hFile = CreateFile(file_path,
243 FILE_ATTRIBUTE_NORMAL,
245 != INVALID_HANDLE_VALUE)
249 if (GetFileSizeEx(hFile, &size))
252 return (size_t)size.QuadPart;
262 size_t UTIL_GetFolderSize(const TCHAR *basepath)
266 TCHAR search_path[MAX_PATH];
269 UTIL_PathFormat(search_path,
270 sizeof(search_path) / sizeof(TCHAR),
274 if ((hFind = FindFirstFile(search_path, &fd)) == INVALID_HANDLE_VALUE)
281 if (tstrcasecmp(fd.cFileName, _T(".")) == 0
282 || tstrcasecmp(fd.cFileName, _T("..")) == 0)
287 if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
289 UTIL_PathFormat(search_path,
290 sizeof(search_path) / sizeof(TCHAR),
294 total += UTIL_GetFolderSize(search_path);
298 UTIL_PathFormat(search_path,
299 sizeof(search_path) / sizeof(TCHAR),
304 total += UTIL_GetFileSize(search_path);
306 } while (FindNextFile(hFind, &fd));