FileSystem.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // WARNING - AUTOGENERATED - DO NOT EDIT
  2. //
  3. // Generated using `sharpie urho`
  4. //
  5. // FileSystem.cs
  6. //
  7. // Copyright 2015 Xamarin Inc. All rights reserved.
  8. using System;
  9. using System.Runtime.InteropServices;
  10. using System.Collections.Generic;
  11. using Urho.Urho2D;
  12. using Urho.Gui;
  13. using Urho.Resources;
  14. using Urho.IO;
  15. using Urho.Navigation;
  16. using Urho.Network;
  17. namespace Urho.IO
  18. {
  19. /// <summary>
  20. /// Subsystem for file and directory operations and access control.
  21. /// </summary>
  22. public unsafe partial class FileSystem : UrhoObject
  23. {
  24. unsafe partial void OnFileSystemCreated ();
  25. [Preserve]
  26. public FileSystem (IntPtr handle) : base (handle)
  27. {
  28. OnFileSystemCreated ();
  29. }
  30. [Preserve]
  31. protected FileSystem (UrhoObjectFlag emptyFlag) : base (emptyFlag)
  32. {
  33. OnFileSystemCreated ();
  34. }
  35. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern int FileSystem_GetType (IntPtr handle);
  37. private StringHash UrhoGetType ()
  38. {
  39. Runtime.ValidateRefCounted (this);
  40. return new StringHash (FileSystem_GetType (handle));
  41. }
  42. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern IntPtr FileSystem_GetTypeName (IntPtr handle);
  44. private string GetTypeName ()
  45. {
  46. Runtime.ValidateRefCounted (this);
  47. return Marshal.PtrToStringAnsi (FileSystem_GetTypeName (handle));
  48. }
  49. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  50. internal static extern int FileSystem_GetTypeStatic ();
  51. private static StringHash GetTypeStatic ()
  52. {
  53. Runtime.Validate (typeof(FileSystem));
  54. return new StringHash (FileSystem_GetTypeStatic ());
  55. }
  56. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern IntPtr FileSystem_GetTypeNameStatic ();
  58. private static string GetTypeNameStatic ()
  59. {
  60. Runtime.Validate (typeof(FileSystem));
  61. return Marshal.PtrToStringAnsi (FileSystem_GetTypeNameStatic ());
  62. }
  63. [Preserve]
  64. public FileSystem () : this (Application.CurrentContext)
  65. {
  66. }
  67. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  68. internal static extern IntPtr FileSystem_FileSystem (IntPtr context);
  69. [Preserve]
  70. public FileSystem (Context context) : base (UrhoObjectFlag.Empty)
  71. {
  72. Runtime.Validate (typeof(FileSystem));
  73. handle = FileSystem_FileSystem ((object)context == null ? IntPtr.Zero : context.Handle);
  74. Runtime.RegisterObject (this);
  75. OnFileSystemCreated ();
  76. }
  77. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  78. internal static extern bool FileSystem_SetCurrentDir (IntPtr handle, string pathName);
  79. /// <summary>
  80. /// Set the current working directory.
  81. /// </summary>
  82. public bool SetCurrentDir (string pathName)
  83. {
  84. Runtime.ValidateRefCounted (this);
  85. return FileSystem_SetCurrentDir (handle, pathName);
  86. }
  87. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  88. internal static extern bool FileSystem_CreateDir (IntPtr handle, string pathName);
  89. /// <summary>
  90. /// Create a directory.
  91. /// </summary>
  92. public bool CreateDir (string pathName)
  93. {
  94. Runtime.ValidateRefCounted (this);
  95. return FileSystem_CreateDir (handle, pathName);
  96. }
  97. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  98. internal static extern void FileSystem_SetExecuteConsoleCommands (IntPtr handle, bool enable);
  99. /// <summary>
  100. /// Set whether to execute engine console commands as OS-specific system command.
  101. /// </summary>
  102. private void SetExecuteConsoleCommands (bool enable)
  103. {
  104. Runtime.ValidateRefCounted (this);
  105. FileSystem_SetExecuteConsoleCommands (handle, enable);
  106. }
  107. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  108. internal static extern int FileSystem_SystemCommand (IntPtr handle, string commandLine, bool redirectStdOutToLog);
  109. /// <summary>
  110. /// Run a program using the command interpreter, block until it exits and return the exit code. Will fail if any allowed paths are defined.
  111. /// </summary>
  112. public int SystemCommand (string commandLine, bool redirectStdOutToLog = false)
  113. {
  114. Runtime.ValidateRefCounted (this);
  115. return FileSystem_SystemCommand (handle, commandLine, redirectStdOutToLog);
  116. }
  117. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  118. internal static extern uint FileSystem_SystemCommandAsync (IntPtr handle, string commandLine);
  119. /// <summary>
  120. /// Run a program using the command interpreter asynchronously. Return a request ID or M_MAX_UNSIGNED if failed. The exit code will be posted together with the request ID in an AsyncExecFinished event. Will fail if any allowed paths are defined.
  121. /// </summary>
  122. public uint SystemCommandAsync (string commandLine)
  123. {
  124. Runtime.ValidateRefCounted (this);
  125. return FileSystem_SystemCommandAsync (handle, commandLine);
  126. }
  127. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  128. internal static extern bool FileSystem_SystemOpen (IntPtr handle, string fileName, string mode);
  129. /// <summary>
  130. /// Open a file in an external program, with mode such as "edit" optionally specified. Will fail if any allowed paths are defined.
  131. /// </summary>
  132. public bool SystemOpen (string fileName, string mode = "")
  133. {
  134. Runtime.ValidateRefCounted (this);
  135. return FileSystem_SystemOpen (handle, fileName, mode);
  136. }
  137. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  138. internal static extern bool FileSystem_Copy (IntPtr handle, string srcFileName, string destFileName);
  139. /// <summary>
  140. /// Copy a file. Return true if successful.
  141. /// </summary>
  142. public bool Copy (string srcFileName, string destFileName)
  143. {
  144. Runtime.ValidateRefCounted (this);
  145. return FileSystem_Copy (handle, srcFileName, destFileName);
  146. }
  147. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  148. internal static extern bool FileSystem_Rename (IntPtr handle, string srcFileName, string destFileName);
  149. /// <summary>
  150. /// Rename a file. Return true if successful.
  151. /// </summary>
  152. public bool Rename (string srcFileName, string destFileName)
  153. {
  154. Runtime.ValidateRefCounted (this);
  155. return FileSystem_Rename (handle, srcFileName, destFileName);
  156. }
  157. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  158. internal static extern bool FileSystem_Delete (IntPtr handle, string fileName);
  159. /// <summary>
  160. /// Delete a file. Return true if successful.
  161. /// </summary>
  162. public bool Delete (string fileName)
  163. {
  164. Runtime.ValidateRefCounted (this);
  165. return FileSystem_Delete (handle, fileName);
  166. }
  167. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  168. internal static extern void FileSystem_RegisterPath (IntPtr handle, string pathName);
  169. /// <summary>
  170. /// Register a path as allowed to access. If no paths are registered, all are allowed. Registering allowed paths is considered securing the Urho3D execution environment: running programs and opening files externally through the system will fail afterward.
  171. /// </summary>
  172. public void RegisterPath (string pathName)
  173. {
  174. Runtime.ValidateRefCounted (this);
  175. FileSystem_RegisterPath (handle, pathName);
  176. }
  177. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  178. internal static extern bool FileSystem_SetLastModifiedTime (IntPtr handle, string fileName, uint newTime);
  179. /// <summary>
  180. /// Set a file's last modified time as seconds since 1.1.1970. Return true on success.
  181. /// </summary>
  182. public bool SetLastModifiedTime (string fileName, uint newTime)
  183. {
  184. Runtime.ValidateRefCounted (this);
  185. return FileSystem_SetLastModifiedTime (handle, fileName, newTime);
  186. }
  187. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  188. internal static extern IntPtr FileSystem_GetCurrentDir (IntPtr handle);
  189. /// <summary>
  190. /// Return the absolute current working directory.
  191. /// </summary>
  192. private string GetCurrentDir ()
  193. {
  194. Runtime.ValidateRefCounted (this);
  195. return Marshal.PtrToStringAnsi (FileSystem_GetCurrentDir (handle));
  196. }
  197. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  198. internal static extern bool FileSystem_GetExecuteConsoleCommands (IntPtr handle);
  199. /// <summary>
  200. /// Return whether is executing engine console commands as OS-specific system command.
  201. /// </summary>
  202. private bool GetExecuteConsoleCommands ()
  203. {
  204. Runtime.ValidateRefCounted (this);
  205. return FileSystem_GetExecuteConsoleCommands (handle);
  206. }
  207. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  208. internal static extern bool FileSystem_HasRegisteredPaths (IntPtr handle);
  209. /// <summary>
  210. /// Return whether paths have been registered.
  211. /// </summary>
  212. public bool HasRegisteredPaths ()
  213. {
  214. Runtime.ValidateRefCounted (this);
  215. return FileSystem_HasRegisteredPaths (handle);
  216. }
  217. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  218. internal static extern bool FileSystem_CheckAccess (IntPtr handle, string pathName);
  219. /// <summary>
  220. /// Check if a path is allowed to be accessed. If no paths are registered, all are allowed.
  221. /// </summary>
  222. public bool CheckAccess (string pathName)
  223. {
  224. Runtime.ValidateRefCounted (this);
  225. return FileSystem_CheckAccess (handle, pathName);
  226. }
  227. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  228. internal static extern uint FileSystem_GetLastModifiedTime (IntPtr handle, string fileName);
  229. /// <summary>
  230. /// Returns the file's last modified time as seconds since 1.1.1970, or 0 if can not be accessed.
  231. /// </summary>
  232. public uint GetLastModifiedTime (string fileName)
  233. {
  234. Runtime.ValidateRefCounted (this);
  235. return FileSystem_GetLastModifiedTime (handle, fileName);
  236. }
  237. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  238. internal static extern bool FileSystem_FileExists (IntPtr handle, string fileName);
  239. /// <summary>
  240. /// Check if a file exists.
  241. /// </summary>
  242. public bool FileExists (string fileName)
  243. {
  244. Runtime.ValidateRefCounted (this);
  245. return FileSystem_FileExists (handle, fileName);
  246. }
  247. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  248. internal static extern bool FileSystem_DirExists (IntPtr handle, string pathName);
  249. /// <summary>
  250. /// Check if a directory exists.
  251. /// </summary>
  252. public bool DirExists (string pathName)
  253. {
  254. Runtime.ValidateRefCounted (this);
  255. return FileSystem_DirExists (handle, pathName);
  256. }
  257. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  258. internal static extern IntPtr FileSystem_GetProgramDir (IntPtr handle);
  259. /// <summary>
  260. /// Return the program's directory.
  261. /// </summary>
  262. private string GetProgramDir ()
  263. {
  264. Runtime.ValidateRefCounted (this);
  265. return Marshal.PtrToStringAnsi (FileSystem_GetProgramDir (handle));
  266. }
  267. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  268. internal static extern IntPtr FileSystem_GetUserDocumentsDir (IntPtr handle);
  269. /// <summary>
  270. /// Return the user documents directory.
  271. /// </summary>
  272. private string GetUserDocumentsDir ()
  273. {
  274. Runtime.ValidateRefCounted (this);
  275. return Marshal.PtrToStringAnsi (FileSystem_GetUserDocumentsDir (handle));
  276. }
  277. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  278. internal static extern IntPtr FileSystem_GetAppPreferencesDir (IntPtr handle, string org, string app);
  279. /// <summary>
  280. /// Return the application preferences directory.
  281. /// </summary>
  282. public string GetAppPreferencesDir (string org, string app)
  283. {
  284. Runtime.ValidateRefCounted (this);
  285. return Marshal.PtrToStringAnsi (FileSystem_GetAppPreferencesDir (handle, org, app));
  286. }
  287. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  288. internal static extern IntPtr FileSystem_GetTemporaryDir (IntPtr handle);
  289. /// <summary>
  290. /// Return path of temporary directory. Path always ends with a forward slash.
  291. /// </summary>
  292. private string GetTemporaryDir ()
  293. {
  294. Runtime.ValidateRefCounted (this);
  295. return Marshal.PtrToStringAnsi (FileSystem_GetTemporaryDir (handle));
  296. }
  297. public override StringHash Type {
  298. get {
  299. return UrhoGetType ();
  300. }
  301. }
  302. public override string TypeName {
  303. get {
  304. return GetTypeName ();
  305. }
  306. }
  307. [Preserve]
  308. public static StringHash TypeStatic {
  309. get {
  310. return GetTypeStatic ();
  311. }
  312. }
  313. public static string TypeNameStatic {
  314. get {
  315. return GetTypeNameStatic ();
  316. }
  317. }
  318. /// <summary>
  319. /// Return the absolute current working directory.
  320. /// </summary>
  321. public string CurrentDir {
  322. get {
  323. return GetCurrentDir ();
  324. }
  325. }
  326. /// <summary>
  327. /// Return whether is executing engine console commands as OS-specific system command.
  328. /// Or
  329. /// Set whether to execute engine console commands as OS-specific system command.
  330. /// </summary>
  331. public bool ExecuteConsoleCommands {
  332. get {
  333. return GetExecuteConsoleCommands ();
  334. }
  335. set {
  336. SetExecuteConsoleCommands (value);
  337. }
  338. }
  339. /// <summary>
  340. /// Return the program's directory.
  341. /// </summary>
  342. public string ProgramDir {
  343. get {
  344. return GetProgramDir ();
  345. }
  346. }
  347. /// <summary>
  348. /// Return the user documents directory.
  349. /// </summary>
  350. public string UserDocumentsDir {
  351. get {
  352. return GetUserDocumentsDir ();
  353. }
  354. }
  355. /// <summary>
  356. /// Return path of temporary directory. Path always ends with a forward slash.
  357. /// </summary>
  358. public string TemporaryDir {
  359. get {
  360. return GetTemporaryDir ();
  361. }
  362. }
  363. }
  364. }