list_chain_build_back(char *fpath)
{
FILINFO fno;
+ DIR pdir;
+ char *fname = &fpath[strnlen(fpath, 255)];
+ if (f_opendir(&pdir, fpath) != FR_OK)
+ return 1;
- // this code handles directory content deletion
- if (f_stat(fpath, &fno) != FR_OK)
- return 1; // fpath does not exist
-
- if (fno.fattrib & AM_DIR) { // process folder contents
- DIR pdir;
- char *fname = fpath + strnlen(fpath, 255);
- if (f_opendir(&pdir, fpath) != FR_OK)
- return 1;
-
- fname[0] = '/';
- fname++;
-
- while (f_readdir(&pdir, &fno) == FR_OK) {
- if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
- continue; // filter out virtual entries
- if (fname[0] == 0)
- strncpy(fname, fno.fname, fpath + 255 - fname);
- if (fno.fname[0] == 0)
- break;
- else // return value won't matter
- list_chain_build_back(fpath);
- }
+ fname[0] = '/';
+ fname++;
+
+ while (f_readdir(&pdir, &fno) == FR_OK) {
+ strncpy(fname, fno.fname, strlen(fno.fname));
+
+ if (fno.fname[0] == 0)
+ break;
- f_closedir(&pdir);
+ FILINFO f2;
+ if (f_stat(fpath, &f2) != FR_OK)
+ break;
- --fname;
- fname[0] = 0;
- } else {
- char* basename = &fpath[strlen(fpath) - 1];
- while(basename[0] != '/') basename--;
- basename++;
+ if (f2.fattrib & AM_DIR) {
+ // return value won't matter
+ list_chain_build_back(fpath);
+ } else {
+ char* basename = &fpath[strlen(fpath) - 1];
+ while(basename[0] != '/') basename--;
+ basename++;
- strncpy(chains[current_chain_index].name, basename, 64);
- strncpy(chains[current_chain_index].desc, fpath, 255);
+ strncpy(chains[current_chain_index].name, basename, 64);
+ strncpy(chains[current_chain_index].desc, fpath, 255);
- chains[current_chain_index].index = 0;
- chains[current_chain_index].allowed = call_fun;
- chains[current_chain_index].a = (uint32_t) chainload_file;
- chains[current_chain_index].b = (uint32_t) chains[current_chain_index].desc;
+ chains[current_chain_index].index = 0;
+ chains[current_chain_index].allowed = call_fun;
+ chains[current_chain_index].a = (uint32_t) chainload_file;
+ chains[current_chain_index].b = (uint32_t) chains[current_chain_index].desc;
- current_chain_index++;
+ current_chain_index++;
+ }
}
+ f_closedir(&pdir);
+ --fname;
+ fname[0] = 0;
+
return 0;
}
list_patches_build_back(char *fpath, int desc_is_path)
{
FILINFO fno;
-
- // this code handles directory content deletion
- if (f_stat(fpath, &fno) != FR_OK)
- return 1; // fpath does not exist
-
- if (fno.fattrib & AM_DIR) { // process folder contents
- DIR pdir;
- char *fname = fpath + strnlen(fpath, 255);
- if (f_opendir(&pdir, fpath) != FR_OK)
- return 1;
-
- fname[0] = '/';
- fname++;
-
- while (f_readdir(&pdir, &fno) == FR_OK) {
- if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
- continue; // filter out virtual entries
- if (fname[0] == 0)
- strncpy(fname, fno.fname, fpath + 255 - fname);
- if (fno.fname[0] == 0)
- break;
- else // return value won't matter
- list_patches_build_back(fpath, desc_is_path);
+ DIR pdir;
+ char *fname = &fpath[strnlen(fpath, 255)];
+ if (f_opendir(&pdir, fpath) != FR_OK)
+ return 1;
+
+ fname[0] = '/';
+ fname++;
+
+ while (f_readdir(&pdir, &fno) == FR_OK) {
+ strncpy(fname, fno.fname, strlen(fno.fname));
+
+ if (fno.fname[0] == 0)
+ break;
+
+ FILINFO f2;
+ if (f_stat(fpath, &f2) != FR_OK)
+ break;
+
+ if (f2.fattrib & AM_DIR) {
+ // return value won't matter
+ list_patches_build_back(fpath, desc_is_path);
+ } else {
+ struct system_patch p;
+ read_file(&p, fpath, sizeof(struct system_patch));
+
+ if (memcmp(p.magic, "AIDA", 4))
+ return 0;
+
+ strncpy(patches[current_menu_index_patches].name, p.name, 64);
+ if (desc_is_path)
+ strncpy(patches[current_menu_index_patches].desc, fpath, 255);
+ else
+ strncpy(patches[current_menu_index_patches].desc, p.desc, 255);
+ patches[current_menu_index_patches].index = p.uuid;
+ patches[current_menu_index_patches].allowed = boolean_val;
+ patches[current_menu_index_patches].a = 0;
+ patches[current_menu_index_patches].b = 0;
+ if (desc_is_path)
+ enable_list[p.uuid] = 0;
+
+ current_menu_index_patches++;
}
-
- f_closedir(&pdir);
- --fname;
- fname[0] = 0;
- } else {
- struct system_patch p;
- read_file(&p, fpath, sizeof(struct system_patch));
-
- if (memcmp(p.magic, "AIDA", 4))
- return 0;
-
- strncpy(patches[current_menu_index_patches].name, p.name, 64);
- if (desc_is_path)
- strncpy(patches[current_menu_index_patches].desc, fpath, 255);
- else
- strncpy(patches[current_menu_index_patches].desc, p.desc, 255);
- patches[current_menu_index_patches].index = p.uuid;
- patches[current_menu_index_patches].allowed = boolean_val;
- patches[current_menu_index_patches].a = 0;
- patches[current_menu_index_patches].b = 0;
- if (desc_is_path)
- enable_list[p.uuid] = 0;
-
- current_menu_index_patches++;
}
+ f_closedir(&pdir);
+ --fname;
+ fname[0] = 0;
+
return 0;
}
rrmdir_back(char *fpath)
{
FILINFO fno;
+ DIR pdir;
+ char *fname = &fpath[strnlen(fpath, 255)];
+ if (f_opendir(&pdir, fpath) != FR_OK)
+ return 1;
- // this code handles directory content deletion
- if (f_stat(fpath, &fno) != FR_OK)
- return 1; // fpath does not exist
-
- if (fno.fattrib & AM_DIR) { // process folder contents
- DIR pdir;
- char *fname = fpath + strnlen(fpath, 255);
- if (f_opendir(&pdir, fpath) != FR_OK)
- return 1;
-
- fname[0] = '/';
- fname++;
-
- while (f_readdir(&pdir, &fno) == FR_OK) {
- if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
- continue; // filter out virtual entries
- if (fname[0] == 0)
- strncpy(fname, fno.fname, fpath + 255 - fname);
- if (fno.fname[0] == 0)
- break;
- else // return value won't matter
- rrmdir_back(fpath);
- }
+ fname[0] = '/';
+ fname++;
+
+ while (f_readdir(&pdir, &fno) == FR_OK) {
+ strncpy(fname, fno.fname, strlen(fno.fname));
+
+ if (fno.fname[0] == 0)
+ break;
- f_closedir(&pdir);
+ FILINFO f2;
+ if (f_stat(fpath, &f2) != FR_OK)
+ break;
- --fname;
- fname[0] = 0;
+ if (f2.fattrib & AM_DIR) {
+ // return value won't matter
+ rrmdir_back(fpath);
+ } else {
+ f_unlink(fpath);
+ }
}
+ f_closedir(&pdir);
+ --fname;
+ fname[0] = 0;
+
return f_unlink(fpath);
}