Support custom dirs

Signed-off-by: luca0N! <63941044+luca0N@users.noreply.github.com>
This commit is contained in:
luca0N! 2020-05-06 15:42:15 -03:00
parent 97dafa0ac2
commit cf25645556
No known key found for this signature in database
GPG Key ID: 9F1B99B522287CAB
4 changed files with 41 additions and 19 deletions

View File

@ -24,3 +24,10 @@ main.o: main.c
clean: clean:
rm *.o *.exe rm *.o *.exe
cleandust:
rm *.o
dustless:
make
make cleandust

View File

@ -18,7 +18,7 @@
; Contact me by e-mail via <mailto:luca0n@protonmail.com> ; Contact me by e-mail via <mailto:luca0n@protonmail.com>
; ;
; ┌──┐ │ ┌── ┌──┐ ─┬─ ┌──┐ │ ; ┌──┐ │ ┌── ┌──┐ ─┬─ ┌──┐ │
; ├──┤ │ ├─ ├─┘ │ ├──┤ │ ; ├──┤ │ ├─ ├\─┘ │ ├──┤ │
; │ │ └── └── │ \ │ │ │ • ; │ │ └── └── │ \ │ │ │ •
; ;
; ALERTA! ; ALERTA!
@ -30,6 +30,6 @@
[Pastas] [Pastas]
Pastas=3 Pastas=3
Pasta1=%appdata% Pasta1=%tmp%\*
Pasta2=%tmp% Pasta2=C:\Windows\Temp\*
Pasta3=C:\Windows\Temp\ Pasta3=C:\Windows\Prefetch\*

36
main.c
View File

@ -19,7 +19,8 @@
*/ */
#include "about.h" #include "about.h"
#include "str.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 <windows.h> #include <windows.h>
#include <stdio.h> #include <stdio.h>
@ -46,27 +47,41 @@ int printLicense(int full){
} }
void getAdditionalDirs(){ void getAdditionalDirs(){
printf("%sRecolhendo pastas adicionais...\n", ANSI_COLOR_CYAN); printf("%s\n", STR_FETCHING_ADD_DIRS);
int dirs; int dirs;
dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, ".\\cfg\\pastas.ini"); dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, ".\\cfg\\pastas.ini");
printf("%s %d\n", STR_DIR_COUNT, dirs); printf("%s %d\n", STR_DIR_COUNT, dirs);
fflush(stdout); fflush(stdout);
for(unsigned short x = 0; x < dirs; x++){ for(unsigned short x = 0; x < dirs; x++){
char dirKey[7] = "Pasta"; // PastaX... // TODO: Tell if item is a directory. If so, then iterate through all items on it.
//strcpy(dirKey, "Pasta"); char dirKey[7] = "Pasta";
char* intPtr = (x + 1) + '0'; char* intPtr = (x + 1) + '0';
strcat(dirKey, &intPtr); strcat(dirKey, &intPtr);
_TCHAR currentPath[128]; _TCHAR currentPath[128];
GetPrivateProfileString("Pastas", dirKey, "null", currentPath, GetPrivateProfileString("Pastas", dirKey, "null", currentPath,
sizeof(currentPath) / sizeof(currentPath[0]), ".\\cfg\\pastas.ini"); sizeof(currentPath) / sizeof(currentPath[0]), ".\\cfg\\pastas.ini");
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath); printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath);
cleanDir(currentPath);
} }
} }
void cleanLoadedDirs(){ void cleanDir(const char* path){
printf("%s%s\n", ANSI_COLOR_CYAN, STR_CLEANING_DIRS); printf("%s %s\n", STR_CLEANING_DIR, path);
// Fetch files in dir
// TODO: Limpar pastas. 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){ int main(void){
@ -75,9 +90,8 @@ int main(void){
printf("--------------------\n%s %d, %s\n", PROGRAM_NAME, PROGRAM_SEASON, PROGRAM_VERSION); printf("--------------------\n%s %d, %s\n", PROGRAM_NAME, PROGRAM_SEASON, PROGRAM_VERSION);
printf("%s\n--------------------\n\n", PROGRAM_COPYRIGHT); 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; char in;
printf(ANSI_COLOR_RESET);
fflush(stdout); fflush(stdout);
scanf("%c", &in); scanf("%c", &in);
@ -89,7 +103,5 @@ int main(void){
if (in != 's' && in != 'S' && in != 'y' && in != 'Y') if (in != 's' && in != 'S' && in != 'y' && in != 'Y')
return 0; return 0;
getAdditionalDirs(); getAdditionalDirs();
cleanLoadedDirs();
printf("%s", ANSI_COLOR_RESET);
return 0; return 0;
} }

7
str.h
View File

@ -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_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_FETCHING_ADD_DIRS "Recolhendo pastas adicionais..."
#define STR_CLEANING_DIRS "Limpando pastas carregadas..."
#define STR_CLEANING_DIR "[Limpando pasta]"
#define STR_REMOVED_FILE "[Arquivo removido]" #define STR_REMOVED_FILE "[Arquivo removido]"
#define STR_REMOVED_DIR "[Pasta removida]" #define STR_REMOVED_DIR "[Pasta removida]"
#define STR_DIR_COUNT "[Contagem de pastas]" #define STR_DIR_COUNT "[Contagem de pastas]"
#define STR_FOUND_DIR "[Pasta encontrada]" #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 <https://www.gnu.org/licenses/> para mais informações." #define STR_ERROR_LIC "Falha ao ler arquivo de licença. Visite <https://www.gnu.org/licenses/> para mais informações."