Added environment variables support
This commit is contained in:
parent
4c77ea405e
commit
bee75691d5
62
main.c
62
main.c
|
@ -26,6 +26,7 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// Removes a directory using the Windows shell
|
// Removes a directory using the Windows shell
|
||||||
|
@ -92,8 +93,17 @@ void getAdditionalDirs(){
|
||||||
|
|
||||||
// Check if the specified path is an environment variable.
|
// Check if the specified path is an environment variable.
|
||||||
// If it starts with %, then we should treat it as such.
|
// If it starts with %, then we should treat it as such.
|
||||||
if (currentPath[0] == '%'){
|
|
||||||
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
|
bool containsVars = false;
|
||||||
|
|
||||||
|
for (unsigned c = 0; c < strlen(currentPath); c++)
|
||||||
|
if (currentPath[c] == '%'){
|
||||||
|
containsVars = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (containsVars){
|
||||||
|
/*HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
WORD wColor;
|
WORD wColor;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||||
GetConsoleScreenBufferInfo(h, &info);
|
GetConsoleScreenBufferInfo(h, &info);
|
||||||
|
@ -101,25 +111,57 @@ void getAdditionalDirs(){
|
||||||
|
|
||||||
SetConsoleTextAttribute(h, FOREGROUND_RED);
|
SetConsoleTextAttribute(h, FOREGROUND_RED);
|
||||||
printf("%s\n\n", STR_ERROR_VAR_CURRENTLY_NOT_SUPPORTED);
|
printf("%s\n\n", STR_ERROR_VAR_CURRENTLY_NOT_SUPPORTED);
|
||||||
SetConsoleTextAttribute(h, wColor);
|
SetConsoleTextAttribute(h, wColor);*/
|
||||||
|
|
||||||
/*char varBuffer[sizeof(currentPath)];
|
/*char varBuffer[sizeof(currentPath)];
|
||||||
memcpy(varBuffer, ¤tPath[1], strlen(currentPath)-3);
|
memcpy(varBuffer, ¤tPath[1], strlen(currentPath)-3);
|
||||||
varBuffer[sizeof(varBuffer)] = '\0';
|
varBuffer[sizeof(varBuffer)] = '\0';*/
|
||||||
|
|
||||||
char varResBuffer[32767];
|
char* buffer;
|
||||||
|
char* varBuffer;
|
||||||
|
|
||||||
|
if ((buffer = malloc(512)) == NULL ||
|
||||||
|
(varBuffer = malloc(64)) == NULL){
|
||||||
|
printf("%s\n", STR_MEM_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = '\0';
|
||||||
|
varBuffer[0] = '\0';
|
||||||
|
bool fetchingVar = false;
|
||||||
|
|
||||||
|
for (unsigned c = 0; c < strlen(currentPath); c++){
|
||||||
|
if (currentPath[c] == '%')
|
||||||
|
if (!fetchingVar)
|
||||||
|
fetchingVar = true;
|
||||||
|
else {
|
||||||
|
// Get the environment variable
|
||||||
|
|
||||||
|
char varValBuffer[256];
|
||||||
GetEnvironmentVariable(
|
GetEnvironmentVariable(
|
||||||
varBuffer,
|
varBuffer,
|
||||||
&varResBuffer,
|
&varValBuffer,
|
||||||
sizeof(varResBuffer)
|
sizeof(varValBuffer)
|
||||||
);
|
);
|
||||||
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, varResBuffer);
|
|
||||||
cleanDir(varResBuffer);*/
|
strncat(buffer, &varValBuffer, strlen(varValBuffer));
|
||||||
|
|
||||||
|
fetchingVar = false;
|
||||||
|
}
|
||||||
|
else if (fetchingVar)
|
||||||
|
strncat(varBuffer, ¤tPath[c], 1);
|
||||||
|
else
|
||||||
|
strncat(buffer, ¤tPath[c], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, buffer);
|
||||||
|
//cleanDir(varResBuffer);
|
||||||
continue;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
str.h
2
str.h
|
@ -37,6 +37,8 @@
|
||||||
#define STR_FAILED_FILE "[Arquivo mantido] Não foi possível remover este arquivo pelo seguinte erro:"
|
#define STR_FAILED_FILE "[Arquivo mantido] Não foi possível remover este arquivo pelo seguinte erro:"
|
||||||
#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_MEM_ERR "[Erro fatal] Não foi possível alocar memória. Tente fechar alguns programas abertos e tente novamente."
|
||||||
|
|
||||||
#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."
|
#define STR_ERROR_VAR_CURRENTLY_NOT_SUPPORTED "[Aviso] O suporte para variáveis de sistema não existe nesta versão."
|
||||||
|
|
||||||
|
|
Reference in New Issue