From c51fbcd156299c85803dd3248c0aad359dac26bd Mon Sep 17 00:00:00 2001 From: OugonNoHane Date: Mon, 31 Oct 2022 17:24:20 +0100 Subject: [PATCH] implementado struct muchoinfo directory --- main.cpp | 112 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/main.cpp b/main.cpp index d49334d..861dda6 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #define IMGUI_IMPLEMENTATION #define GL_SILENCE_DEPRECATION + #define log_debugc(str, ...) do { if (debug) fprintf(stdout, "[DEBUG] (%s:%d): " (str) "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0) #define log_debugcpp(str) do { \ if (debug) std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << (str) << std::endl; \ @@ -13,6 +14,9 @@ #define log_volume(str) if(debugVerbosity & DEBUG_VOLUME) log_debugcpp((str)) #define log_extension(str) if(debugVerbosity & DEBUG_EXTENSION) log_debugcpp((str)) + +#define MAX_LISTDIR_PATH_LENGTH (MAX_PATH - 3) + #include "imgui/misc/single_file/imgui_single_file.h" #include #include @@ -45,9 +49,16 @@ bool debug = true; typedef struct { - std::vector size; - std::vector name; -} directoriesInfo, volumesInfo; + long long size; + //TODO yel spacsio NELLA MEMoria + TCHAR name[MAX_LISTDIR_PATH_LENGTH]; + SYSTEMTIME createTime; + SYSTEMTIME lastAccessTime; + SYSTEMTIME lastWriteTime; + bool isFile; + bool isHidden; + +} directoriesInfo; //TODO UNICORDEO /* FILE PICKER MOMENTO */ @@ -61,25 +72,25 @@ bool retrieveCurrentDirectory(char** currentPath){ } bool moveDirectory(char** currentPath){ - if (debug) std::cout << *currentPath << std::endl; + log_debugcpp(*currentPath); if(SetCurrentDirectory(*currentPath)) return true; return false; } -int listDirectory(std::string path, std::vector *directoryContents, std::vector *desiredExtensions = nullptr){ +int listDirectory(std::string path, std::vector *directoryContents, std::vector *desiredExtensions = nullptr){ HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATA ffd; LARGE_INTEGER filesize; bool skipDueToExtension = false; int numFiles = 0; - if (path.length() > (MAX_PATH - 3)) return -1; + if (path.length() > (MAX_LISTDIR_PATH_LENGTH)) return -1; path = path + "\\*"; hFind = FindFirstFile(path.c_str(), &ffd); if (INVALID_HANDLE_VALUE == hFind) return -2; do { if(!strcmp(ffd.cFileName, ".") || !strcmp(ffd.cFileName, "..")) continue; - + log_debugcpp("BUCLE listDirectory iteracion " + std::to_string(numFiles)); //Codigo pa saltarse arxibus k no estiendan /*if(desiredExtensions != nullptr){ TCHAR* fileExtension = strrchr(ffd.cFileName, '.'); @@ -95,38 +106,45 @@ int listDirectory(std::string path, std::vector *directoryContents, std:: skipDueToExtension = true; } } - }*/ - - - if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue; - - //TODO multi info Struct - if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - //strcat(itemPath, " "); - } else { - - // filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow); - // char buf[16]; buf[0] = ' '; - // itoa(filesize.QuadPart, buf + 1 , 10 ); - // strcat(itemPath, buf); } + if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue;*/ - - char* itemPath; + //TODO Borrar legado + // char* itemPath; + // if (directoryContents->size() <= numFiles){ + // itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR)); + // directoryContents->push_back(itemPath); + // } else { + // itemPath = directoryContents->at(numFiles); + // } + directoriesInfo* itemInfo; if (directoryContents->size() <= numFiles){ - itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR)); - directoryContents->push_back(itemPath); + itemInfo = new directoriesInfo(); + directoryContents->push_back(itemInfo); } else { - itemPath = directoryContents->at(numFiles); + itemInfo = directoryContents->at(numFiles); } - + log_debugcpp("MEMORIA ASIGNADA iteracion " + std::to_string(numFiles)); + + //A registrar info, fiera + itemInfo->isFile = (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false; + itemInfo->isHidden = (ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false; + //TamaƱo + filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow); + itemInfo->size = filesize.QuadPart; + //Fechitssss + FileTimeToSystemTime(&ffd.ftCreationTime, &itemInfo->createTime); + FileTimeToSystemTime(&ffd.ftLastAccessTime, &itemInfo->lastAccessTime); + FileTimeToSystemTime(&ffd.ftLastWriteTime, &itemInfo->lastWriteTime); + //Nombre de la cosita uint64_t idx = 0; do { - itemPath[idx] = ffd.cFileName[idx]; + itemInfo->name[idx] = ffd.cFileName[idx]; idx++; } while (ffd.cFileName[idx]); - itemPath[idx] = '\0'; - + itemInfo->name[idx] = '\0'; + log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles)); + numFiles++; } while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); @@ -214,17 +232,16 @@ int listVolumes(std::vector *onPresentPaths){ } //std::cout << volumePaths << std::endl; - if (debug) std::cout << std::to_string(volumePathLength) + " " ; - if (debug) std::cout << "THE END" << std::endl; + log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH"); + log_debugcpp("THE END"); }else{ - if (debug) std::cout << "no volumes found wtf" << std::endl; + log_debugcpp("no volumes found wtf"); } std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0'); } while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0); - - if (debug) std::cout << std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN" << std::endl; + log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN"); FindVolumeClose(hFind); return numVolumes; } @@ -351,8 +368,8 @@ int main(int, char**) static bool isListVolumesAdequate = true; static bool isListDirectoriesAdequate = true; - //Listar UNA VEZ volumenes + //Listar UNA VEZ volumenes static int numVolumes; static std::vector onPresentPaths; @@ -360,7 +377,7 @@ int main(int, char**) isListVolumesAdequate = false; //std::cout << isListVolumesAdequate << std::endl; numVolumes = listVolumes(&onPresentPaths); - if (debug) std::cout << std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()) << std::endl; + log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size())); } @@ -370,28 +387,27 @@ int main(int, char**) static char* currentPathPtr = ¤tPath[0]; //static int currentItemIdx = -1; - //TODO David momento - //static std::vector displayContents; - static std::vector directoryContents; + //static std::vector directoryContents; + static std::vector directoryContents; static int numFiles = 0; - if (debug) ImGui::Text("%s primir", currentPath); + ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath); if(isListDirectoriesAdequate) { - log_debugcpp("renderiso"); + log_debugcpp("ADECUADO LISTAR DIRECTORIOS"); isListDirectoriesAdequate = false; if(!retrieveCurrentDirectory(¤tPathPtr)) { - if (debug) std::cout << "pencaste"; + log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()"); goto filepickerFailure; } // //TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE - static std::vector restrictToExe{"exe", "DSDFD"}; + //static std::vector restrictToExe{"exe", "DSDFD"}; numFiles = (listDirectory(std::string(currentPath), &directoryContents));//, &restrictToExe)); //std::cout << numFiles; if (numFiles < 0) { //ImGui::Text("Path not valid"); - if (debug) std::cout << "pencaste 2 el repencazo"; + log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO"); goto filepickerFailure; } @@ -401,7 +417,7 @@ int main(int, char**) //It's renderin' time ImGui::Text("Select a file:"); - if (debug) ImGui::Text("%s ", currentPath); + if (debug) ImGui::Text("%s TEMPADDRBAR", currentPath); //Y a que los VOLUMENES pinta2 pa100pre //if (debug) std::cout << std::to_string(onPresentPaths.size()) + "<- numvols" << std::endl; @@ -440,10 +456,10 @@ int main(int, char**) //const bool isSelected = (currentItemIdx == i); bool isSelected = false; - if (ImGui::Selectable(directoryContents.at(idx), &isSelected)){ + if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){ //currentItemIdx = i; strcat(currentPath, "\\"); - strcat(currentPath, directoryContents.at(idx)); + strcat(currentPath, directoryContents.at(idx)->name); moveDirectory(¤tPathPtr); //currentItemIdx = -1; isListDirectoriesAdequate = true;