diff --git a/main.cpp b/main.cpp index 5f6314b..5f92786 100644 --- a/main.cpp +++ b/main.cpp @@ -20,8 +20,8 @@ #define MAX_ERRORSTR_LEN 512 //HISTORY HANDLING MACRO -#define MIN_HISTORY_POS history->historyTraversalPos <= 0 -#define MAX_HISTORY_POS history->historyTraversalPos >= history->historyDepth +#define MIN_HISTORY_POS (history->historyTraversalPos <= 0) +#define MAX_HISTORY_POS (history->historyTraversalPos >= history->historyDepth) #include "imgui/misc/single_file/imgui_single_file.h" #include @@ -66,10 +66,13 @@ typedef struct { } directoriesInfo; + struct History{ std::vector previousPaths; - //TODO C++ david momento + //warnings e 1 cosa //int historyDepth = -1; + //TODO Limitar historial + //const int maxHistoryDepth = 10000; int historyDepth; int historyTraversalPos; bool isAdditionTime; @@ -94,13 +97,6 @@ enum agnosticDirError { AGDIR_ERROR_ACCESS_DENIED = 1 }; -// struct ErrorMessages{ - // const std::string addrBarError = "Failed to open folder: invalid path"; - // const std::string tableElementError = "Failed to open folder: access restricted to non-admin users"; - // const std::string listDirectoryError = "Failed to open folder: access denied"; - // const std::string moveUpError = "Failed to move up: reached volume root?"; -// }; - namespace ErrorMessages { char addrBarError[] = "Failed to open folder: invalid path"; char tableElementError[] = "Failed to open folder: access restricted to non-admin users"; @@ -270,7 +266,7 @@ int listVolumes(std::vector *onPresentPaths){ }else{ log_debugcpp("no volumes found wtf"); } - + //TODO benchimarqui std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0'); } while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0); log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN"); @@ -317,8 +313,8 @@ void handleFolderAccessResult(bool isListDirectoriesAdequate, char* currentPath, void addPathToHistory(History *history, char* pathToAdd){ char* path; - int ajjj = history->previousPaths.size(); - if (history->historyTraversalPos + 1 >= ajjj){ + //int ajjj = history->previousPaths.size(); + if (history->historyTraversalPos + 1 >= history->previousPaths.size()){ path = (char*)calloc(1, MAX_PATH); history->previousPaths.push_back(path); } else { @@ -330,23 +326,22 @@ void addPathToHistory(History *history, char* pathToAdd){ history->isAdditionTime = false; } -char** moveThroughHistory(History *history, HistoryMovement movement){ +char** moveThroughHistory(History *history, HistoryMovement movement) { + int sign = (movement == HISTORY_BACKWARD ? -1 : 1); switch(movement){ case HISTORY_BACKWARD: if(MIN_HISTORY_POS) return &history->previousPaths.at(history->historyTraversalPos); - history->historyTraversalPos--; - return &history->previousPaths.at(history->historyTraversalPos); break; case HISTORY_FORWARD: if(MAX_HISTORY_POS) return &history->previousPaths.at(history->historyDepth); - history->historyTraversalPos++; - return &history->previousPaths.at(history->historyTraversalPos); break; default: return &history->previousPaths.at(history->historyDepth); } + history->historyTraversalPos += sign; + return &history->previousPaths.at(history->historyTraversalPos); } @@ -469,7 +464,6 @@ int main(int, char**) { { ImGui::Begin("File Picker in 4K"); - //TODO is dis bector in hipp? static History* history = new History(); static bool showError = false; static char error[MAX_ERRORSTR_LEN]; @@ -487,7 +481,6 @@ int main(int, char**) { log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size())); } - //Listar UNA VEZ directorios //cursed C momento: necesario ptr en otra var para mandar a char** de firma static char currentPath[MAX_PATH]; @@ -531,7 +524,6 @@ int main(int, char**) { strcpy(error, ErrorMessages::listDirectoryError); strcpy(currentPath, addrBarVal); numFiles = listDirectory(std::string(currentPath), &directoryContents); - history->isAdditionTime = false; break; } history->isAdditionTime = false; @@ -597,7 +589,6 @@ int main(int, char**) { ImGui::SameLine(); //BARRA DE DIRECCIONES - //TODO a point ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize("Enter").x + ImGui::GetStyle().ItemSpacing.x * 2) ); if(ImGui::InputText("##addrbar", addrBarVal, IM_ARRAYSIZE(addrBarVal), ImGuiInputTextFlags_EnterReturnsTrue )){ log_debugcpp(currentPath <<" ADDRBAR INTENTO");