Extensions: rename repository "remote_path" to "remote_url"

Existing repository preferences will be reset to defaults.
This commit is contained in:
Campbell Barton
2024-05-14 20:50:22 +10:00
parent e86018fc43
commit cdee8627b2
9 changed files with 61 additions and 59 deletions

View File

@@ -1637,7 +1637,7 @@ class USERPREF_UL_asset_libraries(UIList):
class USERPREF_UL_extension_repos(UIList):
def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
repo = item
icon = 'INTERNET' if repo.use_remote_path else 'DISK_DRIVE'
icon = 'INTERNET' if repo.use_remote_url else 'DISK_DRIVE'
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.prop(repo, "name", text="", icon=icon, emboss=False)
elif self.layout_type == 'GRID':
@@ -1648,7 +1648,7 @@ class USERPREF_UL_extension_repos(UIList):
if repo.enabled:
if (
(repo.use_custom_directory and repo.custom_directory == "") or
(repo.use_remote_path and repo.remote_path == "")
(repo.use_remote_url and repo.remote_url == "")
):
layout.label(text="", icon='ERROR')
@@ -1664,7 +1664,7 @@ class USERPREF_UL_extension_repos(UIList):
for index, orig_index in enumerate(sorted(
range(len(items)),
key=lambda i: (
items[i].use_remote_path is False,
items[i].use_remote_url is False,
items[i].name.lower(),
)
)):
@@ -2126,14 +2126,14 @@ class USERPREF_PT_extensions_repos(Panel):
# NOTE: changing repositories from remote to local & vice versa could be supported but is obscure enough
# that it can be hidden entirely. If there is a some justification to show this, it can be exposed.
# For now it can be accessed from Python if someone is.
# `layout.prop(active_repo, "use_remote_path", text="Use Remote URL")`
# `layout.prop(active_repo, "use_remote_url", text="Use Remote URL")`
if active_repo.use_remote_path:
if active_repo.use_remote_url:
row = layout.row()
split = row.split(factor=0.936)
if active_repo.remote_path == "":
if active_repo.remote_url == "":
split.alert = True
split.prop(active_repo, "remote_path", text="", icon='URL', placeholder="Repository URL")
split.prop(active_repo, "remote_url", text="", icon='URL', placeholder="Repository URL")
split = row.split()
layout.prop(active_repo, "use_sync_on_startup")

View File

