pwetty big refactor: isAdeq>LIST_DIR, char**>*

This commit is contained in:
OugonNoHane 2022-11-13 13:30:53 +01:00
commit f36ed343d5

View file

@ -27,23 +27,6 @@
namespace fp { namespace fp {
bool debug = true;
// int debugVerbosity = 0;
// enum enumDebugVerbosity {
// DEBUG_DIRECTORY = (1<<0),
// DEBUG_VOLUME = (1<<1),
// DEBUG_EXTENSION = (1<<2)
// };
// debugVerbosity = DEBUG_DIRECTORY | DEBUG_EXTENSION;
// debugVerbosity &= ~DEBUG_DIRECTORY;
// if (debugVerbosity & (DEBUG_DIRECTORY | DEBUG_EXTENSION));
int windowFlags = 0;
typedef struct { typedef struct {
long long size; long long size;
//TODO yel spacsio NELLA MEMoria //TODO yel spacsio NELLA MEMoria
@ -95,6 +78,71 @@ namespace ErrorMessages {
char moveUpError[] = "Failed to move up: reached volume root?"; char moveUpError[] = "Failed to move up: reached volume root?";
}; };
enum listFlags {
LIST_DIRECTORY = (1<<0),
LIST_VOLUME = (1<<1)
};
//VARS
bool debug = true;
History* history = new History();
//Flags used to determine:
// window format
int windowFlags = 0;
// if it's time to load new data
int listFlags = LIST_DIRECTORY | LIST_VOLUME;
//Array used to display current error
char error[MAX_ERRORSTR_LEN];
bool showError = false;
//Stores found volumes
//TODO onPresentPaths???? wtf is dis naem bru
std::vector<char*> onPresentPaths;
int numVolumes;
//currentPath is the one used to retrieve data, then copied to addrBalVar for display.
//addrBalVar is also used as a bacukp in case new currentPath is invalid
//TODO: hay historial. Coalescer en una sola?
//TODO: david wtf
//cursed C momento: necesario ptr en otra var para mandar a char** de firma
char currentPath[MAX_PATH];
char* currentPathPtr = &currentPath[0];
char addrBarVal[MAX_LISTDIR_PATH_LENGTH];
char* addrBarValPtr = &addrBarVal[0];
//Stores entires found within a given directory
//static int currentItemIdx = -1;
std::vector<directoriesInfo*> directoryContents;
int numFiles = 0;
//Going one level up needs to be hardcoded like this due to function inputMove needing a char**
//c pervirtio con unicode std::wstring s(L"←→↑↓");
char moveUp[] = "..";
char* moveUpPtr = &moveUp[0];
bool isListVolumesAdequate = true;
bool isListDirectoriesAdequate = true;
//RenderTime vars for filtering
bool showHidden = false;
bool filterByExtension = false;
std::vector<std::string> extensions;
// int debugVerbosity = 0;
// enum enumDebugVerbosity {
// DEBUG_DIRECTORY = (1<<0),
// DEBUG_VOLUME = (1<<1),
// DEBUG_EXTENSION = (1<<2)
// };
// debugVerbosity = DEBUG_DIRECTORY | DEBUG_EXTENSION;
// debugVerbosity &= ~DEBUG_DIRECTORY;
// if (debugVerbosity & (DEBUG_DIRECTORY | DEBUG_EXTENSION));
//TODO UNICORDEO //TODO UNICORDEO
/* FILE PICKER MOMENTO */ /* FILE PICKER MOMENTO */
@ -102,14 +150,14 @@ namespace ErrorMessages {
/* DIRECTORIES */ /* DIRECTORIES */
bool retrieveCurrentDirectory(char** currentPath){ bool retrieveCurrentDirectory(char* currentPath){
if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true; if(GetCurrentDirectory(MAX_PATH, currentPath)) return true;
return false; return false;
} }
bool moveDirectory(char** currentPath){ bool moveDirectory(char* currentPath){
log_debugcpp(*currentPath); log_debugcpp(currentPath);
if(SetCurrentDirectory(*currentPath)) return true; if(SetCurrentDirectory(currentPath)) return true;
return false; return false;
} }
@ -193,7 +241,7 @@ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator,
int pathLengthIdx = 0; int pathLengthIdx = 0;
for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) { for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) {
if (debug) { std::cout << volumePaths[0]; std::cout << " ENTERS " + std::to_string(pathLengthIdx) << std::endl; } log_debugcpp(volumePaths[0] << " ENTERS " << std::to_string(pathLengthIdx));
itemPath[pathLengthIdx] = volumePaths[pathLengthIdx]; itemPath[pathLengthIdx] = volumePaths[pathLengthIdx];
} }
itemPath[pathLengthIdx + 1] = '\0'; itemPath[pathLengthIdx + 1] = '\0';
@ -227,7 +275,10 @@ int listVolumes(std::vector<char*> *onPresentPaths){
if(GetVolumePathNamesForVolumeName(volumeName, volumePaths, volumePathsBufferSize, &volumePathLength)){ if(GetVolumePathNamesForVolumeName(volumeName, volumePaths, volumePathsBufferSize, &volumePathLength)){
if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; } if (volumePathLength == 1) {
log_debugcpp("Skill Issue");
continue;
}
log_debugcpp(volumeName); log_debugcpp(volumeName);
//DEBUG: pathSchecker //DEBUG: pathSchecker
@ -242,18 +293,18 @@ int listVolumes(std::vector<char*> *onPresentPaths){
// std::cout << std::endl << "I IA" << std::endl; // std::cout << std::endl << "I IA" << std::endl;
// exit(1); // exit(1);
// } // }
if (debug) {
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){ if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
for (int i = 0; i < onPresentPaths->size(); i++){ for (int i = 0; i < onPresentPaths->size(); i++){
std::cout << onPresentPaths->at(i) << std::endl; log_debugcpp(onPresentPaths->at(i));
}
} }
} }
//std::cout << volumePaths << std::endl; //std::cout << volumePaths << std::endl;
log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH"); log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH");
log_debugcpp("THE END"); log_debugcpp("THE END");
} else {
}else{
log_debugcpp("no volumes found wtf"); log_debugcpp("no volumes found wtf");
} }
//TODO benchimarqui //TODO benchimarqui
@ -286,24 +337,57 @@ bool compareLastChar(std::vector<std::string> *lastCharCandidates, char* string)
return matchingExtension; return matchingExtension;
} }
bool inputMove(bool* error, char** str){ //TODO huh
// int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
// const char* errorContent, History* history, char* currentPath = NULL, char* addrBarVal = NULL){
// *error = false;
// if(!moveDirectory(nextPath)) {
// *error = true;
// if(currentPath && addrBarVal) {
// strcpy(errorDest, errorContent);
// strcpy(addrBarVal, currentPath);
// }
// return listFlags;
// }
// if(currentPath && addrBarVal) {
// strcpy(currentPath, addrBarVal);
// history->isAdditionTime = true;
// }
// return (listFlags |= LIST_DIRECTORY);
// }
//TODO huh, vale, no pasa por listdirectory por la flag, pero esto se podria hacer mejor manteniendo el no tirar de disco tb?
int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
const char* errorContent, History* history, char* currentPath , char* addrBarVal){
*error = false; *error = false;
if(!moveDirectory(str)) { *error = true; return false; } if(!moveDirectory(nextPath)) {
return true; *error = true;
strcpy(errorDest, errorContent);
strcpy(addrBarVal, currentPath);
return listFlags;
}
//strcpy(currentPath, addrBarVal);
history->isAdditionTime = true;
return (listFlags |= LIST_DIRECTORY);
} }
void handleFolderAccessResult(bool isListDirectoriesAdequate, char* currentPath, \ int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
char* addrBarVal, char* errorDest, const char* errorContent, History* history){ const char* errorContent, History* history, bool isAdditionTime){
if (isListDirectoriesAdequate) { strcpy(currentPath, addrBarVal); history->isAdditionTime = true; } *error = false;
else strcpy(addrBarVal, currentPath); if(!moveDirectory(nextPath)) {
strcpy(errorDest, errorContent); *error = true;
strcpy(errorDest, errorContent);
return listFlags;
}
if (isAdditionTime) history->isAdditionTime = true;
return (listFlags |= LIST_DIRECTORY);
} }
/* HISTORIAL */ /* HISTORIAL */
void addPathToHistory(History *history, char* pathToAdd){ void addPathToHistory(History *history, char* pathToAdd){
char* path; char* path;
//int ajjj = history->previousPaths.size();
if (history->historyTraversalPos + 1 >= history->previousPaths.size()){ if (history->historyTraversalPos + 1 >= history->previousPaths.size()){
path = (char*)calloc(1, MAX_PATH); path = (char*)calloc(1, MAX_PATH);
history->previousPaths.push_back(path); history->previousPaths.push_back(path);
@ -316,22 +400,22 @@ void addPathToHistory(History *history, char* pathToAdd){
history->isAdditionTime = false; history->isAdditionTime = false;
} }
char** moveThroughHistory(History *history, HistoryMovement movement) { char* moveThroughHistory(History *history, HistoryMovement movement) {
int sign = (movement == HISTORY_BACKWARD ? -1 : 1); int sign = (movement == HISTORY_BACKWARD ? -1 : 1);
switch(movement){ switch(movement){
case HISTORY_BACKWARD: case HISTORY_BACKWARD:
if(MIN_HISTORY_POS) if(MIN_HISTORY_POS)
return &history->previousPaths.at(history->historyTraversalPos); return history->previousPaths.at(history->historyTraversalPos);
break; break;
case HISTORY_FORWARD: case HISTORY_FORWARD:
if(MAX_HISTORY_POS) if(MAX_HISTORY_POS)
return &history->previousPaths.at(history->historyDepth); return history->previousPaths.at(history->historyDepth);
break; break;
default: default:
return &history->previousPaths.at(history->historyDepth); return history->previousPaths.at(history->historyDepth);
} }
history->historyTraversalPos += sign; history->historyTraversalPos += sign;
return &history->previousPaths.at(history->historyTraversalPos); return history->previousPaths.at(history->historyTraversalPos);
} }
@ -347,45 +431,23 @@ void filePickerMomento(bool isFullViewport = false){
} }
ImGui::Begin("File Picker in 4K", NULL, windowFlags); ImGui::Begin("File Picker in 4K", NULL, windowFlags);
if (isFullViewport) ImGui::PopStyleVar(1); if (isFullViewport) ImGui::PopStyleVar(1);
static History* history = new History();
static bool showError = false;
static char error[MAX_ERRORSTR_LEN];
static bool isListVolumesAdequate = true;
static bool isListDirectoriesAdequate = true;
//Listar UNA VEZ volumenes //Listar UNA VEZ volumenes
static int numVolumes; if (listFlags & LIST_VOLUME) {
static std::vector<char*> onPresentPaths; listFlags &= ~LIST_VOLUME;
if (isListVolumesAdequate) {
isListVolumesAdequate = false;
//std::cout << isListVolumesAdequate << std::endl;
numVolumes = listVolumes(&onPresentPaths); numVolumes = listVolumes(&onPresentPaths);
log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size())); log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()));
} }
//Listar UNA VEZ directorios //Listar UNA VEZ directorios
//cursed C momento: necesario ptr en otra var para mandar a char** de firma
static char currentPath[MAX_PATH];
static char* currentPathPtr = &currentPath[0];
static char addrBarVal[MAX_LISTDIR_PATH_LENGTH];
static char* addrBarValPtr = &addrBarVal[0];
//static int currentItemIdx = -1;
//static std::vector<char*> directoryContents;
static std::vector<directoriesInfo*> directoryContents;
static int numFiles = 0;
//ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath); //ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath);
if (listFlags & LIST_DIRECTORY) {
if(isListDirectoriesAdequate) { listFlags &= ~LIST_DIRECTORY;
log_debugcpp("ADECUADO LISTAR DIRECTORIOS"); log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
isListDirectoriesAdequate = false; if(!retrieveCurrentDirectory(currentPath)) {
if(!retrieveCurrentDirectory(&currentPathPtr)) {
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()"); log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
goto filepickerFailure; exit(EXIT_FAILURE);
} }
// //
//TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE //TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE
@ -432,9 +494,6 @@ void filePickerMomento(bool isFullViewport = false){
*/ */
static bool showHidden = false;
static bool filterByExtension = false;
static std::vector<std::string> extensions;
if(showError){ if(showError){
ImGui::Text(error); ImGui::Text(error);
@ -445,31 +504,28 @@ void filePickerMomento(bool isFullViewport = false){
//Permanentes e increiblemente utilitarios botones en Cuatro K: BACK //Permanentes e increiblemente utilitarios botones en Cuatro K: BACK
ImGui::BeginDisabled(MIN_HISTORY_POS); ImGui::BeginDisabled(MIN_HISTORY_POS);
if(ImGui::Button("Back")) { if(ImGui::Button("Back")) {
char** interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_BACKWARD); char* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_BACKWARD);
isListDirectoriesAdequate = inputMove(&showError, interfaceMovementButtonsPath);
//TODO: ERROR //TODO: ERROR
strcpy(error, ErrorMessages::moveUpError); listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
&showError, error, ErrorMessages::moveUpError, history, false);
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
//FORWARD //FORWARD
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(MAX_HISTORY_POS); ImGui::BeginDisabled(MAX_HISTORY_POS);
if(ImGui::Button("Forward")) { if(ImGui::Button("Forward")) {
char** interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD); //TODO david????????????????????????????????????
isListDirectoriesAdequate = inputMove(&showError, interfaceMovementButtonsPath); char* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD);
strcpy(error, ErrorMessages::moveUpError); listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
&showError, error, ErrorMessages::moveUpError, history, false);
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
//MOVE UP //MOVE UP
ImGui::SameLine(); ImGui::SameLine();
//c pervirtio con unicode std::wstring s(L"←→↑↓");
static char moveUp[] = "..";
static char* moveUpPtr = &moveUp[0];
if(ImGui::Button("Move Up")) { if(ImGui::Button("Move Up")) {
isListDirectoriesAdequate = inputMove(&showError, (&moveUpPtr)); listFlags = handleFolderAccessResult(listFlags, moveUp, &showError,
strcpy(error, ErrorMessages::moveUpError); error, ErrorMessages::moveUpError, history, true);
history->isAdditionTime = true;
} }
ImGui::SameLine(); ImGui::SameLine();
@ -477,15 +533,15 @@ void filePickerMomento(bool isFullViewport = false){
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize("Enter").x + ImGui::GetStyle().ItemSpacing.x * 2) ); ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize("Enter").x + ImGui::GetStyle().ItemSpacing.x * 2) );
if(ImGui::InputText("##addrbar", addrBarVal, IM_ARRAYSIZE(addrBarVal), ImGuiInputTextFlags_EnterReturnsTrue )){ if(ImGui::InputText("##addrbar", addrBarVal, IM_ARRAYSIZE(addrBarVal), ImGuiInputTextFlags_EnterReturnsTrue )){
log_debugcpp(currentPath <<" ADDRBAR INTENTO"); log_debugcpp(currentPath <<" ADDRBAR INTENTO");
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::addrBarError, history); history, currentPath, addrBarVal);
}; };
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Enter")){ if(ImGui::Button("Enter")){
log_debugcpp(currentPath <<" ADDRBAR INTENTO"); log_debugcpp(currentPath <<" ADDRBAR INTENTO");
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::addrBarError, history); history, currentPath, addrBarVal);
} }
//ImGui::Text("%s TEMPADDRBAR", currentPath); //ImGui::Text("%s TEMPADDRBAR", currentPath);
@ -512,8 +568,9 @@ void filePickerMomento(bool isFullViewport = false){
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i / 7.0f, 0.7f, 0.7f)); 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)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f));
if(ImGui::Button(onPresentPaths.at(i))){ if(ImGui::Button(onPresentPaths.at(i))){
isListDirectoriesAdequate = inputMove(&showError, &onPresentPaths.at(i)); //TODO xdddddddd
history->isAdditionTime = true; listFlags = handleFolderAccessResult(listFlags, onPresentPaths.at(i), &showError, error,
ErrorMessages::moveUpError, history, true);
} }
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
if (i != onPresentPaths.size() - 1) ImGui::TableNextRow(); if (i != onPresentPaths.size() - 1) ImGui::TableNextRow();
@ -525,7 +582,6 @@ void filePickerMomento(bool isFullViewport = false){
ImGui::TableNextColumn(); ImGui::TableNextColumn();
//DIRECTORIOS ENCONTRADOS bien pinta2 //DIRECTORIOS ENCONTRADOS bien pinta2
static ImGuiTableFlags directoriesFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable |ImGuiTableFlags_ScrollY ; static ImGuiTableFlags directoriesFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable |ImGuiTableFlags_ScrollY ;
if (ImGui::BeginTable("##directoriesTable", 3, directoriesFlags, ImVec2(-FLT_MIN, 20 * ImGui::GetTextLineHeightWithSpacing()))){ if (ImGui::BeginTable("##directoriesTable", 3, directoriesFlags, ImVec2(-FLT_MIN, 20 * ImGui::GetTextLineHeightWithSpacing()))){
@ -554,8 +610,8 @@ void filePickerMomento(bool isFullViewport = false){
if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){ if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){
strcat(addrBarVal, "\\"); strcat(addrBarVal, "\\");
strcat(addrBarVal, directoryContents.at(idx)->name); strcat(addrBarVal, directoryContents.at(idx)->name);
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr); listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error,
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::tableElementError, history); ErrorMessages::tableElementError, history, currentPath, addrBarVal);
//currentItemIdx = -1; //currentItemIdx = -1;
} }
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -589,8 +645,6 @@ void filePickerMomento(bool isFullViewport = false){
ImGui::Checkbox("Filter by .exe", &filterByExtension); ImGui::Checkbox("Filter by .exe", &filterByExtension);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Button("Select"); ImGui::Button("Select");
filepickerFailure:
ImGui::End(); ImGui::End();
} }