Notifications
Clear all
[Closed] Readline with max 2012
Jul 11, 2011 1:22 pm
Hi guys
I have a problem with a function that works in max2011 alright, but fails in 2012. And I am unsure where the actual error is. All I am trying to do is write a password into a file, then open the file again and check the password. Pretty straight forward process:
fn register =
(
pw = "I am the password" -- some password
regfile = createfile (getDir #temp + "\\license.tmp") -- create a temporary license file
format pw to:regfile -- write the password into the file
encryptfile (getDir #temp + "\\license.tmp") (getDir #temp + "\\license.lic") 1234567 -- make an encrypted version
close regfile -- close the temporary file..
deletefile (getDir #temp + "\\license.tmp") -- ..so that it can be deleted
)
fn isregistered =
(
registered = false-- create boolean registered
if (doesfileexist (getDir #temp + "\\license.lic")) then-- check for file
(
checkfile = openencryptedfile (getDir #temp + "\\license.lic") 1234567 -- open the license file
password = readline checkfile -- read the first line, containing the password
close checkfile -- close the file again
if password == "I am the password" then registered = true -- if it matches, registering worked
)
if registered then messagebox "hooray, it works"
)
register()
isregistered()
So if you run the code in max 2011 you should get a messagebox saying "hooray, it works". One would think the same applies to max 2012, but there I get:
-- [color=Red]Error occurred in isregistered(); filename: D:\Projekte\3dsmax\scripts\registertest.ms; position: 826; line: 20[/color]
-- Frame:
-- registered: false
-- checkfile: <File:C:\Users\David\AppData\Local\Autodesk\3dsMax\2012 - 64bit\enu emp\license.lic>
-- password: undefined
-- Runtime error: Read past end of file
What could be the explanation? It must be something 2012 specific, I guess.
thanks, David
2 Replies
Jul 11, 2011 1:22 pm
i guess it’s because you try to encrypt your file before you closed it
swap that two lines i marked bold in the quote and it should work
Jul 11, 2011 1:22 pm
Wow. that solved the error. Thanks a lot!!! I am glad that the solution is so simple (in terms of additional scripting work).
I still don’t understand why max2012 reacts different to the script then 2011, but hey, who cares, it is working, now.
thanks again, David