Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. function GetName()
  2.     local rootNode = xmlLoadFile("details.xml")
  3.     if rootNode then -- If the file is found
  4.         local UserName = xmlFindChild(rootNode, "Username", 0) -- Find the childnode
  5.         if UserName then -- If the childnode is found
  6.         local succes = xmlNodeGetValue (UserName) -- Get the value of the childnode
  7.         end
  8.        
  9.         xmlUnloadFile(rootNode)
  10.         if succes then
  11.             return tostring(succes)
  12.         else
  13.             return ""
  14.         end
  15.     end
  16.     return ""
  17. end
  18.  
  19. function GetPassword()
  20.     local rootNode = xmlLoadFile("details.xml")
  21.     if rootNode then -- If the file is found
  22.         local Password = xmlFindChild(rootNode, "Password", 0) -- Find the childnode
  23.         if Password then -- If the childnode is found
  24.         local succes = xmlNodeGetValue (Password) -- Get the value of the childnode
  25.         end
  26.         xmlUnloadFile(rootNode)
  27.         if succes then
  28.             return tostring(succes)
  29.         else
  30.             return ""
  31.         end
  32.     end
  33.     return ""
  34. end
  35.  
  36. function saveDetails(username, password)
  37.     local RootNode = xmlLoadFile("details.xml")
  38.     local Username, Password, success1, success2
  39.     -- Check if there is a file called "details.xml" on the client's computer
  40.     if not rootNode then
  41.         RootNode = xmlCreateFile("details.xml","Details") -- If "details.xml" is not on the clients computer then create new file
  42.     end
  43.    
  44.     -- Find the nodes
  45.     Username = xmlFindChild (RootNode, "Username", 0)
  46.     Password = xmlFindChild (RootNode, "Password", 0)
  47.    
  48.     if Username and not Password then -- If username is found but password not
  49.         Password = xmlCreateChild(RootNode, "Password") -- Create new password child
  50.        
  51.     elseif not Username and Password then -- If username is not found but password is
  52.         Username = xmlCreateChild(RootNode, "Username") -- Create new username child
  53.        
  54.     elseif not Username and not Password then -- If none is found
  55.         Username = xmlCreateChild(RootNode, "Username") -- Create new username child
  56.         Password = xmlCreateChild(RootNode, "Password") -- Create new password child
  57.     end
  58.         -- Set the values of the childnodes
  59.         success1 = xmlNodeSetValue(Username, username)
  60.         success2 = xmlNodeSetValue(Password, password)
  61.  
  62.     if success1 and success2 then
  63.         xmlSaveFile(RootNode)
  64.         xmlUnloadFile(RootNode)
  65.     else
  66.         return false
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement