Debug verbosity, modified README

This commit is contained in:
Hane 2024-01-15 21:27:42 +01:00
commit 380008ec95
3 changed files with 205 additions and 120 deletions

View file

@ -1,45 +1,56 @@
Single-header file picker Windows library for ImGui.
Single-header file picker library for ImGui.
Currently, this library is Windows-only. Support for Linux is planned.
# How to use
int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
Call `int fp::renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0);` within the render loop providing a pre-allocated C-string buffer of MAX_PATH characters in `userPath`. `windowOpen` must be initially set to `true`, and will set itself to `false` when execution is done. If succesful, your buffer will contain a valid path. You can check the file picker state each frame by parsing this function's return value. You can provide `windowFlags` to customize its appearance.
## Window states
This library exposes three functions:
```
- fp::ExitFlags::EXIT_CONTINUE : Window will render next frame.
- fp::ExitFlags::EXIT_SELECTED : A path has been successfully returned, window will close.
- fp::ExitFlags::EXIT_CLOSED : User has closed the window. No path is returned.
- fp::ExitFlags::EXIT_ERROR : An unexpected error has ocurred. No path is returned.
void renderFilePicker(char* userPath, bool* windowOpen, bool* memoryFreed, int windowFlags);
```
## Valid window flags
Call this function within the render loop providing a pre-allocated buffer of MAX_PATH characters in `userPath`, which will be filled with a UTF-8 string. `windowOpen` must be initially set to `true`, and will set itself to `false` when execution is done. If succesful, your buffer will contain a valid path. `memoryFreed` will be set to `true`, and must be checked once the window is closed to free memory resources acquired by this library. You can provide `windowFlags` to customize its appearance.
### Window customization flags
```
- fp::WindowFlags::FP_FULLSCREEN`: Render window in full screen, without decorations.
fp::WindowFlags::FULLSCREEN : Render window in full screen, without decorations.
```
```
void freeMemory(bool* memoryFreed);
```
Memory resources will be deallocated alongside miscellaneous internal tasks, and `memoryFreed` will be set to `true`.
```
void setDebugInfo(int debugVerbosity);
```
When `FPDEBUG` is enabled, this allows you to configure debug granularity.
### Debug flags
```
fp::DebugVerbosity::DIRECTORY
fp::DebugVerbosity::VOLUME
fp::DebugVerbosity::EXTENSION
```
# Library dependencies
- **C++ STL**: This library uses `vector` and `w\string`.
## Build considerations
Define `DEBUG` to print relevant information to the console.
- **C++ STL**: This library uses `vector`, `fill` and `w\string`.
# Demo build instructions
## Build requirements
- [**GLFW v3**](https://github.com/glfw/glfw/releases): used as rendering backend. Executable in releases is compiled with version [`3.3.8`](https://github.com/glfw/glfw/releases/tag/3.3.8).
- Compiled with `clang` using [**llvm-mingw 20220906**](https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906).
- [**GLFW v3**](https://github.com/glfw/glfw/releases): used as rendering backend. Executable in releases is compiled with version [`3.3.9`](https://github.com/glfw/glfw/releases/tag/3.3.9).
- Developed and tested with `clang` using [**llvm-mingw 20220906**](https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906). Any `MinGW`-backed `clang` compiler should work, but your mileage may vary.
## How to compile
Download GLFW and pick your libraries according to your toolchain(`mingw-w64` in this example).
Then, call your compiler directly (`clang` is demonstrated here) specifying both libs needed and your paths to the necessary header and lib files:
Download GLFW and pick your libraries according to your toolchain. Then, call your compiler directly specifying both libs needed and your paths to the necessary header and lib files:
```
clang++ demo/main.cpp -o demo/demo.exe -L C:/pathtollvmmingw/x86_64-w64-mingw32/bin -I C:\pathtollvmmingw\include -L C:/pathtoglfw/lib-mingw-w64 -I C:\pathtoglfw\include -lglfw3 -l libc++
@ -48,10 +59,8 @@ int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
If you want to statically link:
```
clang++ demo/main.cpp -o demo/si.exe -DDEBUG -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L C:\capybara\libclang\x86_64-w64-mingw32\lib -I C:\capybara\libclang\include -std=c++17 -lglfw3 -l opengl32 -l gdi32 -l user32 -l kernel32 -l imm32 -static-libstdc++ --verbose
clang++ demo/main.cpp -o demo/demo.exe -L C:/pathtoglfw/lib-mingw-w64 -L C:/pathtollvmmingw/x86_64-w64-mingw32/lib -I C:\pathtollvmmingw\include -I C:\pathtoglfw\include -std=c++17 -stdlib=libc++ -rtlib=compiler-rt -static -l glfw3 -l gdi32 -l opengl32 -l user32 -l kernel32 -static-libstdc++
```
Add `-DDEBUG` to print filepicker's debug information, if you so desire.
# To-Dos

