#ifdef IVY_CONVERT //--------------------------------------------------------------------------- #include #pragma hdrstop #include "IvyConvert_F.h" #include "SheafManager.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzShellDialogs" #pragma resource "*.dfm" TIvyConvertForm *IvyConvertForm; //--------------------------------------------------------------------------- __fastcall TIvyConvertForm::TIvyConvertForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //#endif void __fastcall TIvyConvertForm::btSelectFileClick(TObject *Sender) { if (OpenDialog1->Execute()) { // lbFilePath->Caption = OpenDialog1->FileName; OpenSelectedFile(OpenDialog1->FileName); } } //--------------------------------------------------------------------------- bool __fastcall TIvyConvertForm::OpenSelectedFile(AnsiString sFile) { WideString filename; sPath = ExtractFileDir(sFile); filename = ExtractFileName(sFile); sFileName = ExtFileName(filename, ".fsf"); for (int i = sPath.Length()-1, k=0; i>=0; i--, k++) { if (sPath.c_str()[i] == '\\') { csvFileName = sPath.SubString(i+2, k); csvFileName += ".csv"; break; } } try { MainForm->OpenFile(sPath, filename); } catch(...) { return false; } return true; } //--------------------------------------------------------------------------- AnsiString __fastcall TIvyConvertForm::MakeCSVFileName(AnsiString s_Path) { AnsiString csvFN; for (int i = s_Path.Length()-1, k=0; i>=0; i--, k++) { if (s_Path.c_str()[i] == '\\') { csvFN = s_Path.SubString(i+2, k); csvFN += ".csv"; break; } } return csvFN; } //--------------------------------------------------------------------------- bool __fastcall TIvyConvertForm::OpenTargetFile(AnsiString tFile) { return OpenSelectedFile(tFile); } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::btConvertClick(TObject *Sender) { if (MainForm->MDIChildCount == 0) return; SelectBaseFileName(); if (basePath.IsEmpty()) { btnSFolderClick(this); } if (!basePath.IsEmpty() && !baseFileName.IsEmpty()) { AnsiString filename = tPath + "\\" + csvFileName; hCsvFile = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); MainForm->OpenFile(basePath, baseFileName); AnalyseFile(0); if (hCsvFile) CloseHandle(hCsvFile); hCsvFile = NULL; } } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::Convert(AnsiString filename) { AnsiString sfilename = sPath + "\\" + filename; AnsiString fpn, backupPath; if (!OpenSelectedFile(sfilename)) goto fail; if (MainForm->MDIChildCount == 0) return; SelectBaseFileName(); if (basePath.IsEmpty() || baseFileName.IsEmpty()) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); goto fail; } try { MainForm->OpenFile(basePath, baseFileName); } catch(...) { goto fail; } AnalyseFile(0); //((TMainReportForm *)MainForm->MDIChildren[1])->Repaint(); ((TMainReportForm *)MainForm->MDIChildren[1])->FSheaf->Title = title; fpn = FullPathName(tPath, filename); SheafManagerForm->Sheaf->SaveToJPGFile(fpn); SheafManagerForm->Sheaf->SaveToTextDBFile(fpn); SheafManagerForm->Sheaf->SaveToFile(fpn); while(MainForm->MDIChildCount) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); delete ((TMainReportForm *)MainForm->MDIChildren[0]); } return; fail: backupPath = basePath + "\\" + "ConvertError"; if (!DirectoryExists(backupPath.c_str())) { if (!CreateDirectory(backupPath.c_str(), NULL)) { Application->MessageBox("Can not create Convert Error Directory!", "Warning", MB_OK);; return; } } fpn = FullPathName(backupPath, filename); CopyFile (sfilename.c_str() ,fpn.c_str(), false); return; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::SearchFileAndRun() { AnsiString dir, fn, path = sPath, subdir; HANDLE hSrch; WIN32_FIND_DATA wfd; bool bResult = true; int length = strlen(path.c_str()); if (path.c_str()[length-1] != '\\') path += "\\"; dir = path + "*.*"; AnsiString filename = tPath + "\\" + csvFileName; hCsvFile = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); hSrch = FindFirstFile(dir.c_str(), &wfd); while(bResult) { if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { subdir = wfd.cFileName; }//directory else { // file fn = wfd.cFileName; if (ExtractFileExt(fn).LowerCase() ==".fsf") { sFileName = ExtFileName(fn, ".fsf"); Convert(sFileName); } } bResult = FindNextFile(hSrch, &wfd); } FindClose(hSrch); if (hCsvFile) CloseHandle(hCsvFile); hCsvFile = NULL; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::SearchFileAndRun(AnsiString s_Path, AnsiString t_Path, int kind) { AnsiString dir, fn, subdir; HANDLE hSrch; WIN32_FIND_DATA wfd; bool bResult = true; AnsiString filename = t_Path + "\\" + MakeCSVFileName(s_Path); int length = strlen(s_Path.c_str()); if (s_Path.c_str()[length-1] != '\\') s_Path += "\\"; dir = s_Path + "*.*"; HANDLE hCsv = NULL; hCsv = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); hSrch = FindFirstFile(dir.c_str(), &wfd); while(bResult) { if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { subdir = wfd.cFileName; if (!(subdir == "." || subdir == "..")) { subdir = t_Path + "\\" + subdir; DWORD attr = GetFileAttributes(subdir.c_str()); if (attr & FILE_ATTRIBUTE_DIRECTORY) { if (!CreateDirectory(subdir.c_str(), NULL)) { Application->MessageBox("The Directory can not be created.", "Warning", MB_OK);; if (hCsvFile) CloseHandle(hCsvFile); hCsvFile = NULL; return; } subdir = wfd.cFileName; SearchFileAndRun(s_Path + "\\" + subdir, t_Path + "\\" + subdir, kind); } } }//directory else { // file fn = wfd.cFileName; if (ExtractFileExt(fn).LowerCase() ==".fsf") { sFileName = ExtFileName(fn, ".fsf"); Convert(s_Path, t_Path, sFileName, hCsv, kind); } } bResult = FindNextFile(hSrch, &wfd); } FindClose(hSrch); if (hCsv) CloseHandle(hCsv); hCsv = NULL; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::Convert(AnsiString s_Path, AnsiString t_Path, AnsiString filename, HANDLE hCsv, int kind) { AnsiString sfilename = s_Path + "\\" + filename; AnsiString fpn, backupPath; if (!OpenSelectedFile(sfilename)) goto fail; if (MainForm->MDIChildCount == 0) return; if (kind == 0) {//ÆÄÀÏ Çü½ÄÀ» º¯°æÇÏ´Â °æ¿ì¿¡¸¸ üũ SelectBaseFileName(); if (basePath.IsEmpty() || baseFileName.IsEmpty()) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); goto fail; } try { MainForm->OpenFile(basePath, baseFileName); AnalyseFile(0, hCsv); //((TMainReportForm *)MainForm->MDIChildren[1])->Repaint(); ((TMainReportForm *)MainForm->MDIChildren[1])->FSheaf->Title = title; fpn = FullPathName(t_Path, filename); SheafManagerForm->Sheaf->SaveToJPGFile(fpn); SheafManagerForm->Sheaf->SaveToTextDBFile(fpn); SheafManagerForm->Sheaf->SaveToFile(fpn); } catch(...) { goto fail; } } else if (kind == 1) { if (!AnalyseFile(hCsv)) goto fail; } while(MainForm->MDIChildCount) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); delete ((TMainReportForm *)MainForm->MDIChildren[0]); } return; fail: backupPath = t_Path + "\\ConvertError"; if (!DirectoryExists(backupPath.c_str())) { if (!CreateDirectory(backupPath.c_str(), NULL)) { Application->MessageBox("Can not create Convert Error Directory!", "Warning", MB_OK);; return; } } fpn = FullPathName(backupPath, filename); CopyFile (sfilename.c_str() ,fpn.c_str(), false); while(MainForm->MDIChildCount) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); delete ((TMainReportForm *)MainForm->MDIChildren[0]); } return; } //--------------------------------------------------------------------------- bool __fastcall TIvyConvertForm::AnalyseFile(int num, HANDLE hCsv) { TMainReportForm *mrf = NULL, *mrf2 = NULL; TPDocSheaf *Sheaf = NULL, *Sheaf2 = NULL; mrf = (TMainReportForm *)MainForm->MDIChildren[num+1]; mrf2 = (TMainReportForm *)MainForm->MDIChildren[num]; Sheaf = mrf->Sheaf; Sheaf2 = mrf2->Sheaf; // sFileName = Sheaf->FileName; if (Sheaf->GetCount() > 1) return false; if (Sheaf2->GetCount() > 1) return false; WideString temp1; AnsiString temp; TPDocSheet *sheet = Sheaf->SheafReportDoc->Sheet; TPDocSheet *sheet2 = Sheaf2->SheafReportDoc->Sheet; TPDocElement *dp = NULL, *dp2 = NULL;; int chartNum = 0; AnsiString detSheafLabelString; for (int i = 0; i < sheet->Element->Count; i++) { dp = (TPDocElement*)sheet->Element->Items[i]; switch (dp->Type) { case detLabel: //dp = new TPDocLabel(this, rc); break; case detEdit: //dp = new TPDocEdit(this, rc); break; case detMemo: //dp = new TPDocMemo(this, rc); { dp2 = (TPDocElement*)sheet2->Element->Items[i]; ((TPDocMemo*)dp2)->Copy(((TPDocMemo*)dp)); WideString kt = ((TPDocMemo*)dp)->Text; detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; break; } break; case detImage: //dp = new TPDocImage(this, rc); { dp2 = (TPDocElement*)sheet2->Element->Items[i]; ((TPDocImage*)dp2)->Copy(((TPDocImage*)dp), false); break; } case detChart: { //((TPDocChart*)dp)->Cell;//TList AnalyseChart(dp, sheet2, i, chartNum); chartNum++; break; } case detArrow: //dp = new TPDocArrow(this, rc); { RECT rc = ((TPDocArrow*)dp)->Range; dp2 = new TPDocArrow(sheet2, rc); ((TPDocArrow*)dp2)->Copy(((TPDocArrow*)dp)); (TPDocElement*)sheet2->Element->Add(dp2); break; } case detSheafImage: //dp = new TPDocSheafImage(this, rc); { RECT rc = ((TPDocSheafImage*)dp)->Range; dp2 = new TPDocSheafImage(sheet2, rc); ((TPDocSheafImage*)dp2)->Copy(((TPDocSheafImage*)dp)); (TPDocElement*)sheet2->Element->Add(dp2); break; } case detSheafLabel: //dp = new TPDocSheafLabel(this, rc); { RECT rc = ((TPDocSheafLabel*)dp)->Range; WideString kt; ((TPDocSheafLabel*)dp)->GetK_Text(kt); if (baseFileName == "type2.fsf" && rc.top >= 785 && rc.bottom < 985) { detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; //WriteCSVFile(kt, hCsv); break; } else if (baseFileName == "type3.fsf" && rc.top >= 729 && rc.bottom < 890) { detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; //WriteCSVFile(kt, hCsv); break; } dp2 = new TPDocSheafLabel(sheet2, rc); ((TPDocSheafLabel*)dp2)->Copy(((TPDocSheafLabel*)dp)); (TPDocElement*)sheet2->Element->Add(dp2); break; } case detTextImage: //dp = new TPDocTextImage(this, rc); //((TPDocTextImage*)dp)->Image;//TTexpiaBitmap break; } } int l = detSheafLabelString.Length(); //¸¶Áö¸·¿¡ ¸®ÅÏÀÌ ÀÖÀ» °æ¿ì¿¡´Â ¸®ÅÏÀ» Áö¿ö¹ö¸°´Ù. if (detSheafLabelString.c_str()[l-2] == '\r') detSheafLabelString = detSheafLabelString.SubString(1, l-2); //±ÛÀÚ°¡ ¾øÀ» °æ¿ì¿¡´Â ÆÄÀÏ¿¡ ¾²Áö ¾Ê´Â´Ù. if (!detSheafLabelString.IsEmpty()) WriteCSVFile(detSheafLabelString, hCsv); return true; } //--------------------------------------------------------------------------- bool __fastcall TIvyConvertForm::AnalyseFile(HANDLE hCsv) { TMainReportForm *mrf = NULL; TPDocSheaf *Sheaf = NULL; mrf = (TMainReportForm *)MainForm->MDIChildren[0]; Sheaf = mrf->Sheaf; typedef struct { RECT rect; WideString text; } TText_Data; if (Sheaf->GetCount() > 1) return false; TPDocSheet *sheet = Sheaf->SheafReportDoc->Sheet; TPDocElement *dp = NULL; int chartNum = 0; RECT memo_rc, notice_rc; AnsiString detSheafLabelString, noticeString; TList *list = new TList; memo_rc.left = 16; memo_rc.top = 1296; memo_rc.right = 1192; memo_rc.bottom = 2000; notice_rc.left = 16; notice_rc.top = 782; notice_rc.right = 857; notice_rc.bottom = 968; for (int i = 0; i < sheet->Element->Count; i++) { dp = (TPDocElement*)sheet->Element->Items[i]; switch (dp->Type) { case detChart: { AnalyseChart(dp, chartNum, memo_rc, detSheafLabelString); chartNum++; break; } case detLabel: //dp = new TPDocLabel(this, rc); break; case detEdit: //dp = new TPDocEdit(this, rc); break; case detMemo: //dp = new TPDocMemo(this, rc); { WideString kt = ((TPDocMemo*)dp)->Text; memo_rc = ((TPDocMemo*)dp)->Range; detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; break; } break; case detImage: //dp = new TPDocImage(this, rc); { break; } case detArrow: //dp = new TPDocArrow(this, rc); { break; } case detSheafImage: //dp = new TPDocSheafImage(this, rc); { break; } case detSheafLabel: //dp = new TPDocSheafLabel(this, rc); { RECT rc = ((TPDocSheafLabel*)dp)->Range; WideString kt; ((TPDocSheafLabel*)dp)->GetK_Text(kt); if (memo_rc.right == 0 && memo_rc.bottom == 0) { TText_Data *data = new TText_Data; data->rect = rc; data->text = kt; list->Add(data); break; } // ÁÖÀÇ»çÇ× ºÎºÐ¿¡ ÀûÇô ÀÖ´Â ¶óº§(ÅØ½ºÆ®¹Ú½º) ³»¿ëÀ» °¡Á®¿È else if (rc.top >= notice_rc.top && rc.bottom <= notice_rc.bottom && rc.left >= notice_rc.left && rc.right <= notice_rc.right) { noticeString = kt; if (!kt.IsEmpty()) noticeString += "\r\n"; break; } // ¸Þ¸ð ºÎºÐ¿¡ ÀûÇô ÀÖ´Â ¶óº§(ÅØ½ºÆ®¹Ú½º) ³»¿ëÀ» °¡Á®¿È else if (rc.top >= memo_rc.top && rc.bottom <= memo_rc.bottom && rc.left >= memo_rc.left && rc.right <= memo_rc.right) { detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; break; } break; } case detTextImage: break; } } for (int i = 0; i < list->Count; i++) { TText_Data *data = NULL; data = (TText_Data*)list->Items[i]; if (data->rect.top >= memo_rc.top && data->rect.bottom < memo_rc.bottom) { detSheafLabelString += data->text; if (!data->text.IsEmpty()) detSheafLabelString += "\r\n"; } delete data; data = NULL; } list->Clear(); delete list; list = NULL; int l = detSheafLabelString.Length(); if (!detSheafLabelString.IsEmpty()) { if (detSheafLabelString.Pos("\"")) return false; } if (!noticeString.IsEmpty()) { if (noticeString.Pos("\"")) return false; if (detSheafLabelString.c_str()[l-2] == '\r') detSheafLabelString = detSheafLabelString.SubString(1, l-2); detSheafLabelString += "\",\""; detSheafLabelString += noticeString; } //¸¶Áö¸·¿¡ ¸®ÅÏÀÌ ÀÖÀ» °æ¿ì¿¡´Â ¸®ÅÏÀ» Áö¿ö¹ö¸°´Ù. if (detSheafLabelString.c_str()[l-2] == '\r') detSheafLabelString = detSheafLabelString.SubString(1, l-2); //±ÛÀÚ°¡ ¾øÀ» °æ¿ì¿¡´Â ÆÄÀÏ¿¡ ¾²Áö ¾Ê´Â´Ù. if (!detSheafLabelString.IsEmpty()) { WriteCSVFile(detSheafLabelString, hCsv); } return true; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::AnalyseChart(TPDocElement *element, TPDocSheet *sheet2, int ElementIndex, int chartNum) { if (baseFileName == "type1.fsf" && chartNum > 3) return; else if (baseFileName == "type2.fsf" && chartNum > 3) return; else if (baseFileName == "type3.fsf" && chartNum > 4) return; TPDocChart* chart = (TPDocChart*)element; TPDocElement *dp = NULL; TPDocChart* chart2 = (TPDocChart*)sheet2->Element->Items[ElementIndex]; TPDocElement *dp2 = NULL; AnsiString temp; for (int i = 0 ;i < chart->Cell->Count; i++) { if (baseFileName == "type1.fsf" && chartNum == 3 && i > 1) break; else if (baseFileName == "type2.fsf" && chartNum == 3 && i > 1) break; else if (baseFileName == "type3.fsf" && chartNum == 1 && i > 10) break; dp = (TPDocElement*)chart->Cell->Items[i]; dp2 = (TPDocElement*)chart2->Cell->Items[i]; switch (dp->Type) { case detLabel: { //temp = ((TPDocLabel*)dp)->Text; //WideString ((TPDocLabel*)dp2)->Copy(((TPDocLabel*)dp)); break; } case detEdit: { if (baseFileName == "type1.fsf" && chartNum == 1 && i ==5) { title = ((TPDocEdit*)dp)->K_Text; //WideString } else if (baseFileName == "type2.fsf" && chartNum == 1 && i == 5) { title = ((TPDocEdit*)dp)->K_Text; //WideString } else if (baseFileName == "type3.fsf" && chartNum == 2 && i == 5) { title = ((TPDocEdit*)dp)->K_Text; //WideString } //title = ((TPDocEdit*)dp)->K_Text; //WideString ((TPDocEdit*)dp2)->Copy(((TPDocEdit*)dp)); break; } case detImage: { //((TPDocImage*)dp)->Image;//TTexpiaBitmap ((TPDocImage*)dp2)->Copy(((TPDocImage*)dp)); break; } case detMemo: { //temp = ((TPDocMemo*)dp)->Text;//WideString ((TPDocMemo*)dp2)->Copy(((TPDocMemo*)dp)); break; } case detTextImage: //dp = new TPDocTextImage(this, rc); break; } } } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::AnalyseChart(TPDocElement *element, int chartNum, RECT &rect, AnsiString &detSheafLabelString) { TPDocChart* chart = (TPDocChart*)element; TPDocElement *dp = NULL; AnsiString temp; for (int i = 0 ;i < chart->Cell->Count; i++) { dp = (TPDocElement*)chart->Cell->Items[i]; switch (dp->Type) { case detLabel: { break; } case detEdit: { break; } case detImage: { break; } case detMemo: { WideString kt = ((TPDocMemo*)dp)->Text; /*if ( detSheafLabelString.IsEmpty() ) { rect = ((TPDocMemo*)dp)->Range; rect.left += chart->Range.left; rect.top += chart->Range.top; rect.right += rect.left; rect.bottom += rect.top; } */ detSheafLabelString += kt; if (!kt.IsEmpty()) detSheafLabelString += "\r\n"; break; } case detTextImage: //dp = new TPDocTextImage(this, rc); break; } } } //--------------------------------------------------------------------------- bool __fastcall TIvyConvertForm::SelectBaseFileName(int num) { TMainReportForm *mrf = NULL; TPDocSheaf *Sheaf = NULL; mrf = (TMainReportForm *)MainForm->MDIChildren[num]; Sheaf = mrf->Sheaf; // sFileName = Sheaf->FileName; if (Sheaf->GetCount() > 1) return false; TPDocSheet *sheet = Sheaf->SheafReportDoc->Sheet; TPDocElement *element = NULL; TPDocChart* chart = NULL; TPDocElement *dp = NULL; AnsiString temp; baseFileName = ""; int chartCount = 0; for (int j = 0; j < sheet->Element->Count; j++) { element = (TPDocElement*)sheet->Element->Items[j]; if (element->Type == detChart) { if (chartCount > 4) return false; chart = (TPDocChart*)element; chartCount++; for (int i = 0 ;i < chart->Cell->Count; i++) { dp = (TPDocElement*)chart->Cell->Items[i]; if (dp->Type == detLabel) { temp = ((TPDocLabel*)dp)->Text; if (temp == "Å×ÀÌÇÁ") { baseFileName = "type1.fsf"; return true; } else if (temp == "°Ñ °¨") { baseFileName = "type3.fsf"; return true; } else if (temp == "½º Ÿ ÀÏ") { baseFileName = "type2.fsf"; return true; } } } } } return false; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::btnTFolderClick(TObject *Sender) { if (RzSelectFolderDialog1->Execute()) { // lbTatget->Caption = RzSelectFolderDialog1->SelectedPathName; // tPath = lbTatget->Caption; tPath = RzSelectFolderDialog1->SelectedPathName; } } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::btnSFolderClick(TObject *Sender) { if (RzSelectFolderDialog1->Execute()) { sPath = RzSelectFolderDialog1->SelectedPathName; for (int i = sPath.Length()-1, k=0; i>=0; i--, k++) { if (sPath.c_str()[i] == '\\') { csvFileName = sPath.SubString(i+2, k); csvFileName += ".csv"; break; } } } } //--------------------------------------------------------------------------- int __fastcall TIvyConvertForm::WriteCSVFile(AnsiString string, HANDLE hCsv) { DWORD dwWritten; int size = 0; AnsiString data; AnsiString sfilename = sFileName.SubString(1, sFileName.Length()-4); data = sfilename; data += ",\""; data += string; data += "\"\r\n"; //char temp[10] ="¹Ú»óÈÆ"; //WriteFile(hCsvFile, temp, strlen(temp), &dwWritten, NULL); if (hCsv) WriteFile(hCsv, data.c_str(), strlen(data.c_str()), &dwWritten, NULL); else WriteFile(hCsvFile, data.c_str(), strlen(data.c_str()), &dwWritten, NULL); size += dwWritten; return size; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::Button1Click(TObject *Sender) { if (RzSelectFolderDialog1->Execute()) { basePath = RzSelectFolderDialog1->SelectedPathName; } } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::Button2Click(TObject *Sender) { if (sPath.IsEmpty() || tPath.IsEmpty() || basePath.IsEmpty()) return; //SearchFileAndRun(); SearchFileAndRun(sPath, tPath); Application->MessageBox("Converting is finished!", "Information", MB_OK); } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::SearchFileAndRun2(AnsiString s_Path, AnsiString t_Path) { AnsiString dir, fn, subdir; HANDLE hSrch; WIN32_FIND_DATA wfd; bool bResult = true; int length = strlen(s_Path.c_str()); if (s_Path.c_str()[length-1] != '\\') s_Path += "\\"; dir = s_Path + "*.*"; HANDLE hCsv = NULL; hSrch = FindFirstFile(dir.c_str(), &wfd); while(bResult) { if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { subdir = wfd.cFileName; if (!(subdir == "." || subdir == "..")) { subdir = t_Path + "\\" + subdir; DWORD attr = GetFileAttributes(subdir.c_str()); if (attr & FILE_ATTRIBUTE_DIRECTORY) { if (!CreateDirectory(subdir.c_str(), NULL)) { Application->MessageBox("The Directory can not be created.", "Warning", MB_OK);; if (hCsvFile) CloseHandle(hCsvFile); hCsvFile = NULL; return; } subdir = wfd.cFileName; SearchFileAndRun(s_Path + "\\" + subdir, t_Path + "\\" + subdir); } } }//directory else { // file fn = wfd.cFileName; if (ExtractFileExt(fn).LowerCase() ==".fsf") { sFileName = ExtFileName(fn, ".fsf"); Convert2(s_Path, t_Path, sFileName, hCsv); } } bResult = FindNextFile(hSrch, &wfd); } FindClose(hSrch); hCsv = NULL; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::Convert2(AnsiString s_Path, AnsiString t_Path, AnsiString filename, HANDLE hCsv) { AnsiString sfilename = s_Path + "\\" + filename; AnsiString fpn, backupPath; if (!OpenSelectedFile(sfilename)) goto fail; if (MainForm->MDIChildCount == 0) return; try { fpn = FullPathName(t_Path, filename); SheafManagerForm->Sheaf->SaveToFile(fpn); } catch(...) { goto fail; } while(MainForm->MDIChildCount) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); delete ((TMainReportForm *)MainForm->MDIChildren[0]); } return; fail: backupPath = t_Path + "\\ConvertError"; if (!DirectoryExists(backupPath.c_str())) { if (!CreateDirectory(backupPath.c_str(), NULL)) { Application->MessageBox("Can not create Convert Error Directory!", "Warning", MB_OK);; return; } } fpn = FullPathName(backupPath, filename); CopyFile (sfilename.c_str() ,fpn.c_str(), false); while(MainForm->MDIChildCount) { ((TMainReportForm *)MainForm->MDIChildren[0])->Close(); delete ((TMainReportForm *)MainForm->MDIChildren[0]); } return; } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::MakeJpgBtnClick(TObject *Sender) { if (sPath.IsEmpty() || tPath.IsEmpty()) return; //SearchFileAndRun(); SearchFileAndRun2(sPath, tPath); Application->MessageBox("Converting is finished!", "Information", MB_OK); } //--------------------------------------------------------------------------- void __fastcall TIvyConvertForm::memoCsvBtnClick(TObject *Sender) { if (sPath.IsEmpty() || tPath.IsEmpty()) return; //SearchFileAndRun(); SearchFileAndRun(sPath, tPath, 1); Application->MessageBox("Converting is finished!", "Information", MB_OK); } //--------------------------------------------------------------------------- #endif //IVY_CONVERT