//--------------------------------------------------------------------------- #include #include #include #include #include #include #include // 2001.4.11 By GreenFish #include // 2001.4.11 By GreenFish #pragma hdrstop #include "Main_F.h" #include "FileManager_F.h" #include "Common.h" //#include "Exception.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzButton" #pragma link "RzFilSys" #pragma link "RzPanel" #pragma link "RzCmboBx" #pragma link "RzEdit" #pragma link "RzPrgres" #pragma link "RzRadChk" #pragma resource "*.dfm" #pragma resource "FileIcon.res" //--------------------------------------------------------------------------- #define IDS_MFOLDER StringTable[0] #define IDS_FILETYPE StringTable[1] #define IDS_DIRECTORY StringTable[2] #define IDS_SEARCH StringTable[3] #define IDS_FILENAME StringTable[4] #define IDS_FOLDERNAME StringTable[5] #define IDS_LARGE StringTable[6] #define IDS_SMALL StringTable[7] #define IDS_LIST StringTable[8] #define IDS_REPORT StringTable[9] #define IDS_REPORT_NAME StringTable[10] #define IDS_REPORT_LAST StringTable[11] #define IDS_MAKE StringTable[12] #define IDS_FCAPTION StringTable[13] #define IDS_COMPRESSION StringTable[14] #define IDS_MESSAGE StringTable[15] #define IDS_SAVE StringTable[16] #define IDS_RENAME StringTable[17] #define IDS_DELETE StringTable[18] #define IDS_REPORT_DESCRIPTION StringTable[19] //--------------------------------------------------------------------------- __fastcall TFileManagerForm::TFileManagerForm(TComponent* Owner) : TForm(Owner) { //======================== 2001.3.27 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è TIniFile *IniFile; int type; //=================================================================== StringTable.Create(BaseDir, Language, "FileManager"); SetSmallFont(Font); SetSmallFont(ListView->Font); SetSmallFont(DirectoryListBox->Font); SetSmallFont(Label4->Font); FDrive = DriveComboBox->Drive; FDirectory = DirectoryListBox->Directory; FFilter = FilterComboBox->Filter; // FFilterIndex = FilterComboBox->ItemIndex; Caption = IDS_FCAPTION; SpeedButtonRead->Caption = IDS_COMMON_READ; SpeedButtonMerge->Caption = IDS_COMMON_MERGE; SpeedButtonSave->Caption = IDS_COMMON_SAVE; SpeedButtonSaveAs->Caption = IDS_COMMON_SAVEAS; SpeedButtonDelete->Caption = IDS_COMMON_DELETE; SpeedButtonMakeFolder->Caption = IDS_MFOLDER; SpeedButtonRename->Caption = IDS_COMMON_RENAME; SpeedButtonExit->Caption = IDS_COMMON_EXIT; Label1->Caption = IDS_COMMON_DRIVE; Label2->Caption = IDS_FILETYPE; Label3->Caption = IDS_DIRECTORY; ListViewRename->Caption = IDS_RENAME; DirectoryRename->Caption = IDS_RENAME; ListViewDelete->Caption = IDS_DELETE; DirectoryDelete->Caption = IDS_DELETE; ListViewSave->Caption = IDS_SAVE; ComboBoxView->Items->Clear(); ComboBoxView->Items->Add(IDS_LARGE); ComboBoxView->Items->Add(IDS_SMALL); ComboBoxView->Items->Add(IDS_LIST); ComboBoxView->Items->Add(IDS_REPORT); CompressCheckBox->Caption = IDS_COMPRESSION; //=================================================================== IniFile = new TIniFile(BaseDir + "\\Main.ini"); if (IniFile) { IniDirName = IniFile->ReadString("FileManager", "DirectoryName", BaseDir+"\\tricot"); DirectoryIndex = IniFile->ReadInteger("FileManager", "DirectoryIndex", 0); CompressCheckBox->Checked = IniFile->ReadBool("FileManager", "CompressCheck", false); Left = IniFile->ReadInteger("FileManager", "FormLeft", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("FileManager", "FormTop", (Screen->Height-Height)>>1); Width = IniFile->ReadInteger("FileManager", "FormWidth", Width); Height = IniFile->ReadInteger("FileManager", "FormHeight", Height); FFilterIndex = IniFile->ReadInteger("FileManager", "Filter", FilterComboBox->ItemIndex); type = IniFile->ReadInteger("FileManager", "ViewType", 0); delete IniFile; } if (SetCurrentDir(IniDirName) == false) { DirectoryListBox->Directory = IniDirName = BaseDir+"\\tricot"; } else { DirectoryListBox->Directory = IniDirName; } FilterComboBox->ItemIndex = FFilterIndex; InitExt = FFilterIndex; ExtIndex = TGraphicFileFormat(FilterComboBox->ItemIndex); StatusBar->Panels->Items[0]->Width = Splitter1->Left + 12; StatusBar->Panels->Items[2]->Width = 120; StatusBar->Panels->Items[1]->Width = StatusBar->Width - StatusBar->Panels->Items[0]->Width - StatusBar->Panels->Items[2]->Width; // InitItem(0); TListColumn *pColumn; pColumn = ListView->Columns->Add(); pColumn->Caption = IDS_REPORT_NAME; pColumn->Width = 150; pColumn = ListView->Columns->Add(); pColumn->Caption = IDS_REPORT_DESCRIPTION; pColumn->Width = 200; pColumn = ListView->Columns->Add(); pColumn->Caption = IDS_COMMON_SIZE; pColumn->Width = 100; pColumn = ListView->Columns->Add(); pColumn->Caption = IDS_REPORT_LAST; pColumn->Width = 150; InitItem(0); ComboBoxView->ItemIndex = type; switch (type) { case 0: ListView->ViewStyle = vsIcon; break; case 1: ListView->ViewStyle = vsSmallIcon; break; case 2: ListView->ViewStyle = vsList; break; case 3: ListView->ViewStyle = vsReport; } reading = false; Ascend[0] = false; Ascend[1] = false; Ascend[2] = false; Ascend[3] = false; ListView->PopupMenu = PopupMenuFile; ListView->DoubleBuffered = true; FileListBox->DoubleBuffered = true; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FormActivate(TObject *Sender) { TIniFile *IniFile; if (SetCurrentDir(IniDirName) == false) { DirectoryListBox->Directory = BaseDir+"\\tricot"; } else { if (reading == false) { DirectoryListBox->Directory = IniDirName; DirectoryListBox->ItemIndex = DirectoryIndex; } } ChangeFunction(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FormCreate(TObject *Sender) { SetFont(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SetFont(){ SetSmallFont(Font); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::InitExtension() { switch (InitExt) { case gffTRC: FileListBox->Mask = "*.trc"; break; case gffTEX: FileListBox->Mask = "*.tex"; break; case gffTFC: FileListBox->Mask = "*.tfc"; break; case gffT3D: FileListBox->Mask = "*.t3d"; break; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FormDestroy(TObject *Sender) { TIniFile *IniFile; TTexVersion *ver; SmallImageList->Clear(); ExitData(); if (Version){ while(Version->Count > 0){ ver = (TTexVersion*)(Version->Last()); Version->Remove(ver); delete ver; } delete Version; Version = NULL; } IniFile = new TIniFile(BaseDir + "\\Main.ini"); if (IniFile) { IniFile->WriteString("FileManager", "DirectoryName", DirectoryListBox->Directory); IniFile->WriteInteger("FileManager", "DirectoryIndex", DirectoryListBox->ItemIndex); IniFile->WriteBool("FileManager", "CompressCheck", CompressCheckBox->Checked); IniFile->WriteInteger("FileManager", "FormLeft", Left); IniFile->WriteInteger("FileManager", "FormTop", Top); IniFile->WriteInteger("FileManager", "FormWidth", Width); IniFile->WriteInteger("FileManager", "FormHeight", Height); IniFile->WriteInteger("FileManager", "Filter", FilterComboBox->ItemIndex); IniFile->WriteInteger("FileManager", "ViewType", ComboBoxView->ItemIndex); delete IniFile; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FormResize(TObject *Sender) { int w = ((Panel1->Width-5)/8)-5; //# margin 5 SpeedButtonRead->Left=5; SpeedButtonRead->Width = w; SpeedButtonMerge->Left = SpeedButtonRead->Left+w+5; SpeedButtonMerge->Width = w; SpeedButtonSave->Left = SpeedButtonMerge->Left+w+5; SpeedButtonSave->Width = w; SpeedButtonSaveAs->Left = SpeedButtonSave->Left+w+5; SpeedButtonSaveAs->Width = w; SpeedButtonDelete->Left = SpeedButtonSaveAs->Left+w+5; SpeedButtonDelete->Width = w; SpeedButtonRename->Left = SpeedButtonDelete->Left+w+5; SpeedButtonRename->Width = w; SpeedButtonMakeFolder->Left = SpeedButtonRename->Left+w+5; SpeedButtonMakeFolder->Width = w; SpeedButtonExit->Left = SpeedButtonMakeFolder->Left+w+5; SpeedButtonExit->Width = w; int LastSpace = 10; int Space = 5; // Panel2 w = (Panel2->Width - (Label1->Width + Label2->Width + Space*2 + LastSpace)) / 2; DriveComboBox->Width = w; FilterComboBox->Width = w; Label2->Left = DriveComboBox->Left + w + 2; FilterComboBox->Left = Label2->Left + Label2->Width; // Panel3 LabelDirectory->Width = Panel3->Width-(LabelDirectory->Left + ComboBoxView->Width + LastSpace + Space*2); ComboBoxView->Left = LabelDirectory->Left + LabelDirectory->Width; // Panel4 Edit4->Width = Panel4->Width - (Edit4->Left+SpeedButton4->Width+ProgressBar->Width+ LastSpace); ProgressBar->Left = Edit4->Left + Edit4->Width + Space; SpeedButton4->Left = ProgressBar->Left + ProgressBar->Width + Space; CompressCheckBox->Left = SpeedButton4->Left + SpeedButton4->Width; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FormShow(TObject *Sender) { Graphics::TBitmap *Bitmap; Bitmap = new Graphics::TBitmap; switch (FExtension) { case 0: Bitmap->Handle = LoadImage(HInstance,"icontrc",IMAGE_BITMAP,16,16,LR_DEFAULTSIZE); SmallImageList->Add(Bitmap,NULL); FilterComboBox->ItemIndex = 0; FileListBox->Mask = "*.trc"; break; default: Bitmap->Handle = LoadImage(HInstance,"icontex",IMAGE_BITMAP,16,16,LR_DEFAULTSIZE); SmallImageList->Add(Bitmap,NULL); Bitmap->Handle = LoadImage(HInstance,"icontfc",IMAGE_BITMAP,16,16,LR_DEFAULTSIZE); SmallImageList->Add(Bitmap,NULL); Bitmap->Handle = LoadImage(HInstance,"icont3d",IMAGE_BITMAP,16,16,LR_DEFAULTSIZE); SmallImageList->Add(Bitmap,NULL); Bitmap->Handle = LoadImage(HInstance,"icontrc",IMAGE_BITMAP,16,16,LR_DEFAULTSIZE); SmallImageList->Add(Bitmap,NULL); FilterComboBox->ItemIndex = InitExt; InitExtension(); } delete Bitmap; InitData(true); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonReadClick(TObject *Sender) { InitItem(0); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonMergeClick(TObject *Sender) { InitItem(1); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonSaveClick(TObject *Sender) { InitItem(2); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonSaveAsClick(TObject *Sender) { Edit4->SetFocus(); InitItem(3); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonDeleteClick(TObject *Sender) { InitItem(4); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonMakeFolderClick(TObject *Sender) { Edit4->SetFocus(); InitItem(5); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonRenameClick(TObject *Sender) { Edit4->SetFocus(); InitItem(6); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButtonExitClick(TObject *Sender) { ModalResult = mrCancel; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::FilterComboBoxChange(TObject *Sender) { ChangeFunction(); InitData(true); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ChangeFunction() { if (FOnRead) SpeedButtonRead->Enabled = true; else SpeedButtonRead->Enabled = false; SpeedButtonMerge->Enabled = false; if (FOnFileName) { if (FOnSave) SpeedButtonSave->Enabled = true; else SpeedButtonSave->Enabled = false; } else { SpeedButtonSave->Enabled = false; } StartLargeImage = true; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ComboBoxViewChange(TObject *Sender) { if (ComboBoxView->ItemIndex == 0) { int i ; if(StartLargeImage){ InitData(false); StartLargeImage = false; } for(i = 0 ; i < ListView->Items->Count ; i++) { ListView->Items->Item[i]->ImageIndex = i; } ListView->ViewStyle = vsIcon; } else if (ComboBoxView->ItemIndex == 1) { IconSet(FilterComboBox->ItemIndex); ListView->ViewStyle = vsSmallIcon; } else if (ComboBoxView->ItemIndex == 2) { IconSet(FilterComboBox->ItemIndex); ListView->ViewStyle = vsList; } else { IconSet(FilterComboBox->ItemIndex); ListView->ViewStyle = vsReport; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::Edit4Change(TObject *Sender) { if (StrLen(Edit4->Text.c_str())>0) SpeedButton4->Enabled = true; else SpeedButton4->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::Edit4KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key==VK_RETURN) SpeedButton4Click(Edit4); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SpeedButton4Click(TObject *Sender) { AnsiString fn, cmfn, cmfn2; TCursor cur; switch (Item) { case 3: if (FOnFileName) { cur = Screen->Cursor; Screen->Cursor = crHourGlass; fn = FOnFileName(Edit4->Text, ExtIndex); for (int i=0; iItems->Count; i++) { cmfn = FileListBox->Items->Strings[i].LowerCase(); cmfn2 = fn.LowerCase(); if (cmfn == cmfn2) { int btn = MessageDlg(IDS_MESSAGE_FILEEXIST+"\n"+IDS_MESSAGE_REALLYFILESAVE, mtWarning, TMsgDlgButtons() << mbOK << mbCancel, 0); if (btn == mrOk) { if (FOnSave) FOnSave(FileListBox->Directory+"\\"+fn, CompressCheckBox->Checked ? cmZLib : cmNone); goto next; } else { goto next; } } } if (FOnSave) FOnSave(FileListBox->Directory+"\\"+fn, CompressCheckBox->Checked ? cmZLib : cmNone); next: Screen->Cursor = cur; } //next: FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); break; case 5: CreateDirectory(Edit4->Text.c_str(), NULL); DirectoryListBox->Update(); //SpeedButtonRead->Down = true; InitItem(0); break; case 6: if (FOnFileName) { if (ListView->Selected) { if (RenameFile(FileName, FOnFileName(Edit4->Text, ExtIndex)) == false) ShowMessage("Unknown Error in "+this->Name); } else { ShowMessage("Unknown Error in "+this->Name); } } FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); break; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DirectoryListBoxChange(TObject *Sender) { IniDirName = DirectoryListBox->Directory; InitData(true); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewDblClick(TObject *Sender) { int n; bool run = true; AnsiString fn, cmfn, cmfn2; TCursor cur; //TFMReadParameter rp; if (ListView->Selected) { n = ListView->Selected->Index; FileName = ListView->Items->Item[n]->Caption; if (Item==0) { int btn = MessageDlg(IDS_MESSAGE_LOSE_CURRENT, mtWarning, TMsgDlgButtons() << mbOK << mbCancel, 0); //ÀåÁø¸¸ : file readÇÒ ¶§ °æ°íâ if (btn != mrOk){ return; } cur = Screen->Cursor; Screen->Cursor = crHourGlass; if (FOnRead) { //rp.DirName = FileListBox->Directory; //rp.FileName = FileName; //rp.ExtIndex = ExtIndex; FOnRead(FileListBox->Directory+"\\"+FileName); } Screen->Cursor = cur; //if (ec != EC_NONE) ShowMessage("Unknown Error in "+this->Name); ModalResult = mrOk; } else if (Item==1) { } else { switch (Item) { /*ÆÄÀÏ ¼¼À̺êÇÒ¶§ °æ°íâ ¾ø¾ú´Âµ¥ ¸¸µë(¹Ø¿¡²¨) case 2: cur = Screen->Cursor; Screen->Cursor = crHourGlass; if (FOnSave) FOnSave(FileListBox->Directory+"\\"+FileName, CompressCheckBox->Checked ? cmZLib : cmNone); Screen->Cursor = cur; break; */ case 2: //file save if (FOnFileName) { cur = Screen->Cursor; Screen->Cursor = crHourGlass; fn = FOnFileName(Edit4->Text, ExtIndex); for (int i=0; iItems->Count; i++) { cmfn = FileListBox->Items->Strings[i].LowerCase(); cmfn2 = fn.LowerCase(); if (cmfn == cmfn2) { int btn = MessageDlg(IDS_MESSAGE_FILEEXIST+"\n"+IDS_MESSAGE_REALLYFILESAVE, mtWarning, TMsgDlgButtons() << mbOK << mbCancel, 0); if (btn == mrOk) { if (FOnSave) FOnSave(FileListBox->Directory+"\\"+fn, CompressCheckBox->Checked ? cmZLib : cmNone); goto next; } else { goto next; } } } if (FOnSave) FOnSave(FileListBox->Directory+"\\"+fn, CompressCheckBox->Checked ? cmZLib : cmNone); next: Screen->Cursor = cur; } //next: FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); break; case 4: Delete_File(FileName); break; case 6: SpeedButton4Click(NULL); run = false; break; } if (run) { FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); } } } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (ListView->Selected) { int n = ListView->Selected->Index; FileName = ListView->Items->Item[n]->Caption; Edit4->Text = FileName; } else FileName = ""; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewColumnClick(TObject *Sender, TListColumn *Column) { Ascend[Column->Index] = !Ascend[Column->Index]; ListView->CustomSort(NULL, Column->Index); ListView->Repaint(); } //--------------------------------------------------------------------------- double __fastcall ExtractSize(AnsiString str) { int pos = Sysutils::AnsiPos('K', str); AnsiString s=str.SubString(1, pos - 1);// AnsiString s=str.SubString(0, pos - 1); //index´Â 1ºÎÅÍ ½ÃÀÛÇÑ´Ù //C++Builder 5ÀÌÀü¿¡¼­´Â index°¡ 0À϶§ 1·Î °íÃļ­½èÁö¸¸ 5¿¡¼­´Â NULLÀ» ¸®ÅÏÇÑ´Ù return StrToFloat(s); } //--------------------------------------------------------------------------- int __fastcall ExtractDate(AnsiString str) { int i, pos; const char p[4] = { '-', '-', ' ', ':' }; AnsiString value; for (i = 0; i < 4; i++) { pos = Sysutils::AnsiPos(p[i], str); if (pos == 2) { value += ("0"+ str.SubString(1, pos - 1)); } else { value += str.SubString(1, pos - 1); } if (i == 2) { str = str.SubString(pos+2, str.Length()); } else { str = str.SubString(pos+1, str.Length()); } } if (str.Length() > 1) { value += str; } else { value += (str + "0"); } return StrToFloat(value); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewCompare(TObject *Sender, TListItem *Item1, TListItem *Item2, int Data, int &Compare) { double size1, size2; switch (Data) { case 0: if (Ascend[0]) { Compare = CompareStr(Item1->Caption, Item2->Caption); } else { Compare = CompareStr(Item2->Caption, Item1->Caption); } break; case 1: if (Ascend[1]) { Compare = CompareStr(Item1->SubItems->Strings[0], Item2->SubItems->Strings[0]); } else { Compare = CompareStr(Item2->SubItems->Strings[0], Item1->SubItems->Strings[0]); } break; case 2: size1 = ExtractSize(Item1->SubItems->Strings[1]); size2 = ExtractSize(Item2->SubItems->Strings[1]); if (Ascend[2]) { Compare = size1 - size2; } else { Compare = size2 - size1; } break; case 3: size1 = ExtractDate(Item1->SubItems->Strings[2]); size2 = ExtractDate(Item2->SubItems->Strings[2]); if (Ascend[3]) { Compare = size1 - size2; } else { Compare = size2 - size1; } break; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewEdited(TObject *Sender, TListItem *Item, AnsiString &S) { if (FOnFileName) { AnsiString newname = FOnFileName(S, ExtIndex); if (RenameFile(FileName, newname) == false) { ShowMessage("Unknown Error in "+this->Name); return; } Item->Caption = newname; FileListBox->Update(); } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::Splitter1Moved(TObject *Sender) { StatusBar->Panels->Items[0]->Width = Splitter1->Left + 12; StatusBar->Panels->Items[1]->Width = StatusBar->Width - StatusBar->Panels->Items[0]->Width; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::PopupSaveClick(TObject *Sender) { TCursor cur; cur = Screen->Cursor; Screen->Cursor = crHourGlass; if (FOnSave) FOnSave(FileListBox->Directory+"\\"+FileName, CompressCheckBox->Checked ? cmZLib : cmNone); Screen->Cursor = cur; FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DirectoryDeleteClick(TObject *Sender) { int i; char *str; AnsiString Astr1, Astr2; for (i=0; iItems->Count; i++) { if (DirectoryListBox->Selected[i]) { Astr1 = DirectoryListBox->Directory; Astr2 = DirectoryListBox->Items->Strings[i]; str = StrPos(Astr1.c_str(), Astr2.c_str()); if (str==NULL) Delete_Folder(Astr2); else Delete_Folder(Astr1); break; } } DirectoryListBox->Update(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DirectoryRenameClick(TObject *Sender) { int i, same, length; char *str; AnsiString Astr1, Astr2, dn, s; if (Edit4->Text == "") ShowMessage(IDS_MESSAGE_INPUTFILE); for (i = 0; i < DirectoryListBox->Items->Count; i++) { if (DirectoryListBox->Selected[i]) { Astr1 = DirectoryListBox->Directory; Astr2 = DirectoryListBox->GetItemPath(i); same = StrComp(Astr1.c_str(), Astr2.c_str()); if (same == 0) dn = Astr1; else dn = Astr2; length = dn.Length(); str = dn.c_str(); while(length) { if (AnsiString(str[length-1]) == "\\") { Astr1 = dn.SubString(1, length); break; } else { length--; } } Astr1 += Edit4->Text; if (MoveFile(dn.c_str(), Astr1.c_str())) { DirectoryListBox->Directory = Astr1; } break; } } DirectoryListBox->Update(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DirectoryListBoxDblClick(TObject *Sender) { int i, same, length; char *str; AnsiString Astr1, Astr2, dn, s; if (Item == 4 || Item == 6) { i = DirectoryListBox->ItemIndex; if (i != -1) { Astr1 = DirectoryListBox->Directory; Astr2 = DirectoryListBox->GetItemPath(i); same = StrComp(Astr1.c_str(), Astr2.c_str()); if (same == 0) dn = Astr1; else dn = Astr2; if (Item == 4) Delete_Folder(dn); else if (Item == 6) { length = dn.Length(); str = dn.c_str(); while(length) { if (AnsiString(str[length-1]) == "\\") { Astr1 = dn.SubString(1, length); break; } else { length--; } } Astr1 += Edit4->Text; if (MoveFile(dn.c_str(), Astr1.c_str())) { DirectoryListBox->Directory = Astr1; } } } DirectoryListBox->Update(); //SpeedButtonRead->Down = true; InitItem(0); } } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::SaveOnTexpiaFile(AnsiString FileName) { // if (ec != EC_NONE) ShowMessage("Unknown Error in "+this->Name); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::InitItem(int i) { Item = i; switch (Item) { case 0: Label4->Caption = IDS_SEARCH; SpeedButton4->Caption = IDS_SEARCH; if (StrLen(Edit4->Text.c_str())>0) SpeedButton4->Enabled = true; else SpeedButton4->Enabled = false; Panel->Height = Panel1->Height + Panel2->Height + Panel3->Height + Panel4->Height; break; case 1: Panel->Height = Panel1->Height + Panel2->Height + Panel3->Height; break; case 2: case 3: Label4->Caption = IDS_FILENAME; if (Item == 2) SpeedButton4->Caption = IDS_COMMON_SAVE; if (Item == 3) SpeedButton4->Caption = IDS_COMMON_SAVEAS; if (StrLen(Edit4->Text.c_str())>0) SpeedButton4->Enabled = true; else SpeedButton4->Enabled = false; Panel->Height = Panel1->Height + Panel2->Height + Panel3->Height + Panel4->Height; break; case 5: Label4->Caption = IDS_FOLDERNAME; SpeedButton4->Caption = IDS_MAKE; if (StrLen(Edit4->Text.c_str())>0) SpeedButton4->Enabled = true; else SpeedButton4->Enabled = false; Panel->Height = Panel1->Height + Panel2->Height + Panel3->Height + Panel4->Height; break; case 6: Label4->Caption = IDS_FILENAME; SpeedButton4->Caption = IDS_COMMON_RENAME; if (StrLen(Edit4->Text.c_str())>0) SpeedButton4->Enabled = true; else SpeedButton4->Enabled = false; Panel->Height = Panel1->Height + Panel2->Height + Panel3->Height + Panel4->Height; break; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::InitData(bool isCheck) { TFileInfor *fi = NULL; TTexpiaBitmap *TexBitmap = NULL; int i, imgindex; TTexVersion *ver; TListItem *pItem; AnsiString fn, time; //-- Graphics::TBitmap *icon = NULL; RGBQUAD rgb[256]; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD size; FILETIME fTime, fLocTime; SYSTEMTIME SysTime; HDC dcSrc = NULL; if (isCheck && FDrive==DriveComboBox->Drive && FDirectory==DirectoryListBox->Directory && FFilter==FilterComboBox->Filter && FFilterIndex==FilterComboBox->ItemIndex) return; ExitData(); int count = FileListBox->Items->Count; if(ComboBoxView->ItemIndex == 0){ if ((fi = new TFileInfor)==NULL) { goto fail; } if ((fi->Bitmap = new Graphics::TBitmap)==NULL) { goto fail; } } if (Version){ while(Version->Count > 0){ ver = (TTexVersion*)(Version->Last()); Version->Remove(ver); delete ver; } delete Version; Version = NULL; } Version = new TList; for (i = 0, imgindex = 0; i < count; i++) { MainData *maindata = new MainData; fn = FileListBox->Items->Strings[i]; if(ComboBoxView->ItemIndex == 0) { TTexpiaBitmap *tag= new TTexpiaBitmap; Main->ReadHeaderFromFile(FileListBox->Directory+"\\"+fn, tag, maindata); fi->Bitmap->PixelFormat = pf24bit; fi->Bitmap->Width = 80; fi->Bitmap->Height = 100; if (fi->Bitmap->Empty) goto next; fi->Bitmap->Canvas->Brush->Color = clWhite; fi->Bitmap->Canvas->FillRect(Rect(0, 0, 80, 100)); if ((dcSrc = tag->CreateDC())==NULL) goto next; SetStretchBltMode(fi->Bitmap->Canvas->Handle, COLORONCOLOR); StretchBlt(fi->Bitmap->Canvas->Handle, 0, 0, 80, 100, dcSrc, 0, 0, tag->Width, tag->Height, SRCCOPY); tag->DeleteDC(dcSrc); dcSrc = NULL; LargeImageList->Add(fi->Bitmap, NULL); delete tag; } else { Main->ReadHeaderFromFile(FileListBox->Directory+"\\"+fn, NULL, maindata); } pItem = ListView->Items->Add(); if (hFile == INVALID_HANDLE_VALUE) { if ((hFile = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto next; } size = GetFileSize(hFile, NULL); pItem->Caption = fn; if(ListView->ViewStyle == vsIcon){ pItem->ImageIndex = imgindex; imgindex++; } else { pItem->ImageIndex = FilterComboBox->ItemIndex; } //maindata ¸¦ ÀÌ¿ëÇÏ¿© file¿¡ ´ëÇÑ °¢Á¾ÀÇ ¼³¸íÀ» º¸¿©ÁØ´Ù pItem->SubItems->Add(maindata->ProductDetail); delete maindata; pItem->SubItems->Add(IntToStr(size/1024) + "KB"); if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == 0xFFFFFFFF) goto next; if (GetFileTime(hFile, NULL, NULL, &fTime)) { FileTimeToLocalFileTime(&fTime, &fLocTime); if (FileTimeToSystemTime(&fLocTime, &SysTime)) { time = Format("%d-%d-%d %d:%d", OPENARRAY(TVarRec, (SysTime.wYear, SysTime.wMonth, SysTime.wDay, SysTime.wHour, SysTime.wMinute))); pItem->SubItems->Add(time); } } CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; ProgressBar->Percent = (100.0 / count) * (i+1); continue; next: if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; } if (TexBitmap) { if (dcSrc) { TexBitmap->DeleteDC(dcSrc); dcSrc = NULL; } delete TexBitmap; TexBitmap = NULL; } } GetDiskInfor(); if(fi) delete fi; ProgressBar->Percent = 0; FDrive = DriveComboBox->Drive; FDirectory = DirectoryListBox->Directory; FFilter = FilterComboBox->Filter; FFilterIndex = FilterComboBox->ItemIndex; StartLargeImage = true; return; fail: if (fi) delete fi; ShowMessage("Unknown Error in "+this->Name); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ExitData() { if (ListView->Items->Count) ListView->Items->Clear(); if (LargeImageList->Count) LargeImageList->Clear(); //-- if (SmallImageList->Count) SmallImageList->Clear(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::Delete_File(AnsiString FileName) { SHFILEOPSTRUCT shfile; AnsiString asFrom; char *ucFrom = NULL, *ch = NULL, *ph; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; int len = DirectoryListBox->Directory.Length(); if ((ch = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len + 2)) == NULL) goto fail; strcpy(ch, DirectoryListBox->Directory.c_str()); ph = ch + (len-1); if (*ph == '\\') asFrom = DirectoryListBox->Directory+FileName; else asFrom = DirectoryListBox->Directory+"\\"+FileName; if ((ucFrom = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asFrom.Length()+2)) == NULL) goto fail; strcpy(ucFrom, asFrom.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); HeapFree(GetProcessHeap(), 0, ch); return; fail: if (ch) HeapFree(GetProcessHeap(), 0, ch); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::Delete_Folder(AnsiString FolderName) { SHFILEOPSTRUCT shfile; char *ucFrom = NULL; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; ucFrom = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FolderName.Length()+2); if (ucFrom) { strcpy(ucFrom, FolderName.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); } else { ShowMessage("Unknown Error in "+this->Name); } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::GetDiskInfor() { ULARGE_INTEGER FreeBytesAvailableToCaller; ULARGE_INTEGER TotalNumberOfBytes; ULARGE_INTEGER TotalNumberOfFreeBytes; int FreeSpace, TotalSpace; char *szDrive = DirectoryListBox->Directory.c_str(); char szBuffer[4]; StrLCopy(szBuffer, szDrive, 1); strcat(szBuffer, ":\\"); ::GetDiskFreeSpaceEx(szBuffer, &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes); FreeSpace = (FreeBytesAvailableToCaller.HighPart << 12) | (FreeBytesAvailableToCaller.LowPart >> 20); TotalSpace = (TotalNumberOfBytes.HighPart << 12) | (TotalNumberOfBytes.LowPart >> 20); StatusBar->Panels->Items[1]->Text = Format("Current Free Spaces : %d M Bytes, Total Disk Spaces : %d M Bytes", OPENARRAY (TVarRec,(FreeSpace, TotalSpace))); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DriveComboBoxChange(TObject *Sender) { DriveChange(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::DriveChange() { /* char drive = DriveComboBox->Drive; AnsiString root, dn; int status; bool success, find = false; TSearchRec sr; if (UpperCase(AnsiString(drive)) != "C") return; root = Format("%s:\\", OPENARRAY(TVarRec, (drive))); dn = "";//"pattern"; status = FindFirst(root + "*.*", faDirectory, sr); while (status == 0) { if (LowerCase(sr.Name) == dn) { find = true; break; } status = FindNext(sr); } FindClose(sr); if (find) { DirectoryListBox->Directory = root + dn; } else { dn = root + dn; success = CreateDirectory(dn.c_str(), NULL); if (success == false) { DirectoryListBox->Directory = root; ShowMessage(IDS_MESSAGE); } else { DirectoryListBox->Directory = dn; } }*/ } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::IconSet(int k) { int i ; for(i = 0 ; i < ListView->Items->Count ; i++) { ListView->Items->Item[i]->ImageIndex = k; } } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int n; // statusbar ¿¡ È­ÀÏ ¹öÀü Ç¥½Ã TTexVersion *ver; TListItem *pItem; AnsiString VerNumber; if(ComboBoxView->ItemIndex) goto next; if(Version->Count) { pItem = ListView->GetItemAt(X,Y); if(!pItem) goto next; n = pItem->Index; if(Version->Count < n) goto next; ver = (TTexVersion *)Version->Items[n]; VerNumber += (" Version " + FloatToStr(ver->Number/100.0)); StatusBar->Panels->Items[2]->Text = VerNumber; } return; next: StatusBar->Panels->Items[2]->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ExitPreferButtonClick(TObject *Sender) { FilePreferBox->SendToBack(); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewRenameClick(TObject *Sender) { if (FOnFileName) { if (ListView->Selected) { if (RenameFile(FileName, FOnFileName(Edit4->Text, ExtIndex)) == false) ShowMessage("Unknown Error in "+this->Name); } else { ShowMessage("Unknown Error in "+this->Name); } } FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); } //--------------------------------------------------------------------------- void __fastcall TFileManagerForm::ListViewDeleteClick(TObject *Sender) { Delete_File(FileName); FileListBox->Update(); InitData(false); //SpeedButtonRead->Down = true; InitItem(0); } //---------------------------------------------------------------------------