From 027400d763d8a5e1c5fc1a30c1b855ec8d647922 Mon Sep 17 00:00:00 2001 From: OugonNoHane Date: Thu, 3 Nov 2022 17:19:57 +0100 Subject: [PATCH] rip bug, mjr errstr hndl: string? adminright msg? --- main.cpp | 67 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/main.cpp b/main.cpp index 97ee972..8d94996 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ #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; \ + if (debug) std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ } while (0) #define log_directory(str) if(debugVerbosity & DEBUG_DIRECTORY) log_debugcpp((str)) #define log_volume(str) if(debugVerbosity & DEBUG_VOLUME) log_debugcpp((str)) @@ -61,6 +61,20 @@ typedef struct { } directoriesInfo; +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?"; +}; + +// struct ErrorMessages{ + // static constexpr char addrBarError[] = "Failed to open folder: invalid path"; + // static constexpr char tableElementError[] = "Failed to open folder: access restricted to non-admin users"; + // static constexpr char listDirectoryError[] = "Failed to open folder: access denied"; + // static constexpr char moveUpError[] = "Failed to move up: reached volume root?"; +// }; + //TODO UNICORDEO /* FILE PICKER MOMENTO */ @@ -153,9 +167,7 @@ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, itemPath[pathLengthIdx + 1] = '\0'; dest->push_back(itemPath); //TODO concat de puto C - log_debugcpp(dest->at(dest->size() - 1)); - log_debugcpp( " EXPLODEPATH"); - + log_debugcpp(dest->at(dest->size() - 1) << " EXPLODEPATH"); if (nextOcurrence[0] == nextOcurrence[1]) return depth; depth++; @@ -177,10 +189,9 @@ int listVolumes(std::vector *onPresentPaths){ TCHAR volumePaths[volumePathsBufferSize]; std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0'); - hFind = FindFirstVolume(volumeName, volumeNameSize); //if (debug) std::cout << volumeNameSize << std::endl; + hFind = FindFirstVolume(volumeName, volumeNameSize); if (INVALID_HANDLE_VALUE == hFind) return -2; do { - //if (debug) std::cout << volumeName << std::endl; if(GetVolumePathNamesForVolumeName(volumeName, volumePaths, volumePathsBufferSize, &volumePathLength)){ @@ -233,8 +244,7 @@ bool compareLastChar(std::vector *lastCharCandidates, char* string) 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())); + log_debugcpp(potentialExtension << " 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"); @@ -250,6 +260,12 @@ bool inputMove(bool* error, char** str){ return true; } +void handleFolderAccessResult(bool isListDirectoriesAdequate, char* currentPath, char* addrBarVal, char* errorDest, const char* errorContent){ + if (isListDirectoriesAdequate) strcpy(currentPath, addrBarVal); + else strcpy(addrBarVal, currentPath); + strcpy(errorDest, errorContent); +} + /* FIN FILE PICKER MOMENTO */ @@ -372,9 +388,10 @@ int main(int, char**) ImGui::Begin("File Picker in 4K"); static bool showError = false; + static char error[MAX_ERRORSTR_LEN]; + static ErrorMessages eMsg; static bool isListVolumesAdequate = true; static bool isListDirectoriesAdequate = true; - static char error[MAX_ERRORSTR_LEN]; //Listar UNA VEZ volumenes static int numVolumes; @@ -417,7 +434,7 @@ int main(int, char**) if (numFiles < 0) { log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles)); showError = true; - strcpy(error, "Failed to open folder: permission denied?"); + strcpy(error, eMsg.listDirectoryError.c_str()); strcpy(currentPath, addrBarVal); numFiles = listDirectory(std::string(currentPath), &directoryContents); } else { @@ -443,31 +460,26 @@ int main(int, char**) static char* moveUpPtr = &moveUp[0]; if(ImGui::Button("Move Up")) { isListDirectoriesAdequate = inputMove(&showError, (&moveUpPtr)); - strcpy(error, "Failed to move up: reached volume root?"); + strcpy(error, eMsg.moveUpError.c_str()); } ImGui::SameLine(); //BARRA DE DIRECCIONES + 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); - log_debugcpp(" ADDRBAR INTENTO"); + log_debugcpp(currentPath <<" ADDRBAR INTENTO"); isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); - if (isListDirectoriesAdequate) strcpy(currentPath, addrBarVal); - else strcpy(addrBarVal, currentPath); - strcpy(error, "Failed to open folder: invalid path"); + handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, eMsg.addrBarError.c_str()); }; + ImGui::PopItemWidth(); ImGui::SameLine(); if(ImGui::Button("Enter")){ - log_debugcpp(currentPath); - log_debugcpp(" ADDRBAR INTENTO"); + log_debugcpp(currentPath <<" ADDRBAR INTENTO"); isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); - if (isListDirectoriesAdequate) strcpy(currentPath, addrBarVal); - else strcpy(addrBarVal, currentPath); - strcpy(error, "Failed to open folder: invalid path"); + handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, eMsg.addrBarError.c_str()); } - //ImGui::Text("%s TEMPADDRBAR", currentPath); - + log_debugcpp(currentPath <<" LEMISIIMIA"); //LA GRAN TABLACIÓN: ACTOR EN LAS SOMBRAS static ImGuiTableFlags splitterTableFlags = ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV; if (ImGui::BeginTable("##splitterTable", 2, splitterTableFlags, ImVec2(-FLT_MIN, 0.8f * ImGui::GetTextLineHeightWithSpacing()))){ @@ -530,11 +542,10 @@ int main(int, char**) //NAME bool isSelected = false; if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){ - //currentItemIdx = i; - strcat(currentPath, "\\"); - strcat(currentPath, directoryContents.at(idx)->name); - isListDirectoriesAdequate = inputMove(&showError, ¤tPathPtr); - strcpy(error, "Failed to open folder: invalid option"); + strcat(addrBarVal, "\\"); + strcat(addrBarVal, directoryContents.at(idx)->name); + isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); + handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, eMsg.tableElementError.c_str()); //currentItemIdx = -1; } ImGui::TableNextColumn();