From 597affa3408da75e9e6a660c2f7ff205e21ccd64 Mon Sep 17 00:00:00 2001 From: luca0N! <63941044+luca0N@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:50:58 -0300 Subject: [PATCH] Added var warning --- main.c | 43 ++++++++++++++++++++++++++++++++++++++++--- str.h | 1 + 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e6d123b..43b4a68 100644 --- a/main.c +++ b/main.c @@ -89,16 +89,53 @@ void getAdditionalDirs(){ _TCHAR currentPath[128]; GetPrivateProfileString("Pastas", dirKey, "null", currentPath, 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, ¤tPath[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); + cleanDir(currentPath); } } // Cleans a directory. 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 - char wildPath[strlen(path) + 1]; - strcpy(wildPath, path); + char wildPath[strlen(validPath) + 1]; + strcpy(wildPath, validPath); strcat(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); char fullPath[pathSize]; - strcpy(fullPath, path); + strcpy(fullPath, validPath); strcat(fullPath, data.cFileName); // If the item is a directory, then delete it through the shell diff --git a/str.h b/str.h index e9b4154..cf64712 100644 --- a/str.h +++ b/str.h @@ -38,5 +38,6 @@ #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 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 \ No newline at end of file