Support custom dirs
Signed-off-by: luca0N! <63941044+luca0N@users.noreply.github.com>
This commit is contained in:
parent
97dafa0ac2
commit
cf25645556
9
Makefile
9
Makefile
|
@ -23,4 +23,11 @@ main.o: main.c
|
|||
gcc -c -s -Os main.c
|
||||
|
||||
clean:
|
||||
rm *.o *.exe
|
||||
rm *.o *.exe
|
||||
|
||||
cleandust:
|
||||
rm *.o
|
||||
|
||||
dustless:
|
||||
make
|
||||
make cleandust
|
|
@ -18,7 +18,7 @@
|
|||
; Contact me by e-mail via <mailto:luca0n@protonmail.com>
|
||||
;
|
||||
; ┌──┐ │ ┌── ┌──┐ ─┬─ ┌──┐ │
|
||||
; ├──┤ │ ├─ ├──┘ │ ├──┤ │
|
||||
; ├──┤ │ ├─ ├\─┘ │ ├──┤ │
|
||||
; │ │ └── └── │ \ │ │ │ •
|
||||
;
|
||||
; ALERTA!
|
||||
|
@ -30,6 +30,6 @@
|
|||
|
||||
[Pastas]
|
||||
Pastas=3
|
||||
Pasta1=%appdata%
|
||||
Pasta2=%tmp%
|
||||
Pasta3=C:\Windows\Temp\
|
||||
Pasta1=%tmp%\*
|
||||
Pasta2=C:\Windows\Temp\*
|
||||
Pasta3=C:\Windows\Prefetch\*
|
36
main.c
36
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 <windows.h>
|
||||
#include <stdio.h>
|
||||
|
@ -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;
|
||||
}
|
7
str.h
7
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 <https://www.gnu.org/licenses/> para mais informações."
|
||||
|
||||
|
|
Reference in New Issue