bmk_ng_utils.bmx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. SuperStrict
  2. Import BRL.MaxUtil
  3. Import BRL.FileSystem
  4. ?Not linux
  5. Import BRL.System
  6. ?
  7. Import BRL.MaxLua
  8. Import BRL.TextStream
  9. ?linux
  10. Import "bmk_cores_linux.bmx"
  11. ?macos
  12. Import "bmk_cores_macos.bmx"
  13. ?win32
  14. Import "bmk_cores_win32.bmx"
  15. ?haiku
  16. Import "bmk_cores_haiku.bmx"
  17. ?
  18. Global utils:TMaxUtils = New TMaxUtils
  19. Global fsys:TSystem = New TSystem
  20. Global futils:TFileUtils = New TFileUtils
  21. ' Access to BRL.MaxUtil
  22. Type TMaxUtils
  23. Method New()
  24. LuaRegisterObject Self,"utils"
  25. End Method
  26. Method BlitzMaxPath:String()
  27. Return BRL.MaxUtil.BlitzMaxPath()
  28. End Method
  29. Method ModulePath:String( modid$ )
  30. Return BRL.MaxUtil.ModulePath(modid)
  31. End Method
  32. Method ModuleIdent:String( modid$ )
  33. Return BRL.MaxUtil.ModuleIdent(modid)
  34. End Method
  35. Method ModuleSource:String( modid$ )
  36. Return BRL.MaxUtil.ModuleSource(modid)
  37. End Method
  38. Method ModuleArchive:String( modid$,mung$="" )
  39. Return BRL.MaxUtil.ModuleArchive(modid, mung)
  40. End Method
  41. Method ModuleInterface:String( modid$,mung$="" )
  42. Return BRL.MaxUtil.ModuleInterface(modid, mung)
  43. End Method
  44. End Type
  45. ' Access to BRL.FileSystem and BRL.System
  46. Type TSystem
  47. Method New()
  48. LuaRegisterObject Self,"sys"
  49. End Method
  50. Method FixPath:String(path:String, dirPath:Int = False)
  51. Local p:String = path
  52. BRL.FileSystem.FixPath(p, dirPath)
  53. Return p
  54. End Method
  55. Method StripDir$( path$ )
  56. Return BRL.FileSystem.StripDir(path)
  57. End Method
  58. Method StripExt$( path$ )
  59. Return BRL.FileSystem.StripExt(path)
  60. End Method
  61. Method StripAll$( path$ )
  62. Return BRL.FileSystem.StripAll(path)
  63. End Method
  64. Method StripSlash$( path$ )
  65. Return BRL.FileSystem.StripSlash(path)
  66. End Method
  67. Method ExtractDir$( path$ )
  68. Return BRL.FileSystem.ExtractDir(path)
  69. End Method
  70. Method ExtractExt$( path$ )
  71. Return BRL.FileSystem.ExtractExt(path)
  72. End Method
  73. Method CurrentDir$()
  74. Return BRL.FileSystem.CurrentDir()
  75. End Method
  76. Method RealPath$( path$ )
  77. Return BRL.FileSystem.RealPath(path)
  78. End Method
  79. Method FileType:Int( path$ )
  80. Return BRL.FileSystem.FileType(path)
  81. End Method
  82. Method CreateFile:Int( path$ )
  83. Return BRL.FileSystem.CreateFile(path)
  84. End Method
  85. Method CreateDir:Int( path$,recurse:Int=False )
  86. Return BRL.FileSystem.CreateDir(path, recurse)
  87. End Method
  88. Method DeleteFile:Int( path$ )
  89. Return BRL.FileSystem.DeleteFile(path)
  90. End Method
  91. Method RenameFile:Int( oldpath$,newpath$ )
  92. Return BRL.FileSystem.RenameFile(oldpath, newpath)
  93. End Method
  94. Method CopyFile:Int( src$,dst$ )
  95. Return BRL.FileSystem.CopyFile(src, dst)
  96. End Method
  97. Method CopyDir:Int( src$,dst$ )
  98. Return BRL.FileSystem.CopyDir(src, dst)
  99. End Method
  100. Method DeleteDir:Int( path$,recurse:Int=False )
  101. Return BRL.FileSystem.DeleteDir(path, recurse)
  102. End Method
  103. Method ChangeDir:Int( path$ )
  104. Return BRL.FileSystem.ChangeDir(path)
  105. End Method
  106. ?Not linux
  107. ' System
  108. Method CurrentDate:String()
  109. Return BRL.System.CurrentDate()
  110. End Method
  111. Method CurrentTime:String()
  112. Return BRL.System.CurrentTime()
  113. End Method
  114. Method Notify(text:String, serious:Int = False)
  115. BRL.System.Notify(text, serious)
  116. End Method
  117. Method OpenURL(url:String)
  118. BRL.System.OpenURL(url)
  119. End Method
  120. ?linux
  121. Method CurrentDate:String(_format$="%d %b %Y")
  122. Local time:Byte[256],buff:Byte[256]
  123. time_(time)
  124. strftime_(buff,256,_format,localtime_( time ))
  125. Return String.FromCString(buff)
  126. End Method
  127. Method CurrentTime:String()
  128. Local time:Byte[256],buff:Byte[256]
  129. time_(time)
  130. strftime_( buff,256,"%H:%M:%S",localtime_( time ) );
  131. Return String.FromCString(buff)
  132. End Method
  133. Method Notify(text:String, serious:Int = False)
  134. WriteStdout text+"~r~n"
  135. End Method
  136. ?
  137. End Type
  138. ' Access to BRL.MaxUtil
  139. Type TFileUtils
  140. Method New()
  141. LuaRegisterObject Self,"futils"
  142. End Method
  143. Method SaveText:Int(filename:String, text:String)
  144. Try
  145. Return BRL.TextStream.SaveText(text, filename)
  146. Catch e:TStreamWriteException
  147. Return False
  148. End Try
  149. End Method
  150. End Type
  151. Private
  152. Global factories:TProcessTaskFactory
  153. Public
  154. Type TProcessTask
  155. Function _DoTasks:Object(data:Object)
  156. Return TProcessTask(data).DoTasks()
  157. End Function
  158. Method DoTasks:Object() abstract
  159. End Type
  160. Type TProcessTaskFactory
  161. Field _succ:TProcessTaskFactory
  162. Method New()
  163. _succ=factories
  164. factories=Self
  165. End Method
  166. Method Create:TProcessTask( cmd:String, src:String, obj:String, supp:String ) Abstract
  167. End Type
  168. Function CreateProcessTask:TProcessTask(cmd:String, src:String, obj:String, supp:String)
  169. Local factory:TProcessTaskFactory=factories
  170. Return factory.Create(cmd, src, obj, supp)
  171. End Function