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

📄 mainunit.cpp

📁 这份是一份压缩解压缩的商业产品的源码JZIP。压缩算法比较不错
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************\
*                                  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 <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include "filectrl.hpp"
#include "MainUnit.h"
#include "AddUnit.h"
#include "ExtractUnit.h"
#include "InstallUnit.h"
#include "CommentUnit.h"
#include "PasswordUnit.h"
#include "ExtractPasswUnit.h"
#include "TestUnit.h"
#include "AboutUnit.h"
#include "EXEUnit.h"
#include "ConfigurationUnit.h"
#include "DragDropUnit.h"
#include "OverwriteUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ZipBuilder"
#pragma link "Placemnt"
#pragma link "ExtListView"
#pragma link "SystemImageList"
#pragma link "DropSource"
#pragma link "DropTarget"
#pragma link "dfsStatusBar"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
    : TForm(Owner)
{
    // Initialize the random engine
    Randomize();

    // Init values
    TotalBytes = 0;
    TotalSelected = 0;
    bExtractSelected = false;
    bYesToAll = false;
    bTesting = false;
    iTestErrors = 0;
    bInProgress = false;
    bDragging = false;
    bDraggingOverUs = false;

    // Allocate a new instance of TStringList
    CleanUpList = new TStringList();
}
//---------------------------------------------------------------------------
__fastcall TMainForm::~TMainForm()
{
    // Clean up tmp dirs
    if (CleanUpList->Count)
    {
        for (int iLoop=0; iLoop < CleanUpList->Count; iLoop++)
        {
            DeleteDir(CleanUpList->Strings[iLoop]);
        }
    }
    CleanUpList->Clear();
    delete CleanUpList;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OpenArchive1Click(TObject *Sender)
{
    // Show Open dialog
    if (OpenDialog->Execute())
    {
        Caption = "JZip - "+MinimizeName( OpenDialog->FileName, Canvas, ClientWidth-Canvas->TextWidth("JZip - ")-140);
        ZipBuilder->ZipFileName = OpenDialog->FileName;
        ZipBuilder->Password = "";
        Update();
    }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::OpenToolButtonClick(TObject *Sender)
{
    // Perform Open
    OpenArchive1Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Update()
{
    // Init values
    TotalBytes = 0;
    TotalSelected = 0;
    InstallToolButton->Enabled = false;
    InstallProgram = "";

    // Clear the List
    ExtListView->Items->Clear();

    // Fill the Grid with the contents of the ZipFile (if any file exists)
    if (ZipBuilder->ZipFileName == "")
    {
        AddToolButton->Enabled = false;
        ExtractToolButton->Enabled = false;
        ViewToolButton->Enabled = false;
//        CheckOutToolButton->Enabled = false; (kept for later use)
        InstallToolButton->Enabled = false;
        StatusBar->SimplePanel = true;

        // Menu bar
        Delete1->Enabled = false;
        CloseArchive1->Enabled = false;
        CreateShortcut1->Enabled = false;
        MoveArchive1->Enabled = false;
        CopyArchive1->Enabled = false;
        RenameArchive1->Enabled = false;
        DeleteArchive1->Enabled = false;
        //-----
        Add1->Enabled = false;
        Extract1->Enabled = false;
        View1->Enabled = false;
        SelectAll1->Enabled = false;
        InvertSelection1->Enabled = false;
        MakeEXEFile1->Enabled = false;
        Test1->Enabled = false;
        Comment1->Enabled = false;
        Install1->Enabled = false;
        //-----
        Password1->Enabled = false;

        // Popup menu
        OpenFile1->Enabled = false;
        Delete2->Enabled = false;
        Add2->Enabled = false;
        Extract2->Enabled = false;
        View2->Enabled = false;
        SelectAll2->Enabled = false;
        InvertSelection2->Enabled = false;
        MakeEXEFile2->Enabled = false;
        Test2->Enabled = false;
        Comment2->Enabled = false;
        Install2->Enabled = false;

        return;
    }
    else
    {
        // Menu bar
        Delete1->Enabled = false;
        CloseArchive1->Enabled = true;
        // ----
        Add1->Enabled = true;
        Extract1->Enabled = true;
        View1->Enabled = false;
        SelectAll1->Enabled = true;
        InvertSelection1->Enabled = true;
        MakeEXEFile1->Enabled = true;
        Test1->Enabled = true;
        Comment1->Enabled = true;
        Install1->Enabled = false;
        Password1->Enabled = true;

        // Popup menu
        OpenFile1->Enabled = true;
        Delete2->Enabled = true;
        Add2->Enabled = true;
        Extract2->Enabled = true;
        View2->Enabled = true;
        SelectAll2->Enabled = true;
        InvertSelection2->Enabled = true;
        MakeEXEFile2->Enabled = true;
        Test2->Enabled = true;
        Comment2->Enabled = true;
        Install2->Enabled = false;

        // Toolbar
        AddToolButton->Enabled = true;
        ViewToolButton->Enabled = false;
        InstallToolButton->Enabled = false;

        // Statusbar
        StatusBar->SimplePanel = false;

        if (ZipBuilder->Count > 0)
        {
            ExtractToolButton->Enabled = true;
//            CheckOutToolButton->Enabled = true; (kept for later use)
        }
        else
        {
            ExtractToolButton->Enabled = false;
//            CheckOutToolButton->Enabled = false; (kept for later use)
        }

    }

    // ---- Fill ListView ---- //
    ZipDirEntry *zde;
    AnsiString FileName;
    TListItem *Item;
    for (int iLoop=0; iLoop < ZipBuilder->Count; iLoop++)
    {
        zde = (ZipDirEntry *)ZipBuilder->ZipContents->Items[ iLoop ];

        // "Names"
        FileName = ExtractFileName(zde->FileName);
        Item = ExtListView->Items->Add();
        Item->Caption = FileName;

        // Set icon
        Item->ImageIndex = SysImgList->GetImageIndex(FileName, false, false, TSystemFileAttributes());

        // "Modified"
        try
        {
            Item->SubItems->Add(FormatDateTime( "ddddd  t", FileDateToDateTime( zde->DateTime ) ));
        }
        catch(...)
        {
            Item->SubItems->Add("Error...");
        }

        // "Size"
        Item->SubItems->Add(IntToStr((int)zde->UncompressedSize));
        // "Ratio"
        if (zde->UncompressedSize)
            Item->SubItems->Add(AnsiString(FloatToStr(100.0-((float)zde->CompressedSize*100.0/(float)zde->UncompressedSize))).SubString(0,5)+"%");
        else
            Item->SubItems->Add("0%");
        // "Packed"
        Item->SubItems->Add( IntToStr((int)zde->CompressedSize) );
        // "Path"
        Item->SubItems->Add( ExtractFileDir(zde->FileName) );

        // Update Total Size
        TotalBytes += zde->UncompressedSize;

        // Check if we should update the install button
        if (FileName.LowerCase() == "setup.exe" || FileName.LowerCase() == "install.exe")
        {
            InstallToolButton->Enabled = true;
            Install1->Enabled = true;
            Install2->Enabled = true;
            InstallProgram = FileName;
        }

    } // end for

    // Update status bar
    if (TotalBytes/1024 > 1)
        StatusBar->Panels->Items[1]->Text = "Total "+IntToStr(ZipBuilder->Count)+" files, "+IntToStr((int)TotalBytes/1024)+" KB";
    else
        StatusBar->Panels->Items[1]->Text = "Total "+IntToStr(ZipBuilder->Count)+" files, "+IntToStr((int)TotalBytes)+" bytes";

}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NewArchive1Click(TObject *Sender)
{
    // Show new dialog
    if (NewDialog->Execute())
    {
        Caption = "JZip - "+MinimizeName( NewDialog->FileName, Canvas, ClientWidth-Canvas->TextWidth("JZip - ")-140);
        ZipBuilder->ZipFileName = NewDialog->FileName;
        ZipBuilder->Password = "";
        Update();
    }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::NewToolButtonClick(TObject *Sender)
{
    // Perform New
    NewArchive1Click(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Add1Click(TObject *Sender)
{
    // Init AddForm vars and components
    AddForm->AddBitBtn->Enabled = false;
    AddForm->SystemListView->Selected = NULL;
    AddForm->NameEdit->Text = AddForm->DefaultWildCard;
    AddForm->Password = "";

    // Show it
    AddForm->ShowModal();
    if (AddForm->ModalResult == mrCancel)
        return;

    /* --- Steps that are default for both with and without wildcard --- */
    // Set compression level
    switch(AddForm->CompressionComboBox->ItemIndex)
    {
        case 0 : // Maximum
            ZipBuilder->AddCompLevel = 9;
            break;
        case 1 : // Normal
            ZipBuilder->AddCompLevel = 6;
            break;
        case 2 : // Fast
            ZipBuilder->AddCompLevel = 3;
            break;
        case 3 : // Superfast
            ZipBuilder->AddCompLevel = 2;
            break;
        case 4 : // None
            ZipBuilder->AddCompLevel = 0;
            break;
    } // end switch

    // Set Action type
    ZipBuilder->AddOptions.Clear();
    switch(AddForm->ActionComboBox->ItemIndex)
    {
        case 0: // Add (and replace)
            // Don nothing. This is the default
            break;
        case 1: // Freshen existing files
            ZipBuilder->AddOptions << AddFreshen;
            break;
        case 2: // Move files
            ZipBuilder->AddOptions << AddMove;
            break;
        case 3: // Update and add
            ZipBuilder->AddOptions << AddUpdate;
            break;
    } // end switch

    // Store 8.3 names
    if (AddForm->ForceDOSCheckBox->Checked)
        ZipBuilder->AddOptions << AddForceDOS;

    // Include SubFolders
    if (AddForm->SubFldrCheckBox->Checked)
    {
        ZipBuilder->AddOptions << AddRecurseDirs;
        ZipBuilder->AddOptions << AddDirNames;
    }

    // Save extra folder info
    if (AddForm->ExtraFldrCheckBox->Checked)
        ZipBuilder->AddOptions << AddDirNames;

    // Include System and hidden files
    if (AddForm->SysFilesCheckBox->Checked)
        ZipBuilder->AddOptions << AddHiddenFiles;

    // Password
    if (AddForm->Password != "")
        ZipBuilder->Password = AddForm->Password;
    if (ZipBuilder->Password != "")
        ZipBuilder->AddOptions << AddEncrypt;

    // Check for special request by user

⌨️ 快捷键说明

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