Advertisement
Guest User

Untitled

a guest
Mar 14th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. --[[GW2 UI loader, made by Vadi ]]
  2.  
  3. local _sep
  4. if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else  _sep = "\\" end
  5.  
  6. function GW2_LOAD()
  7.     GW2_LOAD = function () end
  8.     if gw2_path then return end -- don't load already if we are
  9.  
  10.     local gw2_location = getMudletHomeDir() .. _sep .. "gw2_location"
  11.     gw2_path = "images/" -- location of the images folder with a trailing slash
  12.     local f,msg
  13.  
  14.     -- first-time launch on profile - no location file
  15.     if not io.open(gw2_path) then
  16.     if not io.open(gw2_location) then
  17.         gw2_path = gw2_whereisit()
  18.         if not gw2_path then return end
  19.     else
  20.         f,msg = io.open(gw2_location, "r+")
  21.         assert(f, msg)
  22.  
  23.         -- this should give us the folder it's in
  24.         gw2_path = f:read("*all")
  25.  
  26.         if string.sub(gw2_path, -1) == "/" or string.sub(gw2_path, -1) == [[\]] then
  27.             gw2_path = string.sub(gw2_path, 1, -2)
  28.         end
  29.    
  30.         -- if we had an invalid path stored
  31.         if not io.open(gw2_path) then
  32.             f = nil -- invalidate handler, so we'll write the new location to disk
  33.             gw2_path = gw2_whereisit()
  34.             if not gw2_path then return end
  35.         end
  36.     end
  37.     end
  38.  
  39.     -- re-add the suffix that we might have had to strip earlier for lfs.attributes to work on Windows
  40.     if not (string.sub(gw2_path, -1) == "/" or string.sub(gw2_path, -1) == [[\]]) then
  41.         gw2_path = gw2_path .. "/"
  42.     end
  43.  
  44.     -- update file
  45.     if not f then
  46.         f,msg = io.open(gw2_location, "w")
  47.         if not f then display(msg) return end
  48.     else
  49.         f:seek("set",0)
  50.     end
  51.  
  52.     f:write(gw2_path)
  53.     f:close()
  54. end
  55.  
  56. -- find the folder
  57. function gw2_whereisit()
  58.     local path = invokeFileDialog(false, "Where is the GW2 images folder? Select it and click Open")
  59.  
  60.     if path == "" then return nil else return path .. _sep end
  61. end
  62.  
  63. GW2_LOAD()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement