//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #ifdef TEXSTYLIST #include "Undo.h" #endif #include "PalFileManager.h" #include "MainImage.h" #include "Palette.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "DIB256s" #pragma link "RzListVw" #pragma link "RzShellCtrls" #pragma link "RzTreeVw" #pragma link "RzButton" #pragma link "RzPanel" #pragma link "RzCmboBx" #pragma link "RzEdit" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_PALFILEMANAGER StringTable[0] #define IDS_DIRECTORY StringTable[1] #define IDS_FILENAME StringTable[2] #define IDS_IFREAD StringTable[3] #define IDS_IFMERGE StringTable[4] #define IDS_IFSAVE StringTable[5] #define IDS_IFSAVEAS StringTable[6] #define IDS_IFDELETE StringTable[7] #define IDS_IFRENAME StringTable[8] #define IDS_INPUTFILENAME StringTable[9] #define IDS_SELECTFILE StringTable[10] //--------------------------------------------------------------------------- __fastcall TPFMForm::TPFMForm(TComponent* Owner) : TForm(Owner) { //========================================= StringTable.Create(DirectoryBin, Language, "PalFileManager"); SetSmallFont(Font); Caption = IDS_PALFILEMANAGER; rztbRead->Caption = IDS_COMMON_READ; rztbMerge->Caption = IDS_COMMON_MERGE; rztbSave->Caption = IDS_COMMON_SAVE; rztbSaveAs->Caption = IDS_COMMON_SAVEAS; rztbRename->Caption = IDS_COMMON_RENAME; rztbDelete->Caption = IDS_COMMON_DELETE; rztbExit->Caption = IDS_COMMON_EXIT; //Label1->Caption = IDS_COMMON_DRIVE; //Label2->Caption = IDS_DIRECTORY; //Label4->Caption = IDS_FILENAME; //sbSv_as->Caption = IDS_COMMON_SAVE; //========================================= } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FormCreate(TObject *Sender) { PFMDirectoryShellTree->SelectedPathName = DirectoryColor; DirName = PFMDirectoryShellTree->SelectedPathName; dirLabel->Caption = DirName; Palette = new TPalette; Palette->ColorCount = MainImageForm->Palette->ColorCount; Palette->UseColor = MainImageForm->Palette->UseColor; for (int i=0; i<256; i++) Palette->ColorData[i]->Copy(MainImageForm->Palette->ColorData[i]); ReviewPalette->SetPalette(Palette); Item = 0; StatusBar->Panels->Items[2]->Text = IDS_IFREAD; ReviewPalette->Repaint(); //sbSv_as->Enabled = false; //ListView->ViewStyle = vsList; if (!FileList) FileList = new TList; InitData(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FormClose(TObject *Sender, TCloseAction &Action) { delete Palette; if (FileList){ ClearFileList(); delete FileList; FileList = NULL; } } //--------------------------------------------------------------------------- /* void __fastcall TPFMForm::ListViewDblClick(TObject *Sender) { if(ListView->Selected == NULL) return; #ifdef TEXSTYLIST MainImageForm->UndoSave(UK_COLOR);//by jeegeo #endif //PChar s; String Name; String wfn = ListView->Items->Item[ListView->Selected->Index]->Caption; String wPath = FullPathName(DirName, wfn); switch (Item) { case 0: //read if (wfn == String("")) return; PaletteForm->DIB256Palette->LoadFromFile(wPath.c_str()); ::RepaintColor(); break; case 1: //Merge MergeMethod(); rztbRead->Down = true; Item = 0; break; case 2: //Save #ifdef TRIAL Application->MessageBox(IDS_TRIAL_NOT_SUPPORTED.c_str(), "", MB_OK); return; #endif SaveMethod(FileEdit->Text); rztbRead->Down = true; Item = 0; break; case 4: //Rename break; case 5: //Delete if (wfn == String("")) return; Delete_File(wPath); InitData(); //PFMFileListBox->Update(); rztbRead->Down = true; Item = 0; break; } } */ //--------------------------------------------------------------------------- void __fastcall TPFMForm::ListBoxDblClick(TObject *Sender) { if(ListBox->Selected[ListBox->ItemIndex] == NULL) return; #ifdef TEXSTYLIST MainImageForm->UndoSave(UK_COLOR);//by jeegeo #endif //PChar s; String Name; String wfn = ListBox->Items->Strings[ListBox->ItemIndex]; String wPath = FullPathName(DirName, wfn); switch (Item) { case 0: //read if (wfn == String("")) return; PaletteForm->DIB256Palette->LoadFromFile(wPath.c_str()); if (PaletteForm->DIB256Palette->Palette->UseColor+1 > PaletteForm->DIB256Palette->Palette->ColorCount) PaletteForm->DIB256Palette->Palette->ColorCount = PaletteForm->DIB256Palette->Palette->UseColor+1; ::RepaintColor(); break; case 1: //Merge MergeMethod(); rztbRead->Down = true; Item = 0; break; case 2: //Save #ifdef TRIAL Application->MessageBox(IDS_TRIAL_NOT_SUPPORTED.c_str(), L"", MB_OK); return; #endif SaveMethod(FileEdit->Text); rztbRead->Down = true; Item = 0; break; case 4: //Rename break; case 5: //Delete if (wfn == String("")) return; Delete_File(wPath); InitData(); //PFMFileListBox->Update(); rztbRead->Down = true; ReviewPalette->ClearAll(); Item = 0; break; } } //--------------------------------------------------------------------------- void __fastcall TPFMForm::Run() { #ifdef TRIAL Application->MessageBox(IDS_TRIAL_NOT_SUPPORTED.c_str(), L"", MB_OK); return; #endif String wfn, cmfn, cmfn2, wPath; //PChar s; //int FileNameLength, last1, last2, last3, last4; //char FileIndex1, FileIndex2, FileIndex3, FileIndex4; if (Item==3) { if (FileEdit->Text != String("")) { /* //=============================================================== FileNameLength = FileEdit->Text.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'f'; FileIndex3 = 'c'; FileIndex4 = 'r'; if((FileIndex1 == FileEdit->Text[last1])&&(FileIndex2 == FileEdit->Text[last2]) && (FileIndex3 == FileEdit->Text[last3])&&(FileIndex4 == FileEdit->Text[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan((PChar)FileEdit->Text.c_str(), '.'); if (s==NULL) FileEdit->Text = FileEdit->Text + String(".fcr"); */ if(ExtractFileExt(FileEdit->Text) != String(".fcr")){ FileEdit->Text = FileEdit->Text + String(".fcr"); } wfn = FileEdit->Text; wPath = FullPathName(DirName, wfn); for (int i=0; i< FileList->Count; i++) { String *wTemp = (String *)FileList->Items[i]; cmfn = LowerCase(*wTemp); cmfn2 = LowerCase(wfn); if (cmfn == cmfn2) { int btn = EXCEPTION_MESSAGE2_OKCANCEL(EC_FILE_EXIST_ALREADY, (IDS_MESSAGE_REALLYFILESAVE).c_str()); if (btn == mrOk) { PaletteForm->DIB256Palette->SaveToFile(wPath.c_str()); goto next; } else { goto next; } } } } else { Sysutils::Beep(); MessageDlg(IDS_MESSAGE_INPUTFILE, mtWarning, TMsgDlgButtons()<DIB256Palette->SaveToFile(wPath.c_str()); next: InitData(); //FMFileListBox->Update(); } else if (Item == 4){ //Rename if (FileEdit->Text != String("")) { /* FileNameLength = FileEdit->Text.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'f'; FileIndex3 = 'c'; FileIndex4 = 'r'; if((FileIndex1 == FileEdit->Text[last1])&&(FileIndex2 == FileEdit->Text[last2]) && (FileIndex3 == FileEdit->Text[last3])&&(FileIndex4 == FileEdit->Text[last4])){ s = "PASS"; }else s=NULL; } if (s==NULL) FileEdit->Text = FileEdit->Text + String(".fcr"); */ if(ExtractFileExt(FileEdit->Text) == String("")) FileEdit->Text = FileEdit->Text + String(".fcr"); //FileEdit->Text += String(".fcr"); if (ListBox->Selected[ListBox->ItemIndex]) { wfn = ListBox->Items->Strings[ListBox->ItemIndex]; RenameFile(FullPathName(DirName, wfn), FullPathName(DirName, FileEdit->Text)); InitData(); //PFMFileListBox->Update(); } else { // À̸§À» º¯°æÇÒ ÆÄÀÏÀ» ¼±ÅÃÇØ¾ßÇÔ - by monkman (2009.10.07) MessageDlg(IDS_SELECTFILE, mtError, TMsgDlgButtons()<Selected) { wfn = ListView->Items->Item[ListView->Selected->Index]->Caption; RenameFile(FullPathName(DirName, wfn), FullPathName(DirName, FileEdit->Text)); InitData(); //PFMFileListBox->Update(); } else { // À̸§À» º¯°æÇÒ ÆÄÀÏÀ» ¼±ÅÃÇØ¾ßÇÔ - by monkman (2009.10.07) MessageDlg(IDS_SELECTFILE, mtError, TMsgDlgButtons()<Enabled = false; rztbRead->Down = true; Item = 0; //k3dogs 1->0 } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FileEditChange(TObject *Sender) { /* if (Item==3) { if (FileEdit->Text.Length() > 0) sbSv_as->Enabled = true; else sbSv_as->Enabled = false; } */ } //--------------------------------------------------------------------------- void __fastcall TPFMForm::MergeMethod() { int i, s, n; TPalette *Userpal; String wfn = ListBox->Items->Strings[ListBox->ItemIndex]; //String wfn = ListView->Items->Item[ListView->Selected->Index]->Caption; String wPath = FullPathName(DirName, wfn); if (wPath == String("")) return; Userpal = new TPalette; Userpal->LoadFromFile(wPath.c_str()); s = PaletteForm->DIB256Palette->Palette->UseColor; if (Userpal->ColorCount + s >= 256){ n = 251-PaletteForm->DIB256Palette->Palette->UseColor + 1; } else { n = Userpal->ColorCount-1; } for (i=1; iDIB256Palette->Palette->ColorData[s+i] = Userpal->ColorData[i+1]; if (s + n > PaletteForm->DIB256Palette->Palette->ColorCount) PaletteForm->DIB256Palette->Palette->ColorCount = s + n; ::RepaintColor(); delete Userpal; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SaveMethod(String Name) { //String wfn = ListView->Items->Item[ListView->Selected->Index]->Caption; String wfn = ListBox->Items->Strings[ListBox->ItemIndex]; if (wfn == String("")) return; if (Name != String("")) { if(ExtractFileExt(Name) == String("")) Name += String(".fcr"); String wPath = FullPathName(DirName, Name); PaletteForm->DIB256Palette->SaveToFile(wPath.c_str()); } else { Sysutils::Beep(); MessageDlg(IDS_MESSAGE_INPUTFILE, mtWarning, TMsgDlgButtons()<Update(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FileEditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) Run(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::ReviewPaletteMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int i = ReviewPalette->CursorIndex; StatusBar->Panels->Items[0]->Text = i-1; StatusBar->Panels->Items[1]->Text = Format("%d - %d - %d", OPENARRAY(TVarRec, (255-Palette->ColorData[i]->RGB.rgbRed, 255-Palette->ColorData[i]->RGB.rgbGreen, 255-Palette->ColorData[i]->RGB.rgbBlue))); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::Delete_File(String FileName) { SHFILEOPSTRUCT shfile; Char *ucFrom = NULL; TPException ec = EC_NONE; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; if ((ucFrom = (Char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Char)*(FileName.Length()+2))) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } _tcscpy(ucFrom, FileName.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); return; fail: EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::InitData(void) { TListItem *pItem; if (!FileList) FileList = new TList; GetFileList(DirName, String("*.fcr")); int count = FileList->Count; /* ListView->Items->Clear(); for (int i = 0; i < count; i++) { String *wTemp = (String *)FileList->Items[i]; String fn = *wTemp; pItem = ListView->Items->Add(); pItem->Caption = fn; } */ ListBox->Items->Clear(); for (int i = 0; i < count; i++) { String *wTemp = (String *)FileList->Items[i]; String fn = *wTemp; ListBox->Items->Add(fn); } } //--------------------------------------------------------------------------- void __fastcall TPFMForm::GetFileList(String Path, String Filter) { HANDLE hSrch = INVALID_HANDLE_VALUE; WIN32_FIND_DATAW wfd; Char fname[MAX_PATH]; BOOL bResult=TRUE; ClearFileList(); if (Path == NULL || Path == "") { return; } String wPath = String(Path+"\\"+Filter); hSrch=FindFirstFile(wPath.c_str(),&wfd); if (hSrch != INVALID_HANDLE_VALUE){ while(bResult){ if (wfd.dwFileAttributes && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)){ //&& !(wfd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)){ String* filename = new String(wfd.cFileName); FileList->Add(filename); } bResult = FindNextFile(hSrch,&wfd); } } else { wPath = Path + String("\\*.*"); hSrch=FindFirstFile(wPath.c_str(),&wfd); if (hSrch != INVALID_HANDLE_VALUE){ while(bResult){ if (/*wfd.dwFileAttributes && */ !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)){ //!(wfd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)){ if (SameText(ExtractFileExt(wfd.cFileName), ExtractFileExt(String(Filter)))){ String* filename = new String(wfd.cFileName); FileList->Add(filename); } } bResult = FindNextFile(hSrch,&wfd); } } } FindClose(hSrch); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::ClearFileList() { String* file = NULL; if (FileList) { while (FileList->Count > 0) { file = (String*) FileList->Last(); if (file) { FileList->Remove(file); delete file; file = NULL; } } } } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FormShow(TObject *Sender) { DirName = PFMDirectoryShellTree->SelectedPathName; InitData(); } //--------------------------------------------------------------------------- /* void __fastcall TPFMForm::ListViewClick(TObject *Sender) { if (ListView->ItemIndex != -1){ String wfn = ListView->Items->Item[ListView->Selected->Index]->Caption; String wPath = FullPathName(DirName, wfn); ReviewPalette->LoadFromFile(wPath.c_str()); FileEdit->Text = wfn; } ReviewPalette->Repaint(); } */ //--------------------------------------------------------------------------- void __fastcall TPFMForm::ListBoxClick(TObject *Sender) { if (ListBox->ItemIndex != -1){ String wfn = ListBox->Items->Strings[ListBox->ItemIndex]; String wPath = FullPathName(DirName, wfn); ReviewPalette->LoadFromFile(wPath.c_str()); FileEdit->Text = wfn; } ReviewPalette->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbReadClick(TObject *Sender) { Item = 0; StatusBar->Panels->Items[2]->Text = IDS_IFREAD; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbMergeClick(TObject *Sender) { Item = 1; StatusBar->Panels->Items[2]->Text = IDS_IFMERGE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbSaveClick(TObject *Sender) { Item = 2; StatusBar->Panels->Items[2]->Text = IDS_IFSAVE; //sbSv_as->Caption = IDS_COMMON_SAVE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbSaveAsClick(TObject *Sender) { Item = 3; FileEdit->Clear(); FileEdit->SetFocus(); StatusBar->Panels->Items[2]->Text = "";//IDS_IFSAVEAS; //sbSv_as->Caption = IDS_COMMON_SAVEAS; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbDeleteClick(TObject *Sender) { Item = 5; StatusBar->Panels->Items[2]->Text = IDS_IFDELETE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbRenameClick(TObject *Sender) { Item = 4; StatusBar->Panels->Items[2]->Text = IDS_IFRENAME; //StatusBar->Panels->Items[2]->Text = IDS_SELECTFILE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::rztbExitClick(TObject *Sender) { ModalResult = mrOk; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::PFMDirectoryShellTreeChange(TObject *Sender, TTreeNode *Node) { DirName = PFMDirectoryShellTree->SelectedPathName; InitData(); dirLabel->Caption = String(DirName); } //---------------------------------------------------------------------------