New topic: File check question.
<http://forums.realsoftware.com/viewtopic.php?t=46059> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message jerryab Post subject: File check question.Posted: Tue Nov 27, 2012 2:18 pm Joined: Mon Dec 12, 2011 7:25 pm Posts: 131 Location: Grand Rapids MI Area I am trying to protect a file that my program uses from being changed. Using the routine shown below this works on both Windows and Mac. My question is. Is there a way that you can check a file to make sure it is the right file on both platforms. What I have now shows 2 different numbers one for Windows and a different one for Mac. Am I correct in assuming it will be different on windows verses mac and not different on all machines. I'm not sure if what I have will work the same on all windows or Mac machines. I have no problem if that is the case but I thought I would ask anyway. dim f as FolderItem dim b as BinaryStream dim s as string dim d as new MD5Digest f = gdbCGLData.Child("CGLogPic.jpg") if f = Nil then return "Nil" end if if f.Exists Then if f.IsReadable = false and f.IsWriteable = false then return "Protected File" else b = BinaryStream.Open(f) while not b.eof s=b.Read(1000000) d.Process s app.DoEvents wend return EncodeHex(d.Value) end if else return "Nil" end if _________________ iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top ktekinay Post subject: Re: File check question.Posted: Tue Nov 27, 2012 3:30 pm Joined: Mon Feb 05, 2007 5:21 pm Posts: 262 Location: New York, NY First, you should not be using DoEvents unless this is a console app. From the LR: Quote: Using DoEvents in a GUI application will likely cause instability. In effect, you would be placing a main event loop inside the ârealâ main event loop. You should consider using threads to handle lengthy operations rather than placing them in the main thread and calling DoEvents to maintain the interface. I can't really see how this code would lead to different results on different platforms as the MD5Digest is just acting on the bytes read from the file. Are you sure the file is identical on both systems? _________________ Kem Tekinay MacTechnologies Consulting http://www.mactechnologies.com/ Need to develop, test, and refine regular expressions? Try RegExRX. Top DaveS Post subject: Re: File check question.Posted: Tue Nov 27, 2012 3:40 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4305 Location: San Diego, CA MD5 Should return the same hash for the same data on either Platform (keyword here is SHOULD) Why are you looping thru your entire file (While/Wend).... yet only returning data from the LAST block? It might be possible that the files on both platforms are not 100% identical? and therefore the last block you read would return a different value (just needs to be 1 bit different) Also... it might be a good idea to lose the app.DoEvents (there are people that will tell you that is "evil" ) _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top jerryab Post subject: Re: File check question.Posted: Tue Nov 27, 2012 3:46 pm Joined: Mon Dec 12, 2011 7:25 pm Posts: 131 Location: Grand Rapids MI Area The file is a small JPEG file and is the same on both platforms. It is even stored in the database when created. I'm just trying to make sure a user does not change it. Any suggestions how to do this better ? _________________ iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top DaveS Post subject: Re: File check question.Posted: Tue Nov 27, 2012 4:09 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4305 Location: San Diego, CA when you store the image in your DB, store a CHKSUM of the image in another field....which is kinda what you were doing with MD5 are you creating the database on one platform, then moving to the other? or is it being created independantly on each platform? if so, that could be a piece of the puzzle... as OSX and WIN may deal slightly differently with processing a JPEG, and since it is a lossy format... you won't "see" the difference.. I have even heard that saving a JPEG over and over again (even with no external changes) creates a different file content each time. Is JPG required? or could you try PNG? or some other format instead? _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top jerryab Post subject: Re: File check question.Posted: Tue Nov 27, 2012 4:30 pm Joined: Mon Dec 12, 2011 7:25 pm Posts: 131 Location: Grand Rapids MI Area Quote:are you creating the database on one platform, then moving to the other? There are 2 ways it's being created. 1. If it's a First time run it is being created from the program. 2. If the user had the old version of my program written in Lua then I copy there old database into the new programs folder and then modify it to work with the new program. While doing this I do change the jpeg file anyway. Quote:or is it being created independantly on each platform? Yes if the program is a new install. The old program was a windows only program. So I have written the new program to be Windows and Mac version but can use the old programs database after I update the database. Quote:Is JPG required? or could you try PNG? or some other format instead? The file is required but I could convert it to a png I would guess. _________________ iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
