Fixed some compiler warnings

This commit is contained in:
luca0N! 2020-06-26 01:49:46 -03:00
parent 1e22096c30
commit f5b564fc0f
No known key found for this signature in database
GPG Key ID: 9F1B99B522287CAB
1 changed files with 60 additions and 59 deletions

119
main.c
View File

@ -76,8 +76,67 @@ int printLicense(int full){
} }
} }
// 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(validPath) + 1];
strcpy(wildPath, validPath);
strcat(wildPath, "*");
printf("%s %s\n", STR_CLEANING_DIR, wildPath);
// Fetch files in dir
WIN32_FIND_DATA data;
HANDLE hFind = FindFirstFile(wildPath, &data);
unsigned int iteration = 0;
if (hFind != INVALID_HANDLE_VALUE){
do{
// Ignore pseudo dirs (. and ..)
iteration++;
if (iteration <= 2)
continue;
printf("%s %s\n", STR_FOUND_ITEM, data.cFileName);
// Attempt to delete item...
int pathSize = strlen(wildPath) + strlen(data.cFileName);
char fullPath[pathSize];
strcpy(fullPath, validPath);
strcat(fullPath, data.cFileName);
// If the item is a directory, then delete it through the shell
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
int shellReturnCode = shellRemoveDir(fullPath);
if (shellReturnCode != 0){
printf(" %s\n", STR_FAILED_DIR);
printf(" --> %s\n", fullPath);
printf(" --> %#010x\n", shellReturnCode);
}
continue;
}
if (DeleteFile(fullPath) == 0){
int lastError = GetLastError();
printf(" %s\n", STR_FAILED_FILE);
printf(" --> %s\n", fullPath);
printf(" --> %#010x\n", lastError);
} else
printf(" %s\n", STR_DELETED_FILE);
} while(FindNextFile(hFind, &data));
} else {
printf("%s\n", STR_FAILED_DIR_LIST);
}
}
// Gets the user defined directories // Gets the user defined directories
void getAdditionalDirs(bool safeMode){ void getAdditionalDirs(bool safeMode){
unsigned objectCount = 0;
printf("\n%s\n", STR_FETCHING_ADD_DIRS); printf("\n%s\n", STR_FETCHING_ADD_DIRS);
int dirs; int dirs;
dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, PATH_CFG); dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, PATH_CFG);
@ -85,7 +144,7 @@ void getAdditionalDirs(bool safeMode){
fflush(stdout); fflush(stdout);
for(unsigned short x = 0; x < dirs; x++){ for(unsigned short x = 0; x < dirs; x++){
char dirKey[7] = "Pasta"; char dirKey[7] = "Pasta";
char* intPtr = (x + 1) + '0'; char* intPtr = (char*) (x + 1) + '0';
strcat(dirKey, &intPtr); strcat(dirKey, &intPtr);
_TCHAR currentPath[128]; _TCHAR currentPath[128];
GetPrivateProfileString("Pastas", dirKey, "null", currentPath, GetPrivateProfileString("Pastas", dirKey, "null", currentPath,
@ -169,64 +228,6 @@ void getAdditionalDirs(bool safeMode){
} }
} }
// 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(validPath) + 1];
strcpy(wildPath, validPath);
strcat(wildPath, "*");
printf("%s %s\n", STR_CLEANING_DIR, wildPath);
// Fetch files in dir
WIN32_FIND_DATA data;
HANDLE hFind = FindFirstFile(wildPath, &data);
unsigned int iteration = 0;
if (hFind != INVALID_HANDLE_VALUE){
do{
// Ignore pseudo dirs (. and ..)
iteration++;
if (iteration <= 2)
continue;
printf("%s %s\n", STR_FOUND_ITEM, data.cFileName);
// Attempt to delete item...
int pathSize = strlen(wildPath) + strlen(data.cFileName);
char fullPath[pathSize];
strcpy(fullPath, validPath);
strcat(fullPath, data.cFileName);
// If the item is a directory, then delete it through the shell
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
int shellReturnCode = shellRemoveDir(fullPath);
if (shellReturnCode != 0){
printf(" %s\n", STR_FAILED_DIR);
printf(" --> %s\n", fullPath);
printf(" --> %#010x\n", shellReturnCode);
}
continue;
}
if (DeleteFile(fullPath) == 0){
int lastError = GetLastError();
printf(" %s\n", STR_FAILED_FILE);
printf(" --> %s\n", fullPath);
printf(" --> %#010x\n", lastError);
} else
printf(" %s\n", STR_DELETED_FILE);
} while(FindNextFile(hFind, &data));
} else {
printf("%s\n", STR_FAILED_DIR_LIST);
}
}
int main(void){ int main(void){
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8);