Advertisement
Guest User

Untitled

a guest
May 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. -- ======================================================
  2. -- begin
  3. -- ======================================================
  4.  
  5. ui.SysMsg('=====================================');
  6.  
  7. _G["ADDON_LOADER"] = {};
  8. local debugLoading = false;
  9. local closeAfter = true;
  10.  
  11. local function trydofile(fullpath)
  12. local f, error = io.open(fullpath,"r");
  13. if (f ~= nil) then
  14. io.close(f);
  15. dofile(fullpath);
  16. return true;
  17. else
  18. return false;
  19. end
  20. end
  21.  
  22. -- ======================================================
  23. -- Fix to make this loader compatible with Excrulon addons
  24. -- ======================================================
  25.  
  26. trydofile('../addons/utility.lua');
  27.  
  28. -- ======================================================
  29. -- load_all function
  30. -- ======================================================
  31.  
  32. _G["ADDON_LOAD_ALL"] = function()
  33.  
  34. ui.SysMsg('Opening addon folders...');
  35.  
  36. -- getting the current directory
  37. local info = debug.getinfo(1,'S');
  38. local directory = info.source:match[[^@?(.*[\/])[^\/]-$]];
  39.  
  40. -- iterating all folders
  41. local i, addons, popen = 0, {}, io.popen;
  42. for filename in popen('dir "'..directory..'" /b /ad'):lines() do
  43. -- checking if there is {folder}/{folder}.lua inside it, and dofile-ing it if there is
  44. if (debugLoading) then ui.SysMsg('- '..filename..' (lua)'); end
  45. local fullpath = '../addons/'..filename..'/'..filename..'.lua';
  46. local loaded = trydofile(fullpath);
  47. -- if there is, we'll store this folder
  48. if (loaded) then
  49. i = i + 1;
  50. addons[i] = filename;
  51. end
  52. end
  53.  
  54. ui.SysMsg('Initializing addons...');
  55.  
  56. -- now, with all the folders that have a {folder}.lua file inside it
  57. for i,filename in pairs(addons) do
  58. if (debugLoading) then ui.SysMsg('- '..filename); end
  59. -- we look for a hook on the ADDON_LOADER global
  60. local fn = _G['ADDON_LOADER'][filename];
  61. local ok = true;
  62. -- and if there is one, we'll call it
  63. if fn then ok = fn(); end
  64. -- if the hook returned false, a error message should be shown
  65. if (not ok) then ui.SysMsg('['..filename..'] failed.') end
  66. end
  67.  
  68. ui.SysMsg('Addons loaded!');
  69. end
  70.  
  71. -- ======================================================
  72. -- calling it as soon as the game open this
  73. -- ======================================================
  74.  
  75. _G['ADDON_LOAD_ALL']();
  76. _G["ADDON_LOADER"]["LOADED"] = closeAfter;
  77.  
  78. -- ======================================================
  79. -- showing the addonloader frame
  80. -- ======================================================
  81.  
  82. local addonLoaderFrame = ui.GetFrame("addonloader");
  83. addonLoaderFrame:Move(0, 0);
  84. --addonLoaderFrame:SetOffset(1600, 320);
  85. addonLoaderFrame:SetOffset(500,30);
  86. addonLoaderFrame:ShowWindow(0);
  87.  
  88. -- ======================================================
  89. -- hooking it on map-init
  90. -- ======================================================
  91.  
  92. function initWithAddons()
  93. if _G["ADDON_LOADER"]["LOADED"] then
  94. local addonLoaderFrame = ui.GetFrame("addonloader");
  95. addonLoaderFrame:ShowWindow(0);
  96. end
  97. end
  98.  
  99. cwAPI.events.on('MAP_ON_INIT',initWithAddons,1);
  100.  
  101. if (not closeAfter) then addonLoaderFrame:ShowWindow(1); end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement