burning cd-rom with wxWidgets

Franco Amato eurofrank at gmail.com
Thu Apr 19 06:56:27 PDT 2007


Thank for your example.
Your code is not so easy :-)


2007/4/19, Piotr Starczewski <pstarczewski at o2.pl>:
>
> This is very basic sample code that I have digged out of my test folder.
> I'm not even sure if it works, but you'll get a basic concept. :)
>
>
> EvaBurnCdDialog::EvaBurnCdDialog( wxWindow* parent)
> : _evaBurnCdDialog( parent)
> {
> //    wxBoxSizer* bSizer5;
> //    bSizer5 =3D new wxBoxSizer( wxVERTICAL );
> //
> //    m_textCtrl1 =3D new wxTextCtrl( this, ID_DEFAULT, wxT(""),
> wxDefaultPosition, wxSize( 510,100 ), wxTE_MULTILINE|wxTE_READONLY );
> //    bSizer5->Add( m_textCtrl1, 0, wxALL, 5 );
> //
> //    m_button6 =3D new wxButton( this, ID_BURNCD, wxT("Burn to CD"),
> wxDefaultPosition, wxDefaultSize, 0 );
> //    bSizer5->Add( m_button6, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
> //
> //    this->SetSizer( bSizer5 );
> //    this->Layout();
> //    bSizer5->Fit( this );
> }
>
> void EvaBurnCdDialog::connect_events()
> {
>    SetTitle("EuroView CD-Burner (Alpha v0.1)");
>
>
> Connect(ID_BURNCD,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(EvaB=
urnCdDialog::on_burncd));
>
>
> Connect(ID_PROCESS_RUNNING,wxEVT_END_PROCESS,wxProcessEventHandler(EvaBur=
nCdDialog::on_proc_stop));
>    Connect(wxEVT_TIMER,wxTimerEventHandler(EvaBurnCdDialog::on_timer));
> }
>
> void EvaBurnCdDialog::on_timer(wxTimerEvent &event)
> {
>    if (!m_stop)
>    {
>        while (m_process->GetErrorStream()->CanRead())
>        {
>            wxTextInputStream in(*m_process->GetErrorStream());
>            if (m_process_count=3D=3D0)
>            {
>                m_scanbus.Add(in.ReadLine());
>            } else
>            {
>                *m_textCtrl1 << in.ReadLine() << "\n";
>            }
>        }
>        while (m_process->GetInputStream()->CanRead())
>        {
>            wxTextInputStream in(*m_process->GetInputStream());
>            if (m_process_count=3D=3D0)
>            {
>                m_scanbus.Add(in.ReadLine());
>            } else
>            {
>                *m_textCtrl1 << in.ReadLine() << "\n";
>            }
>        }
>    }
> }
>
> void EvaBurnCdDialog::on_proc_stop(wxProcessEvent &event)
> {
>    m_stop =3D true;
>    if (m_process_count=3D=3D1)
>    {
>        m_process_count++;
>        burn_cd();
>    } else
>    {
>        m_msg_timer->Stop();
>        delete m_msg_timer;
>        m_process_count++;
>        wxRemoveFile("./temp.iso");
>        wxRemoveFile("./eva");
>        wxRemoveFile("./autorun.inf");
>        delete m_disabler;
>        wxMessageBox("All done");
>    }
> }
>
> void EvaBurnCdDialog::scanbus()
> {
> //    m_process =3D new wxProcess(this,ID_PROCESS_RUNNING);
> //    m_process->Redirect();
>    m_scanbus.Clear();
>    wxArrayString dummy;
>    long pid =3D wxExecute("./cdrecord.exe -scanbus",m_scanbus,m_scanbus);
>
>        // Allow to choose cd-recorder
>        wxArrayString drives;
>        for (size_t i=3D0; i<m_scanbus.GetCount(); ++i)
>        {
>            if (m_scanbus[i].First("CD-ROM")!=3D-1)
>            {
>                wxString val =3D m_scanbus[i];
>                val.Trim(false);
>                val.Replace("\t"," ");
>                int id =3D val.First(" ");
>                val.Remove(id+1,val.First("'")-id-1);
>                drives.Add(val);
>            }
>        }
>        wxSingleChoiceDialog dlg(this,"Choose your CD-ROM
> drive","CD-BURNER",drives);
>        if (dlg.ShowModal()=3D=3DwxID_OK)
>        {
>            m_disabler =3D new wxWindowDisabler();
>            int id =3D dlg.GetSelection();
>            wxString drive =3D drives[id];
>            drive.Trim(false);
>            id =3D drive.First(" ");
>            m_dev =3D drive.Mid(0,id);
>            m_process_count++;
>            prepare_cd();
>        }
> }
>
> void EvaBurnCdDialog::prepare_cd()
> {
>    m_process =3D new wxProcess(this,ID_PROCESS_RUNNING);
>    m_process->Redirect();
>    wxString cmd =3D "mkisofs -o temp.iso -joliet-long -R ";
>    cmd << m_file;
>    //wxMessageBox(cmd);
>    long pid =3D wxExecute(cmd,wxEXEC_ASYNC,m_process);
>    m_stop =3D false;
> }
>
> void EvaBurnCdDialog::burn_cd()
> {
>    wxString cmd =3D "";
>    cmd <<"cdrecord dev=3D"<<m_dev<<" -multi -eject -v ./temp.iso"; // add
> -dummy for test purpous
>    m_process =3D new wxProcess(this,ID_PROCESS_RUNNING);
>    m_process->Redirect();
>    long pid =3D wxExecute(cmd,wxEXEC_ASYNC,m_process);
>    m_stop =3D false;
> }
>
> void EvaBurnCdDialog::on_burncd(wxCommandEvent &event)
> {
>    wxArrayString path;
>    wxArrayInt size;
>    wxArrayString output,err;
>
>    {
>        Config config("./evs");
>        long l =3D config.GetLong("data",0);
>        for (long i=3D0; i<l; ++i)
>        {
>            path.Add(config.GetString(wxString::Format("data/p%ld",i),""));
>            size.Add(config.GetInt(wxString::Format("data/s%ld",i),0));
>        }
>    }
>
>    if (size[0]>0)
>    {
>        // create file list for burning standalone browser
>        wxFile file("./autorun.inf",wxFile::write);
>        file.Write(wxString("[autorun]\nopen=3Dplayer.exe"));
>        file.Close();
>
>        {
>            Config config("./eva",true);
>            config.SetLong("data",1);
>            config.SetString("data/p0","./");
>            config.SetInt("data/s0",200);
>        }
>
>
>        m_file =3D "./player.exe ./eva ./autorun.inf ./MFC71.dll
> ./msvcr71.dll ./wxmsw26_gl_vc_ev.dll ./wxmsw26_vc_ev.dll ";
>        m_file << path[0] << "/" << wxString::Format("%010d.dat",1);
>        m_file.Replace("\\","/");
>
>        // get external msg timer
>        m_process_count =3D 0;
>        m_stop =3D true;
>        m_msg_timer =3D new wxTimer(this);
>        m_msg_timer->Start(1);
>
>        scanbus();
>    }
> }
>
>
> Franco Amato wrote:
> > Hi Piotr,
> > thank you very much for your reply...
> > Can I have a piece of code as example of integration?
> > Because I never used wxProcess :-(    (what does it do?)
> > Franco
> >
> >
> > 2007/4/19, Piotr Starczewski <pstarczewski at o2.pl
> > <mailto:pstarczewski at o2.pl>>:
> >
> >     I don't think that you are able to burn CD/DVD using wx native
> >     functions. If you want something that works and can be quite easy to
> >     implement try CdRecord
> >     http://cdrecord.berlios.de/old/private/cdrecord.html
> >
> >     I have used it successfully by connecting it with my application via
> >     wxProcess. They also have good support and the project is free.
> >
> >     Regards,
> >     Peter
> >
> >     Franco Amato wrote:
> >     > Hi people,
> >     > does anyone know how to integrate a cd-rom data burner in a wx
> >     > application?
> >     > Is possible to do it with the wxfunctions or not?
> >     > Kind Regards
> >     > Frank
> >     >
> >
> >
> ---------------------------------------------------------------------
> >     To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> >     <mailto:wx-users-unsubscribe at lists.wxwidgets.org>
> >     For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
> >     <mailto:wx-users-help at lists.wxwidgets.org>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20070419/2e8=
f2abd/attachment.htm


More information about the wx-users mailing list