Skip to content

Commit 3149059

Browse files
committed
API for "has project file first save completed"
1 parent 6857114 commit 3149059

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

binaryninjaapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,6 +3656,8 @@ namespace BinaryNinja {
36563656
bool SetFolder(Ref<ProjectFolder> folder);
36573657
bool Export(const std::string& destination) const;
36583658
int64_t GetCreationTimestamp() const;
3659+
bool IsReady() const;
3660+
bool SetReady(bool ready);
36593661
bool AddDependency(Ref<ProjectFile> file);
36603662
bool RemoveDependency(Ref<ProjectFile> file);
36613663
std::vector<Ref<ProjectFile>> GetDependencies() const;

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,8 @@ extern "C"
43894389
BINARYNINJACOREAPI BNProject* BNProjectFileGetProject(BNProjectFile* file);
43904390
BINARYNINJACOREAPI bool BNProjectFileExport(BNProjectFile* file, const char* destination);
43914391
BINARYNINJACOREAPI int64_t BNProjectFileGetCreationTimestamp(BNProjectFile* file);
4392+
BINARYNINJACOREAPI bool BNProjectFileIsReady(BNProjectFile* file);
4393+
BINARYNINJACOREAPI bool BNProjectFileSetReady(BNProjectFile* file, bool ready);
43924394
BINARYNINJACOREAPI bool BNProjectFileAddDependency(BNProjectFile* file, BNProjectFile* dep);
43934395
BINARYNINJACOREAPI bool BNProjectFileRemoveDependency(BNProjectFile* file, BNProjectFile* dep);
43944396
BINARYNINJACOREAPI BNProjectFile** BNProjectFileGetDependencies(BNProjectFile* file, size_t* count);

project.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,18 @@ int64_t ProjectFile::GetCreationTimestamp() const
680680
}
681681

682682

683+
bool ProjectFile::IsReady() const
684+
{
685+
return BNProjectFileIsReady(m_object);
686+
}
687+
688+
689+
bool ProjectFile::SetReady(bool ready)
690+
{
691+
return BNProjectFileSetReady(m_object, ready);
692+
}
693+
694+
683695
bool ProjectFile::AddDependency(Ref<ProjectFile> file)
684696
{
685697
return BNProjectFileAddDependency(m_object, file->m_object);

python/project.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ def description(self, new_description: str) -> bool:
159159
"""
160160
return core.BNProjectFileSetDescription(self._handle, new_description)
161161

162+
@property
163+
def ready(self) -> bool:
164+
"""
165+
Check if this file is ready (first save has completed)
166+
167+
:return: True if this file is ready, False otherwise
168+
"""
169+
return core.BNProjectFileIsReady(self._handle)
170+
171+
@ready.setter
172+
def ready(self, value: bool) -> bool:
173+
"""
174+
Set whether this file is ready (first save has completed)
175+
176+
:param value: Desired ready state
177+
"""
178+
return core.BNProjectFileSetReady(self._handle, value)
179+
162180
@property
163181
def folder(self) -> Optional['ProjectFolder']:
164182
"""

rust/src/project/file.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use binaryninjacore_sys::{
77
BNProjectFileGetCreationTimestamp, BNProjectFileGetDependencies, BNProjectFileGetDescription,
88
BNProjectFileGetFolder, BNProjectFileGetId, BNProjectFileGetName,
99
BNProjectFileGetPathInProject, BNProjectFileGetPathOnDisk, BNProjectFileGetProject,
10-
BNProjectFileGetRequiredBy, BNProjectFileRemoveDependency, BNProjectFileSetDescription,
11-
BNProjectFileSetFolder, BNProjectFileSetName,
10+
BNProjectFileGetRequiredBy, BNProjectFileIsReady, BNProjectFileRemoveDependency,
11+
BNProjectFileSetDescription, BNProjectFileSetFolder, BNProjectFileSetName,
12+
BNProjectFileSetReady,
1213
};
1314
use std::fmt::Debug;
1415
use std::hash::Hash;
@@ -94,6 +95,16 @@ impl ProjectFile {
9495
.unwrap()
9596
}
9697

98+
/// Check if this file is ready (first save has completed)
99+
pub fn is_ready(&self) -> bool {
100+
unsafe { BNProjectFileIsReady(self.handle.as_ptr()) }
101+
}
102+
103+
/// Set whether this file is ready (first save has completed)
104+
pub fn set_ready(&self, value: bool) -> bool {
105+
unsafe { BNProjectFileSetReady(self.handle.as_ptr(), value) }
106+
}
107+
97108
/// Get the folder that contains this file
98109
pub fn folder(&self) -> Option<Ref<ProjectFolder>> {
99110
let result = unsafe { BNProjectFileGetFolder(self.handle.as_ptr()) };
@@ -146,6 +157,7 @@ impl Debug for ProjectFile {
146157
.field("name", &self.name())
147158
.field("description", &self.description())
148159
.field("creation_time", &self.creation_time())
160+
.field("ready", &self.is_ready())
149161
.field("exists_on_disk", &self.exists_on_disk())
150162
.field("project", &self.project())
151163
.field("folder", &self.folder())

0 commit comments

Comments
 (0)