/// <summary> /// Reads the file at the specified file path. /// </summary> /// <param name="path">The specified path to read from.</param> /// <param name="callback">Callback for Filekit to call when file is read.</param> public static void ReadFile(string path, FileReadComplete callback) { #if BROWSER GCHandle filepathHandle = new GCHandle(); try { Int32 filepathLength; filepathHandle = Common.NewUTF8String(path, out filepathLength); UInt32 size; var fileSizeResult = trail_flk_get_file_size( SDK.Raw, filepathHandle.AddrOfPinnedObject(), filepathLength, out size ); if (size > int.MaxValue) { callback.Invoke(Result.FLKFileTooBig, null, 0); return; } if (fileSizeResult.IsError()) { callback.Invoke(fileSizeResult, null, 0); } var data = new byte[(int)size]; var wrapper = new FileReadWrapper(data, (int)size, callback); trail_flk_read_file( SDK.Raw, filepathHandle.AddrOfPinnedObject(), filepathLength, wrapper.arrayHandle.AddrOfPinnedObject(), size, Marshal.GetFunctionPointerForDelegate(new ReadFileCB(FileKit.OnReadFileCB)), GCHandle.ToIntPtr(GCHandle.Alloc(wrapper)) ); } finally { filepathHandle.Free(); } #else callback.Invoke(Result.InternalError, null, 0); #endif }
public void Done(Result result) { callback.Invoke(result, (byte[])arrayHandle.Target, length); }