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

📄 unit1.cpp

📁 刻录机源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include <stdio.h>
#include "Unit1.h"
#include "Unit2.h"
#include "ImportSession.h"
#include "ConfigurationSettings.h"
#include "DiscLayout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "mbCDBC"
#pragma link "mbDrvLib"
#pragma link "mbExDD"
#pragma resource "*.dfm"
TForm1 *Form1;
byte buf[65536];
WORD GetSpeed(String ss)
{
  int Divider, Medium;
  if (ss == "Max")
    {
    return 0;
    }
  else
    {

    Medium = Form1->mcdb->DiscType();
    if ( Medium >= mtDVD_ROM )
      {
      Divider = 7;
      }
    else
      {
      Divider = 1;
      }
      return StrToInt( ss[ ss.Pos("X") - 1 ] ) * Divider;
     }
}

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}

void __fastcall TForm1::Panel12Resize(TObject *Sender)
{
  DriveCB->Width = Panel2->Width - bNetwork->Width-4;
}

/*******************************************************************************
              Function     =  clBoxDragOver
              Description  =  Tell the system which files to accept by checking
                              the source. If the dragged item is either from the
                              File List or Directory List Box or from the Shell
                              Accept it other wise dont accept it.
*******************************************************************************/

void __fastcall TForm1::clBoxDragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
   Accept = Source->ClassNameIs("TDirectoryListBox") || Source->ClassNameIs("TFileListBox");
}

/*******************************************************************************
              Function     =  FormShow
              Description  =  Initializes the form Settings
                          1. Check and display For Trial Version.
                          2. Initialize ASPI.
                          3. Display all the Devices.
                          4. Display the speed.
                          5. initilaize the MCDB.
*******************************************************************************/
void __fastcall TForm1::FormShow(TObject *Sender)
{
  int i;                 // counter for Temporary Work
  String State;          // State of the System
  TIniFile* ini;         // initialzation File

  if (TrialMCDB)
    {
      Caption = Caption + " (TRIAL VERSION)";
    }
  mcdb->DebugMsg(">>> " + Caption, 0);
  mcdb->InitializeASPI(true, "");
  if (!(mcdb->ASPIInitialized))
  {
    pTop->Enabled  = false;
    pTop2->Enabled = false;
    ShowMessage("Error initializing ASPI Layer, Please visit support page, http://forum.binarymagics.com for more information");
    return;
  }
  cbSpeedDropDown(Sender);
  if ( (mcdb->Devices != NULL) && (mcdb->Devices->Count > 0) )
  {
    cbDrives->Items->Assign(mcdb->Devices);
    cbDrives->ItemIndex = 0;
    cbDrivesChange(Sender);
  }
  oArchiveFiles = true;
  oImportSession = true;
  State = "CHECKED2q";
  if ( UpperCase(State) == "GRAYED" )
    cPathInfo->State = cbGrayed;
  else if (UpperCase(State) == "CHECKED")
    cPathInfo->State = cbChecked;
  else
    cPathInfo->State = cbUnchecked;

  mcdb->DebugMsg(" ", 0);

  ini = new TIniFile("MCDB.INI");

  oArchiveFiles = ini->ReadBool("Options", "ArchiveFiles", oArchiveFiles);
  oImportSession = ini->ReadBool("Options", "ImportSession", oImportSession);
  State = ini->ReadString("Options", "SavePath", "");
  if (UpperCase(State) == "GRAYED")
    cPathInfo->State = cbGrayed;
  else if (UpperCase(State) == "CHECKED")
    cPathInfo->State = cbChecked;
  else
    cPathInfo->State = cbUnchecked;
  mcdb->FinalizeDisc = ini->ReadBool("Options", "CloseDisc", mcdb->FinalizeDisc);
  mcdb->JolietFileSystem = ini->ReadBool("Options", "JolietFS", mcdb->JolietFileSystem);
  mcdb->TestWrite = ini->ReadBool("Options", "TestWrite", mcdb->TestWrite);
  mcdb->PerformOPC = ini->ReadBool("Options", "PerformOPC", mcdb->PerformOPC);
  QuickSaveISO = ini->ReadBool("Options", "QuickSaveISO", QuickSaveISO);
  if (ini->ReadBool("Options", "ImportSession", false) == true)
    SessionToImport = ini->ReadInteger("Options", "SessionNo", mcdb->SessionToImport);
  else
    SessionToImport = 0;
  ccEject = ini->ReadBool("Options", "EjectDisc", False);
  ccShowFiles = ini->ReadBool("Options", "ShowFiles", False);
  ccImportSession = ini->ReadBool("Options", "ImportSession", False);

  mcdb->BootImage = ini->ReadString("Options", "BootImage", mcdb->BootImage);
  mcdb->IdVolume = ini->ReadString("Options", "VolumeLable", mcdb->IdVolume);
  mcdb->CacheSize = ini->ReadInteger("Options", "CacheSize", mcdb->CacheSize);

  delete ini;
}

