Minor changes

- Added hidden support for ignoring the warning and license disclaimer when the program starts;
- Made changes based on issue #3.
This commit is contained in:
luca0N! 2020-06-19 13:13:14 -03:00
parent 0cd02d1752
commit 3537a786bd
No known key found for this signature in database
GPG Key ID: 9F1B99B522287CAB
3 changed files with 36 additions and 18 deletions

7
cfg.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef LCFG
#define LCFG
#define PATH_LICENSE ".\\LICENSE"
#define PATH_CFG ".\\cfg\\cfg.ini"
#endif

View File

@ -28,9 +28,10 @@
; Após execução, não será possível restaurar os arquivos removidos.
;
[Pastas]
; Formato necessário: <Caminho>\
Pastas=3
Pasta1=%tmp%\
Pasta1=%tmp%
Pasta2=C:\Windows\Temp\
Pasta3=C:\Windows\Prefetch\

44
main.c
View File

@ -19,6 +19,7 @@
*/
#include "about.h"
#include "str.h"
#include "cfg.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"
@ -30,7 +31,7 @@
// Removes a directory using the Windows shell
int shellRemoveDir(LPCTSTR dirPath){
// Remove the directory
//printf("!! ATTEMPT TO REMOVE %s\\...\n", dirPath);
//printf("!! ATTEMPT TO REMOVE (%d) %s\\...\n", len, shortPath);
// Append null to the end of the path
// Double null terminated path string
@ -38,7 +39,12 @@ int shellRemoveDir(LPCTSTR dirPath){
strcpy(dntps, dirPath);
strcat(dntps, "\\\0");
SHFILEOPSTRUCT dir = {
SHFILEOPSTRUCT dir = {0};
dir.wFunc = FO_DELETE;
dir.pFrom = dntps;
dir.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
dir.fAnyOperationsAborted = 0;
/*dir = {
NULL,
FO_DELETE,
dntps,
@ -47,7 +53,7 @@ int shellRemoveDir(LPCTSTR dirPath){
0,
0,
""
};
};*/
return SHFileOperation(&dir);
}
@ -57,7 +63,7 @@ int printLicense(int full){
printf("%s\n", LICENSE);
return 0;
} else {
FILE* flic = fopen("./LICENSE", "r");
FILE* flic = fopen(PATH_LICENSE, "r");
if (flic == NULL){
printf("%s\n", STR_ERROR_LIC);
return -1;
@ -71,9 +77,9 @@ int printLicense(int full){
// Gets the user defined directories
void getAdditionalDirs(){
printf("%s\n", STR_FETCHING_ADD_DIRS);
printf("\n%s\n", STR_FETCHING_ADD_DIRS);
int dirs;
dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, ".\\cfg\\pastas.ini");
dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, PATH_CFG);
printf("%s %d\n", STR_DIR_COUNT, dirs);
fflush(stdout);
for(unsigned short x = 0; x < dirs; x++){
@ -82,7 +88,7 @@ void getAdditionalDirs(){
strcat(dirKey, &intPtr);
_TCHAR currentPath[128];
GetPrivateProfileString("Pastas", dirKey, "null", currentPath,
sizeof(currentPath) / sizeof(currentPath[0]), ".\\cfg\\pastas.ini");
sizeof(currentPath) / sizeof(currentPath[0]), PATH_CFG);
printf("%s [%s] %s\n", STR_FOUND_DIR, dirKey, currentPath);
cleanDir(currentPath);
}
@ -145,18 +151,22 @@ int main(void){
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);
unsigned int ignoreWarning = GetPrivateProfileInt("Geral", "IgnorarAlerta", 0, PATH_CFG);
unsigned int licenseAccepted = GetPrivateProfileInt("Geral", "AceitarLicença", 0, PATH_CFG);
if (!ignoreWarning || !licenseAccepted){
printf("%s ", STR_USE_WARNING, ignoreWarning, licenseAccepted);
char in;
fflush(stdout);
printf("%s\n", STR_USE_WARNING);
char in;
fflush(stdout);
scanf("%c", &in);
scanf("%c", &in);
if (in == 'w' || in == 'c')
if (printLicense(1) != 0)
return -2;
if (in != 's' && in != 'S' && in != 'y' && in != 'Y')
return 0;
if (in == 'w' || in == 'c')
if (printLicense(1) != 0)
return -2;
if (in != 's' && in != 'S' && in != 'y' && in != 'Y')
return 0;
}
getAdditionalDirs();
return 0;
}