• Post Reply Bookmark Topic Watch Topic
  • New Topic

NX: Usage of Magic Cookie

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to ask, what is the usage of the Magic Cookie, which read from the 1st 4-byte in the data file.
Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12059
232
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicholas,
Some dumb end user could try and use your application to open their favourite MS Word document. Or they might try and open my database file instead of the database file that your program works with.
But in either of those two cases, the magic cookie that is read when your application first starts up will not match the magic cookie that is in your database file.
So you can check the magic cookie to ensure that the file your program is reading is indeed the correct database format.
Regards, Andrew
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thus, I need to hard code the magic cookie in the program, or put it somewhere (in property file or constaints) in order to use it to verify whether the DB file is the correct one?
Thanks for advice.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hard-coded it rather than using property file.
See info in magic cookie thread for more information.
TJ
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!