⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addunit.cpp

📁 Winzip的源代码
💻 CPP
字号:
/******************************************************************************\
*                                  JZip                                        *
*                                                                              *
* COPYRIGHT:                                                                   *
*   (C) Copyright 1999-2000 Cramon Utilities and Bytamin-C                     *
*                                                                              *
* WWW:                                                                         *
*   http://www.bytamin-c.com                                                   *
*                                                                              *
* DISCLAMER:                                                                   *
*   THE AUTHOR(S) MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY *
*   OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO   *
*   THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR        *
*   PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR(S) SHALL NOT BE LIABLE FOR ANY    *
*   DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR            *
*   DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.                             *
*                                                                              *
* ---------------------------------------------------------------------------- *
* Last changed      Name                   Changes                             *
* 01/13-2000        Jeppe Cramon           Prepared for OpenSource release     *
\******************************************************************************/

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Registry.hpp"
#include "AddUnit.h"
#include "PasswordUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SystemComboBox"
#pragma link "SystemControlPack"
#pragma link "SystemListView"
#pragma resource "*.dfm"
TAddForm *AddForm;
//---------------------------------------------------------------------------
__fastcall TAddForm::TAddForm(TComponent* Owner)
    : TForm(Owner)
{
    bDoubleClick = false;
}
//---------------------------------------------------------------------------
void __fastcall TAddForm::UpBitBtnClick(TObject *Sender)
{
    // Move up one level
    if (SystemComboBox->ActiveFolderName[2] == ':' && SystemComboBox->ActiveFolderName.Length() == 3)
    {
        SystemComboBox->ItemIndex--;
        while (SystemComboBox->ActiveFolderName[2] == ':' && SystemComboBox->ActiveFolderName.Length() == 3)
            SystemComboBox->ItemIndex--;
    }
    else
        SystemComboBox->ItemIndex--;

    // Update ListView
    SystemComboBox->NotifyLinkedControls(false);

    // Update Button
    if (SystemComboBox->ItemIndex == 0)
        UpBitBtn->Enabled = false;
    else
        UpBitBtn->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::Timer1Timer(TObject *Sender)
{
    // Check if desktop or not
    if (SystemComboBox->ItemIndex == 0)
        UpBitBtn->Enabled = false;
    else
        UpBitBtn->Enabled = true;

    /* --- Check for selections --- */
    if (!SystemListView->Selected)
    {
        AddBitBtn->Enabled = false;
        NameEdit->Text = DefaultWildCard;
        return;
    }

    // Somethings selected
    AddBitBtn->Enabled = true;
    NameEdit->Text = "";

    // Get all selected items and add them to the NameEdit edit seperated with
    // commas
    TListItem *SelItem = SystemListView->Selected;
    TItemStates SearchState;
    SearchState << isSelected;

    while( SelItem )
    {
        NameEdit->Text = NameEdit->Text + "\""+SelItem->Caption+"\", ";
        SelItem = SystemListView->GetNextItem(SelItem, sdAll, SearchState);
    }

}
//---------------------------------------------------------------------------

void __fastcall TAddForm::SystemComboBoxChange(TObject *Sender)
{
    // Check if desktop or not
    if (SystemComboBox->ItemIndex == 0)
        UpBitBtn->Enabled = false;
    else
        UpBitBtn->Enabled = true;

    // Disable button if the item is My Computer
    if (SystemComboBox->ItemIndex == 1)
    {
        AddWtihWBitBtn->Enabled = false;
        AddBitBtn->Enabled = false;
    }
    else
    {
        AddWtihWBitBtn->Enabled = true;
        AddBitBtn->Enabled = true;
    }
}
//---------------------------------------------------------------------------


void __fastcall TAddForm::ListSpeedButtonClick(TObject *Sender)
{
    SystemListView->ViewStyle = vsList;
    DetailsSpeedButton->Down = false;
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::DetailsSpeedButtonClick(TObject *Sender)
{
    SystemListView->ViewStyle = vsReport;
    ListSpeedButton->Down = false;
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::FormCreate(TObject *Sender)
{
    /* --- Load settings --- */
    TRegistry* thisReg = new TRegistry();
    thisReg->OpenKey("SOFTWARE\\JZip\\AddForm", true);

    if (thisReg->ValueExists("Action"))
        ActionComboBox->ItemIndex = thisReg->ReadInteger("Action");
    if (thisReg->ValueExists("Compression"))
        CompressionComboBox->ItemIndex = thisReg->ReadInteger("Compression");

    if (thisReg->ValueExists("Include SubFolders"))
        SubFldrCheckBox->Checked = thisReg->ReadInteger("Include SubFolders");

    if (thisReg->ValueExists("Save Extra Folder Info"))
        ExtraFldrCheckBox->Checked = thisReg->ReadInteger("Save Extra Folder Info");

    if (thisReg->ValueExists("Include Sys and Hidden Files"))
        SysFilesCheckBox->Checked = thisReg->ReadInteger("Include Sys and Hidden Files");

    if (thisReg->ValueExists("Force DOS"))
        ForceDOSCheckBox->Checked = thisReg->ReadInteger("Force DOS");

    // clean up
    delete thisReg;

    if (ActionComboBox->ItemIndex == -1)
        ActionComboBox->ItemIndex = 0;
    if (CompressionComboBox->ItemIndex == -1)
        CompressionComboBox->ItemIndex = 1;

    DefaultWildCard = "*.*";
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::NameEditChange(TObject *Sender)
{
    if (!SystemListView->SelCount && NameEdit->Text != "")
    {
        DefaultWildCard = NameEdit->Text;
        SystemListView->FileMask = NameEdit->Text;
    }
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::FormShow(TObject *Sender)
{
    Password = "";
    SystemListViewPopulated(NULL);
    if (!SystemListView->SelCount)
    {
        NameEdit->Text = DefaultWildCard;
        AddBitBtn->Enabled = false;
    }
    else
        AddBitBtn->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::PasswordBitBtnClick(TObject *Sender)
{
    PasswordForm->Password1Edit->Text = "";
    PasswordForm->Password2Edit->Text = "";
     PasswordForm->ShowModal();
    if (PasswordForm->ModalResult == mrOk)
        Password = PasswordForm->Password1Edit->Text;
}
//---------------------------------------------------------------------------

void __fastcall TAddForm::SystemListViewPopulated(TObject *Sender)
{

    if (SystemListView->Items->Count == 0)
    {
        RootDir = "";
        AddWtihWBitBtn->Enabled = false;
        AddBitBtn->Enabled = false;

        return;
    }

    AnsiString asTmp;
    for (int iLoop = 0; iLoop < SystemListView->Items->Count; iLoop++)
    {
        RootDir = ExtractFilePath(SystemListView->GetFullPath(SystemListView->Items->Item[iLoop]));
        if (IsDirectory(RootDir))
            asTmp = RootDir;

        if (RootDir != "" && !IsDirectory(SystemListView->GetFullPath(SystemListView->Items->Item[iLoop])))
        {
            AddWtihWBitBtn->Enabled = true;
            AddBitBtn->Enabled = true;
            return;
        }
    }

    if (IsDirectory(asTmp))
    {
        AddWtihWBitBtn->Enabled = true;
        AddBitBtn->Enabled = true;
        RootDir = asTmp;
    }
    else
    {
        RootDir = "";
        AddWtihWBitBtn->Enabled = false;
        AddBitBtn->Enabled = false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TAddForm::FormDestroy(TObject *Sender)
{
    /* --- Save settings --- */
    TRegistry* thisReg = new TRegistry();
    thisReg->OpenKey("SOFTWARE\\JZip\\AddForm", true);

    thisReg->WriteInteger("Action", ActionComboBox->ItemIndex);
    thisReg->WriteInteger("Compression", CompressionComboBox->ItemIndex);

    thisReg->WriteInteger("Include SubFolders", SubFldrCheckBox->Checked);
    thisReg->WriteInteger("Save Extra Folder Info", ExtraFldrCheckBox->Checked);
    thisReg->WriteInteger("Include Sys and Hidden Files", SysFilesCheckBox->Checked);
    thisReg->WriteInteger("Force DOS", ForceDOSCheckBox->Checked);

    // clean up
    delete thisReg;

}
//---------------------------------------------------------------------------
bool __fastcall TAddForm::IsDirectory(AnsiString Dir)
{
    AnsiString asTmp = GetCurrentDir();
    int rc = SetCurrentDir(Dir);
    SetCurrentDir(asTmp);
    return rc;
}
//---------------------------------------------------------------------------
void __fastcall TAddForm::SystemListViewKeyPress(TObject *Sender,
      char &Key)
{
    if (Key == 1)
    {
        // Select All
        TListItem* Item;
        for (int iLoop=0; iLoop < SystemListView->Items->Count; iLoop++)
        {
            Item = SystemListView->Items->Item[iLoop];
            Item->Selected = true;
        }
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -