//--------------------------------------------------------------------------- #include #include // ³×Æ®¿öÅ© ¿¬°á À¯¹« - by monkman (2008.12.15) //--------------------------------------------------------------------------- #pragma hdrstop #include "ExceptionReport_F.h" #include "define.h" #include "common.h" // Indy 10¿¡¼­ ÷ºÎ ÆÄÀÏ º¸³»±â - by monkman (2010.07.08) #include //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- #pragma link "sensapi.lib" // ³×Æ®¿öÅ© ¿¬°á À¯¹« - by monkman (2008.12.15) //--------------------------------------------------------------------------- #pragma link "RzButton" #pragma link "RzEdit" #pragma link "RzLabel" #pragma link "RzRadChk" #pragma link "IdExplicitTLSClientServerBase" #pragma link "IdSMTPBase" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_TITLE StringTable[0] #define IDS_NOTICE StringTable[1] #define IDS_POSITION StringTable[2] #define IDS_PART StringTable[3] #define IDS_EMAIL StringTable[4] #define IDS_WORK StringTable[5] #define IDS_SENDMAIL StringTable[6] #define IDS_DELETELOG StringTable[7] #define IDS_CANCEL StringTable[8] #define IDS_NETWORKDEAD StringTable[9] #define IDS_ERROR_REPORTING StringTable[10] //--------------------------------------------------------------------------- TExceptionReportForm *ExceptionReportForm; //--------------------------------------------------------------------------- __fastcall TExceptionReportForm::TExceptionReportForm(TComponent* Owner) : TForm(Owner) { AttachFileList = NULL; strsFilters = NULL; StringTable.Create(DirectoryBin, Language, "ExceptionReport"); Caption = IDS_TITLE; rzlbNotice->Caption = IDS_NOTICE; rzlbPosition->Caption = IDS_POSITION; rzlbPart->Caption = IDS_PART; rzlbEmail->Caption = IDS_EMAIL; rzlbWork->Caption = IDS_WORK; rzbitbtnSendMail->Caption = IDS_SENDMAIL; rzbitbtnDelete->Caption = IDS_DELETELOG; rzbitbtnCancel->Caption = IDS_CANCEL; rzchkbxErrorReport->Caption = IDS_ERROR_REPORTING; SetSmallFont(edPosition->Font); SetSmallFont(edPart->Font); SetSmallFont(edEmail->Font); SetSmallFont(memoWork->Font); } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::FormCreate(TObject *Sender) { String strFilename; AttachFileList = new TStringList; strsFilters = new TStringList; strsFilters->Add(".tex"); strsFilters->Add(".tfc"); strsFilters->Add(".log"); strFilename = DefaultDir + "\\Bin\\error_report.bmp"; if (FileExists(strFilename)) { imgErrorReport->Picture->LoadFromFile(strFilename); } } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::FormClose(TObject *Sender, TCloseAction &Action) { // ¿À·ù º¸°í ±â´É »ç¿ë üũ - by monkman (2009.02.17) TIniFile *IniFile = NULL; if (rzchkbxErrorReport->Checked == true) { IniFile = new TIniFile(AppDataBin + "\\Configuration.ini"); if (IniFile) { IniFile->WriteString("Common", "ErrorReport", "false"); delete IniFile; } } IniFile = NULL; } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::FormDestroy(TObject *Sender) { if (AttachFileList) delete AttachFileList; if (strsFilters) delete strsFilters; AttachFileList = NULL; } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::rzbitbtnSendMailClick(TObject *Sender) { // ¸ÞÀÏ º¸³»±â String strDirName, strBody; UTF8String utf8strBody; DWORD dwNetworkFlag; dwNetworkFlag = NETWORK_ALIVE_LAN | NETWORK_ALIVE_WAN | NETWORK_ALIVE_AOL; if (IsNetworkAlive(&dwNetworkFlag)) { // ³×Æ®¿öÅ© ¿¬°á À¯¹« - by monkman (2008.12.15) IdSMTP->Host = L"www.texclub.com"; IdSMTP->HeloName = L"debug"; // ³ÖÁö ¾ÊÀ¸¸é ÄÄÇ»ÅÍ À̸§ÀÌ ¿µ¹®ÀÌ ¾Æ´Ò °æ¿ì "5.0.0 Invalid domain name" ¿¡·¯°¡ ¶á´Ù. IdMsg->From->Text = ExtractFileName(Application->ExeName) + " " + TexStylistVersion + " User"; if (edEmail->Text.IsEmpty() == false) IdMsg->From->Text = edEmail->Text; IdMsg->Subject = "[EXCEPTION] " + ExtractFileName(Application->ExeName) + " " + TexStylistVersion; // Indy 10¿¡¼­ ¸ÞÀÏ º»¹® »ç¿ëÇϱâ - by monkman (2010.07.08) //IdMsg->ContentType = "multipart/form-data"; IdMsg->ContentType = "multipart/mixed; charset=utf-8"; IdMsg->Recipients->EMailAddresses = "debug@texclub.com"; /* IdMsg->Body->Add("[Exception]"); IdMsg->Body->Add(ExtractFileName(Application->ExeName) + " " + TexProVersion + " User"); IdMsg->Body->Add(""); if (rzedPosition->Text.IsEmpty() == false) IdMsg->Body->Add("Company(School) name : " + rzedPosition->Text); if (rzedPart->Text.IsEmpty() == false) IdMsg->Body->Add("Division(major) : " + rzedPart->Text); if (rzmemoWork->Text.IsEmpty() == false) IdMsg->Body->Add("Work : " + rzmemoWork->Text); */ strBody = L"[Exception]"; strBody += L"\r\n" + ExtractFileName(Application->ExeName) + L" " + TexStylistVersion + L" User"; strBody += L"\r\n"; if (edPosition->Text.IsEmpty() == false) strBody += L"\r\nCompany(School) name : " + edPosition->Text; if (edPart->Text.IsEmpty() == false) strBody += L"\r\nDivision(major) : " + edPart->Text; if (memoWork->Text.IsEmpty() == false) strBody += L"\r\nWork : " + memoWork->Text; utf8strBody = UTF8Encode(strBody); IdMsg->Body->Add(utf8strBody); strDirName = AppDataBin + "\\Exception"; FindFiles(strDirName, strsFilters, false); for (int i = 0; i < AttachFileList->Count; i++) { // Indy 10¿¡¼­ ÷ºÎ ÆÄÀÏ º¸³»±â - by monkman (2010.07.08) TIdAttachmentFile(IdMsg->MessageParts, AttachFileList->Strings[i]); } try { // Indy 10¿¡¼­ ¸ÞÀÏ º¸³»±â - by monkman (2010.07.08) //IdSMTP->Connect(10); // 10ÃÊ IdSMTP->Connect(); IdSMTP->Send(IdMsg); for (int i = 0; i < AttachFileList->Count; i++) { DeleteFile(AttachFileList->Strings[i].c_str()); // ÆÄÀÏ »èÁ¦ } Close(); } catch (EIdSocketError &exception) { MessageDlg(IDS_NETWORKDEAD, mtInformation, TMsgDlgButtons() << mbOK, 0); IdSMTP->Disconnect(); delete IdSMTP; delete IdMsg; if (ExceptionReportForm) delete ExceptionReportForm; IdSMTP = NULL; IdMsg = NULL; ExceptionReportForm = NULL; Close(); } } else { MessageDlg(IDS_NETWORKDEAD, mtInformation, TMsgDlgButtons() << mbOK, 0); Close(); } } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::rzbitbtnDeleteClick(TObject *Sender) { // Exception Æú´õ ¾Æ·¡ ÆÄÀÏ Áö¿ì±â String strDirName; SHFILEOPSTRUCT shfoDelete; strDirName = AppDataBin + "\\Exception"; FindFiles(strDirName, strsFilters, false); memset(&shfoDelete, 0, sizeof(SHFILEOPSTRUCT)); shfoDelete.hwnd = Handle; shfoDelete.wFunc = FO_DELETE; shfoDelete.fFlags = FOF_SIMPLEPROGRESS | FOF_ALLOWUNDO | FOF_NOCONFIRMATION; for (int i = 0; i < AttachFileList->Count; i++) { DeleteFile(AttachFileList->Strings[i].c_str()); // ÆÄÀÏ »èÁ¦ // ÈÞÁöÅëÀ¸·Î º¸³»µµ·Ï º¯°æ - by monkman (2009.10.14) /* shfoDelete.pFrom = new Char[AttachFileList->Strings[i].Length()+2]; // ¸¶Áö¸·ÀÌ '\0\0'À̾î¾ß ÇÑ´Ù memset((void *)shfoDelete.pFrom, 0, sizeof(Char) * AttachFileList->Strings[i].Length()+2); _tcscpy((Char *)shfoDelete.pFrom, AttachFileList->Strings[i].c_str()); SHFileOperation(&shfoDelete); if (shfoDelete.pFrom) delete []shfoDelete.pFrom; shfoDelete.pFrom = NULL; */ } Close(); } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::rzbitbtnCancelClick(TObject *Sender) { // Exception Æú´õ ¾Æ·¡ Cancel Æú´õ¿¡ ¿Å°Ü³õÀ½ - by monkman (2009.12.24) String strSrcDirName, strDstDirName, strSrcPath, strDstPath, strFileName; strSrcDirName = AppDataBin + "\\Exception"; strDstDirName = AppDataBin + "\\Exception\\Cancel"; FindFiles(strSrcDirName, strsFilters, false); // Æú´õ°¡ Á¸ÀçÇÏÁö ¾ÊÀ» °æ¿ì Æú´õ »ý¼º if (DirectoryExists(strDstDirName.c_str()) == false) CreateDirectory(strDstDirName.c_str(), 0); for (int i = 0; i < AttachFileList->Count; i++) { // Cancel Æú´õ·Î À̵¿ strSrcPath = AttachFileList->Strings[i]; strFileName = ExtractFileName(strSrcPath); strDstPath = strDstDirName + "\\" + strFileName; MoveFile(strSrcPath.c_str(), strDstPath.c_str()); } Close(); } //--------------------------------------------------------------------------- bool __fastcall TExceptionReportForm::MatchesFilenameFilters(const String strFileName, TStrings* strsFilters) { for (int i = 0; i < strsFilters->Count; i++){ if (ExtractFileExt(strFileName).LowerCase() == strsFilters->Strings[i].LowerCase()) { return true; } } return false; } //--------------------------------------------------------------------------- void __fastcall TExceptionReportForm::FindFiles(const String strDirName, TStrings *strsFilters, bool bRecursive) { // ÆÄÀÏ °Ë»ö TSearchRec sr; int iAttributes = faReadOnly | faHidden | faSysFile | faVolumeID | faDirectory | faArchive | faAnyFile; AttachFileList->Clear(); if (DirectoryExists(strDirName)) { if (FindFirst(strDirName+"\\*.*", iAttributes, sr)==0){ do { if (sr.Attr & faDirectory) { if (bRecursive && sr.Name[1] != '.') FindFiles(strDirName+"\\"+sr.Name, strsFilters, bRecursive); } else { if (MatchesFilenameFilters(sr.Name, strsFilters)) AttachFileList->Add(strDirName + "\\" + sr.Name); //ÆÄÀÏÇÊÅÍ¿¡ ¸ÂÀ½ } } while (FindNext(sr) == 0); FindClose(sr); } } } //---------------------------------------------------------------------------