diff --git a/main.cpp b/main.cpp index df12cbe..97ee972 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ #define MAX_LISTDIR_PATH_LENGTH (MAX_PATH - 3) +#define MAX_ERRORSTR_LEN 512 #include "imgui/misc/single_file/imgui_single_file.h" #include @@ -63,27 +64,6 @@ typedef struct { //TODO UNICORDEO /* FILE PICKER MOMENTO */ -/* PROPOSITO GENERAL */ - -bool compareLastChar(std::vector *lastCharCandidates, char* string){ - bool matchingExtension = false; - for (int i = 0; i < lastCharCandidates->size(); i++){ - log_debugcpp(lastCharCandidates->at(i) + " <- FILTERING EXTENSION"); - - if(strlen(string) < lastCharCandidates->at(i).length()) continue; - char* potentialExtension = &string[strlen(string) - lastCharCandidates->at(i).length()]; - - log_debugcpp(potentialExtension); - log_debugcpp(" LEN " + std::to_string(strlen(potentialExtension)) + " <- VS -> " + lastCharCandidates->at(i) + " LEN " + std::to_string(lastCharCandidates->at(i).length())); - //+ strlen(potentialExtension) + std::to_string(lastCharCandidates->at(i).length()) - if(!strcmp(potentialExtension, lastCharCandidates->at(i).c_str())) { - log_debugcpp("VALID EXTENSION"); - matchingExtension = true; - } - } - return matchingExtension; -} - /* DIRECTORIES */ @@ -239,7 +219,37 @@ int listVolumes(std::vector *onPresentPaths){ log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN"); FindVolumeClose(hFind); return numVolumes; -} +} + + +/* DISPLAY */ + + +bool compareLastChar(std::vector *lastCharCandidates, char* string){ + bool matchingExtension = false; + for (int i = 0; i < lastCharCandidates->size(); i++){ + log_debugcpp(lastCharCandidates->at(i) + " <- FILTERING EXTENSION"); + + if(strlen(string) < lastCharCandidates->at(i).length()) continue; + char* potentialExtension = &string[strlen(string) - lastCharCandidates->at(i).length()]; + + log_debugcpp(potentialExtension); + log_debugcpp(" LEN " + std::to_string(strlen(potentialExtension)) + " <- VS -> " + lastCharCandidates->at(i) + " LEN " + std::to_string(lastCharCandidates->at(i).length())); + //+ strlen(potentialExtension) + std::to_string(lastCharCandidates->at(i).length()) + if(!strcmp(potentialExtension, lastCharCandidates->at(i).c_str())) { + log_debugcpp("VALID EXTENSION"); + matchingExtension = true; + } + } + return matchingExtension; +} + +bool inputMove(bool* error, char** str){ + *error = false; + if(!moveDirectory(str)) { *error = true; return false; } + return true; +} + /* FIN FILE PICKER MOMENTO */ @@ -361,9 +371,10 @@ int main(int, char**) { ImGui::Begin("File Picker in 4K"); - static bool isInvalidPath = false; + static bool showError = false; static bool isListVolumesAdequate = true; static bool isListDirectoriesAdequate = true; + static char error[MAX_ERRORSTR_LEN]; //Listar UNA VEZ volumenes static int numVolumes; @@ -381,13 +392,15 @@ int main(int, char**) //cursed C momento: necesario ptr en otra var para mandar a char** de firma static char currentPath[MAX_PATH]; static char* currentPathPtr = ¤tPath[0]; - + static char addrBarVal[MAX_LISTDIR_PATH_LENGTH]; + static char* addrBarValPtr = &addrBarVal[0]; + //static int currentItemIdx = -1; //static std::vector directoryContents; static std::vector directoryContents; static int numFiles = 0; - ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath); + //ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath); if(isListDirectoriesAdequate) { log_debugcpp("ADECUADO LISTAR DIRECTORIOS"); @@ -403,7 +416,13 @@ int main(int, char**) //std::cout << numFiles; if (numFiles < 0) { log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles)); - isInvalidPath = true; + showError = true; + strcpy(error, "Failed to open folder: permission denied?"); + strcpy(currentPath, addrBarVal); + numFiles = listDirectory(std::string(currentPath), &directoryContents); + } else { + showError = false; + strcpy(addrBarVal, currentPath); } } @@ -411,6 +430,11 @@ int main(int, char**) static bool showHidden = false; static bool filterByExtension = false; static std::vector extensions; + + if(showError){ + ImGui::Text(error); + } + ImGui::Text("Select a file:"); //Permanentes e increiblemente utilitarios botones en Cuatro K: MOVE UP @@ -418,14 +442,31 @@ int main(int, char**) static char moveUp[] = ".."; static char* moveUpPtr = &moveUp[0]; if(ImGui::Button("Move Up")) { - moveDirectory(&moveUpPtr); - isInvalidPath = false; - isListDirectoriesAdequate = true; + isListDirectoriesAdequate = inputMove(&showError, (&moveUpPtr)); + strcpy(error, "Failed to move up: reached volume root?"); } ImGui::SameLine(); //BARRA DE DIRECCIONES - ImGui::Text("%s TEMPADDRBAR", currentPath); + if(ImGui::InputText("##addrbar", addrBarVal, IM_ARRAYSIZE(addrBarVal), ImGuiInputTextFlags_EnterReturnsTrue )){ + log_debugcpp(currentPath); + log_debugcpp(" ADDRBAR INTENTO"); + isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); + if (isListDirectoriesAdequate) strcpy(currentPath, addrBarVal); + else strcpy(addrBarVal, currentPath); + strcpy(error, "Failed to open folder: invalid path"); + }; + ImGui::SameLine(); + if(ImGui::Button("Enter")){ + log_debugcpp(currentPath); + log_debugcpp(" ADDRBAR INTENTO"); + isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); + if (isListDirectoriesAdequate) strcpy(currentPath, addrBarVal); + else strcpy(addrBarVal, currentPath); + strcpy(error, "Failed to open folder: invalid path"); + } + + //ImGui::Text("%s TEMPADDRBAR", currentPath); //LA GRAN TABLACIÓN: ACTOR EN LAS SOMBRAS static ImGuiTableFlags splitterTableFlags = ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV; @@ -450,8 +491,7 @@ int main(int, char**) 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; + isListDirectoriesAdequate = inputMove(&showError, &onPresentPaths.at(i)); } ImGui::PopStyleColor(3); if (i != onPresentPaths.size() - 1) ImGui::TableNextRow(); @@ -493,9 +533,9 @@ int main(int, char**) //currentItemIdx = i; strcat(currentPath, "\\"); strcat(currentPath, directoryContents.at(idx)->name); - moveDirectory(¤tPathPtr); + isListDirectoriesAdequate = inputMove(&showError, ¤tPathPtr); + strcpy(error, "Failed to open folder: invalid option"); //currentItemIdx = -1; - isListDirectoriesAdequate = true; } ImGui::TableNextColumn(); @@ -512,9 +552,7 @@ int main(int, char**) } //DISPLAYING ALTERNATIVE INFO if (!idx) { - ImGui::TableNextRow(); ImGui::TableNextColumn(); - if (isInvalidPath) ImGui::Text("Failed to access: Path not valid"); - else ImGui::Text("Folder is empty"); + ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("Folder is empty"); } ImGui::EndTable(); }