From f5b564fc0faf3815821b7c7096c0bbb2334719bd Mon Sep 17 00:00:00 2001 From: luca0N! <63941044+luca0N@users.noreply.github.com> Date: Fri, 26 Jun 2020 01:49:46 -0300 Subject: [PATCH] Fixed some compiler warnings --- main.c | 119 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/main.c b/main.c index 45ed617..59d3a27 100644 --- a/main.c +++ b/main.c @@ -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 void getAdditionalDirs(bool safeMode){ + unsigned objectCount = 0; printf("\n%s\n", STR_FETCHING_ADD_DIRS); int dirs; dirs = GetPrivateProfileInt("Pastas", "Pastas", 3, PATH_CFG); @@ -85,7 +144,7 @@ void getAdditionalDirs(bool safeMode){ fflush(stdout); for(unsigned short x = 0; x < dirs; x++){ char dirKey[7] = "Pasta"; - char* intPtr = (x + 1) + '0'; + char* intPtr = (char*) (x + 1) + '0'; strcat(dirKey, &intPtr); _TCHAR currentPath[128]; 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){ SetConsoleOutputCP(CP_UTF8);