1
0

operations.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include ".\main.h"
  2. #include ".\xzip\xzip.h"
  3. #include ".\smtp\smtp.h"
  4. #include ".\email\sendemail.h"
  5. #include <strsafe.h>
  6. const wchar_t* GetFileName(const wchar_t *fullname)
  7. {
  8. if (!fullname) return NULL;
  9. const wchar_t *start = wcsrchr(fullname, L'\\');
  10. if (start && start != fullname) start = CharNext(start);
  11. return start;
  12. }
  13. BOOL ZipData(void)
  14. {
  15. BOOL retCode = FALSE;
  16. HZIP hz = CreateZip(settings.zipPath, 0, ZIP_FILENAME);
  17. if (hz)
  18. {
  19. retCode = TRUE;
  20. if (settings.createLOG && settings.ReadLogCollectResult()) retCode = (ZR_OK == ZipAdd(hz, GetFileName(settings.logPath), settings.logPath, 0, ZIP_FILENAME));
  21. if (retCode && settings.createDMP && settings.ReadDmpCollectResult()) retCode = (ZR_OK == ZipAdd(hz, GetFileName(settings.dumpPath), settings.dumpPath, 0, ZIP_FILENAME));
  22. }
  23. CloseZip(hz);
  24. return retCode;
  25. }
  26. LPCTSTR BuildSubjectString(LPCTSTR subject)
  27. {
  28. static wchar_t subject_str[512] = {L"Winamp Error Report"};
  29. wchar_t uid_str[64] = {0}, path[MAX_PATH] = {0};
  30. if (GetModuleFileName(0, path, MAX_PATH))
  31. {
  32. PathRemoveFileSpec(path);
  33. wchar_t *p = path + wcslen(path) - 1;
  34. while(p && *p && *p != L'\\')
  35. {
  36. p = CharPrev(path, p);
  37. }
  38. if (p) *p = 0;
  39. PathAppend(path, L"winamp.exe");
  40. HKEY hkey = NULL;
  41. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Nullsoft\\Winamp", 0, 0, 0, KEY_READ, NULL, &hkey, NULL) == ERROR_SUCCESS)
  42. {
  43. DWORD s = 512, t = REG_SZ;
  44. if (RegQueryValueEx(hkey, path, 0, &t, (LPBYTE)uid_str, &s) != ERROR_SUCCESS || t != REG_SZ) uid_str[0] = 0;
  45. RegCloseKey(hkey);
  46. }
  47. }
  48. // if it fails then we'll need to make something...
  49. if (!uid_str[0])
  50. {
  51. GUID guid;
  52. UuidCreate(&guid);
  53. StringCbPrintf(uid_str, ARRAYSIZE(uid_str), L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  54. (int)guid.Data1, (int)guid.Data2, (int)guid.Data3, (int)guid.Data4[0],
  55. (int)guid.Data4[1], (int)guid.Data4[2], (int)guid.Data4[3],
  56. (int)guid.Data4[4], (int)guid.Data4[5], (int)guid.Data4[6], (int)guid.Data4[7]);
  57. }
  58. if (StringCchPrintfW(subject_str, ARRAYSIZE(subject_str), L"%s [%s]", subject, uid_str) == S_OK)
  59. return subject_str;
  60. else
  61. return subject;
  62. }
  63. BOOL SendData(HWND hwnd)
  64. {
  65. BOOL retCode = FALSE;
  66. const wchar_t *subject = L"Winamp Error Report";
  67. const wchar_t *senderName = L"Winamp Error Reporter";
  68. const wchar_t *recipientAddress = L"[email protected]";
  69. const wchar_t *recipientName = L"Nullsoft Bug Reporting";
  70. wchar_t *msgInfo = _wcsdup(settings.ReadBody());
  71. wchar_t *p = msgInfo, *end = p + wcslen(msgInfo);
  72. while(p != end)
  73. {
  74. if (*p == 1) *p = L'\r';
  75. if (*p == 2) *p = L'\n';
  76. p++;
  77. }
  78. if (settings.sendBySMTP)
  79. {
  80. CSmtp smtp;
  81. CSmtpMessage msg;
  82. CSmtpMessageBody body;
  83. CSmtpAttachment attach;
  84. msg.Subject = BuildSubjectString(subject);
  85. // Who the message is from
  86. msg.Sender.Name = senderName;
  87. msg.Sender.Address = settings.smtpAddress;
  88. msg.Recipient.Address = recipientAddress;
  89. msg.Recipient.Name = recipientName;
  90. if(settings.zipData )
  91. {
  92. attach.FileName = settings.zipPath;
  93. msg.Attachments.Add(attach);
  94. }
  95. else
  96. {
  97. if (settings.createLOG && settings.ReadLogCollectResult()) attach.FileName = settings.logPath;
  98. msg.Attachments.Add(attach);
  99. if (settings.createDMP && settings.ReadDmpCollectResult()) attach.FileName = settings.dumpPath;
  100. msg.Attachments.Add(attach);
  101. }
  102. // smtp.m_wSmtpPort = settings.smtpPort; - not working for some reasons
  103. if (settings.smtpAuth)
  104. {
  105. smtp.m_strUser = settings.smtpUser;
  106. smtp.m_strPass = settings.smtpPwd;;
  107. }
  108. body = L"This message was generated by Winamp Error Reporter v1.09.\r\nPlease check attachments for viruses.\r\n";
  109. body.Data.append(L"\r\n");
  110. body.Data.append(msgInfo);
  111. msg.Message.Add(body);
  112. retCode = smtp.Connect(settings.smtpServer);
  113. if ( retCode )
  114. {
  115. // Send the message and close the connection afterwards
  116. retCode = (smtp.SendMessage(msg) == 0);
  117. smtp.Close();
  118. }
  119. }
  120. else if(settings.sendByClient)
  121. {
  122. retCode = SendEmail(hwnd, recipientAddress, recipientName, BuildSubjectString(subject), msgInfo, settings.zipPath);
  123. }
  124. return retCode;
  125. }
  126. BOOL Restart(void)
  127. {
  128. STARTUPINFO si = {0};
  129. si.cb = sizeof(si);
  130. si.dwFlags = STARTF_USESHOWWINDOW;
  131. si.wShowWindow = SW_SHOW;
  132. PROCESS_INFORMATION pi = {0};
  133. return CreateProcess(
  134. settings.ReadWinamp(), // name of executable module
  135. NULL, // command line string
  136. NULL, // process attributes
  137. NULL, // thread attributes
  138. FALSE, // handle inheritance option
  139. 0, // creation flags
  140. NULL, // new environment block
  141. NULL, // current directory name
  142. &si, // startup information
  143. &pi // process information
  144. );
  145. }