Compare commits

...

2 commits

Author SHA1 Message Date
William Wilgus
1c3e9c181e [Fix Red] openplugins -- import and export thru settings save / restore settings
Change-Id: Ief990b282459637a2f5974b46a6250a52b444cc0
2026-01-22 11:19:44 -05:00
William Wilgus
045d148697 openplugins -- import and export thru settings save / restore settings
saves openplugin entries to the config file for later import to the database

lang_english_to_id() allows entries to be transfered between builds

Change-Id: I47e01c5f75f8b0e69c203828e21759ef24bf125d
2026-01-22 10:41:50 -05:00
4 changed files with 109 additions and 4 deletions

View file

@ -27,6 +27,7 @@
#include "splash.h" #include "splash.h"
#include "lang.h" #include "lang.h"
#include "filetypes.h" #include "filetypes.h"
#include "language.h" /*lang_english_to_id*/
/* Define LOGF_ENABLE to enable logf output in this file */ /* Define LOGF_ENABLE to enable logf output in this file */
/*#define LOGF_ENABLE*/ /*#define LOGF_ENABLE*/
@ -520,4 +521,86 @@ void open_plugin_cache_flush(void)
op_update_dat(op_entry, true); op_update_dat(op_entry, true);
} }
static bool op_entry_read(int fd, int selected_item, off_t data_sz, struct open_plugin_entry_t *op_entry)
{
op_clear_entry(op_entry);
return ((selected_item >= 0) && (fd >= 0) &&
(lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) &&
(read(fd, op_entry, data_sz) == data_sz) && op_entry_checksum(op_entry) > 0);
}
void open_plugin_import(char *strdat)
{
/* Note: Destroys strdat */
char *vect[5];
/* expected openplugin strdat: "englishid", "name", "path", "param" */
if (split_string(strdat, ',', vect, 5) == 4)
{
/* Space for 5 values so we will fail if excess arguments or too few */
for(int i = 0; i < 4; i++)
{
vect[i] = skip_whitespace(vect[i]);
int eos = ((int)strlen(vect[i]))-2;
/* Failure if string is not quoted */
if (vect[i][0] != '"' || eos < 0 || vect[i][eos + 1] != '"')
{
logf("%s[%d] error: quoted string expected\n", __func__, i);
return;
}
vect[i]++; /* skip first " */
vect[i][eos] = '\0'; /* skip other " */
}
char *key = vect[1];
int lang_id = lang_english_to_id(vect[0]);
if (lang_id >= 0)
key = ID2P(lang_id);
/* if key exists it will be overwritten */
open_plugin_add_path(key, vect[2], vect[3]);
return;
}
logf("%s error: importing entries", __func__);
}
void open_plugin_export(int cfg_fd)
{
/* NOTE: assumes cfg_fd is valid */
char *lang_name;
int fd;
int index = 0;
struct open_plugin_entry_t *op_entry = open_plugin_get_entry();
/* if another entry is loaded; flush it to disk before we destroy it */
op_update_dat(op_entry, true);
fd = open(OPEN_PLUGIN_DAT, O_RDONLY, 0666);
if (fd < 0)
{
logf("%s error: opening %s", __func__, OPEN_PLUGIN_DAT);
return; /* OPEN_PLUGIN_NOT_FOUND */
}
while (op_entry_read(fd, index++, op_entry_sz, op_entry))
{
/* don't save the LANG_OPEN_PLUGIN entry -- it is for internal use */
if (op_entry->lang_id == LANG_OPEN_PLUGIN)
{
continue;
}
if (op_entry->lang_id >=0)
lang_name = P2STR(ID2P(op_entry->lang_id));
else
lang_name = "[USER]"; /* needs to be an invalid lang string */
fdprintf(cfg_fd,"%s: \"%s\", \"%s\", \"%s\", \"%s\"\n",
"openplugin", lang_name, op_entry->name, op_entry->path, op_entry->param);
logf("openplugin[%d]: \"%s\", \"%s\", \"%s\", \"%s\"\n lang id: %d hash: %x, csum: %x\n",
index, lang_name, op_entry->name, op_entry->path, op_entry->param,
op_entry->lang_id, op_entry->hash, op_entry->checksum);
}
close(fd);
logf("%s exported %d entries", __func__, index);
}
#endif /* ndef __PCTOOL__ */ #endif /* ndef __PCTOOL__ */

View file

@ -84,6 +84,8 @@ int open_plugin_load_entry(const char *key);
void open_plugin_browse(const char *key); void open_plugin_browse(const char *key);
int open_plugin_run(const char *key); int open_plugin_run(const char *key);
void open_plugin_cache_flush(void); /* flush to disk */ void open_plugin_cache_flush(void); /* flush to disk */
void open_plugin_import(char *strdat);
void open_plugin_export(int cfg_fd);
#endif #endif
#endif /*ndef __PCTOOL__ */ #endif /*ndef __PCTOOL__ */

View file

@ -80,6 +80,7 @@
#endif #endif
#ifndef __PCTOOL__ #ifndef __PCTOOL__
#include "open_plugin.h"
struct user_settings global_settings; struct user_settings global_settings;
struct system_status global_status; struct system_status global_status;
static uint32_t user_settings_crc; static uint32_t user_settings_crc;
@ -293,11 +294,11 @@ bool copy_filename_setting(char *buf, size_t buflen, const char *input,
return true; return true;
} }
void string_to_cfg(const char *name, char* value, bool *theme_changed) bool string_to_cfg(const char *name, char* value, bool *theme_changed)
{ {
const struct settings_list *setting = find_setting_by_cfgname(name); const struct settings_list *setting = find_setting_by_cfgname(name);
if (!setting) if (!setting)
return; return false;
uint32_t flags = setting->flags; uint32_t flags = setting->flags;
@ -366,6 +367,7 @@ void string_to_cfg(const char *name, char* value, bool *theme_changed)
{ {
logf("Error: %s: Not Found! [%s]\r\n", logf("Error: %s: Not Found! [%s]\r\n",
setting->cfg_name, value); setting->cfg_name, value);
return false;
} }
} }
break; break;
@ -394,6 +396,7 @@ void string_to_cfg(const char *name, char* value, bool *theme_changed)
break; break;
} }
} }
return true;
} }
bool settings_load_config(const char* file, bool apply) bool settings_load_config(const char* file, bool apply)
@ -412,7 +415,17 @@ bool settings_load_config(const char* file, bool apply)
char *name, *value; char *name, *value;
if (!settings_parseline(line, &name, &value)) if (!settings_parseline(line, &name, &value))
continue; continue;
string_to_cfg(name, value, &theme_changed);
if (!string_to_cfg(name, value, &theme_changed))
{
#ifndef __PCTOOL__
/* if we are here then name was not a valid setting */
if (!strcmp(name, "openplugin"))
{
open_plugin_import(value);
}
#endif
}
} /* while(...) */ } /* while(...) */
close(fd); close(fd);
@ -630,6 +643,13 @@ static bool settings_write_config(const char* filename, int options)
fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value); fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value);
} /* for(...) */ } /* for(...) */
#ifndef __PCTOOL__
if (options == SETTINGS_SAVE_ALL)
{
/* add openplugin entries to the open settings file */
open_plugin_export(fd);
}
#endif
close(fd); close(fd);
return true; return true;
} }

View file

@ -308,7 +308,7 @@ const struct settings_list* find_setting_by_cfgname(const char* name);
bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len); bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len);
bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str); bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str);
void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len); void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len);
void string_to_cfg(const char *name, char* value, bool *theme_changed); bool string_to_cfg(const char *name, char* value, bool *theme_changed);
bool copy_filename_setting(char *buf, size_t buflen, const char *input, bool copy_filename_setting(char *buf, size_t buflen, const char *input,
const struct filename_setting *fs); const struct filename_setting *fs);