Skip to content

Commit 0893cdf

Browse files
committed
feat: OpenExistingDatabaseAsync
1 parent d5f567b commit 0893cdf

File tree

1 file changed

+117
-4
lines changed

1 file changed

+117
-4
lines changed

Handle/BNBinaryView.cs

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public ulong Length
135135
}
136136

137137
public BinaryView? Load(
138-
bool updateAnalysis ,
139-
string options ,
140-
ProgressDelegate? progress
138+
bool updateAnalysis = false ,
139+
string options = "",
140+
ProgressDelegate? progress = null
141141
)
142142
{
143143
return BinaryView.TakeHandle(
@@ -154,6 +154,63 @@ public ulong Length
154154
)
155155
);
156156
}
157+
158+
public Task<BinaryView?> LoadAsync(
159+
bool updateAnalysis = false,
160+
string options = "" ,
161+
CancellationToken? cancellationToken = null
162+
)
163+
{
164+
return Task.Run(() =>
165+
{
166+
bool cancelled = false;
167+
168+
ProgressDelegate progress = (param2 , param3) =>
169+
{
170+
if (null != cancellationToken)
171+
{
172+
if (cancellationToken.GetValueOrDefault().IsCancellationRequested)
173+
{
174+
cancelled = true;
175+
176+
return false;
177+
}
178+
}
179+
180+
return true;
181+
};
182+
183+
if (cancelled)
184+
{
185+
return null;
186+
}
187+
188+
BinaryView? view = BinaryView.TakeHandle(
189+
NativeMethods.BNLoadBinaryView(
190+
this.handle ,
191+
updateAnalysis ,
192+
options ,
193+
Marshal.GetFunctionPointerForDelegate<NativeDelegates.BNProgressFunction>(
194+
UnsafeUtils.WrapProgressDelegate(progress)
195+
),
196+
IntPtr.Zero
197+
)
198+
);
199+
200+
if (null == view)
201+
{
202+
return null;
203+
}
204+
205+
if (cancelled && ( null != cancellationToken) )
206+
{
207+
cancellationToken.GetValueOrDefault().ThrowIfCancellationRequested();
208+
}
209+
210+
return view;
211+
}
212+
);
213+
}
157214

158215
/// <summary>
159216
///
@@ -241,7 +298,7 @@ public ulong Length
241298
);
242299
}
243300

244-
public static BinaryView? OpenExisting(string filename , ProgressDelegate? progress = null)
301+
public static BinaryView? OpenExistingDatabase(string filename , ProgressDelegate? progress = null)
245302
{
246303
FileMetadata file = new FileMetadata(filename);
247304

@@ -269,6 +326,62 @@ public ulong Length
269326
}
270327
}
271328

329+
public static Task<BinaryView?> OpenExistingDatabaseAsync(
330+
string filename ,
331+
CancellationToken? cancellationToken = null
332+
)
333+
{
334+
return Task.Run(() =>
335+
{
336+
bool cancelled = false;
337+
338+
ProgressDelegate progress = (param2 , param3) =>
339+
{
340+
if (null != cancellationToken)
341+
{
342+
if (cancellationToken.GetValueOrDefault().IsCancellationRequested)
343+
{
344+
cancelled = true;
345+
346+
return false;
347+
}
348+
}
349+
350+
return true;
351+
};
352+
353+
if (cancelled)
354+
{
355+
return null;
356+
}
357+
358+
FileMetadata file = new FileMetadata(filename);
359+
360+
BinaryView? view = BinaryView.TakeHandle(
361+
NativeMethods.BNOpenExistingDatabaseWithProgress(
362+
file.DangerousGetHandle() ,
363+
filename ,
364+
Marshal.GetFunctionPointerForDelegate<NativeDelegates.BNProgressFunction>(
365+
UnsafeUtils.WrapProgressDelegate(progress)) ,
366+
IntPtr.Zero
367+
)
368+
);
369+
370+
if (null == view)
371+
{
372+
return null;
373+
}
374+
375+
if (cancelled && ( null != cancellationToken) )
376+
{
377+
cancellationToken.GetValueOrDefault().ThrowIfCancellationRequested();
378+
}
379+
380+
return view;
381+
}
382+
);
383+
}
384+
272385
public BinaryView? Parent
273386
{
274387
get

0 commit comments

Comments
 (0)