diff --git a/main.cpp b/main.cpp index 5069286..03123db 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#define DEBUG true // [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. // To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. @@ -24,8 +23,19 @@ static void glfw_error_callback(int error, const char* description) fprintf(stderr, "Glfw Error %d: %s\n", error, description); } +bool debug = true; + +typedef struct { + std::vector size; + std::vector name; +} directoriesInfo, volumesInfo; + +//TODO UNICORDEO /* FILE PICKER MOMENTO */ +/* DIRECTORIES */ + + bool retrieveCurrentDirectory(char** currentPath){ if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true; return false; @@ -75,6 +85,82 @@ int listDirectory(std::string path, std::vector *directoryContents){ FindClose(hFind); return numFiles; } + +/* VOLUMES */ + + +//new char*[CharCount * sizeof(WCHAR) +/*idea, si quisiera que empezase en punto X del string + coger el param opcional y crear un puntero a la posicion X del array para empezar desde ahi + int explodePaths(TCHAR* volumePaths, int volumePathLength, int volumePathBufferSize, + char separator, std::vector *dest, , int startingFrom = 0); + if (nextOcurrence == NULL) return 0; +*/ + +int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector *dest){ + char* nextOcurrence = strchr(volumePaths, separator); + if (nextOcurrence[0] == nextOcurrence[sizeof(TCHAR)]) return 0; + + char* itemPath; + itemPath = (char*)calloc(1, volumePathsBufferSize); + for (int i = 0; &volumePaths[i] == nextOcurrence; i++) { + itemPath[i] = volumePaths[i]; + } + dest->push_back(itemPath); + + + return explodePaths(nextOcurrence, volumePathsBufferSize, separator, dest); +} + + +int listVolumes(std::vector *onPresentPaths){ +//int listVolumes(){ + HANDLE hFind = INVALID_HANDLE_VALUE; + char separator = '\0'; + + int numVolumes = 0; + //Volume name + TCHAR volumeName[MAX_PATH]; + int volumeNameSize = sizeof volumeName / sizeof volumeName[0]; + //Paths + int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(TCHAR); + unsigned long volumePathLength; + TCHAR volumePaths[volumePathsBufferSize]; + + + hFind = FindFirstVolume(volumeName, volumeNameSize); + //if (debug) std::cout << volumeNameSize << std::endl; + if (INVALID_HANDLE_VALUE == hFind) return -2; + do { + //if (debug) std::cout << volumeName << std::endl; + + if(GetVolumePathNamesForVolumeName(volumeName, volumePaths, volumePathsBufferSize, &volumePathLength)){ + + if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; } + if (debug) std::cout << volumeName; + if (debug) { + if(explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){ + if (debug) std::cout << volumePaths << std::endl; + for (int i = 0; i < onPresentPaths->size(); i++){ + std::cout << onPresentPaths->at(i) << std::endl; + } + } + //std::cout << volumePaths << std::endl; + } + if (debug) std::cout << std::to_string(volumePathLength) + " " ; + if (debug) std::cout << "THE END" << std::endl; + + }else{ + if (debug) std::cout << "cagaste" << std::endl; + } + + numVolumes++; + + } while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0); + + FindVolumeClose(hFind); + return numVolumes; +} /* FIN FILE PICKER MOMENTO */ @@ -196,6 +282,15 @@ int main(int, char**) { ImGui::Begin("File Picker in 4K"); + //TODO test listar volumenes + static bool isListVolumesAdequate = true; + if (debug && isListVolumesAdequate) { + isListVolumesAdequate = false; + std::cout << isListVolumesAdequate << std::endl; + std::vector onPresentPaths; + listVolumes(&onPresentPaths); + } + // static bool renderListbox = true; //cursed C momento: necesario ptr en otra var para mandar a char** de firma @@ -207,20 +302,20 @@ int main(int, char**) std::vector directoryContents; static int numFiles = 0; - if (DEBUG) ImGui::Text("%s primir", currentPath); + if (debug) ImGui::Text("%s primir", currentPath); if(renderListbox) { - if (DEBUG) std::cout << "renderiso"; + if (debug) std::cout << "renderiso" << std::endl; renderListbox = false; if(!retrieveCurrentDirectory(&ptr)) { - if (DEBUG) std::cout << "pencaste"; + if (debug) std::cout << "pencaste"; goto filepickerFailure; } // numFiles = (listDirectory(std::string(currentPath), &directoryContents)); //std::cout << numFiles; if (numFiles < 0) { - if (DEBUG) std::cout << "pencaste 2 el repencazo"; + if (debug) std::cout << "pencaste 2 el repencazo"; goto filepickerFailure; } displayContents = std::move(directoryContents); @@ -228,10 +323,9 @@ int main(int, char**) if(numFiles > 0){ ImGui::Text("Select a file:"); - if (DEBUG) ImGui::Text("%s %d", currentPath, currentItemIdx); + if (debug) ImGui::Text("%s %d", currentPath, currentItemIdx); if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){ for (int i = 0; i < numFiles; i++) { - // ImGui::Selectable(directoryContents.at(i), false); const bool isSelected = (currentItemIdx == i); if (ImGui::Selectable(displayContents.at(i), isSelected))