pwetty big refactor: isAdeq>LIST_DIR, char**>*
This commit is contained in:
parent
3e0711a00f
commit
f36ed343d5
1 changed files with 153 additions and 99 deletions
252
filepicker.hpp
252
filepicker.hpp
|
|
@ -27,23 +27,6 @@
|
|||
|
||||
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 {
|
||||
long long size;
|
||||
//TODO yel spacsio NELLA MEMoria
|
||||
|
|
@ -95,6 +78,71 @@ namespace ErrorMessages {
|
|||
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 = ¤tPath[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
|
||||
/* FILE PICKER MOMENTO */
|
||||
|
||||
|
|
@ -102,14 +150,14 @@ namespace ErrorMessages {
|
|||
/* DIRECTORIES */
|
||||
|
||||
|
||||
bool retrieveCurrentDirectory(char** currentPath){
|
||||
if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true;
|
||||
bool retrieveCurrentDirectory(char* currentPath){
|
||||
if(GetCurrentDirectory(MAX_PATH, currentPath)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool moveDirectory(char** currentPath){
|
||||
log_debugcpp(*currentPath);
|
||||
if(SetCurrentDirectory(*currentPath)) return true;
|
||||
bool moveDirectory(char* currentPath){
|
||||
log_debugcpp(currentPath);
|
||||
if(SetCurrentDirectory(currentPath)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +241,7 @@ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator,
|
|||
|
||||
int pathLengthIdx = 0;
|
||||
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 + 1] = '\0';
|
||||
|
|
@ -227,7 +275,10 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
|
||||
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);
|
||||
|
||||
//DEBUG: pathSchecker
|
||||
|
|
@ -242,18 +293,18 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
// std::cout << std::endl << "I IA" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
|
||||
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
||||
for (int i = 0; i < onPresentPaths->size(); i++){
|
||||
std::cout << onPresentPaths->at(i) << std::endl;
|
||||
if (debug) {
|
||||
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
||||
for (int i = 0; i < onPresentPaths->size(); i++){
|
||||
log_debugcpp(onPresentPaths->at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
//std::cout << volumePaths << std::endl;
|
||||
|
||||
log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH");
|
||||
log_debugcpp("THE END");
|
||||
|
||||
}else{
|
||||
} else {
|
||||
log_debugcpp("no volumes found wtf");
|
||||
}
|
||||
//TODO benchimarqui
|
||||
|
|
@ -286,24 +337,57 @@ bool compareLastChar(std::vector<std::string> *lastCharCandidates, char* string)
|
|||
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;
|
||||
if(!moveDirectory(str)) { *error = true; return false; }
|
||||
return true;
|
||||
if(!moveDirectory(nextPath)) {
|
||||
*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, \
|
||||
char* addrBarVal, char* errorDest, const char* errorContent, History* history){
|
||||
if (isListDirectoriesAdequate) { strcpy(currentPath, addrBarVal); history->isAdditionTime = true; }
|
||||
else strcpy(addrBarVal, currentPath);
|
||||
strcpy(errorDest, errorContent);
|
||||
int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
|
||||
const char* errorContent, History* history, bool isAdditionTime){
|
||||
*error = false;
|
||||
if(!moveDirectory(nextPath)) {
|
||||
*error = true;
|
||||
strcpy(errorDest, errorContent);
|
||||
return listFlags;
|
||||
}
|
||||
if (isAdditionTime) history->isAdditionTime = true;
|
||||
return (listFlags |= LIST_DIRECTORY);
|
||||
}
|
||||
|
||||
/* HISTORIAL */
|
||||
|
||||
void addPathToHistory(History *history, char* pathToAdd){
|
||||
char* path;
|
||||
//int ajjj = history->previousPaths.size();
|
||||
if (history->historyTraversalPos + 1 >= history->previousPaths.size()){
|
||||
path = (char*)calloc(1, MAX_PATH);
|
||||
history->previousPaths.push_back(path);
|
||||
|
|
@ -316,22 +400,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);
|
||||
return history->previousPaths.at(history->historyTraversalPos);
|
||||
break;
|
||||
case HISTORY_FORWARD:
|
||||
if(MAX_HISTORY_POS)
|
||||
return &history->previousPaths.at(history->historyDepth);
|
||||
return history->previousPaths.at(history->historyDepth);
|
||||
break;
|
||||
default:
|
||||
return &history->previousPaths.at(history->historyDepth);
|
||||
return history->previousPaths.at(history->historyDepth);
|
||||
}
|
||||
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);
|
||||
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;
|
||||
if (isFullViewport) ImGui::PopStyleVar(1);
|
||||
|
||||
//Listar UNA VEZ volumenes
|
||||
static int numVolumes;
|
||||
static std::vector<char*> onPresentPaths;
|
||||
|
||||
if (isListVolumesAdequate) {
|
||||
isListVolumesAdequate = false;
|
||||
//std::cout << isListVolumesAdequate << std::endl;
|
||||
if (listFlags & LIST_VOLUME) {
|
||||
listFlags &= ~LIST_VOLUME;
|
||||
numVolumes = listVolumes(&onPresentPaths);
|
||||
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];
|
||||
static char* currentPathPtr = ¤tPath[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);
|
||||
|
||||
if(isListDirectoriesAdequate) {
|
||||
if (listFlags & LIST_DIRECTORY) {
|
||||
listFlags &= ~LIST_DIRECTORY;
|
||||
log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
|
||||
isListDirectoriesAdequate = false;
|
||||
if(!retrieveCurrentDirectory(¤tPathPtr)) {
|
||||
if(!retrieveCurrentDirectory(currentPath)) {
|
||||
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
|
||||
goto filepickerFailure;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
//
|
||||
//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){
|
||||
ImGui::Text(error);
|
||||
|
|
@ -445,31 +504,28 @@ void filePickerMomento(bool isFullViewport = false){
|
|||
//Permanentes e increiblemente utilitarios botones en Cuatro K: BACK
|
||||
ImGui::BeginDisabled(MIN_HISTORY_POS);
|
||||
if(ImGui::Button("Back")) {
|
||||
char** interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_BACKWARD);
|
||||
isListDirectoriesAdequate = inputMove(&showError, interfaceMovementButtonsPath);
|
||||
char* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_BACKWARD);
|
||||
//TODO: ERROR
|
||||
strcpy(error, ErrorMessages::moveUpError);
|
||||
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
||||
&showError, error, ErrorMessages::moveUpError, history, false);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
//FORWARD
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(MAX_HISTORY_POS);
|
||||
if(ImGui::Button("Forward")) {
|
||||
char** interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD);
|
||||
isListDirectoriesAdequate = inputMove(&showError, interfaceMovementButtonsPath);
|
||||
strcpy(error, ErrorMessages::moveUpError);
|
||||
//TODO david????????????????????????????????????
|
||||
char* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD);
|
||||
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
||||
&showError, error, ErrorMessages::moveUpError, history, false);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
//MOVE UP
|
||||
ImGui::SameLine();
|
||||
//c pervirtio con unicode std::wstring s(L"←→↑↓");
|
||||
static char moveUp[] = "..";
|
||||
static char* moveUpPtr = &moveUp[0];
|
||||
if(ImGui::Button("Move Up")) {
|
||||
isListDirectoriesAdequate = inputMove(&showError, (&moveUpPtr));
|
||||
strcpy(error, ErrorMessages::moveUpError);
|
||||
history->isAdditionTime = true;
|
||||
listFlags = handleFolderAccessResult(listFlags, moveUp, &showError,
|
||||
error, ErrorMessages::moveUpError, history, true);
|
||||
}
|
||||
|
||||
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) );
|
||||
if(ImGui::InputText("##addrbar", addrBarVal, IM_ARRAYSIZE(addrBarVal), ImGuiInputTextFlags_EnterReturnsTrue )){
|
||||
log_debugcpp(currentPath <<" ADDRBAR INTENTO");
|
||||
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr);
|
||||
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::addrBarError, history);
|
||||
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
|
||||
history, currentPath, addrBarVal);
|
||||
};
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Enter")){
|
||||
log_debugcpp(currentPath <<" ADDRBAR INTENTO");
|
||||
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr);
|
||||
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::addrBarError, history);
|
||||
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
|
||||
history, currentPath, addrBarVal);
|
||||
}
|
||||
//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_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f));
|
||||
if(ImGui::Button(onPresentPaths.at(i))){
|
||||
isListDirectoriesAdequate = inputMove(&showError, &onPresentPaths.at(i));
|
||||
history->isAdditionTime = true;
|
||||
//TODO xdddddddd
|
||||
listFlags = handleFolderAccessResult(listFlags, onPresentPaths.at(i), &showError, error,
|
||||
ErrorMessages::moveUpError, history, true);
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
if (i != onPresentPaths.size() - 1) ImGui::TableNextRow();
|
||||
|
|
@ -525,7 +582,6 @@ void filePickerMomento(bool isFullViewport = false){
|
|||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
|
||||
//DIRECTORIOS ENCONTRADOS bien pinta2
|
||||
static ImGuiTableFlags directoriesFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable |ImGuiTableFlags_ScrollY ;
|
||||
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)){
|
||||
strcat(addrBarVal, "\\");
|
||||
strcat(addrBarVal, directoryContents.at(idx)->name);
|
||||
isListDirectoriesAdequate = inputMove(&showError, &addrBarValPtr);
|
||||
handleFolderAccessResult(isListDirectoriesAdequate, currentPath, addrBarVal, error, ErrorMessages::tableElementError, history);
|
||||
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error,
|
||||
ErrorMessages::tableElementError, history, currentPath, addrBarVal);
|
||||
//currentItemIdx = -1;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
|
|
@ -589,8 +645,6 @@ void filePickerMomento(bool isFullViewport = false){
|
|||
ImGui::Checkbox("Filter by .exe", &filterByExtension);
|
||||
ImGui::SameLine();
|
||||
ImGui::Button("Select");
|
||||
filepickerFailure:
|
||||
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue