📄 mainunit.cpp
字号:
if (AddForm->SubFldrCheckBox->Checked && !AddForm->ExtraFldrCheckBox->Checked)
{
SetCurrentDir(AddForm->RootDir);
AddForm->RootDir = "";
}
ZipBuilder->FSpecArgs->Clear();
// Check if it's Add with WildCard
if (AddForm->ModalResult == mrYes)
{
if (AddForm->RootDir=="")
ZipBuilder->FSpecArgs->Add(AddForm->NameEdit->Text);
else
ZipBuilder->FSpecArgs->Add(AddForm->RootDir+AddForm->NameEdit->Text);
} // else it's just plain Add
else if (AddForm->ModalResult == mrOk)
{
ZipBuilder->FSpecArgs->CommaText = AddForm->NameEdit->Text;
for (int iLoop=0; iLoop < ZipBuilder->FSpecArgs->Count; iLoop++)
{
ZipBuilder->FSpecArgs->Strings[iLoop] = AddForm->RootDir+ZipBuilder->FSpecArgs->Strings[iLoop];
// Check if it's a directory we're adding
if (AddForm->IsDirectory(ZipBuilder->FSpecArgs->Strings[iLoop]))
{
ZipBuilder->FSpecArgs->Strings[iLoop] = ZipBuilder->FSpecArgs->Strings[iLoop]+"\\*.*";
}
}
}
// --- Do the works ;) --- //
ZipBuilder->Add();
// Update the system
Update();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::AddToolButtonClick(TObject *Sender)
{
// Perform Add
Add1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExtListViewChange(TObject *Sender,
TListItem *Item, TItemChange Change)
{
// Init Values
TListItem *SelItem = ExtListView->Selected;
TItemStates SearchState;
SearchState << isSelected;
// Set menues and toolbar status' according to selection
if (ExtListView->SelCount==1)
{
ViewToolButton->Enabled = true;
View1->Enabled = true;
Delete1->Enabled = true;
OpenFile1->Enabled = true;
View2->Enabled = true;
Delete2->Enabled = true;
}
else
{
ViewToolButton->Enabled = false;
OpenFile1->Enabled = false;
View1->Enabled = false;
View2->Enabled = false;
if (ExtListView->SelCount)
{
Delete1->Enabled = true;
Delete2->Enabled = true;
}
else
{
Delete1->Enabled = false;
Delete2->Enabled = false;
}
}
// Count selected bytes
TotalSelected = 0;
while( SelItem )
{
TotalSelected += StrToInt( SelItem->SubItems->Strings[1]);
SelItem = ExtListView->GetNextItem(SelItem, sdAll, SearchState);
}
// Update StatusBar
if (TotalSelected/1024 > 1)
StatusBar->Panels->Items[0]->Text = "Total "+IntToStr(ExtListView->SelCount)+" files, "+IntToStr((int)TotalSelected/1024)+" KB";
else
StatusBar->Panels->Items[0]->Text = "Total "+IntToStr(ExtListView->SelCount)+" files, "+IntToStr((int)TotalSelected)+" bytes";
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SelectAll1Click(TObject *Sender)
{
// Select all items
TListItem *Item;
for (int iLoop=0; iLoop < ExtListView->Items->Count; iLoop++)
{
Item = ExtListView->Items->Item[iLoop];
Item->Selected = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::InvertSelection1Click(TObject *Sender)
{
// Invert selection
TListItem *Item;
for (int iLoop=0; iLoop < ExtListView->Items->Count; iLoop++)
{
Item = ExtListView->Items->Item[iLoop];
Item->Selected = !Item->Selected;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
// Check if the user has answered yes to the license agreement
TRegistry* thisReg = new TRegistry();
thisReg->OpenKey("SOFTWARE\\JZip", true);
if (thisReg->ReadString("") != "1")
{
if (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.\n\nJZip is released under GPL license."
"Press \"Yes\" if you accept this disclaimer agreement!",
"JZip disclaimer", MB_YESNO | MB_ICONWARNING) == ID_YES)
{
thisReg->WriteString("", "1");
thisReg->CloseKey();
}
else
{
thisReg->WriteString("", "");
thisReg->CloseKey();
delete thisReg;
Application->Terminate();
return;
}
}
else
{
thisReg->CloseKey();
}
// Clean up
delete thisReg;
// Set zip DLL dir
if (FileExists(ExtractFilePath(ParamStr(0))+"UnzDll.dll"))
{
ZipBuilder->DLLDirectory = ExtractFilePath(ParamStr(0));
}
/* --- Read configuration --- */
ReadConfiguration();
SetConfiguration();
// Check if the user needs a newer version of COMCTL32.DLL
if (ExtListView->RequireComCtlUpdate)
{
Application->MessageBox("You need a newer version of COMCTL32.DLL to run JZip properly!", "Version Check", MB_OK | MB_ICONWARNING);
}
// Set drag/drop support
DropFileTarget->Register(ExtListView);
// Get temp dir
LPTSTR szTmpDir = new TCHAR[MAX_PATH];
GetTempPath(MAX_PATH, szTmpDir);
ZipBuilder->TempDir = szTmpDir;
delete szTmpDir;
// DLL's
ZipBuilder->DLLDirectory = ExtractFilePath(ParamStr(0));
ZipBuilder->Load_Zip_Dll();
ZipBuilder->Load_Unz_Dll();
// Get startup directory
StartupDirectory = GetCurrentDir();
// Set SFX dir
ZipBuilder->SFXPath = ExtractFilePath(ParamStr(0));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
// Unregister drag/drop
DropFileTarget->Unregister();
// Unload ZIP dlls
ZipBuilder->Unload_Zip_Dll();
ZipBuilder->Unload_Unz_Dll();
// Save configuration
WriteConfiguration();
}
//---------------------------------------------------------------------------
// Update Progress bar
void __fastcall TMainForm::ZipBuilderProgress(TObject *Sender,
ProgressType ProgrType, AnsiString FileName, long FileSize)
{
// Local statis vars (made static for speed)
static long TotalSize;
static long BytesProcessed;
static float fTmp;
switch(ProgrType)
{
case TotalSize2Process :
// Start
bInProgress = true;
bYesToAll = false;
// Set everything to Cursor Hourglass
Cursor = crHourGlass;
ToolBar->Cursor = crHourGlass;
ExtListView->Cursor = crHourGlass;
StatusBar->Cursor = crHourGlass;
// Disable components
File1->Enabled = false;
Actions1->Enabled = false;
Options1->Enabled = false;
Help1->Enabled = false;
ToolBar->Enabled = false;
NewToolButton->Enabled = false;
OpenToolButton->Enabled = false;
AddToolButton->Enabled = false;
ExtractToolButton->Enabled = false;
ViewToolButton->Enabled = false;
InstallToolButton->Enabled = false;
AboutToolButton->Enabled = false;
ExtListView->Enabled = false;
// Set 2. panel to Gauge
StatusBar->Panels->Items[1]->PanelType = sptGauge;
StatusBar->Panels->Items[1]->GaugeAttrs->Position = 0;
StatusBar->Panels->Items[1]->Text = "";
// Update TotalSize
// Workaround for bug in TZipBuilder
if (bExtractSelected)
TotalSize = TotalSelected;
else
TotalSize = FileSize;
BytesProcessed=0;
break;
case NewFile:
// Set text in panel 1
StatusBar->Panels->Items[0]->Text = "Processing: "+FileName;
break;
case ProgressUpdate :
// Update Bytes processed
BytesProcessed += FileSize;
if (TotalSize > 0)
{
// Update Gauge
fTmp = (float)BytesProcessed/TotalSize;
fTmp *= 100.0;
StatusBar->Panels->Items[1]->GaugeAttrs->Position = (int)fTmp;
}
// Make the app live a little to let the user be able to cancel the operation
Application->ProcessMessages();
break;
case EndOfBatch :
// End
bInProgress = false;
bYesToAll = false;
// Set 2. panel back to Text
StatusBar->Panels->Items[1]->PanelType = sptNormal;
StatusBar->Panels->Items[1]->Alignment = taLeftJustify;
bExtractSelected = false; // Bug workaround
// Restore Current directory
if (AddForm->SubFldrCheckBox->Checked && !AddForm->ExtraFldrCheckBox->Checked)
SetCurrentDir(StartupDirectory);
// 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;
break;
} // end switch
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Extract1Click(TObject *Sender)
{
// Set buttons
if (ExtListView->Selected == NULL)
{
ExtractForm->SelRadioButton->Enabled = false;
ExtractForm->AllRadioButton->Checked = true;
}
else
{
ExtractForm->SelRadioButton->Enabled = true;
ExtractForm->SelRadioButton->Checked = true;
}
// Show
ExtractForm->ShowModal();
if (ExtractForm->ModalResult == mrCancel)
return;
// Set options
ZipBuilder->ExtrOptions.Clear();
if (ExtractForm->UserFolderNamesCheckBox->Checked)
ZipBuilder->ExtrOptions << ExtrDirNames;
if (ExtractForm->SkipOlderCheckBox->Checked)
ZipBuilder->ExtrOptions << ExtrUpdate;
if (ExtractForm->OverwriteCheckBox->Checked)
ZipBuilder->ExtrOptions << ExtrOverWrite;
// Set FSpecArgs
ZipBuilder->FSpecArgs->Clear();
AnsiString asTmp;
if (ExtractForm->SelRadioButton->Checked)
{
TListItem *SelItem = ExtListView->Selected;
TItemStates SearchState;
SearchState << isSelected;
while( SelItem )
{
if (SelItem->SubItems->Strings[4] == "")
asTmp = SelItem->Caption;
else
asTmp = SelItem->SubItems->Strings[4]+"\\"+SelItem->Caption;
// Add it
ZipBuilder->FSpecArgs->Add(asTmp);
SelItem = ExtListView->GetNextItem(SelItem, sdAll, SearchState);
}
bExtractSelected = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -