pmt: initial 2.4.0 update

This commit is contained in:
2024-07-09 19:26:18 +03:00
parent 4dd49c2509
commit 964d9b5426
21 changed files with 487 additions and 313 deletions

158
jni/pmt.c
View File

@@ -68,8 +68,10 @@ check_optsym(const char* _Nonnull mystring)
{
if (strncmp(mystring, opt_symbol, 1) == 0)
{
if (!pmt_force_mode) error(1, "%s", common_symbol_rule);
else exit(1);
if (!pmt_force_mode)
LOGE("%s\n", common_symbol_rule);
else
exit(1);
}
}
@@ -81,31 +83,40 @@ check_optsym(const char* _Nonnull mystring)
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
get_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
struct stat search_stat;
struct stat get_stat;
if (stat(filepath, &search_stat) != 0) return 0;
if (stat(filepath, &get_stat) != 0)
return 0;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
if (S_ISDIR(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
if (S_ISREG(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
if (S_ISBLK(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
if (S_ISLNK(get_stat.st_mode))
return 0;
else
return -1;
}
return 0;
@@ -120,19 +131,24 @@ int main(int argc, char* argv[])
static char* langctrl_str;
langctrl_str = loadlang();
if (strcmp(langctrl_str, "en") == 0) current = &en;
else if (strcmp(langctrl_str, "tr") == 0) current = &tr;
if (strcmp(langctrl_str, "en") == 0)
current = &en;
else if (strcmp(langctrl_str, "tr") == 0)
current = &tr;
sprintf(common_symbol_rule, "%s\n", current->common_symbol_rule);
if (search_sls() == 0)
{
if (current->welcome_ != NULL) printf("%s", current->welcome_);
printf("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
if (current->welcome_ != NULL)
LOGD("%s\n", current->welcome_);
LOGD("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
}
/* check argument total */
if (argc < 2) error(1, "%s\n%s `%s --help' %s.", current->missing_operand, current->try_h, argv[0], current->for_more);
if (argc < 2)
LOGE("%s\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, argv[0], current->for_more);
/* a structure for long arguments */
struct option long_options[] = {
@@ -171,22 +187,16 @@ int main(int argc, char* argv[])
case 'l':
check_root();
check_dev_point();
if (pmt_logical) pmt_use_logical = true;
if (pmt_logical)
pmt_use_logical = true;
else
{
if (!pmt_force_mode) error(1, "%s", current->not_logical);
else return 1;
}
LOGE("%s\n", current->not_logical);
break;
/* context selector option */
case 'c':
pmt_use_cust_cxt = true;
cust_cxt = strdup(optarg);
if (strncmp(cust_cxt, opt_symbol, 1) == 0)
{
if (!pmt_force_mode) error(1, "%s", common_symbol_rule);
else return 1;
}
check_optsym(cust_cxt);
break;
/* partition lister function */
case 'p':
@@ -227,17 +237,18 @@ int main(int argc, char* argv[])
break;
/* for invalid options */
case '?':
printf("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more);
LOGD("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more);
return 1;
break;
default:
printf("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
return 1;
}
}
/* stop the program if multiple viewer is used */
if (combo_wiewers) error(1, "%s", current->multiple_wiewers);
if (combo_wiewers)
LOGE("%s", current->multiple_wiewers);
/* controller to handle viewer */
if (wiew_help)
@@ -263,10 +274,10 @@ int main(int argc, char* argv[])
if (pmt_setlang)
{
printf("%s: %s\n", argv[0], current->switching_lang);
LOGD("%s: %s\n", argv[0], current->switching_lang);
setlang(langpr);
sleep(2);
printf("%s: %s.\n", argv[0], current->please_rerun);
LOGD("%s: %s.\n", argv[0], current->please_rerun);
return 0;
}
@@ -285,10 +296,7 @@ int main(int argc, char* argv[])
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_silent) error(1, "%s 0.", current->expected_backup_arg);
else return 1;
}
LOGE("%s 0.\n", current->expected_backup_arg);
target_partition = argv[getvar_temp];
@@ -303,6 +311,7 @@ int main(int argc, char* argv[])
check_optsym(out);
pmt_backup = true;
break;
}
else if (strcmp(argv[argtest], "flash") == 0)
@@ -310,16 +319,10 @@ int main(int argc, char* argv[])
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_force_mode || !pmt_silent) error(1, "%s 0.", current->expected_flash_arg);
else return 1;
}
LOGE("%s 0.\n", current->expected_flash_arg);
if (argc == check_getvar_temp)
{
if (!pmt_force_mode || !pmt_silent) error(1, "%s 1.", current->expected_flash_arg);
else return 1;
}
LOGE("%s 1.\n", current->expected_flash_arg);
target_flash_file = argv[getvar_temp];
@@ -330,6 +333,7 @@ int main(int argc, char* argv[])
check_optsym(target_partition);
pmt_flash = true;
break;
}
else if (strcmp(argv[argtest], "format") == 0)
@@ -337,16 +341,10 @@ int main(int argc, char* argv[])
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_force_mode) error(1, "%s 0.", current->expected_format_arg);
else return 1;
}
LOGE("%s 0.\n", current->expected_format_arg);
if (argc == check_getvar_temp)
{
if (!pmt_force_mode) error(1, "%s 1.", current->expected_format_arg);
else return 1;
}
LOGE("%s 1.\n", current->expected_format_arg);
format_fs = argv[getvar_temp];
@@ -357,13 +355,14 @@ int main(int argc, char* argv[])
check_optsym(target_partition);
pmt_format = true;
break;
}
}
/* target control is done */
if (!pmt_backup && !pmt_flash && !pmt_format && !pmt_silent) error(1, "%s\n%s `%s --help` %s", argv[0], current->missing_operand, current->try_h, current->for_more);
else return 1;
if (!pmt_backup && !pmt_flash && !pmt_format)
LOGE("%s `%s --help` %s\n", current->missing_operand, current->try_h, current->for_more);
/* checks */
check_root();
@@ -372,54 +371,37 @@ int main(int argc, char* argv[])
if (pmt_format)
{
if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
{
if (!pmt_force_mode) error(1, "%s: %s", current->unsupported_fs, format_fs);
else return 1;
}
LOGE("%s: %s\n", current->unsupported_fs, format_fs);
}
if (pmt_flash)
{
search_result = search_stat(target_flash_file, "file");
search_result = get_stat(target_flash_file, "file");
if (search_result == 1)
{
if (!pmt_silent) error(1, "%s `%s': %s", current->cannot_stat, target_flash_file, strerror(errno));
else return 1;
}
LOGE("%s `%s': %s\n", current->cannot_stat, target_flash_file, strerror(errno));
else if (search_result == -1)
{
if (!pmt_silent) error(1, "`%s': %s", target_flash_file, current->not_file);
else return 1;
}
LOGE("`%s': %s\n", target_flash_file, current->not_file);
}
/* custom context checker */
if (pmt_use_cust_cxt)
{
search_result = search_stat(cust_cxt, "dir");
search_result = get_stat(cust_cxt, "dir");
if (search_result == 1)
{
if (!pmt_silent) error(1, "%s `%s': %s", current->cannot_stat, cust_cxt, strerror(errno));
else return 1;
}
LOGE("%s `%s': %s\n", current->cannot_stat, cust_cxt, strerror(errno));
else if (search_result == -1)
{
if (!pmt_silent) error(1, "`%s': %s", cust_cxt, current->not_dir);
else return 1;
}
LOGE("`%s': %s\n", cust_cxt, current->not_dir);
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode) error(1, "%s", current->not_in_dev);
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode)
LOGE("%s\n", current->not_in_dev);
}
if (target_partition == NULL)
{
if (!pmt_force_mode)
{
if (!pmt_silent) error(1, "%s\n%s `%s --help' %s", current->req_part_name, current->try_h, argv[0], current->for_more);
}
else return 1;
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, argv[0], current->for_more);
}
else
{
@@ -430,10 +412,14 @@ int main(int argc, char* argv[])
*
* 3 = format
*/
if (pmt_backup) return pmt(1);
else if (pmt_flash) return pmt(2);
else if (pmt_format) return pmt(3);
else if (!pmt_silent) error(1, "%s\n%s `%s --help' %s", current->no_target, current->try_h, argv[0], current->for_more);
if (pmt_backup)
return pmt(1);
else if (pmt_flash)
return pmt(2);
else if (pmt_format)
return pmt(3);
else
LOGE("%s\n%s `%s --help' %s\n", current->no_target, current->try_h, argv[0], current->for_more);
}
}