Added console color support
This commit is contained in:
parent
b1e196443d
commit
df325b783a
7
colors.h
7
colors.h
|
@ -20,12 +20,15 @@
|
|||
#ifndef COLORS_DEF
|
||||
#define COLORS_DEF
|
||||
|
||||
#define ANSI_COLOR_RED "\x1b[31m"
|
||||
/*#define ANSI_COLOR_RED "\x1b[31m"
|
||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||
#define ANSI_COLOR_BLUE "\x1b[34m"
|
||||
#define ANSI_COLOR_MAGENTA "\x1b[35m"
|
||||
#define ANSI_COLOR_CYAN "\x1b[36m"
|
||||
#define ANSI_COLOR_RESET "\033[0m"
|
||||
#define ANSI_COLOR_RESET "\033[0m"*/
|
||||
|
||||
#define RESET_CONSOLE_COLOR 7
|
||||
#define FOREGROUND_YELLOW FOREGROUND_RED | FOREGROUND_GREEN
|
||||
|
||||
#endif
|
42
main.c
42
main.c
|
@ -22,7 +22,7 @@
|
|||
#include "cfg.h"
|
||||
|
||||
// Because this program is currently targeted at Windows only, the use of ANSI colors are no longer used as of May 5, 2020.
|
||||
// #include "colors.h"
|
||||
#include "colors.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
@ -31,6 +31,16 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
void setConsoleColor(int consoleColor){
|
||||
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
WORD wColor;
|
||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
GetConsoleScreenBufferInfo(h, &info);
|
||||
wColor = info.wAttributes;
|
||||
|
||||
SetConsoleTextAttribute(h, consoleColor);
|
||||
}
|
||||
|
||||
// Prints the program license to the user.
|
||||
int printLicense(int full){
|
||||
if (full == 0) {
|
||||
|
@ -112,15 +122,19 @@ void cleanDir(const char* path, unsigned* objectCount, unsigned long* totalDelet
|
|||
}
|
||||
|
||||
if (DeleteFile(fullPath) == 0){
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_RED);
|
||||
int lastError = GetLastError();
|
||||
printf(" %s\n", STR_FAILED_FILE);
|
||||
printf(" --> %s\n", fullPath);
|
||||
printf(" --> %#010x\n", lastError);
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
} else {
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_BLUE);
|
||||
printf(" %s\n", STR_DELETED_FILE);
|
||||
// Update the deleted object count if the process was successful.
|
||||
(*objectCount)++;
|
||||
(*totalDeletedBytes) += length;
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
}
|
||||
} while(FindNextFile(hFind, &data));
|
||||
} else {
|
||||
|
@ -157,20 +171,6 @@ void getAdditionalDirs(bool safeMode){
|
|||
}
|
||||
|
||||
if (containsVars){
|
||||
/*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* buffer;
|
||||
char* varBuffer;
|
||||
|
||||
|
@ -221,7 +221,8 @@ void getAdditionalDirs(bool safeMode){
|
|||
if (!safeMode)
|
||||
cleanDir(currentPath, &objectCount, &totalDeletedBytes);
|
||||
}
|
||||
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_GREEN);
|
||||
printf(FMT_STR_OBJECT_COUNT, objectCount);
|
||||
// Determine whether we should output the size as bytes, KiB, MiB or GiB.
|
||||
if (totalDeletedBytes < 1024){
|
||||
printf(FMT_STR_TOTAL_DELETED_BYTES, totalDeletedBytes);
|
||||
|
@ -230,22 +231,26 @@ void getAdditionalDirs(bool safeMode){
|
|||
printf(FMT_STR_TOTAL_DELETED_KIBIBYTES, kib);
|
||||
} else if (totalDeletedBytes < (unsigned long) pow(1024, 3)){
|
||||
float mib = (unsigned long) totalDeletedBytes / pow(1024, 2);// / (float) 1024 / (float) 1024;
|
||||
printf("%lu\n", totalDeletedBytes);
|
||||
printf(FMT_STR_TOTAL_DELETED_MEBIBYTES, mib);
|
||||
} else {
|
||||
float gib = (unsigned long) totalDeletedBytes / pow(1024, 3);
|
||||
printf(FMT_STR_TOTAL_DELETED_GIBIBYTES, gib);
|
||||
}
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
}
|
||||
|
||||
int main(void){
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_YELLOW);
|
||||
printLicense(0);
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_BLUE);
|
||||
printf("%s\n%s %d, %s\n", STR_LN, PROGRAM_NAME, PROGRAM_SEASON, PROGRAM_VERSION);
|
||||
printf("%s\n%s\n\n", PROGRAM_COPYRIGHT, STR_LN);
|
||||
|
||||
setConsoleColor(FOREGROUND_INTENSITY | FOREGROUND_YELLOW);
|
||||
unsigned int ignoreWarning = GetPrivateProfileInt("Geral", "IgnorarAlerta", 0, PATH_CFG);
|
||||
unsigned int licenseAccepted = GetPrivateProfileInt("Geral", "AceitarLicença", 0, PATH_CFG);
|
||||
if (!ignoreWarning || !licenseAccepted){
|
||||
|
@ -253,6 +258,7 @@ int main(void){
|
|||
char in;
|
||||
fflush(stdout);
|
||||
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
scanf("%c", &in);
|
||||
|
||||
if (in == 'w' || in == 'c')
|
||||
|
@ -261,7 +267,7 @@ int main(void){
|
|||
if (in != 's' && in != 'S' && in != 'y' && in != 'Y')
|
||||
return 0;
|
||||
}
|
||||
|
||||
setConsoleColor(RESET_CONSOLE_COLOR);
|
||||
unsigned int safeMode = GetPrivateProfileInt("Geral", "ModoSeguro", 1, PATH_CFG);
|
||||
|
||||
getAdditionalDirs(safeMode);
|
||||
|
|
Reference in New Issue