View file

@ -1,5 +1,4 @@
//Demo executable based on GLFW
#define IMGUI_IMPLEMENTATION
#define GL_SILENCE_DEPRECATION
@ -40,7 +39,7 @@ int main(int, char**) {
#endif
// Create window with graphics context
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(1280, 720, "File Picker Demo", NULL, NULL);
if (window == NULL)
return 1;
glfwMakeContextCurrent(window);
@ -58,11 +57,20 @@ int main(int, char**) {
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// Our state
bool show_demo_window = true;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
//
bool debugDirectory = true;
bool debugVolume = true;
bool debugExtension = true;
bool debugLogic = true;
// Our state
char path[MAX_PATH * 4] = "";// = malloc(MAX_PATH * sizeof(char));
int debugVerbosity = fp::DebugVerbosity::DIRECTORY | fp::DebugVerbosity::VOLUME | fp::DebugVerbosity::EXTENSION | fp::DebugVerbosity::LOGIC;
bool windowOpen = true;
bool memoryFreed = true;
// Main loop
while (!glfwWindowShouldClose(window)) {
// Poll and handle events (inputs, window resize, etc.)
@ -75,13 +83,41 @@ int main(int, char**) {
ImGui::NewFrame();
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
static wchar_t path[MAX_PATH];// = malloc(MAX_PATH * sizeof(char));
static bool windowOpen = true;
fp::setDebugInfo(debugVerbosity);
if(windowOpen)
fp::renderFilePicker(&path[0], &windowOpen, 0);
fp::renderFilePicker(&path[0], &windowOpen, &memoryFreed, 0);
else if(!memoryFreed)
fp::freeResources(&memoryFreed);
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
//if (show_demo_window)
ImGui::SetNextWindowSize(ImVec2(500.0f, 500.0f));
ImGui::Begin("Values", NULL, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PopStyleVar(1);
ImGui::Text(path);
// debugVerbosity = DEBUG_DIRECTORY | DEBUG_EXTENSION;
// debugVerbosity &= ~DEBUG_DIRECTORY;
// if (debugVerbosity & (DEBUG_DIRECTORY | DEBUG_EXTENSION));
ImGui::Text("Debug verbosity");
ImGui::Checkbox("Directory" , &debugDirectory);
ImGui::Checkbox("Volume" , &debugVolume );
ImGui::Checkbox("Extension" , &debugExtension);
ImGui::Checkbox("Logic" , &debugLogic );
debugVerbosity = (debugDirectory) ? debugVerbosity | fp::DIRECTORY : debugVerbosity& ~fp::DIRECTORY;
debugVerbosity = (debugVolume) ? debugVerbosity | fp::VOLUME : debugVerbosity& ~fp::VOLUME;
debugVerbosity = (debugExtension) ? debugVerbosity | fp::EXTENSION : debugVerbosity& ~fp::EXTENSION;
debugVerbosity = (debugLogic) ? debugVerbosity | fp::LOGIC : debugVerbosity& ~fp::LOGIC;
//fp::DebugVerbosity::DIRECTORY | fp::DebugVerbosity::VOLUME | fp::DebugVerbosity::EXTENSION | fp::DebugVerbosity::LOGIC;
if (!windowOpen)
if(ImGui::Button("Open file picker")) {
windowOpen = !windowOpen;
}
//ImGui::Text(std::to_string(state).c_str());
//ImGui::Text(state);
ImGui::End();
//ImGui::ShowDemoWindow(&show_demo_window);
// Rendering
ImGui::Render();

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,30 @@
#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_logic(str) do { \
if(debugVerbosity & LOGIC) 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)
#define log_wlogic(str) do { \
if(debugVerbosity & LOGIC) log_wdebugcpp(str); \
} while (0)
#else
#define log_debugc(str, ...)
#define log_debugcpp(str)
@ -17,6 +38,11 @@
#define log_directory(str)
#define log_volume(str)
#define log_extension(str)
#define log_wdirectory(str)
#define log_wvolume(str)
#define log_wextension(str)
#define log_logic(str)
#define log_wlogic(str)
#endif
//PATH MACRO
@ -62,6 +88,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 +110,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 +128,47 @@ 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),
LOGIC = (1<<3)
};
//VARS
#ifdef DEBUG
#ifdef FPDEBUG
bool debug = true;
#else
bool debug = false;
@ -193,30 +227,24 @@ std::vector<std::wstring> extensions;
History* history;
// 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 */
int debugVerbosity = 0;
/* DEBUG VERBOSITY */
void setDebugInfo(int debugFlags) {
debugVerbosity = debugFlags;
}
/* FILE PICKER MOMENTO */
/* DIRECTORIES */
bool retrieveCurrentDirectory(wchar_t* currentPath){
if(GetCurrentDirectory(MAX_PATH, currentPath)) return true;
return false;
}
bool moveDirectory(wchar_t* currentPath){
log_debugcpp(currentPath);
log_directory(currentPath);
if(SetCurrentDirectory(currentPath)) return true;
return false;
}
@ -233,7 +261,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 +270,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 +291,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 +333,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 +343,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 +373,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_wvolume(volumeName);
//DEBUG: pathSchecker
// if (debug && volumePaths[0] == 'E') {
@ -365,21 +393,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_wvolume(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 +419,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;
}
}
@ -495,15 +523,19 @@ wchar_t* moveThroughHistory(History *history, HistoryMovement movement) {
/* RENDERING */
int windowRendering(wchar_t*, bool*, int);
int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
void windowRendering(char*, bool*, bool*, int);
void renderFilePicker(char* userPath, bool* windowOpen, bool* memoryFreed, int windowFlags = 0) {
//TODO filesystem watcher
//TODO let user handle memory management
//TODO use local val to create actual windowFlags when expanding functionality
#ifdef WIN32
SetConsoleOutputCP(65001);
#endif
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;
@ -514,17 +546,12 @@ int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
//const ImGuiViewport* viewport = ImGui::GetMainViewport();
}
windowConfigured = true;
*memoryFreed = false;
} else windowFlags = 0;
return windowRendering(userPath, windowOpen, windowFlags);
windowRendering(userPath, windowOpen, memoryFreed, windowFlags);
}
int exitWindow(wchar_t* userPath, bool* windowOpen, int exitFlag){
if(exitFlag & EXIT_SELECTED) {
if (chosenPath[0] == '\0') return EXIT_CONTINUE;
wcscpy(userPath, chosenPath);
*windowOpen = false;
}
//Memory cleanup
void freeResources(bool* memoryFreed){
windowConfigured = false;
for (int i = 0; i < history->previousPaths.size(); i++){
free(history->previousPaths.at(i));
@ -532,13 +559,30 @@ int exitWindow(wchar_t* userPath, bool* windowOpen, int exitFlag){
for (int i = 0; i < onPresentPaths.size(); i++){
free(onPresentPaths.at(i));
}
onPresentPaths.resize(0);
std::vector<wchar_t*> previousPaths;
delete history;
return exitFlag;
for (int i = 0; i < history->previousPathsUTF8.size(); i++){
free(history->previousPathsUTF8.at(i));
}
for (int i = 0; i < onPresentPathsUTF8.size(); i++){
free(onPresentPathsUTF8.at(i));
}
onPresentPaths.resize(0);
onPresentPathsUTF8.resize(0);
//previousPaths.resize(0);
delete history;
*memoryFreed = true;
}
void exitWindow(char* userPath, bool* windowOpen, bool* memoryFreed, int exitFlag){
if(exitFlag & SELECTED) {
if (chosenPath[0] == '\0') return;
strcpy(userPath, chosenPathUTF8);
*windowOpen = false;
}
freeResources(memoryFreed);
return;
}
int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
void windowRendering(char* userPath, bool* windowOpen, bool* memoryFreed, int windowFlags = 0){
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::Begin("File picker", windowOpen, windowFlags);
ImGui::PopStyleVar(1);
@ -547,7 +591,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 +599,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 +611,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 +671,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 +752,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,17 +804,13 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
ImGui::SameLine();
if(ImGui::Button("Select")) {
log_wdebugcpp(chosenPath << " TRIED TO RETURN");
ImGui::End();
return exitWindow(userPath, windowOpen, ExitFlags::EXIT_SELECTED);
log_directory(chosenPath << " TRIED TO RETURN");
//ImGui::End();
exitWindow(userPath, windowOpen, memoryFreed, 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);
}