Skip to content

Commit 5111bc0

Browse files
committed
Initial progress towards new remote project ux
1 parent c3f286e commit 5111bc0

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

binaryninjaapi.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,10 @@ namespace BinaryNinja {
27522752
bool Export(const std::string& destination, const std::function<bool(size_t progress, size_t total)>& progressCallback = {}) const;
27532753
};
27542754

2755+
namespace Collaboration
2756+
{
2757+
class RemoteFile;
2758+
}
27552759
/*!
27562760

27572761
\ingroup project
@@ -2773,6 +2777,7 @@ namespace BinaryNinja {
27732777
void SetFolder(Ref<ProjectFolder> folder);
27742778
bool Export(const std::string& destination) const;
27752779
int64_t GetCreationTimestamp() const;
2780+
Ref<Collaboration::RemoteFile> GetRemoteFile() const;
27762781
};
27772782

27782783

@@ -20436,8 +20441,9 @@ namespace BinaryNinja::Collaboration
2043620441
Ref<RemoteFile> GetFileByName(const std::string& name);
2043720442
void PullFiles(std::function<bool(size_t, size_t)> progress = {});
2043820443
void PullFolders(std::function<bool(size_t, size_t)> progress = {});
20439-
Ref<RemoteFile> CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress = {}, Ref<ProjectFile> coreFile = nullptr);
20440-
Ref<RemoteFolder> CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress = {}, Ref<ProjectFolder> coreFolder = nullptr);
20444+
Ref<RemoteFile> UploadProjectFile(Ref<ProjectFile> projectFile, std::function<bool(size_t, size_t)> progress);
20445+
Ref<RemoteFile> CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress = {});
20446+
Ref<RemoteFolder> CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress = {});
2044120447
void PushFile(Ref<RemoteFile> file, const std::vector<std::pair<std::string, std::string>>& extraFields = {});
2044220448
void PushFolder(Ref<RemoteFolder> folder, const std::vector<std::pair<std::string, std::string>>& extraFields = {});
2044320449
void DeleteFolder(const Ref<RemoteFolder> folder);

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,7 @@ extern "C"
39243924
BINARYNINJACOREAPI BNProject* BNProjectFileGetProject(BNProjectFile* file);
39253925
BINARYNINJACOREAPI bool BNProjectFileExport(BNProjectFile* file, const char* destination);
39263926
BINARYNINJACOREAPI int64_t BNProjectFileGetCreationTimestamp(BNProjectFile* file);
3927+
BINARYNINJACOREAPI BNRemoteFile* BNProjectFileGetRemoteFile(BNProjectFile* file);
39273928

39283929

39293930
// ProjectFolder object
@@ -7916,6 +7917,7 @@ extern "C"
79167917
BINARYNINJACOREAPI BNRemoteFile* BNRemoteProjectGetFileById(BNRemoteProject* project, const char* id);
79177918
BINARYNINJACOREAPI BNRemoteFile* BNRemoteProjectGetFileByName(BNRemoteProject* project, const char* name);
79187919
BINARYNINJACOREAPI bool BNRemoteProjectPullFiles(BNRemoteProject* project, BNProgressFunction progress, void* progressContext);
7920+
BINARYNINJACOREAPI BNRemoteFile* BNRemoteProjectUploadProjectFile(BNRemoteProject* project, BNProjectFile* file, BNProgressFunction progress, void* progressContext);
79197921
BINARYNINJACOREAPI BNRemoteFile* BNRemoteProjectCreateFile(BNRemoteProject* project, const char* filename, uint8_t* contents, size_t contentsSize, const char* name, const char* description, BNRemoteFolder* folder, BNRemoteFileType type, BNProgressFunction progress, void* progressContext);
79207922
BINARYNINJACOREAPI bool BNRemoteProjectPushFile(BNRemoteProject* project, BNRemoteFile* file, const char** extraFieldKeys, const char** extraFieldValues, size_t extraFieldCount);
79217923
BINARYNINJACOREAPI bool BNRemoteProjectDeleteFile(BNRemoteProject* project, BNRemoteFile* file);

collaboration.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,18 @@ void RemoteProject::PullFolders(std::function<bool(size_t, size_t)> progress)
13531353
}
13541354

13551355

1356-
Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress, Ref<ProjectFile> coreFile)
1356+
Ref<RemoteFile> RemoteProject::UploadProjectFile(Ref<ProjectFile> projectFile, std::function<bool(size_t, size_t)> progress)
1357+
{
1358+
ProgressContext pctxt;
1359+
pctxt.callback = progress;
1360+
BNRemoteFile* remoteFile = BNRemoteProjectUploadProjectFile(m_object, projectFile->m_object, ProgressCallback, &pctxt);
1361+
if (remoteFile == nullptr)
1362+
return nullptr;
1363+
return new RemoteFile(remoteFile);
1364+
}
1365+
1366+
1367+
Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress)
13571368
{
13581369
ProgressContext pctxt;
13591370
pctxt.callback = progress;
@@ -1364,7 +1375,7 @@ Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vect
13641375
}
13651376

13661377

1367-
Ref<RemoteFolder> RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress, Ref<ProjectFolder> coreFolder)
1378+
Ref<RemoteFolder> RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress)
13681379
{
13691380
ProgressContext pctxt;
13701381
pctxt.callback = progress;

project.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,17 @@ int64_t ProjectFile::GetCreationTimestamp() const
625625
}
626626

627627

628+
Ref<Collaboration::RemoteFile> ProjectFile::GetRemoteFile() const
629+
{
630+
631+
BNRemoteFile* remoteFile = BNProjectFileGetRemoteFile(m_object);
632+
if (remoteFile == nullptr)
633+
return nullptr;
634+
return new Collaboration::RemoteFile(remoteFile);
635+
}
636+
637+
638+
628639
ProjectFolder::ProjectFolder(BNProjectFolder* folder)
629640
{
630641
m_object = folder;

ui/projectbrowser.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ class BINARYNINJAUIAPI ProjectStatusWidget: public MenuHelper
4141
};
4242

4343

44+
class BINARYNINJAUIAPI ProjectItemDelegate: public QStyledItemDelegate
45+
{
46+
Q_OBJECT
47+
48+
ProjectRef m_project;
49+
50+
public:
51+
ProjectItemDelegate(ProjectRef project, QObject* parent = nullptr);
52+
53+
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
54+
};
55+
56+
4457
class BINARYNINJAUIAPI ProjectItemModel: public QStandardItemModel, public BinaryNinja::ProjectNotification
4558
{
4659
Q_OBJECT
@@ -101,15 +114,27 @@ class BINARYNINJAUIAPI ProjectItemModel: public QStandardItemModel, public Binar
101114
IdRole,
102115
DiskPathRole,
103116
SortRole,
117+
SyncStateRole,
104118
};
105119

106120
enum {
107121
FileType,
108122
FolderType,
109123
};
110124

125+
enum SyncState {
126+
Synced,
127+
Unknown,
128+
MissingFromRemote,
129+
MissingFromLocal,
130+
MissingFromLocalAndRemote, // For folders that have some contents missing from either
131+
Uploading,
132+
Downloading,
133+
};
134+
111135
enum {
112136
COL_NAME = 0,
137+
COL_SYNC_STATUS,
113138
COL_TYPE,
114139
COL_SIZE_ON_DISK,
115140
COL_CREATED,
@@ -342,6 +367,8 @@ private slots:
342367
void PromptEditProjectDetails();
343368
void Refresh();
344369
void DownloadSelectedFilesRecursive();
370+
void UploadSelectedFilesRecursive();
371+
345372

346373
public:
347374
ProjectBrowser(QWidget* parent, ProjectRef project);

0 commit comments

Comments
 (0)