mirror of
https://github.com/WinampDesktop/winamp.git
synced 2024-12-27 17:23:10 +01:00
163 lines
4.6 KiB
C++
163 lines
4.6 KiB
C++
#include ".\main.h"
|
|
#include ".\xzip\xzip.h"
|
|
#include ".\smtp\smtp.h"
|
|
#include ".\email\sendemail.h"
|
|
#include <strsafe.h>
|
|
|
|
const wchar_t* GetFileName(const wchar_t *fullname)
|
|
{
|
|
if (!fullname) return NULL;
|
|
const wchar_t *start = wcsrchr(fullname, L'\\');
|
|
if (start && start != fullname) start = CharNext(start);
|
|
|
|
return start;
|
|
}
|
|
|
|
BOOL ZipData(void)
|
|
{
|
|
BOOL retCode = FALSE;
|
|
HZIP hz = CreateZip(settings.zipPath, 0, ZIP_FILENAME);
|
|
if (hz)
|
|
{
|
|
retCode = TRUE;
|
|
if (settings.createLOG && settings.ReadLogCollectResult()) retCode = (ZR_OK == ZipAdd(hz, GetFileName(settings.logPath), settings.logPath, 0, ZIP_FILENAME));
|
|
if (retCode && settings.createDMP && settings.ReadDmpCollectResult()) retCode = (ZR_OK == ZipAdd(hz, GetFileName(settings.dumpPath), settings.dumpPath, 0, ZIP_FILENAME));
|
|
}
|
|
CloseZip(hz);
|
|
return retCode;
|
|
}
|
|
|
|
LPCTSTR BuildSubjectString(LPCTSTR subject)
|
|
{
|
|
static wchar_t subject_str[512] = {L"Winamp Error Report"};
|
|
wchar_t uid_str[64] = {0}, path[MAX_PATH] = {0};
|
|
if (GetModuleFileName(0, path, MAX_PATH))
|
|
{
|
|
PathRemoveFileSpec(path);
|
|
wchar_t *p = path + wcslen(path) - 1;
|
|
while(p && *p && *p != L'\\')
|
|
{
|
|
p = CharPrev(path, p);
|
|
}
|
|
if (p) *p = 0;
|
|
PathAppend(path, L"winamp.exe");
|
|
|
|
HKEY hkey = NULL;
|
|
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Nullsoft\\Winamp", 0, 0, 0, KEY_READ, NULL, &hkey, NULL) == ERROR_SUCCESS)
|
|
{
|
|
DWORD s = 512, t = REG_SZ;
|
|
if (RegQueryValueEx(hkey, path, 0, &t, (LPBYTE)uid_str, &s) != ERROR_SUCCESS || t != REG_SZ) uid_str[0] = 0;
|
|
RegCloseKey(hkey);
|
|
}
|
|
}
|
|
|
|
// if it fails then we'll need to make something...
|
|
if (!uid_str[0])
|
|
{
|
|
GUID guid;
|
|
UuidCreate(&guid);
|
|
StringCbPrintf(uid_str, ARRAYSIZE(uid_str), L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
|
|
(int)guid.Data1, (int)guid.Data2, (int)guid.Data3, (int)guid.Data4[0],
|
|
(int)guid.Data4[1], (int)guid.Data4[2], (int)guid.Data4[3],
|
|
(int)guid.Data4[4], (int)guid.Data4[5], (int)guid.Data4[6], (int)guid.Data4[7]);
|
|
}
|
|
|
|
if (StringCchPrintfW(subject_str, ARRAYSIZE(subject_str), L"%s [%s]", subject, uid_str) == S_OK)
|
|
return subject_str;
|
|
else
|
|
return subject;
|
|
}
|
|
|
|
BOOL SendData(HWND hwnd)
|
|
{
|
|
BOOL retCode = FALSE;
|
|
const wchar_t *subject = L"Winamp Error Report";
|
|
const wchar_t *senderName = L"Winamp Error Reporter";
|
|
const wchar_t *recipientAddress = L"bug@winamp.com";
|
|
const wchar_t *recipientName = L"Nullsoft Bug Reporting";
|
|
wchar_t *msgInfo = _wcsdup(settings.ReadBody());
|
|
|
|
wchar_t *p = msgInfo, *end = p + wcslen(msgInfo);
|
|
while(p != end)
|
|
{
|
|
if (*p == 1) *p = L'\r';
|
|
if (*p == 2) *p = L'\n';
|
|
p++;
|
|
}
|
|
|
|
if (settings.sendBySMTP)
|
|
{
|
|
CSmtp smtp;
|
|
CSmtpMessage msg;
|
|
CSmtpMessageBody body;
|
|
CSmtpAttachment attach;
|
|
|
|
msg.Subject = BuildSubjectString(subject);
|
|
|
|
// Who the message is from
|
|
msg.Sender.Name = senderName;
|
|
msg.Sender.Address = settings.smtpAddress;
|
|
msg.Recipient.Address = recipientAddress;
|
|
msg.Recipient.Name = recipientName;
|
|
if(settings.zipData )
|
|
{
|
|
attach.FileName = settings.zipPath;
|
|
msg.Attachments.Add(attach);
|
|
}
|
|
else
|
|
{
|
|
if (settings.createLOG && settings.ReadLogCollectResult()) attach.FileName = settings.logPath;
|
|
msg.Attachments.Add(attach);
|
|
if (settings.createDMP && settings.ReadDmpCollectResult()) attach.FileName = settings.dumpPath;
|
|
msg.Attachments.Add(attach);
|
|
}
|
|
|
|
// smtp.m_wSmtpPort = settings.smtpPort; - not working for some reasons
|
|
if (settings.smtpAuth)
|
|
{
|
|
smtp.m_strUser = settings.smtpUser;
|
|
smtp.m_strPass = settings.smtpPwd;;
|
|
}
|
|
|
|
body = L"This message was generated by Winamp Error Reporter v1.09.\r\nPlease check attachments for viruses.\r\n";
|
|
body.Data.append(L"\r\n");
|
|
body.Data.append(msgInfo);
|
|
|
|
msg.Message.Add(body);
|
|
retCode = smtp.Connect(settings.smtpServer);
|
|
if ( retCode )
|
|
{
|
|
// Send the message and close the connection afterwards
|
|
retCode = (smtp.SendMessage(msg) == 0);
|
|
smtp.Close();
|
|
}
|
|
}
|
|
else if(settings.sendByClient)
|
|
{
|
|
retCode = SendEmail(hwnd, recipientAddress, recipientName, BuildSubjectString(subject), msgInfo, settings.zipPath);
|
|
}
|
|
|
|
return retCode;
|
|
}
|
|
|
|
BOOL Restart(void)
|
|
{
|
|
STARTUPINFO si = {0};
|
|
si.cb = sizeof(si);
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
si.wShowWindow = SW_SHOW;
|
|
|
|
PROCESS_INFORMATION pi = {0};
|
|
return CreateProcess(
|
|
settings.ReadWinamp(), // name of executable module
|
|
NULL, // command line string
|
|
NULL, // process attributes
|
|
NULL, // thread attributes
|
|
FALSE, // handle inheritance option
|
|
0, // creation flags
|
|
NULL, // new environment block
|
|
NULL, // current directory name
|
|
&si, // startup information
|
|
&pi // process information
|
|
);
|
|
} |