diff --git a/.gitignore b/.gitignore index 2abc06d..fabee7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ *.ini -*.exe -*.rdbg -*.pdb \ No newline at end of file +*.exe \ No newline at end of file diff --git a/main.cpp b/main.cpp index 861dda6..21756c4 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,6 @@ #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; \ @@ -14,9 +13,6 @@ #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 @@ -49,16 +45,9 @@ bool debug = true; typedef struct { - 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; + std::vector size; + std::vector name; +} directoriesInfo, volumesInfo; //TODO UNICORDEO /* FILE PICKER MOMENTO */ @@ -72,25 +61,27 @@ bool retrieveCurrentDirectory(char** currentPath){ } bool moveDirectory(char** currentPath){ - log_debugcpp(*currentPath); + if (debug) std::cout << *currentPath << std::endl; 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_LISTDIR_PATH_LENGTH)) return -1; + if (path.length() > (MAX_PATH - 3)) return -1; path = path + "\\*"; hFind = FindFirstFile(path.c_str(), &ffd); if (INVALID_HANDLE_VALUE == hFind) return -2; do { + + //TODO laberga k momento educativo 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, '.'); @@ -106,45 +97,37 @@ int listDirectory(std::string path, std::vector *directoryCont skipDueToExtension = true; } } - } - if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue;*/ + }*/ - //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){ - itemInfo = new directoriesInfo(); - directoryContents->push_back(itemInfo); + + if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue; + + //TODO multi info Struct + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + //strcat(itemPath, " "); } else { - itemInfo = directoryContents->at(numFiles); + + // filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow); + // char buf[16]; buf[0] = ' '; + // itoa(filesize.QuadPart, buf + 1 , 10 ); + // strcat(itemPath, buf); } - 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 + + + char* itemPath; + if (directoryContents->size() <= numFiles){ + itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR)); + directoryContents->push_back(itemPath); + } else { + itemPath = directoryContents->at(numFiles); + } + uint64_t idx = 0; do { - itemInfo->name[idx] = ffd.cFileName[idx]; + itemPath[idx] = ffd.cFileName[idx]; idx++; } while (ffd.cFileName[idx]); - itemInfo->name[idx] = '\0'; - log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles)); - + numFiles++; } while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); @@ -232,16 +215,17 @@ int listVolumes(std::vector *onPresentPaths){ } //std::cout << volumePaths << std::endl; - log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH"); - log_debugcpp("THE END"); + if (debug) std::cout << std::to_string(volumePathLength) + " " ; + if (debug) std::cout << "THE END" << std::endl; }else{ - log_debugcpp("no volumes found wtf"); + if (debug) std::cout << "no volumes found wtf" << std::endl; } std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0'); } while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0); - log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN"); + + if (debug) std::cout << std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN" << std::endl; FindVolumeClose(hFind); return numVolumes; } @@ -368,8 +352,8 @@ int main(int, char**) static bool isListVolumesAdequate = true; static bool isListDirectoriesAdequate = true; - //Listar UNA VEZ volumenes + static int numVolumes; static std::vector onPresentPaths; @@ -377,7 +361,7 @@ int main(int, char**) isListVolumesAdequate = false; //std::cout << isListVolumesAdequate << std::endl; numVolumes = listVolumes(&onPresentPaths); - log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size())); + if (debug) std::cout << std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()) << std::endl; } @@ -386,96 +370,103 @@ int main(int, char**) static char currentPath[MAX_PATH]; static char* currentPathPtr = ¤tPath[0]; - //static int currentItemIdx = -1; - //static std::vector directoryContents; - static std::vector directoryContents; + static int currentItemIdx = -1; + //TODO David momento + static std::vector displayContents; + std::vector directoryContents; static int numFiles = 0; - ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath); + if (debug) ImGui::Text("%s primir", currentPath); if(isListDirectoriesAdequate) { - log_debugcpp("ADECUADO LISTAR DIRECTORIOS"); + log_debugcpp("renderiso"); isListDirectoriesAdequate = false; if(!retrieveCurrentDirectory(¤tPathPtr)) { - log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()"); + if (debug) std::cout << "pencaste"; 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"); - log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO"); + ImGui::Text("Path not valid"); + if (debug) std::cout << "pencaste 2 el repencazo"; goto filepickerFailure; } - - //displayContents = std::move(directoryContents); - //directoryContents.clear(); + if (numFiles == 0) { + if (debug) std::cout << std::to_string (numFiles) << "<- NUM FILES" << std::endl; + char empty[] = "Empty"; + numFiles++; + directoryContents.push_back(empty); + } + displayContents = std::move(directoryContents); + directoryContents.clear(); } //It's renderin' time - ImGui::Text("Select a file:"); - 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; - if (numVolumes > 0) { - for (int i = 0; i < onPresentPaths.size(); i++) { - if (i > 0) ImGui::SameLine(); - // if (debug) std::cout << std::to_string(i) + "<- WE IN" << std::endl; - // ImGui::PushID(i); - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, 0.6f, 0.6f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i / 7.0f, 0.7f, 0.7f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f)); - if(ImGui::Button(onPresentPaths.at(i))){ - moveDirectory(&onPresentPaths.at(i)); - isListDirectoriesAdequate = true; + if(numFiles > 0){ + ImGui::Text("Select a file:"); + if (debug) ImGui::Text("%s %d", currentPath, currentItemIdx); + + //Y a que los VOLUMENES pinta2 pa100pre + //if (debug) std::cout << std::to_string(onPresentPaths.size()) + "<- numvols" << std::endl; + if (numVolumes > 0) { + for (int i = 0; i < onPresentPaths.size(); i++) { + if (i > 0) ImGui::SameLine(); + // if (debug) std::cout << std::to_string(i) + "<- WE IN" << std::endl; + // ImGui::PushID(i); + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, 0.6f, 0.6f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i / 7.0f, 0.7f, 0.7f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f)); + if(ImGui::Button(onPresentPaths.at(i))){ + moveDirectory(&onPresentPaths.at(i)); + isListDirectoriesAdequate = true; + } + ImGui::PopStyleColor(3); + // ImGui::PopID(); } - ImGui::PopStyleColor(3); - // ImGui::PopID(); } - } - - - //Permanentes e increiblemente utilitarios botones en Cuatro K - //c pervirtio con unicode std::wstring s(L"←→↑↓"); - static char moveUp[] = ".."; - static char* moveUpPtr = &moveUp[0]; - if(ImGui::Button("Move Up")){ - moveDirectory(&moveUpPtr); - isListDirectoriesAdequate = true; - } - - - //DIRECTORIOS ENCONTRADOS bien pinta2 - if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){ - int idx = 0; - for (; idx < numFiles; idx++) { - - //const bool isSelected = (currentItemIdx == i); - bool isSelected = false; - if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){ - //currentItemIdx = i; - strcat(currentPath, "\\"); - strcat(currentPath, directoryContents.at(idx)->name); - moveDirectory(¤tPathPtr); - //currentItemIdx = -1; - isListDirectoriesAdequate = true; + + + //Permanentes e increiblemente utilitarios botones en Cuatro K + //c pervirtio con unicode std::wstring s(L"←→↑↓"); + static char moveUp[] = ".."; + static char* moveUpPtr = &moveUp[0]; + if(ImGui::Button("Move Up")){ + moveDirectory(&moveUpPtr); + isListDirectoriesAdequate = true; + } + + + //DIRECTORIOS ENCONTRADOS bien pinta2 + if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){ + for (int i = 0; i < numFiles; i++) { + + const bool isSelected = (currentItemIdx == i); + if (ImGui::Selectable(displayContents.at(i), isSelected)) + currentItemIdx = i; + + if (isSelected) { + strcat(currentPath, "\\"); + strcat(currentPath, displayContents.at(i)); + moveDirectory(¤tPathPtr); + currentItemIdx = -1; + isListDirectoriesAdequate = true; + } + //ImGui::SetItemDefaultFocus(); + } - - //ImGui::SetItemDefaultFocus(); - + ImGui::EndListBox(); } - if (!idx) ImGui::Text("Folder is empty"); - ImGui::EndListBox(); + } else { + ImGui::Text("cagaste"); } - - //ImGui::TreePop(); - filepickerFailure: - ImGui::End(); - + //ImGui::TreePop(); + filepickerFailure: + ImGui::End(); + }