thread or nothing?

i just need an advice from you.
in my application i need to check if the right optical media is inserted by the user, i mean, i need to burn a dvd that’s 4gb so i prompt the user to insert the dvd.
what i want to do is how to wait for the right media, check if it is blank, if the user insert a wrong media and update the main window
i think a thread will be my friend but i cannot control it.
what will you do in my place?

ps. for all the checks i use the command shell (drutil), i know it’s not the right way but i’m not cocoa friend… thanks

Start a Timer. Every iteration of the Timer will check and notify your window of what it finds. Once the right media has been inserted, the Timer can be stopped.

Shell is quite fine with Cocoa. I use it all the time.

thanks Kem and Michel for your answer…

I know I cannot ask you more than that but a prototype code would be very appreciated (thread and timer)
thank you all

This is something you could and should do yourself, it’s really simple. Here’s some more info that will help:

Very typically what you are asking for is a MsgBox that says “Insert DVD” and instead of waiting for the user to click away the dialog (although you want a Cancel button here), it’s the insertion of the desired DVD that you want.

So a MsgBox isn’t going to help, since it’s modal and you aren’t executing code in the modal state. So you’ll need to make your own Window that looks like a MsgBox or similar, put a Label on there (plus your App icon to make it look cool) and a Cancel button, and a Timer control. In the Action event of the Timer control, put the DVD checking code there. Once it finds the DVD, execute some code (optional) that indicates the DVD is there, and then call Self.Close to make the custom MsgBox go away.

These types of things have been discussed in forum threads (and the old Mailing List) regarding Timed Dialogs, also.

That’s it!

This will be extremely short, and you will need to experiment by yourself to make it perfectly suited to your needs. drutil has many options all listed here

Basically, you got two options. The simplest is to ask drutil for the status of the disk in the timer. Put this in the Action event of a timer :

dim s as new shell s.execute "drutil -drive 1 status" if instr(s.result,"No Media Inserted") = 0 then msgbox "Thank you for inserting a disk" end if s.Close

I assume the Mac has only one DVD drive. When a media is inserted, the msgbox appears. Note that it can be anything : blank or not. To determine which has been inserted, you need to look at the content of Result. Here is what I get for a CD :

[code]Vendor Product Rev

       Type: CD-R                 Name: /dev/disk4

Write Speeds: 10x, 16x, 24x
Overwritable: 79:57:69 blocks: 359844 / 736.96MB / 702.82MiB
Space Free: 79:57:69 blocks: 359844 / 736.96MB / 702.82MiB
Space Used: 00:00:00 blocks: 0 / 0.00MB / 0.00MiB
Writability: appendable, blank, overwritable

You will need to experiment with your particular configuration to see what is of interest for your app.

The issue with the timer technique is that it puts a drain on the app every time the timer executes, since it needs to run a new drutil.

A more elaborate solution is to :

  • Insert a class
  • Make its super “Shell”
  • Drag an instance over your window ; lets call it S1.
  • Add to the instance the DataAvailable event
  • S1.execute(“drutil -drive 1 poll”)

From now on, every action on the drive will trigger DataAvailable and feed S1.Result. A lot of information is available on the type of media, the status of the drive, etc.

This is kind of equivalent to a thread, since drutil poll works in the background and sends information to your app only when something new happens.

For burning of optical media, use the MBS routines which bring up the burning dialog, which takes care of this completely without extra coding. It’s just another case where MBS saves time money and effort. Worth the cash.

I used to use drutil but it doesn’t give useable progress.

Sorry I didn’t read your question thoroughly at first.

thanks Garth and Kem and Michel for your help.
i’m testing Garth solution, it seems to easier one… (the first one). The MBS solution i tried to test it and ask Christian a couple of things but I think it’s to complicated for a newbie like me.
btw, is it possible have 2 timer in the same window? how can i manage them?

No, it’s easy, use the MBS example code. That’s what I used. The cool thing about example code is that it turns a newbie into a genius. You are essentially leveraging all the work Apple has already done and making it work for you.

Here’s my code. f is a FolderItem that represents the image file that I’m burning. Note: I omitted parts of the code that 1) make sure the image file’s size is a multiple of 2048 (seems to be necessary) and also that the file name’s extension is always .dmg (seems to also matter). Note also that this snippet might be pretty much exactly what MBS"s example code is. =)

  Dim track As DRTrackMBS
  Dim bsp As DRBurnSetupPanelMBS
  Dim bpp As DRBurnProgressPanelMBS
  Dim Response As Boolean
  // This file must be one that can be read by DiscRecording.
  // The supported image types include: .dmg, .iso, .cue, and .toc.
  // For .cue and .toc files the corresponding data files (.bin, .img, etc) must also be present and correctly referenced in the .cue/.toc file.
  bsp = new DRBurnSetupPanelMBS
  // set a few options
  bsp.setCanSelectAppendableMedia true
  bsp.setCanSelectTestBurn true
  if bsp.runSetupPanel = bsp.NSOKButton then
    bpp = new DRBurnProgressPanelMBS
    // And start off the burn itself. This will put up the progress dialog
    // and do all the nice pretty things that a happy app does.
    // write the image
    Response = bpp.beginProgressPanelForImageFile(bsp.burnObject, f)
    If Response = False then
      MsgBox "Failed to write " + f.Name + " onto the CD/DVD."
    End If
  end if

thank you Garth for you example, seems easy at first sight.
the only thing I forgot to say is I have to manage 2 burners at the same time and burn the same file with the identical media.
anyway thanks for your help!