From cf25645556d17e14fd23b25e0620e1a04df93905 Mon Sep 17 00:00:00 2001 From: luca0N! <63941044+luca0N@users.noreply.github.com> Date: Wed, 6 May 2020 15:42:15 -0300 Subject: [PATCH] Support custom dirs Signed-off-by: luca0N! <63941044+luca0N@users.noreply.github.com> --- Makefile | 9 ++++++++- cfg/pastas.ini | 8 ++++---- main.c | 36 ++++++++++++++++++++++++------------ str.h | 7 +++++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 7d3f2d3..0eda51f 100644 --- a/Makefile +++ b/Makefile @@ -23,4 +23,11 @@ main.o: main.c gcc -c -s -Os main.c clean: - rm *.o *.exe \ No newline at end of file + rm *.o *.exe + +cleandust: + rm *.o + +dustless: + make + make cleandust \ No newline at end of file diff --git a/cfg/pastas.ini b/cfg/pastas.ini index a36cc32..9779b2b 100644 --- a/cfg/pastas.ini +++ b/cfg/pastas.ini @@ -18,7 +18,7 @@ ; Contact me by e-mail via ; ; ┌──┐ │ ┌── ┌──┐ ─┬─ ┌──┐ │ -; ├──┤ │ ├─ ├──┘ │ ├──┤ │ +; ├──┤ │ ├─ ├\─┘ │ ├──┤ │ ; │ │ └── └── │ \ │ │ │ • ; ; ALERTA! @@ -30,6 +30,6 @@ [Pastas] Pastas=3 -Pasta1=%appdata% -Pasta2=%tmp% -Pasta3=C:\Windows\Temp\ \ No newline at end of file +Pasta1=%tmp%\* +Pasta2=C:\Windows\Temp\* +Pasta3=C:\Windows\Prefetch\* \ No newline at end of file diff --git a/main.c b/main.c index 24c30ac..738ce66 100644 --- a/main.c +++ b/main.c @@ -19,7 +19,8 @@ */ #include "about.h" #include "str.h" -#include "colors.h" +// Because this program is currently target at Windows only, the use of ANSI colors are no longer used as of May 5, 2020. +// #include "colors.h" #include #include @@ -46,27 +47,41 @@ int printLicense(int full){ } void getAdditionalDirs(){ - printf("%sRecolhendo pastas adicionais...\n", ANSI_COLOR_CYAN); + printf("%s\n", STR_FETCHING_ADD_DIRS); int dirs; dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, ".\\cfg\\pastas.ini"); printf("%s %d\n", STR_DIR_COUNT, dirs); fflush(stdout); for(unsigned short x = 0; x < dirs; x++){ - char dirKey[7] = "Pasta"; // PastaX... - //strcpy(dirKey, "Pasta"); + // TODO: Tell if item is a directory. If so, then iterate through all items on it. + char dirKey[7] = "Pasta"; char* intPtr = (x + 1) + '0'; strcat(dirKey, &intPtr); _TCHAR currentPath[128]; GetPrivateProfileString("Pastas", dirKey, "null", currentPath, sizeof(currentPath) / sizeof(currentPath[0]), ".\\cfg\\pastas.ini"); printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath); + cleanDir(currentPath); } } -void cleanLoadedDirs(){ - printf("%s%s\n", ANSI_COLOR_CYAN, STR_CLEANING_DIRS); - - // TODO: Limpar pastas. +void cleanDir(const char* path){ + printf("%s %s\n", STR_CLEANING_DIR, path); + // Fetch files in dir + WIN32_FIND_DATA data; + HANDLE hFind = FindFirstFile(path, &data); + unsigned int iteration = 0; + if (hFind != INVALID_HANDLE_VALUE){ + do{ + // Ignore pseudo dirs (. and ..) + iteration++; + if (iteration <= 2) + continue; + printf("%s %s\n", STR_FOUND_ITEM, data.cFileName); + } while(FindNextFile(hFind, &data)); + } else { + printf("%s\n", STR_FAILED_DIR_LIST); + } } int main(void){ @@ -75,9 +90,8 @@ int main(void){ printf("--------------------\n%s %d, %s\n", PROGRAM_NAME, PROGRAM_SEASON, PROGRAM_VERSION); printf("%s\n--------------------\n\n", PROGRAM_COPYRIGHT); - printf("%s%s\n", ANSI_COLOR_YELLOW, STR_USE_WARNING); + printf("%s\n", STR_USE_WARNING); char in; - printf(ANSI_COLOR_RESET); fflush(stdout); scanf("%c", &in); @@ -89,7 +103,5 @@ int main(void){ if (in != 's' && in != 'S' && in != 'y' && in != 'Y') return 0; getAdditionalDirs(); - cleanLoadedDirs(); - printf("%s", ANSI_COLOR_RESET); return 0; } \ No newline at end of file diff --git a/str.h b/str.h index b1b9a0b..8b21bee 100644 --- a/str.h +++ b/str.h @@ -22,13 +22,16 @@ #define STR_USE_WARNING "Aviso: é recomendado fechar todos os programas abertos antes de utilizar este programa para poder remover mais arquivos temporários. Deseja continuar? (S/n)" -#define STR_FETCHING_ADD "Recolhendo pastas adicionais..." -#define STR_CLEANING_DIRS "Limpando pastas carregadas..." +#define STR_FETCHING_ADD_DIRS "Recolhendo pastas adicionais..." +#define STR_CLEANING_DIR "[Limpando pasta]" #define STR_REMOVED_FILE "[Arquivo removido]" #define STR_REMOVED_DIR "[Pasta removida]" #define STR_DIR_COUNT "[Contagem de pastas]" #define STR_FOUND_DIR "[Pasta encontrada]" +#define STR_FOUND_FILE "[Arquivo encontrado]" +#define STR_FOUND_ITEM "[Item encontrado]" +#define STR_FAILED_DIR_LIST "Um erro ocorreu ao tentar enumerar os arquivos dentro de uma pasta especificada." #define STR_ERROR_LIC "Falha ao ler arquivo de licença. Visite para mais informações."