📄 mainunit.cpp
字号:
// Set everything back to normal cursors
Cursor = crDefault;
ToolBar->Cursor = crDefault;
ExtListView->Cursor = crDefault;
StatusBar->Cursor = crDefault;
File1->Enabled = true;
Actions1->Enabled = true;
Options1->Enabled = true;
Help1->Enabled = true;
ToolBar->Enabled = true;
NewToolButton->Enabled = true;
OpenToolButton->Enabled = true;
AddToolButton->Enabled = true;
ExtractToolButton->Enabled = true;
AboutToolButton->Enabled = true;
ExtListView->Enabled = true;
}
else if (ErrCode != 0)
{
Application->MessageBox(Message.c_str(), AnsiString("JZip - Error: "+IntToStr(ErrCode)).c_str(), MB_OK | MB_ICONERROR);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::About1Click(TObject *Sender)
{
// Show about box
AboutBox->ShowModal();
}
//---------------------------------------------------------------------------
// Delete files in archive
void __fastcall TMainForm::Delete1Click(TObject *Sender)
{
if (Application->MessageBox("Are you sure you want to delete the file(s)?", "Delete File(s)", MB_ICONQUESTION | MB_YESNO) == ID_NO)
return;
ZipBuilder->FSpecArgs->Clear();
TListItem *SelItem = ExtListView->Selected;
TItemStates SearchState;
SearchState << isSelected;
// Find all selected items
while( SelItem )
{
if (SelItem->SubItems->Strings[4] == "")
ZipBuilder->FSpecArgs->Add(SelItem->Caption);
else
ZipBuilder->FSpecArgs->Add(SelItem->SubItems->Strings[4]+"\\"+SelItem->Caption);
SelItem = ExtListView->GetNextItem(SelItem, sdAll, SearchState);
}
// Delete them
ZipBuilder->Delete();
// Update
Update();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MakeEXEFile1Click(TObject *Sender)
{
// Show Exe form
EXEForm->ShowModal();
if (EXEForm->ModalResult == mrCancel)
return;
ZipBuilder->SFXDefaultDir = EXEForm->NameEdit->Text;
// perform convertion
int rc = ZipBuilder->ConvertSFX();
switch(rc)
{
case 0: // On succes.
Application->MessageBox("Self-Extracting Archive was created successfully!", "Done", MB_OK | MB_ICONINFORMATION);
break;
case -1: // Error in creation of destination.
Application->MessageBox("Failed!\nReason: Error in creation of destination.", "Self-Extracting Archive", MB_OK | MB_ICONERROR);
break;
case -2: // Read or write error during copy. (Could be: Not enough space on disk)
Application->MessageBox("Failed!\nReason: Read or write error during copy. (Could be: Not enough space on disk)", "Self-Extracting Archive", MB_OK | MB_ICONERROR);
break;
case -3: // Error in open of source.
Application->MessageBox("Failed!\nReason: Error in open of source.", "Self-Extracting Archive", MB_OK | MB_ICONERROR);
break;
case -9: // General failure during copy.
Application->MessageBox("Failed!\nReason: General failure during copy.", "Self-Extracting Archive", MB_OK | MB_ICONERROR);
break;
} // end switch
}
//---------------------------------------------------------------------------
// Create a shortcut in a given destination (O: Desktop, 1: Startmenu)
void __fastcall TMainForm::CreateShortCut(const AnsiString &file, int iDestination)
{
IShellLink* pLink;
IPersistFile* pPersistFile;
LPMALLOC ShellMalloc;
LPITEMIDLIST DesktopPidl;
char DesktopDir[MAX_PATH];
// We are going to create a pidl, and it will need to be
// freed by the shell mallocator. Get the shell mallocator
// object using API SHGetMalloc function. Return if failure.
if(FAILED(SHGetMalloc(&ShellMalloc)))
return;
// Check for the destination of our shortcut
switch(iDestination)
{
case 0: // Desktop
// use the API to get a pidl for the desktop directory
// if function fails, return without proceeding
if(FAILED(SHGetSpecialFolderLocation(NULL,
CSIDL_DESKTOPDIRECTORY,
&DesktopPidl)))
return;
break;
case 1: // Startmenu
if(FAILED(SHGetSpecialFolderLocation(NULL,
CSIDL_STARTMENU,
&DesktopPidl)))
return;
}
// Now convert the pidl to a character string
// return if function fails
if(!SHGetPathFromIDList(DesktopPidl, DesktopDir))
{
ShellMalloc->Free(DesktopPidl);
ShellMalloc->Release();
return;
}
// At this point, we are done with the pidl and the
// mallocator, so free them up
ShellMalloc->Free(DesktopPidl);
ShellMalloc->Release();
if(SUCCEEDED(CoInitialize(NULL)))
{
if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **) &pLink)))
{
pLink->SetPath(file.c_str());
pLink->SetDescription("JZip Archive Manager");
pLink->SetShowCmd(SW_SHOW);
if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile,
(void **)&pPersistFile)))
{
WideString strShortCutLocation(DesktopDir);
strShortCutLocation += "\\JZip.lnk";
pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE);
pPersistFile->Release();
}
pLink->Release();
}
CoUninitialize();
}
}
//----------------------------------------------------------------------
void __fastcall TMainForm::LicenseAgreement1Click(TObject *Sender)
{
Application->MessageBox( "This software is provided \"as is\" without warranty of any kind, "
"either expressed or implied. the entire risk as to the "
"quality and performance of the software is with you. Should the "
"software prove defective, you assume the cost of all necessary "
"servicing, repair, or correction. in no event shall the author, "
"copyright holder, or any other party who may redistribute the "
"software be liable to you for damages, including any general, "
"special, incidental, or consequential damages arising out of "
"the use or inability to use the software (including, but not "
"limited to, loss of data, data being rendered inaccurate, loss of "
"business profits, loss of business information, business "
"interruptions, loss sustained by you or third parties, or a "
"failure of the software to operate with any other software) even "
"if the author, copyright holder, or other party has been advised "
"of the possibility of such damages.", "JZip Disclaimer",
MB_OK | MB_ICONINFORMATION);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OpenFile1Click(TObject *Sender)
{
// Perform View
View1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Add2Click(TObject *Sender)
{
// Perform Add
Add1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Delete2Click(TObject *Sender)
{
// Perform Delete
Delete1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Extract2Click(TObject *Sender)
{
// Perform Extract
Extract1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::View2Click(TObject *Sender)
{
// Perform View
View1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SelectAll2Click(TObject *Sender)
{
// Select All
SelectAll1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::InvertSelection2Click(TObject *Sender)
{
// Invert Selection
InvertSelection1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MakeEXEFile2Click(TObject *Sender)
{
// Convert Zip to Exe file
MakeEXEFile1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Test2Click(TObject *Sender)
{
// Perform Test
Test1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Comment2Click(TObject *Sender)
{
// Show comment
Comment1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Install2Click(TObject *Sender)
{
// Perform install
Install1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::AboutToolButtonClick(TObject *Sender)
{
// Show about box
About1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Exit1Click(TObject *Sender)
{
// Close app
Application->Terminate();
}
void __fastcall TMainForm::ExtListViewMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TPoint point;
point.x = X;
point.y = Y;
// NB: There's problems using DragDetect.
// After having dragged something from JZip to something else
// the next click in the ListView will perform an extraction.
// The authors of DragDropSuite hasn't been able to location the bug
// in the source, so it's possible that the problem lies with DragDetect.
// This should be investigated some more.
// Notice: After build 192 (where the ExtListView was updated) and under the
// new Windows 2000 Professional version (build 2195) the problem seems to
// have vanished. Tests needs to be done under Win9x and Win NT 4.
if (DragDetect(ExtListView->Handle, point))
{
DropFileTarget->Unregister();
//clear any filenames left from a previous drag operation...
DropFileSource->Files->Clear();
ZipBuilder->FSpecArgs->Clear();
/* --- Add the file names --- */
// Create temp dir
AnsiString TempDir = CreateTempDir();
// Add the temp dir to the CleanUpList
CleanUpList->Add(TempDir);
ZipBuilder->ExtrBaseDir = TempDir;
// Add files
TListItem *SelItem = ExtListView->Selected;
TItemStates SearchState;
SearchState << isSelected;
// Find selected item
AnsiString asTmp;
while( SelItem )
{
if (SelItem->SubItems->Strings[4] == "")
asTmp = SelItem->Caption;
else
asTmp = SelItem->SubItems->Strings[4]+"\\"+SelItem->Caption;
// Add it
ZipBuilder->FSpecArgs->Add(asTmp);
DropFileSource->Files->Add(TempDir+"\\"+asTmp);
SelItem = ExtListView->GetNextItem(SelItem, sdAll, SearchState);
}
bDraggingOverUs = true;
bDragging = true;
//Do the dragdrop...
DropFileSource->Execute();
DropFileTarget->Register(ExtListView);
}
else
{
bDraggingOverUs = false;
bDragging = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DropFileSourceDrop(TObject *Sender,
TDragType DragType, bool &ContinueDrop)
{
ContinueDrop = true;
// Set options
ZipBuilder->ExtrOptions.Clear();
ZipBuilder->ExtrOptions << ExtrOverWrite;
ZipBuilder->ExtrOptions << ExtrDirNames;
// Extract
ZipBuilder->Extract();
Update();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Password1Click(TObject *Sender)
{
// Password
PasswordForm->Password1Edit->Text = "";
PasswordForm->Password2Edit->Text = "";
PasswordForm->ShowModal();
if (PasswordForm->ModalResult == mrOk)
ZipBuilder->Password = PasswordForm->Password1Edit->Text;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ZipBuilderPasswordError(TObject *Sender,
AnsiString &NewPassword, AnsiString ForFile, unsigned &RepeatCount)
{
// Password required
ExtractPasswForm->PasswEdit->Text = "";
ExtractPasswForm->ShowModal();
if (ExtractPasswForm->ModalResult == mrOk)
{
NewPassword = ExtractPasswForm->PasswEdit->Text;
}
else
NewPassword = "";
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormResize(TObject *Sender)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -