From 54bd3a914eb9da466fbb9dc86d8737c6aef952ff Mon Sep 17 00:00:00 2001 From: OugonNoHane Date: Thu, 27 Oct 2022 19:50:46 +0200 Subject: [PATCH] Movimiento por carpetas/1 steam x dir --- main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 520d1e1..b4f4f03 100644 --- a/main.cpp +++ b/main.cpp @@ -23,17 +23,25 @@ static void glfw_error_callback(int error, const char* description) fprintf(stderr, "Glfw Error %d: %s\n", error, description); } +/* FILE PICKER MOMENTO */ + bool retrieveCurrentDirectory(char** currentPath){ if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true; return false; } + + +bool moveDirectory(char** currentPath){ + if(SetCurrentDirectory(*currentPath)) return true; + return false; +} int listDirectory(std::string path, std::vector *directoryContents){ HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATA ffd; LARGE_INTEGER filesize; int numFiles = 0; - + if (path.length() > (MAX_PATH - 3)) return -1; path = path + "\\*"; hFind = FindFirstFile(path.c_str(), &ffd); @@ -54,12 +62,12 @@ int listDirectory(std::string path, std::vector *directoryContents){ } while (ffd.cFileName[idx]); if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - strcat(itemPath, " "); + //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); + // filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow); + // char buf[16]; buf[0] = ' '; + // itoa(filesize.QuadPart, buf + 1 , 10 ); + // strcat(itemPath, buf); } numFiles++; @@ -68,6 +76,7 @@ int listDirectory(std::string path, std::vector *directoryContents){ return numFiles; } +/* FIN FILE PICKER MOMENTO */ @@ -188,28 +197,50 @@ int main(int, char**) { ImGui::Begin("File Picker in 4K"); - //cursed C momento + //cursed C momento: necesario ptr en otra var para mandar a char** de firma + static bool renderList = true; static char currentPath[MAX_PATH]; - char* ptr = ¤tPath[0]; + static char* ptr = ¤tPath[0]; - static int currentItemIdx = 0; + static int currentItemIdx = -1; + static std::vector displayContents; std::vector directoryContents; + ImGui::Text("%s primir", currentPath); + static int numFiles = 0; - if(!retrieveCurrentDirectory(&ptr)) goto filepickerFailure; + if(renderList) { + renderList = false; + if(!retrieveCurrentDirectory(&ptr)) + goto filepickerFailure; + // + numFiles = (listDirectory(std::string(currentPath), &directoryContents)); + //std::cout << numFiles; + if (numFiles < 0) + goto filepickerFailure; + displayContents = std::move(directoryContents); + } - if(int numFiles = (listDirectory(".", &directoryContents))){ + if(numFiles > 0){ ImGui::Text("Select a file:"); + //TODO quitar + 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(directoryContents.at(i), isSelected)) + if (ImGui::Selectable(displayContents.at(i), isSelected)) currentItemIdx = i; //Set the initial focus when opening the combo (scrolling + keyboard navigation focus) - if (isSelected) - ImGui::SetItemDefaultFocus(); + if (isSelected) { + strcat(currentPath, "\\"); + strcat(currentPath, displayContents.at(i)); + moveDirectory(&ptr); + currentItemIdx = -1; + renderList = true; + } + //ImGui::SetItemDefaultFocus(); } ImGui::EndListBox();