21 Replies Latest reply on Jun 4, 2006 3:41 PM by DigitalDesignMedia

    Buddy File

    DigitalDesignMedia Level 1
      Hi,
      I'm using buddy file to decrypt a file before my director application opens it and the encrypt it again when its finished with. I'm doing this so that the external files can only be opened within my director application.

      My problem is that after the file decrypted, buddy file seems to keep its reference to the file and I can't open it. I know this because during debugging, if I try and open the file outside my director application straight after the decryption (before I open it with code) it says that it can't be opened because it’s in use by another application. If I close my director application then the file opens fine.
      I even tried clearing all variable but the file won't open until I close the director file that decrypted it.
      Has anyone any experience with using buddy file for encryption/decryption??? Any help is always appreciated.

      Thanks
      Jason
        • 1. Re: Buddy File
          Level 7
          While I haven't used BudFile's encryption routines before, I just gave
          them a quick test and they seem to work fine for me. No file locking or
          similar. I'm on Windows XP SP2 with Director 10.1 and BudFile Version 2.1

          Can you share some code? Is it possible you're instantiating the xtra
          before calling methods? If so, you don't need to do that - the methods
          become part of the global scope when the xtra loads.
          • 2. Re: Buddy File
            DigitalDesignMedia Level 1
            I'm using Windows SP2 Director 10.1 and BudFile 2.1.

            I started a brand new director file and used this code and the same thing happens. Its an Impressario member opening a PDF file.

            on decryptFile (me)
            iPath = "my path\"
            iFile = "lesson_02.pdf"
            -- test if file is encrypted
            mIsEncrypted = baIsEncryptedBF( iPath & iFile)
            -- if file is encrypted then DecryptIT
            if mIsEncrypted then mEncryptOK = baDecryptBF(iPath & iFile, "Password" )

            member("PDF Member").PathType = #Absolute
            member("PDF Member").fileName = iPath & iFile
            end

            • 3. Re: Buddy File
              Level 7
              > I started a brand new director file and used this code and the same thing
              > happens. Its an Impressario member opening a PDF file.
              >
              > on decryptFile (me)
              > iPath = "my path\"
              > iFile = "lesson_02.pdf"
              > -- test if file is encrypted
              > mIsEncrypted = baIsEncryptedBF( iPath & iFile)
              > -- if file is encrypted then DecryptIT
              > if mIsEncrypted then mEncryptOK = baDecryptBF(iPath & iFile, "Password" )
              >
              > member("PDF Member").PathType = #Absolute
              > member("PDF Member").fileName = iPath & iFile
              > end

              IMHO - unless that's an edited example you posted - you should always
              provide full paths to external files, /especially/ if you're using
              absolute paths.
              Beyond that, what does mEncryptOK evalute to?
              on decryptFile (me)
              iPath = _movie.path & "my path\"
              iFile = "lesson_02.pdf"
              -- test if file is encrypted
              mIsEncrypted = baIsEncryptedBF( iPath & iFile)
              -- if file is encrypted then DecryptIT
              if mIsEncrypted then
              mEncryptOK = baDecryptBF(iPath & iFile, "Password" )
              put "mEncryptOK:", mEncryptOK
              end if
              member("PDF Member").PathType = #Absolute
              member("PDF Member").fileName = iPath & iFile
              end
              • 4. Re: Buddy File
                DigitalDesignMedia Level 1
                Thanks Sean,

                I edited that path for the purpose of the post, if the path was incorrect the file wouldn't decrypt at all. mEncryptOK is the result of the decryption it returns 1 if the encryption/decryption was successful.
                Thanks
                Jason
                • 5. Re: Buddy File
                  Level 7
                  > mEncryptOK is the result of the decryption it
                  > returns 1 if the encryption/decryption was successful.

                  :-)
                  I understand what mEncryptOK represents, I was suggesting that in the
                  code you posted you weren't monitoring it to see what it was, therefore
                  I amended that so you would get some message window feedback.
                  I was asking - in your specific case where it fails - what does
                  mEncryptOK evaluate to in the message window.

                  It's probably a red herring. Even if the decryption failed it should be
                  displaying garbage instead of complaining about a file-in-use error.
                  I would suggest eliminating Impressario from the mix first and using the
                  decryption on a plain text file that you link to or import into a #text
                  member. It may be that Impressario is pointing at the file and so
                  locking it.
                  • 6. Re: Buddy File
                    DigitalDesignMedia Level 1
                    Hi Sean,

                    The file decrypts and then I get the error
                    'Impressario Xtra error -1000'
                    'The last action could not be completed’
                    -- this occurs when I change the filename of the pdf member.

                    If run the code and then leave director open and go to the pdf file and open it outside of director Acrobat says:
                    'There was an error opening this document. This file is already open or in use by another application.'

                    As soon as I close director and try and open the file again it opens fine. This even happens if I don't change the filename of the pdf member. So somehow the buddy file xtra isn't letting go of the file. I'll try it on a text file now and see what happens.

                    Impressario isn’t pointing at the file and locking it because in my tests I’ve even deleted the Impressario member run the decryption code and tried to open the file within acrobat after running the decryption code and it gives the same message as above.
                    Thanks
                    Jason
                    • 7. Re: Buddy File
                      ManOfMac
                      Could you try:
                      baSetFileAttributes( "c:\\data\\student.dat" , "" ) -- clear all attributes
                      This may remove whatever the ghosts have set ??
                      • 8. Re: Buddy File
                        DigitalDesignMedia Level 1
                        No that didn't work either.
                        Thanks
                        Jason
                        • 9. Re: Buddy File
                          Level 7
                          >>So somehow the buddy file xtra isn't letting go of the file.

                          I believe you are correct, but I'm not sure it's a bug or not as you can
                          work around it. What you must do is first use baGetFile() to get a handle to
                          the pdf, then after checking it with baIsEncryptedBF() (and decrypting if
                          necessary) you must close the the file with baCloseFile(handle).


                          For instance, in a PDF viewer I have here I can open the message window and
                          do only:

                          put baIsEncryptedBF(somePDF)

                          If I then try to view the PDF I'll get an error, as I guess the isEncrypted
                          method leaves the file open. If instead I do:

                          h = baGetFile(somePDF, "RW")
                          put baIsEncyptedBF(somePDF)
                          baCloseFile(h)

                          all is well when I view the file... You can decrypt etc.. just be sure to
                          always get the handle, do the operation, and then close.


                          --
                          Dave -
                          Adobe Community Expert
                          www.blurredistinction.com
                          www.macromedia.com/support/forums/team_macromedia/


                          • 10. Re: Buddy File
                            Level 7
                            > What you must do is first use baGetFile() to get a handle to
                            > the pdf, then after checking it with baIsEncryptedBF() (and decrypting if
                            > necessary) you must close the the file with baCloseFile(handle).
                            >
                            > h = baGetFile(somePDF, "RW")
                            > put baIsEncyptedBF(somePDF)
                            > baCloseFile(h)

                            Interesting idea - the docs don't suggest that the encryption routines
                            require a handle to an open file, and it seems to work flawlessly for a
                            plain text file without this. It'll be interesting to hear back from the
                            OP about whether this works.
                            • 11. Re: Buddy File
                              DigitalDesignMedia Level 1
                              Thanks Dave for your input,

                              But that still gives me problems, if I use h = baGetFile(somePDF, "RW") and then try and get baIsEncyptedBF(somePDF) it returns 0 even when the files encrypted. (see my code below)

                              iPath =_movie.path & "filename.pdf"
                              ihandle = baGetFile(iPath , "rw")
                              mIsEncrypted = baIsEncryptedBF(iPath )
                              baCloseFile(ihandle)


                              mIsEncrypted returns 0

                              but with the code below the correct result is returned.

                              iPath =_movie.path & "filename.pdf"
                              mIsEncrypted = baIsEncryptedBF(iPath )


                              So in other words if I open the file using baGetFile() I can't do anything to that file because it is unavailable.
                              Is there another way to release the file after using buddy file in this way?
                              All I want to do is check to see if its encrypted and if so decrypt it and then assign the file name to the Impressario member.

                              Thanks
                              Jason
                              • 12. Re: Buddy File
                                Level 7
                                Jason, can you pare down an example file to its bare bones and post it
                                somewhere? Perhaps using a pdf file, but without Impressario in the mix.
                                • 13. Re: Buddy File
                                  Level 7
                                  Interesting. I could encrypt and decrypt the PDF's once I did the handle
                                  thing... I wonder why it's not working for you. I'll try and do a little
                                  more testing this afternoon.
                                  --
                                  Dave -
                                  Adobe Community Expert
                                  www.blurredistinction.com
                                  http://www.adobe.com/communities/experts/


                                  • 14. Re: Buddy File
                                    Level 7
                                    You could use Unlocker from http://ccollomb.free.fr/unlocker to confirm what
                                    has the lock on the file.

                                    You're /sure/ that's the only place you refer to that file?

                                    Andrew


                                    • 15. Re: Buddy File
                                      DigitalDesignMedia Level 1
                                      OK here is what happened after I downloaded and installed 'Unlocker'
                                      I created a brand new director file with this handler in the movie script

                                      on decryptFileTest
                                      iPath = _movie.path & "myPDF.pdf"
                                      mIsEncrypted = baIsEncryptedBF(iPath )
                                      end


                                      There is definitely nothing else pointing to the file, after running the handler I opened windows explorer & right clicked on the file and selected 'Unlocker' from the menu. It said that director had a lock on the file, Click here for a screenshot. As soon as I closed director the lock on the file was gone.
                                      That obviously confirms that 'baIsEncryptedBF' puts a lock on the file.

                                      Then I tried this code
                                      on decryptFileTest
                                      iPath = _movie.path & "myPDF.pdf"
                                      ihandle = baGetFile(iPath & iFile, "rw")
                                      mIsEncrypted = baIsEncryptedBF( iPath & iFile)
                                      put "mIsEncrypted :" && mIsEncrypted
                                      baCloseFile(ihandle)
                                      end


                                      Sure enough after running this handler there is no lock on the file but 'baIsEncryptedBF()' returns 0 even though the file is encrypted. To me this means that 'baGetFile()' is putting a lock on the file and 'baIsEncryptedBF()' can't return a result because it can't access the file because its locked.

                                      Anyone got any other ideas???
                                      Thanks
                                      • 16. Re: Buddy File
                                        Level 7
                                        > OK here is what happened after I downloaded and installed 'Unlocker'
                                        > I created a brand new director file with this handler in the movie script
                                        >
                                        > on decryptFileTest
                                        > iPath = _movie.path & "myPDF.pdf"
                                        > mIsEncrypted = baIsEncryptedBF(iPath )
                                        > end

                                        I can confirm that issuing baIsEncryptedBF(aPath) and pointing the
                                        filename at a pdf file results in a locked file. I suggest that this is
                                        a bug and that you should contact the developer of the xtra directly
                                        with reproducible steps so that he can fix it. His contact details are
                                        available from his website
                                        • 17. Re: Buddy File
                                          Level 7
                                          >>I suggest that this is a bug and that you should contact the developer of
                                          >>the xtra directly with reproducible steps so that he can fix it.

                                          It's definitely a bug. I think Sean's idea is best - get Gary to fix the
                                          Xtra. I did some more testing as well and found out, as JtA suggested, that
                                          isEncrypted does indeed return 0 once the handle is retrieved. I don't think
                                          that's a bug though, as getHandle should lock the file. The only real bug is
                                          that isEncrypted locks the file when it shouldn't. I also noticed if you run
                                          baDecryptBF twice, on the same file, it will hose the file...

                                          --
                                          Dave -
                                          Adobe Community Expert
                                          www.blurredistinction.com
                                          http://www.adobe.com/communities/experts/


                                          • 18. Re: Buddy File
                                            DigitalDesignMedia Level 1
                                            Thanks Sean & Dave,

                                            I emailed Gary yesterday outlining these issues so hopefully I'll hear back soon. Also I noticed that if you run baDecryptBF twice the file is toast, so I let Gary know this as well. Until then my project is on hold or I'll have to use another method to encrypt/decrypt these files.

                                            Cheers,
                                            Jason
                                            • 19. Re: Buddy File
                                              Level 7
                                              > Until then my project is on hold or I'll have to
                                              > use another method to encrypt/decrypt these files.

                                              How's about Buddy API's baEncryptFile()?
                                              • 20. Re: Buddy File
                                                DigitalDesignMedia Level 1
                                                Gary has provided me with a fixed version of BuddyFile for windows and it works as expected now. MAC version is coming...

                                                Jason
                                                • 21. Re: Buddy File
                                                  DigitalDesignMedia Level 1
                                                  That was what I was originally using but you have more control over buddyFile methods (you can test if the file is encrypted etc) and also it uses BlowFish algorithm.

                                                  Thanks
                                                  Jason