fileLoader.ed.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function loadDirectory(%path, %type, %dsoType)
  23. {
  24. if( %type $= "" )
  25. %type = "ed.cs";
  26. if( %dsoType $= "" )
  27. %dsoType = "edso";
  28. %cspath = %path @ "/*." @ %type;
  29. // Because in a shipping version there will be no .cs files, we can't just
  30. // find all the cs files and exec them.
  31. // First we find all the scripts and compile them if there are any
  32. // In the shipping version, this wont find anything.
  33. if( !$Scripts::ignoreDSOs )
  34. {
  35. %dsoReloc = compileDirectory(%cspath);
  36. // Finally we find all the dsos and exec them instead
  37. // If the DSOs are relocated by the engine (which will be the case when
  38. // running the tools) then we need to look for the scripts again.
  39. if(! %dsoReloc)
  40. %dsopath = %path @ "/*." @ %type @ "." @ %dsoType;
  41. else
  42. %dsopath = %cspath;
  43. }
  44. else
  45. %dsopath = %cspath;
  46. //error("Execing Directory " @ %dsopath @ " ...");
  47. %file = findFirstFile(%dsopath);
  48. while(%file !$= "")
  49. {
  50. //error(" Found File: " @ %file);
  51. // As we cant exec() a .dso directly, we need to strip that part from the filename
  52. %pos = strstr(%file, "." @ %dsoType);
  53. if(%pos != -1)
  54. %csfile = getSubStr(%file, 0, %pos);
  55. else
  56. %csfile = %file;
  57. exec(%csfile);
  58. %file = findNextFile(%dsopath);
  59. }
  60. }
  61. function compileDirectory(%path, %dsoPath)
  62. {
  63. %saveDSOPath = $Scripts::OverrideDSOPath;
  64. $Scripts::OverrideDSOPath = %dsoPath;
  65. %dsoReloc = false;
  66. %file = findFirstFile(%path);
  67. //error("Compiling Directory " @ %path @ " ...");
  68. while(%file !$= "")
  69. {
  70. //error(" Found File: " @ %file @ " (" @ getDSOPath(%file) @ ")");
  71. if(filePath(%file) !$= filePath(getDSOPath(%file)))
  72. %dsoReloc = true;
  73. compile(%file);
  74. %file = findNextFile(%path);
  75. }
  76. $Scripts::OverrideDSOPath = %saveDSOPath;
  77. return %dsoReloc;
  78. }
  79. function listDirectory(%path)
  80. {
  81. %file = findFirstFile(%path);
  82. echo("Listing Directory " @ %path @ " ...");
  83. while(%file !$= "")
  84. {
  85. echo(" " @ %file);
  86. %file = findNextFile(%path);
  87. }
  88. }