/*******************************************************************************
          Function       bBurnClick
          Description  = Burn the CD
                       = Steps

                       1.  Read buffer capacity of the device.
                       2.  Set The Speed
                       3.  Proces the Message So That Application Should Not
                           Go Idle.
                       4.  Check If the Dir Count and  File Count is 0 then
                           do nothing.
                       5.  Add Files To CD
                       6.  if Show Files is True then Show Files in the Form
                       7.  Prepares data for burning on the media or for Saving
                           to .ISO file.
                       8.  Start burning the cd.
*******************************************************************************/

void __fastcall TForm1::bBurnClick(TObject *Sender)
{
  unsigned int   a;     // temporary Variables For Results
  unsigned int   b;
  String         msg;


  mcdb->ReadBufferCapacity(a, b);
  pHBuf->Max = a;
  if ( cbSpeed->ItemIndex == -1)
       cbSpeed->ItemIndex = 0;
  mcdb->WriteSpeed = GetSpeed(cbSpeed->Text);
  Application->ProcessMessages();
  mcdb->ClearAll(MaxFiles,MaxDirs);
  AddFilesToCD();
  mcdb->DebugMsg(">>> ADD FILES/DIRS TO CD DONE.", 0);
  Application->ProcessMessages();
  if ((mcdb->DirsCount == 0) && (mcdb->FilesCount == 0))
    {
     return;
    };
  if (ccShowFiles)
  {
    frmDiscLayout = new TfrmDiscLayout(this);
    frmDiscLayout->ShowModal();
  }
  mcdb->Prepare(false, NULL);
  pcd->Max = mcdb->ImageSize;
  if ( (TrialMCDB) && (mcdb->ImageSize > 65024 ) )
  {
    msg = "You can not write more than 127 MB in trial version of this software \n Only first 127 MB out of "+
    FormatFloat("#,##0.00", (double )(mcdb->ImageSize * 2048 / (1024 * 1024)))+
    " MB will be usable \n still want to continue ?";
    if ( Application->MessageBox(msg.c_str(), "This is a size limited TRIAL VERSION", MB_DEFBUTTON1+MB_ICONSTOP+MB_YESNO) == ID_YES )
      goto okDoBurn;
    else
    {
      Timer1->Enabled = false;
      return;
    }
  }
  msg = "Start Writing " + FormatFloat("#,##0.00\0", (double )(mcdb->ImageSize * 2048.0 / (1024.0 * 1024.0)))+" MB";
  if  (Application->MessageBox(msg.c_str(), "Want to Burn the CD ?", MB_DEFBUTTON1+MB_ICONQUESTION+MB_YESNO) == ID_YES)
  {
okDoBurn:
    bAbort->Visible   = true;
    Timer1->Enabled   = true;
    mcdb->DebugMsg(">>> STARTING BURNCD ON " + mcdb->Device, 0);
    pTop->Enabled     = false;
    pTop2->Enabled    = false;
    bBurnISO->Enabled = false;
    bSaveISO->Enabled = false;
    DriveCB->Enabled  = false;

    mcdb->BurnCD();
  }
  else
    Timer1->Enabled = false;
}
/*******************************************************************************
              Function         Timer1Timer
              Description  =   This function Will Set the Progress bar and
                               Displays the Messages at a fixed interval of time
                               as they are progressed.
*******************************************************************************/
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  if ( !(mcdb->Erasing))
  {
    lSize->Caption = FormatFloat("#,##0.00", ((double )mcdb->BytesWritten / (1024.0 * 1024.00)))+"/"+FormatFloat("#,##0.00", ((double )(mcdb->ImageSize * 2048.0) / (1024.0 * 1024.0)))+ " MB ";
    pBuf->Position = mcdb->BufferProgress();
    pcd->Position = mcdb->BytesWritten / 2048;
    if (mcdb->DeviceBufferSize >= mcdb->DeviceFreeBufferSize)
    {
      pHBuf->Position = (int) (mcdb->DeviceBufferSize - mcdb->DeviceFreeBufferSize);
    }
   }
   else
   {
    pcd->Max = 100;
    pcd->Position = mcdb->EraseProgress();
  };
}
/*******************************************************************************
              Function        cbDrivesChange
              Description  =  Drive Combo Box Changes
                              Check The capabilities of the Drive and Set the
                              Burn Button Enable or Disable.
*******************************************************************************/
void __fastcall TForm1::cbDrivesChange(TObject *Sender)
{
  char Letter;
  char buffer[32];
  mcdb->Device = cbDrives->Text;
  cbDrives->Hint = cbDrives->Text;
  Letter = mcdb->DeviceByDriveLetter;
  if ( Letter == '\0')
  {
    lDrive->Caption = "  Drive :";
  }
  else
  {
    sprintf(buffer, "Drive %c: ", Letter);
    lDrive->Caption = buffer; // ,Letter); // convert it later
  }
  if ( ( mcdb->DeviceCapabilitiesA.Contains(dcWriteCDR))
        ||(mcdb->DeviceCapabilitiesA.Contains(dcWriteDVDR)) ||
         (mcdb->DeviceCapabilitiesA.Contains(dcWriteDVDRAM)) )
    bBurn->Enabled = true;
  else
    bBurn->Enabled = false;
}
/*******************************************************************************
              Function        bQEraseClick()
              Description  =  check if the  Disc is Erasable or not Then
                              Erase the Data on the disc
*******************************************************************************/
void __fastcall TForm1::bQEraseClick(TObject *Sender)
{

  if ( !(mcdb->Erasable() ) &&  ( mcdb->DiscType() != mtDVD_RAM ) )
   {
    ShowMessage("Disc is not Erasable");
   }
  else
  if ( Application->MessageBox("All Data on the CD will be lost", "Want to Quick Erase the Disc ?", MB_DEFBUTTON2+MB_ICONWARNING+MB_YESNO) == ID_YES)
  {
    Timer1->Enabled = true;
    mcdb->WriteSpeed = GetSpeed(cbSpeed->Text);
    mcdb->EraseDisc(etQuick);
  }
}
/*******************************************************************************
              Function         Load Medium
              Description  =   Loads the Medium (e.g closes the CD tray if it is
                               outside)
*******************************************************************************/

void __fastcall TForm1::bLoadClick(TObject *Sender)
{
  if (mcdb->LoadMedium(false))
  {
    mcdb->DebugMsg(">>> LOAD MEDIUM COMMAND DONE.", 0);
  }
}
/*******************************************************************************
              Function        Ejects
              Description  =  Ejects The (C D/DVD etc) drive tray
*******************************************************************************/

void __fastcall TForm1::bEjectClick(TObject *Sender)
{
  mcdb->FlushCache(10000, false);
  mcdb->LockMedium(true);
  if (mcdb->LoadMedium(true))
    mcdb->DebugMsg(">>> EJECT MEDIUM COMMAND DONE.", 0);
  else
    mcdb->DebugMsg(">>> EJECT MEDIUM COMMAND FAILED.", 0);

}
/*******************************************************************************

⌨️ 快捷键说明

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