@@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 34
#define BLENDER_FILE_SUBVERSION 35
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -107,8 +107,8 @@ bUserExtensionRepo *BKE_preferences_extension_repo_find_by_module(const UserDef
/**
* Using a full URL/remote path to find a repository that shares its prefix.
*/
bUserExtensionRepo *BKE_preferences_extension_repo_find_by_remote_path_prefix(
const UserDef *userdef, const char *remote_path_full, const bool only_enabled);
bUserExtensionRepo *BKE_preferences_extension_repo_find_by_remote_url_prefix(
const UserDef *userdef, const char *remote_url_full, const bool only_enabled);
/**
* Skip the `https` or `http` part of a URL `https://`, return zero if none is found.
*/
@@ -116,7 +116,7 @@ int BKE_preferences_extension_repo_remote_scheme_end(const char *url);
/**
* Set a name based on a URL, e.g. `https://www.example.com/path` -> `www.example.com`.
*/
void BKE_preferences_extension_remote_to_name(const char *remote_path, char name[64]);
void BKE_preferences_extension_remote_to_name(const char *remote_url, char name[64]);
int BKE_preferences_extension_repo_get_index(const UserDef *userdef,
const bUserExtensionRepo *repo);

View File

@@ -199,8 +199,8 @@ bUserExtensionRepo *BKE_preferences_extension_repo_add_default(UserDef *userdef)
{
bUserExtensionRepo *repo = BKE_preferences_extension_repo_add(
userdef, "extensions.blender.org", "blender_org", "");
STRNCPY(repo->remote_path, "https://extensions.blender.org");
repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH;
STRNCPY(repo->remote_url, "https://extensions.blender.org");
repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL;
return repo;
}
@@ -295,11 +295,11 @@ static bool url_char_is_delimiter(const char ch)
return false;
}
bUserExtensionRepo *BKE_preferences_extension_repo_find_by_remote_path_prefix(
const UserDef *userdef, const char *path_full, const bool only_enabled)
bUserExtensionRepo *BKE_preferences_extension_repo_find_by_remote_url_prefix(
const UserDef *userdef, const char *remote_url_full, const bool only_enabled)
{
const int path_full_len = strlen(path_full);
const int path_full_offset = BKE_preferences_extension_repo_remote_scheme_end(path_full);
const int path_full_len = strlen(remote_url_full);
const int path_full_offset = BKE_preferences_extension_repo_remote_scheme_end(remote_url_full);
LISTBASE_FOREACH (bUserExtensionRepo *, repo, &userdef->extension_repos) {
if (only_enabled && (repo->flag & USER_EXTENSION_REPO_FLAG_DISABLED)) {
@@ -307,16 +307,16 @@ bUserExtensionRepo *BKE_preferences_extension_repo_find_by_remote_path_prefix(
}
/* Has a valid remote path to check. */
if ((repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH) == 0) {
if ((repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL) == 0) {
continue;
}
if (repo->remote_path[0] == '\0') {
if (repo->remote_url[0] == '\0') {
continue;
}
/* Set path variables which may be offset by the "scheme". */
const char *path_repo = repo->remote_path;
const char *path_test = path_full;
const char *path_repo = repo->remote_url;
const char *path_test = remote_url_full;
int path_test_len = path_full_len;
/* Allow paths beginning with both `http` & `https` to be considered equivalent.
@@ -371,18 +371,18 @@ int BKE_preferences_extension_repo_remote_scheme_end(const char *url)
return 0;
}
void BKE_preferences_extension_remote_to_name(const char *remote_path,
void BKE_preferences_extension_remote_to_name(const char *remote_url,
char name[sizeof(bUserExtensionRepo::name)])
{
name[0] = '\0';
if (int offset = BKE_preferences_extension_repo_remote_scheme_end(remote_path)) {
remote_path += (offset + 3);
if (int offset = BKE_preferences_extension_repo_remote_scheme_end(remote_url)) {
remote_url += (offset + 3);
}
if (UNLIKELY(remote_path[0] == '\0')) {
if (UNLIKELY(remote_url[0] == '\0')) {
return;
}
const char *c = remote_path;
const char *c = remote_url;
/* Skip any delimiters (likely forward slashes for `file:///` on UNIX). */
while (*c && url_char_is_delimiter(*c)) {
c++;
@@ -393,7 +393,7 @@ void BKE_preferences_extension_remote_to_name(const char *remote_path,
}
BLI_strncpy_utf8(
name, remote_path, std::min(size_t(c - remote_path) + 1, sizeof(bUserExtensionRepo::name)));
name, remote_url, std::min(size_t(c - remote_url) + 1, sizeof(bUserExtensionRepo::name)));
}
int BKE_preferences_extension_repo_get_index(const UserDef *userdef,

View File

@@ -943,11 +943,14 @@ void blo_do_versions_userdef(UserDef *userdef)
}
}
if (!USER_VERSION_ATLEAST(402, 6)) {
if (BLI_listbase_is_empty(&userdef->extension_repos)) {
BKE_preferences_extension_repo_add_default(userdef);
BKE_preferences_extension_repo_add_default_user(userdef);
if (!USER_VERSION_ATLEAST(402, 35)) {
/* Reset repositories. */
while (!BLI_listbase_is_empty(&userdef->extension_repos)) {
BKE_preferences_extension_repo_remove(
userdef, static_cast<bUserExtensionRepo *>(userdef->extension_repos.first));
}
BKE_preferences_extension_repo_add_default(userdef);
BKE_preferences_extension_repo_add_default_user(userdef);
}
/**

View File

@@ -274,7 +274,7 @@ static int preferences_extension_repo_add_exec(bContext *C, wmOperator *op)
BKE_callback_exec_null(bmain, BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE);
char name[sizeof(bUserExtensionRepo::name)] = "";
char remote_path[sizeof(bUserExtensionRepo::remote_path)] = "";
char remote_url[sizeof(bUserExtensionRepo::remote_url)] = "";
char custom_directory[sizeof(bUserExtensionRepo::custom_dirpath)] = "";
const bool use_custom_directory = RNA_boolean_get(op->ptr, "use_custom_directory");
@@ -285,7 +285,7 @@ static int preferences_extension_repo_add_exec(bContext *C, wmOperator *op)
}
if (repo_type == bUserExtensionRepoAddType::Remote) {
RNA_string_get(op->ptr, "remote_path", remote_path);
RNA_string_get(op->ptr, "remote_url", remote_url);
}
/* Setup the name using the following logic:
@@ -303,7 +303,7 @@ static int preferences_extension_repo_add_exec(bContext *C, wmOperator *op)
if (name[0] == '\0') {
switch (repo_type) {
case bUserExtensionRepoAddType::Remote: {
BKE_preferences_extension_remote_to_name(remote_path, name);
BKE_preferences_extension_remote_to_name(remote_url, name);
break;
}
case bUserExtensionRepoAddType::Local: {
@@ -351,8 +351,8 @@ static int preferences_extension_repo_add_exec(bContext *C, wmOperator *op)
}
if (repo_type == bUserExtensionRepoAddType::Remote) {
STRNCPY(new_repo->remote_path, remote_path);
new_repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH;
STRNCPY(new_repo->remote_url, remote_url);
new_repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL;
}
/* Activate new repository in the UI for further setup. */
@@ -399,7 +399,7 @@ static void preferences_extension_repo_add_ui(bContext * /*C*/, wmOperator *op)
switch (repo_type) {
case bUserExtensionRepoAddType::Remote: {
uiItemR(layout, op->ptr, "remote_path", UI_ITEM_R_IMMEDIATE, nullptr, ICON_NONE);
uiItemR(layout, op->ptr, "remote_url", UI_ITEM_R_IMMEDIATE, nullptr, ICON_NONE);
uiItemR(layout, op->ptr, "use_sync_on_startup", UI_ITEM_NONE, nullptr, ICON_NONE);
break;
}
@@ -468,12 +468,12 @@ static void PREFERENCES_OT_extension_repo_add(wmOperatorType *ot)
}
{ /* Remote Path. */
const char *prop_id = "remote_path";
const char *prop_id = "remote_url";
PropertyRNA *prop_ref = RNA_struct_type_find_property(type_ref, prop_id);
PropertyRNA *prop = RNA_def_string(ot->srna,
prop_id,
nullptr,
sizeof(bUserExtensionRepo::remote_path),
sizeof(bUserExtensionRepo::remote_url),
RNA_property_ui_name_raw(prop_ref),
RNA_property_ui_description_raw(prop_ref));
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
@@ -529,7 +529,7 @@ static bool preferences_extension_repo_remote_active_enabled_poll(bContext *C)
const bUserExtensionRepo *repo = BKE_preferences_extension_repo_find_index(
&U, U.active_extension_repo);
if (repo == nullptr || (repo->flag & USER_EXTENSION_REPO_FLAG_DISABLED) ||
!(repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH))
!(repo->flag & USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL))
{
CTX_wm_operator_poll_msg_set(C, "An enabled remote repository must be selected");
return false;
@@ -954,7 +954,7 @@ static bool drop_extension_url_poll(bContext * /*C*/, wmDrag *drag, const wmEven
/* Check the URL has a `.zip` suffix OR has a known repository as a prefix.
* This is needed to support redirects which don't contain an extension. */
if (!(cstr_ext && STRCASEEQ(cstr_ext, ".zip")) &&
!BKE_preferences_extension_repo_find_by_remote_path_prefix(&U, cstr, true))
!BKE_preferences_extension_repo_find_by_remote_url_prefix(&U, cstr, true))
{
return false;
}

View File

@@ -33,7 +33,7 @@
.name = {'\0'}, \
.module = {'\0'}, \
.custom_dirpath = {'\0'}, \
.remote_path = {'\0'}, \
.remote_url = {'\0'}, \
.flag = 0, \
}

View File

@@ -641,7 +641,7 @@ typedef struct bUserExtensionRepo {
* When unset, use `{BLENDER_USER_EXTENSIONS}/{bUserExtensionRepo::module}`.
*/
char custom_dirpath[1024]; /* FILE_MAX */
char remote_path[1024]; /* FILE_MAX */
char remote_url[1024]; /* FILE_MAX */
int flag;
char _pad0[4];
@@ -652,7 +652,7 @@ typedef enum eUserExtensionRepo_Flag {
USER_EXTENSION_REPO_FLAG_NO_CACHE = 1 << 0,
USER_EXTENSION_REPO_FLAG_DISABLED = 1 << 1,
USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY = 1 << 2,
USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH = 1 << 3,
USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL = 1 << 3,
USER_EXTENSION_REPO_FLAG_SYNC_ON_STARTUP = 1 << 4,
} eUserExtensionRepo_Flag;

View File

@@ -420,10 +420,10 @@ static void rna_userdef_extension_repo_use_custom_directory_set(PointerRNA *ptr,
ptr, value, USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY);
}
static void rna_userdef_extension_repo_use_remote_path_set(PointerRNA *ptr, bool value)
static void rna_userdef_extension_repo_use_remote_url_set(PointerRNA *ptr, bool value)
{
rna_userdef_extension_repo_generic_flag_set_impl(
ptr, value, USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH);
ptr, value, USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL);
}
static void rna_userdef_script_autoexec_update(Main * /*bmain*/,
@@ -525,7 +525,7 @@ static void rna_userdef_asset_library_remove(ReportList *reports, PointerRNA *pt
static bUserExtensionRepo *rna_userdef_extension_repo_new(const char *name,
const char *module,
const char *custom_directory,
const char *remote_path)
const char *remote_url)
{
Main *bmain = G.main;
BKE_callback_exec_null(bmain, BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE);
@@ -533,12 +533,12 @@ static bUserExtensionRepo *rna_userdef_extension_repo_new(const char *name,
bUserExtensionRepo *repo = BKE_preferences_extension_repo_add(
&U, name ? name : "", module ? module : "", custom_directory ? custom_directory : "");
if (remote_path) {
STRNCPY(repo->remote_path, remote_path);
if (remote_url) {
STRNCPY(repo->remote_url, remote_url);
}
if (repo->remote_path[0]) {
repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH;
if (repo->remote_url[0]) {
repo->flag |= USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL;
}
if (repo->custom_dirpath[0]) {
repo->flag |= USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY;
@@ -6699,8 +6699,8 @@ static void rna_def_userdef_filepaths_extension_repo(BlenderRNA *brna)
"rna_userdef_extension_repo_directory_length",
nullptr);
prop = RNA_def_property(srna, "remote_path", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, nullptr, "remote_path");
prop = RNA_def_property(srna, "remote_url", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, nullptr, "remote_url");
RNA_def_property_ui_text(prop, "URL", "Remote URL or path for extension repository");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_FILEBROWSER);
RNA_def_property_update(prop, 0, "rna_userdef_update");
@@ -6733,11 +6733,10 @@ static void rna_def_userdef_filepaths_extension_repo(BlenderRNA *brna)
RNA_def_property_boolean_funcs(
prop, nullptr, "rna_userdef_extension_repo_use_custom_directory_set");
prop = RNA_def_property(srna, "use_remote_path", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", USER_EXTENSION_REPO_FLAG_USE_REMOTE_PATH);
RNA_def_property_ui_text(
prop, "Use Remote", "Synchronize the repository with a remote URL/path");
RNA_def_property_boolean_funcs(prop, nullptr, "rna_userdef_extension_repo_use_remote_path_set");
prop = RNA_def_property(srna, "use_remote_url", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL);
RNA_def_property_ui_text(prop, "Use Remote", "Synchronize the repository with a remote URL");
RNA_def_property_boolean_funcs(prop, nullptr, "rna_userdef_extension_repo_use_remote_url_set");
}
static void rna_def_userdef_script_directory(BlenderRNA *brna)
@@ -6855,7 +6854,7 @@ static void rna_def_userdef_extension_repos_collection(BlenderRNA *brna, Propert
"Custom Directory",
"");
RNA_def_string(
func, "remote_path", nullptr, sizeof(bUserExtensionRepo::remote_path), "Remote Path", "");
func, "remote_url", nullptr, sizeof(bUserExtensionRepo::remote_url), "Remote URL", "");
/* return type */
parm = RNA_def_pointer(func, "repo", "UserExtensionRepo", "", "Newly added repository");