Added var warning

This commit is contained in:
luca0N! 2020-06-19 22:50:58 -03:00
parent 52bc7b5511
commit 597affa340
No known key found for this signature in database
GPG Key ID: 9F1B99B522287CAB
2 changed files with 41 additions and 3 deletions

43
main.c
View File

@ -89,16 +89,53 @@ void getAdditionalDirs(){
_TCHAR currentPath[128]; _TCHAR currentPath[128];
GetPrivateProfileString("Pastas", dirKey, "null", currentPath, GetPrivateProfileString("Pastas", dirKey, "null", currentPath,
sizeof(currentPath) / sizeof(currentPath[0]), PATH_CFG); sizeof(currentPath) / sizeof(currentPath[0]), PATH_CFG);
// Check if the specified path is an environment variable.
// If it starts with %, then we should treat it as such.
if (currentPath[0] == '%'){
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
WORD wColor;
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(h, &info);
wColor = info.wAttributes;
SetConsoleTextAttribute(h, FOREGROUND_RED);
printf("%s\n\n", STR_ERROR_VAR_CURRENTLY_NOT_SUPPORTED);
SetConsoleTextAttribute(h, wColor);
/*char varBuffer[sizeof(currentPath)];
memcpy(varBuffer, &currentPath[1], strlen(currentPath)-3);
varBuffer[sizeof(varBuffer)] = '\0';
char varResBuffer[32767];
GetEnvironmentVariable(
varBuffer,
&varResBuffer,
sizeof(varResBuffer)
);
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, varResBuffer);
cleanDir(varResBuffer);*/
continue;
}
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath); printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath);
cleanDir(currentPath); cleanDir(currentPath);
} }
} }
// Cleans a directory. // Cleans a directory.
void cleanDir(const char* path){ void cleanDir(const char* path){
const char* validPath = path;
//char validPath[sizeof(path) + 1];
//strcpy(validPath, path);
/*// Check if the path ends with '\'
if (path[strlen(path)] != '\\'){
strcat(validPath, "\\");
}*/
// Path with wildcard // Path with wildcard
char wildPath[strlen(path) + 1]; char wildPath[strlen(validPath) + 1];
strcpy(wildPath, path); strcpy(wildPath, validPath);
strcat(wildPath, "*"); strcat(wildPath, "*");
printf("%s %s\n", STR_CLEANING_DIR, wildPath); printf("%s %s\n", STR_CLEANING_DIR, wildPath);
@ -117,7 +154,7 @@ void cleanDir(const char* path){
int pathSize = strlen(wildPath) + strlen(data.cFileName); int pathSize = strlen(wildPath) + strlen(data.cFileName);
char fullPath[pathSize]; char fullPath[pathSize];
strcpy(fullPath, path); strcpy(fullPath, validPath);
strcat(fullPath, data.cFileName); strcat(fullPath, data.cFileName);
// If the item is a directory, then delete it through the shell // If the item is a directory, then delete it through the shell

1
str.h
View File

@ -38,5 +38,6 @@
#define STR_FAILED_DIR "[Pasta mantida] Não foi possível remover esta pasta pelo seguinte erro:" #define STR_FAILED_DIR "[Pasta mantida] Não foi possível remover esta pasta pelo seguinte erro:"
#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."
#define STR_ERROR_VAR_CURRENTLY_NOT_SUPPORTED "[Aviso] O suporte para variáveis de sistema não existe nesta versão."
#endif #endif