File.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. // WARNING - AUTOGENERATED - DO NOT EDIT
  2. //
  3. // Generated using `sharpie urho`
  4. //
  5. // File.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. /// %File opened either through the filesystem or from within a package file.
  21. /// </summary>
  22. public unsafe partial class File : UrhoObject, IAbstractFile
  23. {
  24. unsafe partial void OnFileCreated ();
  25. [Preserve]
  26. public File (IntPtr handle) : base (handle)
  27. {
  28. OnFileCreated ();
  29. }
  30. [Preserve]
  31. protected File (UrhoObjectFlag emptyFlag) : base (emptyFlag)
  32. {
  33. OnFileCreated ();
  34. }
  35. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern int File_GetType (IntPtr handle);
  37. private StringHash UrhoGetType ()
  38. {
  39. Runtime.ValidateRefCounted (this);
  40. return new StringHash (File_GetType (handle));
  41. }
  42. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern IntPtr File_GetTypeName (IntPtr handle);
  44. private string GetTypeName ()
  45. {
  46. Runtime.ValidateRefCounted (this);
  47. return Marshal.PtrToStringAnsi (File_GetTypeName (handle));
  48. }
  49. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  50. internal static extern int File_GetTypeStatic ();
  51. private static StringHash GetTypeStatic ()
  52. {
  53. Runtime.Validate (typeof(File));
  54. return new StringHash (File_GetTypeStatic ());
  55. }
  56. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern IntPtr File_GetTypeNameStatic ();
  58. private static string GetTypeNameStatic ()
  59. {
  60. Runtime.Validate (typeof(File));
  61. return Marshal.PtrToStringAnsi (File_GetTypeNameStatic ());
  62. }
  63. [Preserve]
  64. public File () : this (Application.CurrentContext)
  65. {
  66. }
  67. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  68. internal static extern IntPtr File_File (IntPtr context);
  69. [Preserve]
  70. public File (Context context) : base (UrhoObjectFlag.Empty)
  71. {
  72. Runtime.Validate (typeof(File));
  73. handle = File_File ((object)context == null ? IntPtr.Zero : context.Handle);
  74. Runtime.RegisterObject (this);
  75. OnFileCreated ();
  76. }
  77. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  78. internal static extern IntPtr File_File0 (IntPtr context, string fileName, FileMode mode);
  79. [Preserve]
  80. public File (Context context, string fileName, FileMode mode = FileMode.Read) : base (UrhoObjectFlag.Empty)
  81. {
  82. Runtime.Validate (typeof(File));
  83. handle = File_File0 ((object)context == null ? IntPtr.Zero : context.Handle, fileName, mode);
  84. Runtime.RegisterObject (this);
  85. OnFileCreated ();
  86. }
  87. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  88. internal static extern IntPtr File_File1 (IntPtr context, IntPtr package, string fileName);
  89. [Preserve]
  90. public File (Context context, PackageFile package, string fileName) : base (UrhoObjectFlag.Empty)
  91. {
  92. Runtime.Validate (typeof(File));
  93. handle = File_File1 ((object)context == null ? IntPtr.Zero : context.Handle, (object)package == null ? IntPtr.Zero : package.Handle, fileName);
  94. Runtime.RegisterObject (this);
  95. OnFileCreated ();
  96. }
  97. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  98. internal static extern uint File_Read (IntPtr handle, IntPtr dest, uint size);
  99. /// <summary>
  100. /// Read bytes from the file. Return number of bytes actually read.
  101. /// </summary>
  102. public uint Read (IntPtr dest, uint size)
  103. {
  104. Runtime.ValidateRefCounted (this);
  105. return File_Read (handle, dest, size);
  106. }
  107. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  108. internal static extern uint File_Seek (IntPtr handle, uint position);
  109. /// <summary>
  110. /// Set position from the beginning of the file.
  111. /// </summary>
  112. public uint Seek (uint position)
  113. {
  114. Runtime.ValidateRefCounted (this);
  115. return File_Seek (handle, position);
  116. }
  117. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  118. internal static extern uint File_Write (IntPtr handle, void* data, uint size);
  119. /// <summary>
  120. /// Write bytes to the file. Return number of bytes actually written.
  121. /// </summary>
  122. public uint Write (void* data, uint size)
  123. {
  124. Runtime.ValidateRefCounted (this);
  125. return File_Write (handle, data, size);
  126. }
  127. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  128. internal static extern IntPtr File_GetName (IntPtr handle);
  129. /// <summary>
  130. /// Return the file name.
  131. /// </summary>
  132. private string GetName ()
  133. {
  134. Runtime.ValidateRefCounted (this);
  135. return Marshal.PtrToStringAnsi (File_GetName (handle));
  136. }
  137. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  138. internal static extern uint File_GetChecksum (IntPtr handle);
  139. /// <summary>
  140. /// Return a checksum of the file contents using the SDBM hash algorithm.
  141. /// </summary>
  142. private uint GetChecksum ()
  143. {
  144. Runtime.ValidateRefCounted (this);
  145. return File_GetChecksum (handle);
  146. }
  147. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  148. internal static extern bool File_Open (IntPtr handle, string fileName, FileMode mode);
  149. /// <summary>
  150. /// Open a filesystem file. Return true if successful.
  151. /// </summary>
  152. public bool Open (string fileName, FileMode mode = FileMode.Read)
  153. {
  154. Runtime.ValidateRefCounted (this);
  155. return File_Open (handle, fileName, mode);
  156. }
  157. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  158. internal static extern bool File_Open2 (IntPtr handle, IntPtr package, string fileName);
  159. /// <summary>
  160. /// Open from within a package file. Return true if successful.
  161. /// </summary>
  162. public bool Open (PackageFile package, string fileName)
  163. {
  164. Runtime.ValidateRefCounted (this);
  165. return File_Open2 (handle, (object)package == null ? IntPtr.Zero : package.Handle, fileName);
  166. }
  167. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  168. internal static extern void File_Close (IntPtr handle);
  169. /// <summary>
  170. /// Close the file.
  171. /// </summary>
  172. public void Close ()
  173. {
  174. Runtime.ValidateRefCounted (this);
  175. File_Close (handle);
  176. }
  177. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  178. internal static extern void File_Flush (IntPtr handle);
  179. /// <summary>
  180. /// Flush any buffered output to the file.
  181. /// </summary>
  182. public void Flush ()
  183. {
  184. Runtime.ValidateRefCounted (this);
  185. File_Flush (handle);
  186. }
  187. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  188. internal static extern void File_SetName (IntPtr handle, string name);
  189. /// <summary>
  190. /// Change the file name. Used by the resource system.
  191. /// </summary>
  192. private void SetName (string name)
  193. {
  194. Runtime.ValidateRefCounted (this);
  195. File_SetName (handle, name);
  196. }
  197. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  198. internal static extern FileMode File_GetMode (IntPtr handle);
  199. /// <summary>
  200. /// Return the open mode.
  201. /// </summary>
  202. private FileMode GetMode ()
  203. {
  204. Runtime.ValidateRefCounted (this);
  205. return File_GetMode (handle);
  206. }
  207. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  208. internal static extern bool File_IsOpen (IntPtr handle);
  209. /// <summary>
  210. /// Return whether is open.
  211. /// </summary>
  212. public bool IsOpen ()
  213. {
  214. Runtime.ValidateRefCounted (this);
  215. return File_IsOpen (handle);
  216. }
  217. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  218. internal static extern IntPtr File_GetHandle (IntPtr handle);
  219. /// <summary>
  220. /// Return the file handle.
  221. /// </summary>
  222. private IntPtr GetHandle ()
  223. {
  224. Runtime.ValidateRefCounted (this);
  225. return File_GetHandle (handle);
  226. }
  227. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  228. internal static extern bool File_IsPackaged (IntPtr handle);
  229. /// <summary>
  230. /// Return whether the file originates from a package.
  231. /// </summary>
  232. private bool IsPackaged ()
  233. {
  234. Runtime.ValidateRefCounted (this);
  235. return File_IsPackaged (handle);
  236. }
  237. public override StringHash Type {
  238. get {
  239. return UrhoGetType ();
  240. }
  241. }
  242. public override string TypeName {
  243. get {
  244. return GetTypeName ();
  245. }
  246. }
  247. [Preserve]
  248. public static StringHash TypeStatic {
  249. get {
  250. return GetTypeStatic ();
  251. }
  252. }
  253. public static string TypeNameStatic {
  254. get {
  255. return GetTypeNameStatic ();
  256. }
  257. }
  258. /// <summary>
  259. /// Return the file name.
  260. /// Or
  261. /// Change the file name. Used by the resource system.
  262. /// </summary>
  263. public string Name {
  264. get {
  265. return GetName ();
  266. }
  267. set {
  268. SetName (value);
  269. }
  270. }
  271. /// <summary>
  272. /// Return a checksum of the file contents using the SDBM hash algorithm.
  273. /// </summary>
  274. public uint Checksum {
  275. get {
  276. return GetChecksum ();
  277. }
  278. }
  279. /// <summary>
  280. /// Return the open mode.
  281. /// </summary>
  282. public FileMode Mode {
  283. get {
  284. return GetMode ();
  285. }
  286. }
  287. /// <summary>
  288. /// Return the file handle.
  289. /// </summary>
  290. public IntPtr FileHandle {
  291. get {
  292. return GetHandle ();
  293. }
  294. }
  295. /// <summary>
  296. /// Return whether the file originates from a package.
  297. /// </summary>
  298. public bool Packaged {
  299. get {
  300. return IsPackaged ();
  301. }
  302. }
  303. }
  304. }