Share Pastebin
Guest
Public paste!

HelixN

By: a guest | Mar 20th, 2010 | Syntax: Lua | Size: 3.85 KB | Hits: 86 | Expires: Never
Copy text to clipboard
  1. function Meta( tab )
  2.         tab.__index = tab
  3.         return setmetatable( tab, {
  4.                 __call = function( self, t )
  5.                         return setmetatable( t, self )
  6.                 end
  7.         } )
  8. end
  9.  
  10. local _F = {}
  11. _F.__index = _F
  12.  
  13. AccessorFunc( _F, "Type", "Type", FORCE_STRING )
  14. AccessorFunc( _F, "Path", "Path", FORCE_STRING )
  15.  
  16. function _F:__tostring()
  17.         return string.format( "[%s] %s", self:GetType(), self:GetPath() )
  18. end
  19.  
  20. function _F:GetExtension()
  21.         return self:GetPath():match( "(%..+)$" )
  22. end
  23.  
  24. function _F:GetFileName()
  25.         return self:GetPath():gsub( ".*[\\/]+(.+)%.", 1 )
  26. end
  27.  
  28. function _F:IsModel()
  29.         return self:GetType() == "Model"
  30. end
  31.  
  32. function _F:IsSound()
  33.         return self:GetType() == "Sound"
  34. end
  35.  
  36. function _F:IsFont()
  37.         return self:GetType() == "Font"
  38. end
  39.  
  40. function _F:IsMaterial()
  41.         return self:GetType() == "Material"
  42. end
  43.  
  44. function _F:IsParticle()
  45.         return self:GetType() == "Particle"
  46. end
  47.  
  48. function _F:AddFile()
  49.         local folder = ""
  50.         if self:IsModel() then
  51.                 folder = "models/"
  52.         elseif self:IsSound() then
  53.                 folder = "sound/"
  54.         elseif self:IsFont() then
  55.                 folder = "resource/"
  56.         elseif self:IsMaterial() then
  57.                 folder = "materials/"
  58.         elseif self:IsParticle() then
  59.                 folder = "particles/"
  60.         end
  61.        
  62.         resource.AddFile( folder .. self:GetPath() )
  63. end
  64.  
  65. function _F:Precache( models, sounds )
  66.         if self:IsSound() and sounds then
  67.                 util.PrecacheSound( self:GetPath() )
  68.         elseif self:IsModel() and models then
  69.                 util.PrecacheModel( self:GetPath() )
  70.         end
  71. end
  72.  
  73. function RSAddFile( name, file )
  74.         table.insert( ResourceSmart.DownloadList[ name ], file )
  75. end
  76.  
  77. function RSCreateFile( path )
  78.         local tbl = setmetatable( {}, _F )
  79.         tbl:SetPath( path )
  80.         local ext = tbl:GetExtension()
  81.         tbl:SetType(
  82.                 (ext == ".mdl") and "Model" or
  83.                 (ext == ".vmt") and "Material" or
  84.                 (ext == ".ttf") and "Font" or
  85.                 (ext == ".pcf") and "Particle" or
  86.                 (ext == ".wav" or ext == ".mp3") and "Sound" or ""
  87.         )
  88.         return tbl
  89. end
  90.  
  91. function RSGetVersion()
  92.         http.Get( ResourceSmart.VersionURL, "", function( contents )
  93.                 if contents == nil then
  94.                         Msg( ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
  95.                         filex.Append( "ResourceSmart/errors.txt", ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
  96.                         return
  97.                 end
  98.                 return contents
  99.         end )
  100. end
  101.  
  102. function RSCheckVersion( debug )
  103.         http.Get( ResourceSmart.VersionURL, "", function( contents )
  104.                 if contents == nil then
  105.                         Msg( ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
  106.                         filex.Append( "ResourceSmart/errors.txt", ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
  107.                         return
  108.                 end
  109.                 if ResourceSmart.Version == contents then
  110.                         if debug then
  111.                                 Msg( ">>> ResourceSmart[ VersionChecker] >> true\n" )
  112.                         end
  113.                         return true
  114.                 else
  115.                         if debug then
  116.                                 Msg( ">>> ResourceSmart[ VersionChecker] >> false\n" )
  117.                         end
  118.                         return false
  119.                 end
  120.         end )
  121. end
  122.  
  123. function RSAddDir( dir )
  124.         for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
  125.                 resource.AddFile( dir .. v )
  126.         end
  127. end
  128.  
  129. function RSConVarAddFile( name, file, cvar )
  130.         if not ConVarExists( tostring( cvar ) ) then
  131.                 CreateConVar( cvar, 1, true )
  132.         end
  133.         if GetConVar( cvar ) == 0 then
  134.                 return
  135.         else
  136.                 table.insert( ResourceSmart.DownloadList[ name ], file )
  137.         end
  138. end
  139.  
  140. function RSConVarAddDir( dir, cvar )
  141.         if not ConVarExists( tostring( cvar ) ) then
  142.                 CreateConVar( cvar, 1, true )
  143.         end
  144.         if GetConVar( cvar ) == 0 then
  145.                 return
  146.         else
  147.                 for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
  148.                         resource.AddFile( dir .. v )
  149.                 end
  150.         end
  151. end
  152.  
  153. function RSMapAddDir( dir, map )
  154.         if not string.lower( game.GetMap() ) == map then return end
  155.         for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
  156.                 resource.AddFile( dir .. v )
  157.         end
  158. end
  159.  
  160. function RSNMapAddDir( dir, map )
  161.         if string.lower( game.GetMap() ) == map then return end
  162.         for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
  163.                 resource.AddFile( dir .. v )
  164.         end
  165. end