Advertisement
Terrah

storage.lua

Aug 13th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1.  
  2. if STORAGE~=nil then
  3.     return;
  4. end
  5.  
  6. STORAGE = {};
  7. STORAGE.PATH = "D:/store/";
  8.  
  9. function STORAGE:RepositoryExists(key)
  10.  
  11.     local info = nwn.GetFileInfo(self.PATH..key);
  12.  
  13.     if info == nil then
  14.         return false;
  15.     else
  16.         return info.isFolder;
  17.     end
  18. end
  19.  
  20. function STORAGE:GetAllFilesInRepo(key)
  21.  
  22.     if not self:RepositoryExists(key) then
  23.         return 0;
  24.     end
  25.  
  26.     local files = {};
  27.     local folder = self.PATH..key.."/";
  28.     local filter = folder.."*.uti";
  29.     local file, attrib = nwn.GetFirstFile(filter);
  30.  
  31.     while file do
  32.  
  33.         if file ~= "." and file ~= ".." then
  34.             table.insert(files,folder..file);
  35.             file, attrib = nwn.GetNextFile();
  36.         end
  37.     end
  38.  
  39.     nwscript.STORAGE = files;
  40.  
  41.     return #files;
  42. end
  43.  
  44. function STORAGE:EmptyRepo(key)
  45.  
  46.     local folder = self.PATH.."/"..key;
  47.  
  48.     if not self:RepositoryExists(key) then
  49.         if nwn.CreateDirectory(folder) then
  50.             return folder.."/";
  51.         else
  52.             return "";
  53.         end
  54.     end
  55.  
  56.     local files = {};
  57.  
  58.     local files = {};
  59.     folder = self.PATH..key.."/";
  60.     local filter = folder.."*.uti";
  61.     local file, attrib = nwn.GetFirstFile(filter);
  62.  
  63.     while file do
  64.  
  65.         if file ~= "." and file ~= ".." then
  66.             table.insert(files,folder..file);
  67.             file, attrib = nwn.GetNextFile();
  68.         end
  69.     end
  70.  
  71.     local cnt = 0;
  72.  
  73.     for n=1,#files do
  74.         nwn.DeleteFile(files[n]);
  75.     end
  76.  
  77.     return folder;
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement