9 Replies Latest reply on Aug 24, 2007 1:09 PM by dandanyeung

    Downloading content using Buddy API

    dandanyeung
      I am currently building a CD that enable users to copy/download word documents on to their harddrive from the CD.

      on mouseUp me
      OK = baOpenFile(_movie.path & "word_documents.doc", "Normal")
      end

      When the button is clicked, a save as window showing the cd directory will pop up, but since I have many different word documents that users can copy to their harddrive, users will need to select the directory that they want to copy the files to every time. Are there any ways I can store where the user save the file last time so that they don't need select the directory each time they save a file?

      Also, users do not know if they save the same file twice, is it possible to put in a prompt message if user try to save the same file name twice?

      Unfortunately I am not an expect in lingo, appreciate anybody can show me how to do this, thanks!
        • 1. Re: Downloading content using Buddy API
          Level 7
          baOpenFile() won't open a dialog box but will open the file you point it
          to with whatever the default application is for handling the file type.

          You can use baGetFolder() to present a folder selection dialog (and save
          the folder chosen for later use). You could then use
          baCopyFile/Progress() to copy the file from CD to their chosen folder.
          To determine whether the named file already exists in the directory you
          are copying to, you could use baFileExists(). Check the docs for all of
          these commands, and if you are still having trouble then post back what
          you've managed to construct.
          • 2. Re: Downloading content using Buddy API
            dandanyeung Level 1
            Thanks so much for your assist, I have done some searching but I only find out baGetFolder and baCopyFile.

            on mouseUp me
            folder = baGetFolder( the moviePath, "Save as..", 1+2, "Select a folder", -1, 0 )
            ok= baCopyFile( the moviePath&"word.doc" , folder&"word.doc","IfNewer" )
            end

            Firstly, how can I save the directory choosen? and how can I bring up the "prompt message" asking whether user want to replace the file or not?

            Sorry about the numbers of problems...thanks so much for your help
            • 3. Re: Downloading content using Buddy API
              Level 7
              > on mouseUp me
              > folder = baGetFolder( the moviePath, "Save as..", 1+2, "Select a folder", -1,
              > 0 )
              > ok= baCopyFile( the moviePath&"word.doc" , folder&"word.doc","IfNewer" )
              > end
              >
              > Firstly, how can I save the directory choosen?

              > and how can I bring up the
              > "prompt message" asking whether user want to replace the file or not?


              Store the folder they choose in a global or property variable and
              reference it when files need to be copied. Perhaps something like (watch
              out for unintentional line breaks):
              --
              global gLocalFolder

              on mouseUp me
              gLocalFolder = baGetFolder( "", "Save as..", 1+2, "Select a folder",
              -1, 0 )
              if gLocalFolder = EMPTY then exit -- user cancelled
              tDestination = gLocalFolder & "word.doc"
              if baFileExists(tDestination) then
              -- prompt to overwrite
              tChose = baMsgBox("The file 'word.doc' already exists." &RETURN&
              "Do you want to overwrite it?", "Overwrite...?", "YesNo", "question", 1)
              if ( tChose = "Yes" ) then
              ok = baCopyFile( the moviePath & "word.doc", tDestination,
              "IfNewer+")
              if OK <> 0 then
              -- error copying file - see the docs for numbers and their meanings
              end if
              end if
              else
              ok = baCopyFile( the moviePath & "word.doc", tDestination, "IfNewer+")
              if OK <> 0 then
              -- error copying file - see the docs for numbers and their meanings
              end if
              end if
              end
              • 4. Re: Downloading content using Buddy API
                dandanyeung Level 1
                Thanks~!
                The replace prompt msg is working, however, I still need to select the directory each time I want to save a file from "My Computer".
                Any suggestion I can fix this too?
                • 5. Re: Downloading content using Buddy API
                  dandanyeung Level 1
                  And also, is it possible to use baGetFilename so that user can change the name of the file when saving?

                  Thanks so much!
                  • 6. Re: Downloading content using Buddy API
                    Level 7
                    > I still need to select the directory each time I want to save a file from "My Computer".
                    > Any suggestion I can fix this too?

                    I assumed you have more than one button and that you could use the
                    global variable. The following might work:
                    --
                    global gLocalFolder

                    on mouseUp me
                    -- check to see whether a local folder has already been selected:
                    if ( voidP(gLocalFolder) OR (baFolderExists(gLocalFolder) = 0) ) then
                    gLocalFolder = baGetFolder( "", "Save as..", 1 + 2, "Select a
                    folder", -1, 0 )
                    if gLocalFolder = EMPTY then exit -- user cancelled
                    end if

                    tDestination = gLocalFolder & "word.doc"
                    if baFileExists(tDestination) then
                    -- prompt to overwrite
                    tChose = baMsgBox("The file 'word.doc' already exists." &RETURN&
                    "Do you want to overwrite it?", "Overwrite...?", "YesNo", "question", 1)
                    if ( tChose = "Yes" ) then
                    ok = baCopyFile( the moviePath & "word.doc", tDestination,
                    "IfNewer+")
                    if OK <> 0 then
                    -- error copying file - see the docs for numbers and their meanings
                    end if
                    end if
                    else
                    ok = baCopyFile( the moviePath & "word.doc", tDestination, "IfNewer+")
                    if OK <> 0 then
                    -- error copying file - see the docs for numbers and their meanings
                    end if
                    end if
                    end
                    • 7. Re: Downloading content using Buddy API
                      Level 7
                      > is it possible to use baGetFilename so that user can change the name of the file when saving?

                      Yes.

                      Have a try writing it yourself and post back with what you come up with
                      if you can't get it working.
                      • 8. Re: Downloading content using Buddy API
                        dandanyeung Level 1
                        I got an String expected error message:
                        Do I need to assign a value for gLocalFolder first?

                        global gLocalFolder

                        on mouseUp me
                        -- check to see whether a local folder has already been selected:
                        if ( voidP(gLocalFolder) OR (baFolderExists(gLocalFolder) = 0) ) then
                        gLocalFolder = baGetFilename( "save", "word.doc", ".doc", 524288, "Save file", false, 0, 0 )
                        if gLocalFolder = EMPTY then exit -- user cancelled
                        end if

                        tDestination = gLocalFolder & "word.doc"
                        if baFileExists(tDestination) then
                        -- prompt to overwrite
                        tChose = baMsgBox("The file 'word.doc' already exists." &RETURN& "Do you want to overwrite it?", "Overwrite...?", "YesNo", "question", 1)
                        if ( tChose = "Yes" ) then
                        ok = baCopyFile( the moviePath & "word.doc", tDestination, "IfNewer+")
                        if OK <> 0 then
                        -- error copying file - see the docs for numbers and their meanings
                        end if
                        end if
                        else
                        ok = baCopyFile( the moviePath & "word.doc", tDestination, "IfNewer+")
                        if OK <> 0 then
                        -- error copying file - see the docs for numbers and their meanings
                        end if
                        end if
                        end
                        • 9. Re: Downloading content using Buddy API
                          dandanyeung Level 1
                          I think I got it working:

                          global gLocalFolder

                          on mouseUp me
                          gLocalFolder = baGetFilename( "save", "", "word.doc", "", 2+32+32768+524288+2097152+4194304, "Save As...", false, 100, 100 )
                          if gLocalFolder = EMPTY then exit
                          tDestination = gLocalFolder
                          ok = baCopyFile( the moviePath & "word.doc", tDestination, "IfNewer+")
                          end

                          Thanks again for your help!