2022-09-03 18:47:48 +00:00
|
|
|
/* radare - LGPL - Copyright 2020-2022 - pancake */
|
2021-01-02 11:25:28 +00:00
|
|
|
|
|
|
|
// project class definition to be used by project.c
|
|
|
|
|
2022-05-26 17:52:01 +00:00
|
|
|
#include "rvc.h"
|
2021-01-02 11:25:28 +00:00
|
|
|
#include <r_core.h>
|
|
|
|
|
|
|
|
R_API RProject *r_project_new(void) {
|
|
|
|
RProject *p = R_NEW0 (RProject);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_project_rename(RProject *p, const char *newname) {
|
2021-01-02 11:27:36 +00:00
|
|
|
if (!r_project_is_loaded (p)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char *newprjdir = r_file_new (p->path, "..", newname, NULL);
|
|
|
|
if (r_file_exists (newprjdir)) {
|
2022-09-03 18:47:48 +00:00
|
|
|
R_LOG_ERROR ("Cannot rename project");
|
2021-01-02 11:27:36 +00:00
|
|
|
free (newprjdir);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
r_file_move (p->path, newprjdir);
|
|
|
|
free (p->path);
|
|
|
|
p->path = newprjdir;
|
|
|
|
free (p->name);
|
|
|
|
p->name = strdup (newname);
|
2021-01-02 11:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_project_is_git(RProject *p) {
|
|
|
|
char *f = r_str_newf ("%s"R_SYS_DIR".git", p->path);
|
|
|
|
bool ig = r_file_is_directory (f);
|
|
|
|
free (f);
|
|
|
|
return ig;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_project_close(RProject *p) {
|
|
|
|
// close the current project
|
|
|
|
R_FREE (p->name);
|
|
|
|
R_FREE (p->path);
|
2022-05-26 17:52:01 +00:00
|
|
|
r_vc_close (p->rvc, true);
|
2022-05-26 20:18:07 +00:00
|
|
|
p->rvc = NULL;
|
2021-01-02 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_project_open(RProject *p, const char *name, const char *path) {
|
|
|
|
r_return_val_if_fail (p && !R_STR_ISEMPTY (name), false);
|
|
|
|
if (r_project_is_loaded (p)) {
|
2021-01-03 00:21:47 +00:00
|
|
|
if (!strcmp (name, p->name)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-02 11:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p->name = strdup (name);
|
|
|
|
if (path) {
|
|
|
|
p->path = strdup (path);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_project_save(RProject *p) {
|
|
|
|
// must call r_core_project_save()
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_project_free(RProject *p) {
|
|
|
|
if (p) {
|
|
|
|
free (p->name);
|
|
|
|
free (p->path);
|
|
|
|
free (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_project_is_loaded(RProject *p) {
|
|
|
|
return !R_STR_ISEMPTY (p->name);
|
|
|
|
}
|