//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "CopyFiles_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzChkLst" #pragma link "RzLstBox" #pragma link "RzChkLst" #pragma link "RzLstBox" #pragma link "RzListVw" #pragma link "RzShellDialogs" #pragma link "RzButton" #pragma resource "*.dfm" TCopyFilesForm *CopyFilesForm; //--------------------------------------------------------------------------- __fastcall TCopyFilesForm::TCopyFilesForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TCopyFilesForm::FormCreate(TObject *Sender) { char buffer[MAXPATH]; AnsiString strFileName, strDstPath; getcwd(buffer, MAXPATH); CurrentFolder = buffer; ConfigFolder = CurrentFolder;// + "\\Configuration"; DstFolder = CurrentFolder; stCurrentPath->Caption = CurrentFolder; stDstPath->Caption = DstFolder; TIniFile *IniFile = new TIniFile(CurrentFolder + "\\FileList.ini"); if (IniFile) { int Count = IniFile->ReadInteger("FileCount", "Count", 5); for (int i = 0; i < Count; i++){ AnsiString strSrc = IniFile->ReadString("FileList", "SrcFile" + IntToStr(i),""); SrcCheckList->Add(strSrc); AnsiString strDst = IniFile->ReadString("FileList", "DstFile" + IntToStr(i),""); DstListBox->Add(strDst); } delete IniFile; } SrcCheckList->CheckAll(); MemoFailed->Clear(); MemoSuccess->Clear(); } //--------------------------------------------------------------------------- void __fastcall TCopyFilesForm::Button1Click(TObject *Sender) { RzSelectFolderDialog1->SelectedPathName = CurrentFolder; RzSelectFolderDialog1->Execute(); DstFolder = RzSelectFolderDialog1->SelectedPathName; stDstPath->Caption = DstFolder; } //--------------------------------------------------------------------------- void __fastcall TCopyFilesForm::CreateDirectories() { for (int i = 0; i < DstListBox->Count; i++){ AnsiString addpath = NULL; if (HasWord(SrcCheckList->Items->Strings[i], "TexPrint")){ // - texprint.exe addpath = DstListBox->Items->Strings[i].SubString(0, DstListBox->Items->Strings[i].Length() - 13); } else { // - configuration.exe addpath = DstListBox->Items->Strings[i].SubString(0, DstListBox->Items->Strings[i].Length() - 18); } AnsiString path = DstFolder + "\\" + addpath; ForceDirectories(path.c_str()); } } //--------------------------------------------------------------------------- void __fastcall TCopyFilesForm::rzbtRunClick(TObject *Sender) { AnsiString SrcName, DstName, SrcFullPathName, DstFullPathName; AnsiString strDstDir; CreateDirectories(); MemoSuccess->Clear(); MemoFailed->Clear(); for (int i = 0; i < SrcCheckList->Count; i++){ if(SrcCheckList->ItemState[i] == cbChecked){ SrcName = SrcCheckList->Items->Strings[i]; DstName = DstListBox->Items->Strings[i]; SrcFullPathName = CurrentFolder + "\\" + SrcName; DstFullPathName = DstFolder + "\\" + DstName; if (CopyFile(SrcFullPathName.c_str(), DstFullPathName.c_str(), false)){ MemoSuccess->Lines->Add(SrcName); } else { MemoFailed->Lines->Add(SrcName); } } } Application->MessageBox("End", "Copy", MB_OK); } //--------------------------------------------------------------------------- bool __fastcall TCopyFilesForm::HasWord(AnsiString string, AnsiString word) { bool rtn = false; int sindex = 0, count = 1; int length = string.Length(); while (length > count){ if (string.SubString(count-1, 1) == "_"){ AnsiString str = string.SubString(sindex, (count-1) - sindex - 1); if (str.AnsiCompare(word) == 0){ rtn = true; break; } else { sindex = count; } } count++; } return rtn; } //---------------------------------------------------------------------------