Debug verbosity, modified README

This commit is contained in:
Hane 2024-01-15 21:27:42 +01:00
commit 19f09f208f
3 changed files with 136 additions and 92 deletions

View file

@ -1,5 +1,5 @@
//DEBUG MACRO
#ifdef DEBUG
#ifdef FPDEBUG
#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; \
@ -7,9 +7,24 @@
#define log_wdebugcpp(str) do { \
if (debug) std::wcout << "[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))
#define log_extension(str) if(debugVerbosity & DEBUG_EXTENSION) log_debugcpp((str))
#define log_directory(str) do { \
if(debugVerbosity & DIRECTORY) log_debugcpp(str); \
} while (0)
#define log_volume(str) do { \
if(debugVerbosity & VOLUME) log_debugcpp(str); \
} while (0)
#define log_extension(str) do { \
if(debugVerbosity & EXTENSION) log_debugcpp(str); \
} while (0)
#define log_wdirectory(str) do { \
if(debugVerbosity & DIRECTORY) log_wdebugcpp(str); \
} while (0)
#define log_wvolume(str) do { \
if(debugVerbosity & VOLUME) log_wdebugcpp(str); \
} while (0)
#define log_wextension(str) do { \
if(debugVerbosity & EXTENSION) log_wdebugcpp(str); \
} while (0)
#else
#define log_debugc(str, ...)
#define log_debugcpp(str)
@ -17,6 +32,9 @@
#define log_directory(str)
#define log_volume(str)
#define log_extension(str)
#define log_wdirectory(str)
#define log_wvolume(str)
#define log_wextension(str)
#endif
//PATH MACRO
@ -62,6 +80,11 @@ struct History {
int historyDepth;
int historyTraversalPos;
bool isAdditionTime;
History(){
historyTraversalPos = historyDepth = -1;
isAdditionTime = true;
}
// wchar* operator[](int idx){
// if (idx > previousPaths.size())
@ -79,19 +102,16 @@ struct History {
// }
// }
History(){
historyTraversalPos = historyDepth = -1;
isAdditionTime = true;
}
};
enum HistoryMovement {
HISTORY_FORWARD = 1,
HISTORY_FORWARD = 1,
HISTORY_BACKWARD = 0
};
enum ListDirectoryError {
DIRECTORY_ERROR_PATH_TOO_LONG = -1,
DIRECTORY_ERROR_PATH_TOO_LONG = -1,
DIRECTORY_ERROR_ACCESSING_CONTENT = -2
};
@ -100,41 +120,46 @@ enum AgnosticDirError {
};
namespace ErrorMessages {
char addrBarError[] = "Failed to open folder: invalid path";
char tableElementError[] = "Failed to open folder: access restricted to non-admin users";
char accessDeniedError[] = "Failed to open folder: access denied";
char addrBarError[] = "Failed to open folder: invalid path";
char tableElementError[] = "Failed to open folder: access restricted to non-admin users";
char accessDeniedError[] = "Failed to open folder: access denied";
char listDirectoryError[] = "Failed to open folder: unknown error";
char moveUpError[] = "Failed to move up: reached volume root?";
char moveUpError[] = "Failed to move up: reached volume root?";
};
namespace Label {
wchar_t saveFileLabel[] = L"Save file: ";
wchar_t loadFileLabel[] = L"Select a file: ";
wchar_t saveFileLabel[] = L"Save file: ";
wchar_t loadFileLabel[] = L"Select a file: ";
wchar_t selectDirectoryLabel[] = L"Select a directory: ";
};
enum ListFlags {
LIST_DIRECTORY = (1<<0),
LIST_VOLUME = (1<<1)
LIST_VOLUME = (1<<1)
};
enum WindowFlags {
FP_FULLSCREEN = (1<<0),
FP_MODAL = (1<<1),
FP_FILE_LOAD = (1<<2),
FP_FILE_SAVE = (1<<3),
FP_DIRECTORY_SELECT = (1<<4)
FULLSCREEN = (1<<0),
MODAL = (1<<1),
FILE_LOAD = (1<<2),
FILE_SAVE = (1<<3),
DIRECTORY_SELECT = (1<<4)
};
enum ExitFlags {
EXIT_CONTINUE = (1<<0),
EXIT_SELECTED = (1<<1),
EXIT_CLOSED = (1<<2),
EXIT_ERROR = (1<<3)
CONTINUE = (1<<0),
SELECTED = (1<<1),
CLOSED = (1<<2)
};
enum DebugVerbosity {
DIRECTORY = (1<<0),
VOLUME = (1<<1),
EXTENSION = (1<<2)
};
//VARS
#ifdef DEBUG
#ifdef FPDEBUG
bool debug = true;
#else
bool debug = false;
@ -193,18 +218,18 @@ std::vector<std::wstring> extensions;
History* history;
// int debugVerbosity = 0;
// enum enumDebugVerbosity {
// DEBUG_DIRECTORY = (1<<0),
// DEBUG_VOLUME = (1<<1),
// DEBUG_EXTENSION = (1<<2)
// };
int debugVerbosity = 0;
// debugVerbosity = DEBUG_DIRECTORY | DEBUG_EXTENSION;
// debugVerbosity &= ~DEBUG_DIRECTORY;
// if (debugVerbosity & (DEBUG_DIRECTORY | DEBUG_EXTENSION));
//TODO UNICORDEO
/* FILE PICKER MOMENTO */
/* DEBUG VERBOSITY */
void setDebugInfo(int debugFlags) {
debugVerbosity = debugFlags;
}
/* FILE PICKER MOMENTO */
/* DIRECTORIES */
@ -216,7 +241,7 @@ bool retrieveCurrentDirectory(wchar_t* currentPath){
}
bool moveDirectory(wchar_t* currentPath){
log_debugcpp(currentPath);
log_directory(currentPath);
if(SetCurrentDirectory(currentPath)) return true;
return false;
}
@ -233,7 +258,7 @@ int listDirectory(std::wstring path, std::vector<directoriesInfo*> *directoryCon
if (INVALID_HANDLE_VALUE == hFind) return DIRECTORY_ERROR_ACCESSING_CONTENT;
do {
if(!wcscmp(ffd.cFileName, L".") || !wcscmp(ffd.cFileName, L"..")) continue;
log_debugcpp("BUCLE listDirectory iteracion " + std::to_string(numFiles));
log_directory("BUCLE listDirectory iteracion " + std::to_string(numFiles));
directoriesInfo* itemInfo;
if (directoryContents->size() <= numFiles){
@ -242,7 +267,7 @@ int listDirectory(std::wstring path, std::vector<directoriesInfo*> *directoryCon
} else {
itemInfo = directoryContents->at(numFiles);
}
log_debugcpp("MEMORY ASSIGNES iteration " + std::to_string(numFiles));
log_directory("MEMORY ASSIGNES iteration " + std::to_string(numFiles));
//A registrar info, fiera
itemInfo->isFile = (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false;
@ -263,7 +288,7 @@ int listDirectory(std::wstring path, std::vector<directoriesInfo*> *directoryCon
} while (ffd.cFileName[idx]);
itemInfo->name[idx] = '\0';
itemInfo->nameUTF8[idx] = '\0';
log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles));
log_directory("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles));
numFiles++;
} while (FindNextFile(hFind, &ffd) != 0);
@ -305,7 +330,7 @@ int explodePaths(wchar_t* volumePaths, int volumePathsBufferSize, wchar_t separa
int pathLengthIdx = 0;
for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) {
log_debugcpp(volumePaths[0] << " ENTERS " << std::to_string(pathLengthIdx));
log_volume(volumePaths[0] << " ENTERS " << std::to_string(pathLengthIdx));
itemPath[pathLengthIdx] = volumePaths[pathLengthIdx];
}
itemPath[pathLengthIdx + 1] = '\0';
@ -315,8 +340,8 @@ int explodePaths(wchar_t* volumePaths, int volumePathsBufferSize, wchar_t separa
destUTF8->push_back(itemPathUTF8);
log_wdebugcpp(dest->at(dest->size() - 1) << L" EXPLODEPATH");
log_debugcpp(dest->at(destUTF8->size() - 1) << " EXPLODEPATH");
log_wvolume(dest->at(dest->size() - 1) << L" EXPLODEPATH");
log_volume(destUTF8->at(destUTF8->size() - 1) << " EXPLODEPATH");
if (nextOcurrence[0] == nextOcurrence[1]) return depth;
depth++;
@ -345,10 +370,10 @@ int listVolumes(std::vector<wchar_t*> *onPresentPaths, std::vector<char*> *onPre
if(GetVolumePathNamesForVolumeName(volumeName, volumePaths, volumePathsBufferSize, &volumePathLength)){
if (volumePathLength == 1) {
log_debugcpp("Skill Issue");
log_volume("Skill Issue");
continue;
}
log_debugcpp(volumeName);
log_volume(volumeName);
//DEBUG: pathSchecker
// if (debug && volumePaths[0] == 'E') {
@ -365,21 +390,21 @@ int listVolumes(std::vector<wchar_t*> *onPresentPaths, std::vector<char*> *onPre
if (debug) {
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths, onPresentPathsUTF8)){
for (int i = 0; i < onPresentPaths->size(); i++){
log_debugcpp(onPresentPaths->at(i));
log_volume(onPresentPaths->at(i));
}
}
}
//std::cout << volumePaths << std::endl;
log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH");
log_debugcpp("THE END");
log_volume(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH");
log_volume("THE END");
} else {
log_debugcpp("no volumes found");
log_volume("no volumes found");
}
//TODO benchimarqui
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
} while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0);
log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN");
log_volume(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN");
FindVolumeClose(hFind);
return numVolumes;
}
@ -391,15 +416,15 @@ int listVolumes(std::vector<wchar_t*> *onPresentPaths, std::vector<char*> *onPre
bool compareLastWchar(std::vector<std::wstring> *lastCharCandidates, wchar_t* string){
bool matchingExtension = false;
for (int i = 0; i < lastCharCandidates->size(); i++){
log_wdebugcpp(lastCharCandidates->at(i) + L" <- FILTERING EXTENSION");
log_wextension(lastCharCandidates->at(i) << L" <- FILTERING EXTENSION");
if(wcslen(string) < lastCharCandidates->at(i).length()) continue;
wchar_t* potentialExtension = &string[wcslen(string) - lastCharCandidates->at(i).length()];
log_wdebugcpp(potentialExtension << L" LEN " + std::to_wstring(wcslen(potentialExtension)) + L" <- VS -> " + lastCharCandidates->at(i) + L" LEN " + std::to_wstring(lastCharCandidates->at(i).length()));
log_wextension(potentialExtension << L" LEN " + std::to_wstring(wcslen(potentialExtension)) + L" <- VS -> " + lastCharCandidates->at(i) + L" LEN " + std::to_wstring(lastCharCandidates->at(i).length()));
//+ strlen(potentialExtension) + std::to_string(lastCharCandidates->at(i).length())
if(!wcscmp(potentialExtension, lastCharCandidates->at(i).c_str())) {
log_debugcpp("VALID EXTENSION");
log_extension("VALID EXTENSION");
matchingExtension = true;
}
}
@ -503,7 +528,7 @@ int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
if (!windowConfigured) {
listFlags = LIST_DIRECTORY | LIST_VOLUME;
history = new History();
if (windowFlags & FP_FULLSCREEN){
if (windowFlags & FULLSCREEN){
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize;
@ -519,8 +544,8 @@ int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
}
int exitWindow(wchar_t* userPath, bool* windowOpen, int exitFlag){
if(exitFlag & EXIT_SELECTED) {
if (chosenPath[0] == '\0') return EXIT_CONTINUE;
if(exitFlag & SELECTED) {
if (chosenPath[0] == '\0') return CONTINUE;
wcscpy(userPath, chosenPath);
*windowOpen = false;
}
@ -547,7 +572,7 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
if (listFlags & LIST_VOLUME) {
listFlags &= ~LIST_VOLUME;
numVolumes = listVolumes(&onPresentPaths, &onPresentPathsUTF8);
log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()));
log_volume(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()));
}
//Listar UNA VEZ directorios
@ -555,9 +580,9 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
if (listFlags & LIST_DIRECTORY) {
listFlags &= ~LIST_DIRECTORY;
chosenPath[0] = '\0';
log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
log_directory("ADECUADO LISTAR DIRECTORIOS");
if(!retrieveCurrentDirectory(currentPath)) {
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
log_directory("NO HABIA DIRECTORIO GetCurrentPath()");
exit(EXIT_FAILURE);
}
//
@ -567,7 +592,7 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
//std::cout << numFiles;
if (numFiles < 0) {
long directoryErrorCode;
log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles));
log_directory("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles));
if (numFiles == DIRECTORY_ERROR_ACCESSING_CONTENT) directoryErrorCode = getLastSystemError();
showError = true;
switch(directoryErrorCode) {
@ -627,14 +652,14 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
WideCharToMultiByte(CP_UTF8, NULL, addrBarVal, -1, addrBarValUTF8,
4 * MAX_PATH, NULL, NULL);
if(ImGui::InputText("##addrbar", addrBarValUTF8, IM_ARRAYSIZE(addrBarValUTF8), ImGuiInputTextFlags_EnterReturnsTrue )){
log_debugcpp(currentPath <<" ADDRBAR INTENTO");
log_directory(currentPath <<" ADDRBAR INTENTO");
MultiByteToWideChar(CP_UTF8, NULL, addrBarValUTF8, -1, addrBarVal, 2 * MAX_PATH);
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError, history, currentPath, addrBarVal);
}
ImGui::PopItemWidth();
ImGui::SameLine();
if(ImGui::Button("Enter")){
log_debugcpp(currentPath <<" ADDRBAR INTENTO");
log_directory(currentPath <<" ADDRBAR INTENTO");
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
history, currentPath, addrBarVal);
}
@ -708,11 +733,11 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
wcscpy(chosenPath, addrBarVal);
wcscat(chosenPath, L"\\");
wcscat(chosenPath, directoryContents.at(idx)->name);
log_wdebugcpp(chosenPath << L" selected");
log_directory(chosenPath << L" selected");
} else {
wcscat(addrBarVal, L"\\");
wcscat(addrBarVal, directoryContents.at(idx)->name);
log_debugcpp("directo selected");
log_directory("directo selected");
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error,
ErrorMessages::tableElementError, history, currentPath, addrBarVal);
}
@ -760,16 +785,16 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
ImGui::SameLine();
if(ImGui::Button("Select")) {
log_wdebugcpp(chosenPath << " TRIED TO RETURN");
log_directory(chosenPath << " TRIED TO RETURN");
ImGui::End();
return exitWindow(userPath, windowOpen, ExitFlags::EXIT_SELECTED);
return exitWindow(userPath, windowOpen, ExitFlags::SELECTED);
}
//listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError, history, currentPath, addrBarVal);
ImGui::End();
if(windowOpen) return EXIT_CONTINUE;
else return exitWindow(userPath, windowOpen, ExitFlags::EXIT_CLOSED);
if(windowOpen) return CONTINUE;
else return exitWindow(userPath, windowOpen, ExitFlags::CLOSED);
}