unicode support, finished base implementation
This commit is contained in:
parent
f36ed343d5
commit
e5feedce3a
4 changed files with 307 additions and 151 deletions
391
filepicker.hpp
391
filepicker.hpp
|
|
@ -1,11 +1,23 @@
|
||||||
//DEBUG MACRO
|
//DEBUG MACRO
|
||||||
|
#ifdef DEBUG
|
||||||
#define log_debugc(str, ...) do { if (debug) fprintf(stdout, "[DEBUG] (%s:%d): " (str) "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
|
#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 { \
|
#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)
|
} while (0)
|
||||||
|
#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_directory(str) if(debugVerbosity & DEBUG_DIRECTORY) log_debugcpp((str))
|
||||||
#define log_volume(str) if(debugVerbosity & DEBUG_VOLUME) 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_extension(str) if(debugVerbosity & DEBUG_EXTENSION) log_debugcpp((str))
|
||||||
|
#else
|
||||||
|
#define log_debugc(str, ...)
|
||||||
|
#define log_debugcpp(str)
|
||||||
|
#define log_wdebugcpp(str)
|
||||||
|
#define log_directory(str)
|
||||||
|
#define log_volume(str)
|
||||||
|
#define log_extension(str)
|
||||||
|
#endif
|
||||||
|
|
||||||
//PATH MACRO
|
//PATH MACRO
|
||||||
#define MAX_LISTDIR_PATH_LENGTH (MAX_PATH - 3)
|
#define MAX_LISTDIR_PATH_LENGTH (MAX_PATH - 3)
|
||||||
|
|
@ -23,14 +35,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace fp {
|
namespace fp {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long long size;
|
long long size;
|
||||||
//TODO yel spacsio NELLA MEMoria
|
//TODO yel spacsio NELLA MEMoria
|
||||||
TCHAR name[MAX_LISTDIR_PATH_LENGTH];
|
WCHAR name[MAX_LISTDIR_PATH_LENGTH];
|
||||||
|
char nameUTF8[MAX_LISTDIR_PATH_LENGTH * 4];
|
||||||
SYSTEMTIME createTime;
|
SYSTEMTIME createTime;
|
||||||
SYSTEMTIME lastAccessTime;
|
SYSTEMTIME lastAccessTime;
|
||||||
SYSTEMTIME lastWriteTime;
|
SYSTEMTIME lastWriteTime;
|
||||||
|
|
@ -40,16 +51,34 @@ typedef struct {
|
||||||
} directoriesInfo;
|
} directoriesInfo;
|
||||||
|
|
||||||
|
|
||||||
struct History{
|
struct History {
|
||||||
std::vector<char*> previousPaths;
|
std::vector<wchar_t*> previousPaths;
|
||||||
|
std::vector<char*> previousPathsUTF8;
|
||||||
//warnings e 1 cosa
|
//warnings e 1 cosa
|
||||||
//int historyDepth = -1;
|
//int historyDepth = -1;
|
||||||
//TODO Limitar historial
|
//TODO Limitar historial
|
||||||
//const int maxHistoryDepth = 10000;
|
//const int maxHistoryDepth = 10000;
|
||||||
|
//int currentStart = 0;
|
||||||
int historyDepth;
|
int historyDepth;
|
||||||
int historyTraversalPos;
|
int historyTraversalPos;
|
||||||
bool isAdditionTime;
|
bool isAdditionTime;
|
||||||
|
|
||||||
|
// wchar* operator[](int idx){
|
||||||
|
// if (idx > previousPaths.size())
|
||||||
|
// int newPos = idx + currentStart;
|
||||||
|
|
||||||
|
// if (newPos < 0) return previousPaths[maxHistoryDepth - (newPos % maxHistoryDepth)];
|
||||||
|
// else return previousPaths[newPos % maxHistoryDepth];
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void push_back(wchar* path){
|
||||||
|
// if (previousPaths.size() < maxHistoryDepth) previousPaths.push_back(path);
|
||||||
|
// else {
|
||||||
|
// previousPaths[currentStart++] = path;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
History(){
|
History(){
|
||||||
historyTraversalPos = historyDepth = -1;
|
historyTraversalPos = historyDepth = -1;
|
||||||
isAdditionTime = true;
|
isAdditionTime = true;
|
||||||
|
|
@ -66,7 +95,7 @@ enum ListDirectoryError {
|
||||||
DIRECTORY_ERROR_ACCESSING_CONTENT = -2
|
DIRECTORY_ERROR_ACCESSING_CONTENT = -2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum agnosticDirError {
|
enum AgnosticDirError {
|
||||||
AGDIR_ERROR_ACCESS_DENIED = 1
|
AGDIR_ERROR_ACCESS_DENIED = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -78,51 +107,81 @@ namespace ErrorMessages {
|
||||||
char moveUpError[] = "Failed to move up: reached volume root?";
|
char moveUpError[] = "Failed to move up: reached volume root?";
|
||||||
};
|
};
|
||||||
|
|
||||||
enum listFlags {
|
namespace Label {
|
||||||
|
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_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)
|
||||||
|
};
|
||||||
|
|
||||||
|
enum exitFlags {
|
||||||
|
EXIT_CONTINUE = (1<<0),
|
||||||
|
EXIT_SELECTED = (1<<1),
|
||||||
|
EXIT_CLOSED = (1<<2),
|
||||||
|
EXIT_ERROR = (1<<3)
|
||||||
|
};
|
||||||
|
|
||||||
//VARS
|
//VARS
|
||||||
|
#ifdef DEBUG
|
||||||
bool debug = true;
|
bool debug = true;
|
||||||
|
#else
|
||||||
|
bool debug = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
History* history = new History();
|
// Window open bool
|
||||||
|
bool windowOpen = true;
|
||||||
|
bool windowConfigured = false;
|
||||||
|
|
||||||
//Flags used to determine:
|
//Flags used to determine:
|
||||||
// window format
|
// window format
|
||||||
int windowFlags = 0;
|
//int windowFlags = 0;
|
||||||
// if it's time to load new data
|
// if it's time to load new data
|
||||||
int listFlags = LIST_DIRECTORY | LIST_VOLUME;
|
int listFlags = LIST_DIRECTORY | LIST_VOLUME;
|
||||||
|
|
||||||
//Array used to display current error
|
//Array used to display current error
|
||||||
char error[MAX_ERRORSTR_LEN];
|
char error[MAX_ERRORSTR_LEN];
|
||||||
|
//wchar_t errorUTF8[MAX_ERRORSTR_LEN * 4];
|
||||||
bool showError = false;
|
bool showError = false;
|
||||||
|
|
||||||
//Stores found volumes
|
//Stores found volumes
|
||||||
//TODO onPresentPaths???? wtf is dis naem bru
|
//TODO onPresentPaths might not be the best name
|
||||||
std::vector<char*> onPresentPaths;
|
std::vector<wchar_t*> onPresentPaths;
|
||||||
|
std::vector<char*> onPresentPathsUTF8;
|
||||||
int numVolumes;
|
int numVolumes;
|
||||||
|
|
||||||
//currentPath is the one used to retrieve data, then copied to addrBalVar for display.
|
//currentPath is the one used to retrieve data, then copied to addrBarVal for display.
|
||||||
//addrBalVar is also used as a bacukp in case new currentPath is invalid
|
//addrBarVal is also used as a bacukp in case new currentPath is invalid
|
||||||
|
//chosenFile stores absolute file path to return
|
||||||
//TODO: hay historial. Coalescer en una sola?
|
//TODO: hay historial. Coalescer en una sola?
|
||||||
//TODO: david wtf
|
//cursed C momento: necesario ptr en otra var para mandar a wchar_t** de firma
|
||||||
//cursed C momento: necesario ptr en otra var para mandar a char** de firma
|
wchar_t currentPath[MAX_PATH];
|
||||||
char currentPath[MAX_PATH];
|
//wchar_t* currentPathPtr = ¤tPath[0];
|
||||||
char* currentPathPtr = ¤tPath[0];
|
wchar_t addrBarVal[MAX_LISTDIR_PATH_LENGTH];
|
||||||
char addrBarVal[MAX_LISTDIR_PATH_LENGTH];
|
char addrBarValUTF8[MAX_LISTDIR_PATH_LENGTH * 4];
|
||||||
char* addrBarValPtr = &addrBarVal[0];
|
//wchar_t* addrBarValPtr = &addrBarVal[0];
|
||||||
|
wchar_t chosenPath[MAX_PATH];
|
||||||
|
char chosenPathUTF8[MAX_PATH * 4];
|
||||||
|
|
||||||
//Stores entires found within a given directory
|
//Stores entires found within a given directory
|
||||||
//static int currentItemIdx = -1;
|
//static int currentItemIdx = -1;
|
||||||
std::vector<directoriesInfo*> directoryContents;
|
std::vector<directoriesInfo*> directoryContents;
|
||||||
int numFiles = 0;
|
int numFiles = 0;
|
||||||
|
|
||||||
//Going one level up needs to be hardcoded like this due to function inputMove needing a char**
|
//Going one level up needs to be hardcoded like this due to function inputMove needing a wchar_t**
|
||||||
//c pervirtio con unicode std::wstring s(L"←→↑↓");
|
//c pervirtio con unicode std::wstring s(L"←→↑↓");
|
||||||
char moveUp[] = "..";
|
wchar_t moveUp[] = L"..";
|
||||||
char* moveUpPtr = &moveUp[0];
|
|
||||||
|
|
||||||
bool isListVolumesAdequate = true;
|
bool isListVolumesAdequate = true;
|
||||||
bool isListDirectoriesAdequate = true;
|
bool isListDirectoriesAdequate = true;
|
||||||
|
|
@ -130,8 +189,9 @@ bool isListDirectoriesAdequate = true;
|
||||||
//RenderTime vars for filtering
|
//RenderTime vars for filtering
|
||||||
bool showHidden = false;
|
bool showHidden = false;
|
||||||
bool filterByExtension = false;
|
bool filterByExtension = false;
|
||||||
std::vector<std::string> extensions;
|
std::vector<std::wstring> extensions;
|
||||||
|
|
||||||
|
History* history;
|
||||||
|
|
||||||
// int debugVerbosity = 0;
|
// int debugVerbosity = 0;
|
||||||
// enum enumDebugVerbosity {
|
// enum enumDebugVerbosity {
|
||||||
|
|
@ -150,29 +210,29 @@ std::vector<std::string> extensions;
|
||||||
/* DIRECTORIES */
|
/* DIRECTORIES */
|
||||||
|
|
||||||
|
|
||||||
bool retrieveCurrentDirectory(char* currentPath){
|
bool retrieveCurrentDirectory(wchar_t* 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(wchar_t* currentPath){
|
||||||
log_debugcpp(currentPath);
|
log_debugcpp(currentPath);
|
||||||
if(SetCurrentDirectory(currentPath)) return true;
|
if(SetCurrentDirectory(currentPath)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int listDirectory(std::string path, std::vector<directoriesInfo*> *directoryContents){
|
int listDirectory(std::wstring path, std::vector<directoriesInfo*> *directoryContents){
|
||||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||||
WIN32_FIND_DATA ffd;
|
WIN32_FIND_DATA ffd;
|
||||||
LARGE_INTEGER filesize;
|
LARGE_INTEGER filesize;
|
||||||
int numFiles = 0;
|
int numFiles = 0;
|
||||||
|
|
||||||
if (path.length() > (MAX_LISTDIR_PATH_LENGTH)) return DIRECTORY_ERROR_PATH_TOO_LONG;
|
if (path.length() > (MAX_LISTDIR_PATH_LENGTH)) return DIRECTORY_ERROR_PATH_TOO_LONG;
|
||||||
path = path + "\\*";
|
path = path + L"\\*";
|
||||||
hFind = FindFirstFile(path.c_str(), &ffd);
|
hFind = FindFirstFile(path.c_str(), &ffd);
|
||||||
if (INVALID_HANDLE_VALUE == hFind) return DIRECTORY_ERROR_ACCESSING_CONTENT;
|
if (INVALID_HANDLE_VALUE == hFind) return DIRECTORY_ERROR_ACCESSING_CONTENT;
|
||||||
do {
|
do {
|
||||||
if(!strcmp(ffd.cFileName, ".") || !strcmp(ffd.cFileName, "..")) continue;
|
if(!wcscmp(ffd.cFileName, L".") || !wcscmp(ffd.cFileName, L"..")) continue;
|
||||||
log_debugcpp("BUCLE listDirectory iteracion " + std::to_string(numFiles));
|
log_debugcpp("BUCLE listDirectory iteracion " + std::to_string(numFiles));
|
||||||
|
|
||||||
directoriesInfo* itemInfo;
|
directoriesInfo* itemInfo;
|
||||||
|
|
@ -198,9 +258,11 @@ int listDirectory(std::string path, std::vector<directoriesInfo*> *directoryCont
|
||||||
uint64_t idx = 0;
|
uint64_t idx = 0;
|
||||||
do {
|
do {
|
||||||
itemInfo->name[idx] = ffd.cFileName[idx];
|
itemInfo->name[idx] = ffd.cFileName[idx];
|
||||||
|
itemInfo->nameUTF8[idx] = ffd.cFileName[idx];
|
||||||
idx++;
|
idx++;
|
||||||
} while (ffd.cFileName[idx]);
|
} while (ffd.cFileName[idx]);
|
||||||
itemInfo->name[idx] = '\0';
|
itemInfo->name[idx] = '\0';
|
||||||
|
itemInfo->nameUTF8[idx] = '\0';
|
||||||
log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles));
|
log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles));
|
||||||
|
|
||||||
numFiles++;
|
numFiles++;
|
||||||
|
|
@ -209,35 +271,37 @@ int listDirectory(std::string path, std::vector<directoriesInfo*> *directoryCont
|
||||||
return numFiles;
|
return numFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getLastDirectorySystemError(){
|
long getLastSystemError(){
|
||||||
long winLastError = GetLastError();
|
DWORD winLastError = GetLastError();
|
||||||
switch(winLastError){
|
switch(winLastError){
|
||||||
case ERROR_ACCESS_DENIED:
|
case ERROR_ACCESS_DENIED:
|
||||||
return AGDIR_ERROR_ACCESS_DENIED;
|
return AGDIR_ERROR_ACCESS_DENIED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return winLastError;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VOLUMES */
|
/* VOLUMES */
|
||||||
|
|
||||||
//new char*[CharCount * sizeof(WCHAR)
|
//new wchar_t*[Wchar_TCount * sizeof(WWCHAR_T)
|
||||||
/*idea, si quisiera que empezase en punto X del string
|
/*idea, si quisiera que empezase en punto X del string
|
||||||
coger el param opcional y crear un puntero a la posicion X del array para empezar desde ahi
|
coger el param opcional y crear un puntero a la posicion X del array para empezar desde ahi
|
||||||
int explodePaths(TCHAR* volumePaths, int volumePathLength, int volumePathBufferSize,
|
int explodePaths(TWCHAR_T* volumePaths, int volumePathLength, int volumePathBufferSize,
|
||||||
char separator, std::vector<char*> *dest, , int startingFrom = 0);
|
wchar_t separator, std::vector<wchar_t*> *dest, , int startingFrom = 0);
|
||||||
if (nextOcurrence == NULL) return 0;
|
if (nextOcurrence == NULL) return 0;
|
||||||
*/
|
*/
|
||||||
int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector<char*> *dest, int depth = 1){
|
int explodePaths(wchar_t* volumePaths, int volumePathsBufferSize, wchar_t separator, std::vector<wchar_t*> *dest, std::vector<char*> *destUTF8, int depth = 1){
|
||||||
//Por alguna razon esta puta mierda que dice acabar con 2 NULL acaba con 3; de locos.
|
//Por alguna razón, esto que dice acabar con 2 NULL acaba con 3; de locos.
|
||||||
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumepathnamesforvolumenamew
|
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumepathnamesforvolumenamew
|
||||||
|
|
||||||
char* nextOcurrence = strchr(volumePaths, separator);
|
wchar_t* nextOcurrence = wcschr(volumePaths, separator);
|
||||||
|
|
||||||
char* itemPath;
|
wchar_t* itemPath;
|
||||||
itemPath = (char*)calloc(1, volumePathsBufferSize);
|
char* itemPathUTF8;
|
||||||
|
itemPath = (wchar_t*)calloc(2, volumePathsBufferSize);
|
||||||
|
itemPathUTF8 = (char*)calloc(4, volumePathsBufferSize);
|
||||||
|
|
||||||
int pathLengthIdx = 0;
|
int pathLengthIdx = 0;
|
||||||
for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) {
|
for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) {
|
||||||
|
|
@ -246,27 +310,32 @@ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator,
|
||||||
}
|
}
|
||||||
itemPath[pathLengthIdx + 1] = '\0';
|
itemPath[pathLengthIdx + 1] = '\0';
|
||||||
dest->push_back(itemPath);
|
dest->push_back(itemPath);
|
||||||
|
WideCharToMultiByte(CP_UTF8, NULL, itemPath, -1, itemPathUTF8,
|
||||||
|
4 * volumePathsBufferSize, NULL, NULL);
|
||||||
|
destUTF8->push_back(itemPathUTF8);
|
||||||
|
|
||||||
log_debugcpp(dest->at(dest->size() - 1) << " EXPLODEPATH");
|
|
||||||
|
log_wdebugcpp(dest->at(dest->size() - 1) << L" EXPLODEPATH");
|
||||||
|
log_debugcpp(dest->at(destUTF8->size() - 1) << " EXPLODEPATH");
|
||||||
|
|
||||||
if (nextOcurrence[0] == nextOcurrence[1]) return depth;
|
if (nextOcurrence[0] == nextOcurrence[1]) return depth;
|
||||||
depth++;
|
depth++;
|
||||||
return explodePaths(nextOcurrence + sizeof(TCHAR), (volumePathsBufferSize - pathLengthIdx), separator, dest, depth);
|
return explodePaths(nextOcurrence + sizeof(wchar_t), (volumePathsBufferSize - pathLengthIdx), separator, dest, destUTF8, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int listVolumes(std::vector<char*> *onPresentPaths){
|
int listVolumes(std::vector<wchar_t*> *onPresentPaths, std::vector<char*> *onPresentPathsUTF8){
|
||||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||||
const char separator = '\0';
|
const wchar_t separator = '\0';
|
||||||
|
|
||||||
int numVolumes = 0;
|
int numVolumes = 0;
|
||||||
//Volume name
|
//Volume name
|
||||||
TCHAR volumeName[MAX_PATH];
|
wchar_t volumeName[MAX_PATH];
|
||||||
int volumeNameSize = sizeof volumeName / sizeof volumeName[0];
|
int volumeNameSize = sizeof volumeName / sizeof volumeName[0];
|
||||||
//Paths
|
//Paths
|
||||||
int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(TCHAR);
|
int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(wchar_t);
|
||||||
unsigned long volumePathLength;
|
unsigned long volumePathLength;
|
||||||
TCHAR volumePaths[volumePathsBufferSize];
|
wchar_t volumePaths[volumePathsBufferSize];
|
||||||
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
||||||
|
|
||||||
hFind = FindFirstVolume(volumeName, volumeNameSize);
|
hFind = FindFirstVolume(volumeName, volumeNameSize);
|
||||||
|
|
@ -294,7 +363,7 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
// exit(1);
|
// exit(1);
|
||||||
// }
|
// }
|
||||||
if (debug) {
|
if (debug) {
|
||||||
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths, onPresentPathsUTF8)){
|
||||||
for (int i = 0; i < onPresentPaths->size(); i++){
|
for (int i = 0; i < onPresentPaths->size(); i++){
|
||||||
log_debugcpp(onPresentPaths->at(i));
|
log_debugcpp(onPresentPaths->at(i));
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +374,7 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
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");
|
||||||
}
|
}
|
||||||
//TODO benchimarqui
|
//TODO benchimarqui
|
||||||
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
||||||
|
|
@ -319,17 +388,17 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
/* DISPLAY */
|
/* DISPLAY */
|
||||||
|
|
||||||
|
|
||||||
bool compareLastChar(std::vector<std::string> *lastCharCandidates, char* string){
|
bool compareLastWchar(std::vector<std::wstring> *lastCharCandidates, wchar_t* string){
|
||||||
bool matchingExtension = false;
|
bool matchingExtension = false;
|
||||||
for (int i = 0; i < lastCharCandidates->size(); i++){
|
for (int i = 0; i < lastCharCandidates->size(); i++){
|
||||||
log_debugcpp(lastCharCandidates->at(i) + " <- FILTERING EXTENSION");
|
log_wdebugcpp(lastCharCandidates->at(i) + L" <- FILTERING EXTENSION");
|
||||||
|
|
||||||
if(strlen(string) < lastCharCandidates->at(i).length()) continue;
|
if(wcslen(string) < lastCharCandidates->at(i).length()) continue;
|
||||||
char* potentialExtension = &string[strlen(string) - lastCharCandidates->at(i).length()];
|
wchar_t* potentialExtension = &string[wcslen(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()));
|
log_wdebugcpp(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())
|
//+ strlen(potentialExtension) + std::to_string(lastCharCandidates->at(i).length())
|
||||||
if(!strcmp(potentialExtension, lastCharCandidates->at(i).c_str())) {
|
if(!wcscmp(potentialExtension, lastCharCandidates->at(i).c_str())) {
|
||||||
log_debugcpp("VALID EXTENSION");
|
log_debugcpp("VALID EXTENSION");
|
||||||
matchingExtension = true;
|
matchingExtension = true;
|
||||||
}
|
}
|
||||||
|
|
@ -338,19 +407,19 @@ bool compareLastChar(std::vector<std::string> *lastCharCandidates, char* string)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO huh
|
//TODO huh
|
||||||
// int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
|
// int handleFolderAccessResult(int listFlags, wchar_t* nextPath, bool* error, wchar_t* errorDest, \
|
||||||
// const char* errorContent, History* history, char* currentPath = NULL, char* addrBarVal = NULL){
|
// const wchar_t* errorContent, History* history, wchar_t* currentPath = NULL, wchar_t* addrBarVal = NULL){
|
||||||
// *error = false;
|
// *error = false;
|
||||||
// if(!moveDirectory(nextPath)) {
|
// if(!moveDirectory(nextPath)) {
|
||||||
// *error = true;
|
// *error = true;
|
||||||
// if(currentPath && addrBarVal) {
|
// if(currentPath && addrBarVal) {
|
||||||
// strcpy(errorDest, errorContent);
|
// wcscpy(errorDest, errorContent);
|
||||||
// strcpy(addrBarVal, currentPath);
|
// wcscpy(addrBarVal, currentPath);
|
||||||
// }
|
// }
|
||||||
// return listFlags;
|
// return listFlags;
|
||||||
// }
|
// }
|
||||||
// if(currentPath && addrBarVal) {
|
// if(currentPath && addrBarVal) {
|
||||||
// strcpy(currentPath, addrBarVal);
|
// wcscpy(currentPath, addrBarVal);
|
||||||
// history->isAdditionTime = true;
|
// history->isAdditionTime = true;
|
||||||
// }
|
// }
|
||||||
// return (listFlags |= LIST_DIRECTORY);
|
// return (listFlags |= LIST_DIRECTORY);
|
||||||
|
|
@ -358,21 +427,21 @@ bool compareLastChar(std::vector<std::string> *lastCharCandidates, char* string)
|
||||||
|
|
||||||
|
|
||||||
//TODO huh, vale, no pasa por listdirectory por la flag, pero esto se podria hacer mejor manteniendo el no tirar de disco tb?
|
//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, \
|
int handleFolderAccessResult(int listFlags, wchar_t* nextPath, bool* error, char* errorDest, \
|
||||||
const char* errorContent, History* history, char* currentPath , char* addrBarVal){
|
const char* errorContent, History* history, wchar_t* currentPath , wchar_t* addrBarVal){
|
||||||
*error = false;
|
*error = false;
|
||||||
if(!moveDirectory(nextPath)) {
|
if(!moveDirectory(nextPath)) {
|
||||||
*error = true;
|
*error = true;
|
||||||
strcpy(errorDest, errorContent);
|
strcpy(errorDest, errorContent);
|
||||||
strcpy(addrBarVal, currentPath);
|
wcscpy(addrBarVal, currentPath);
|
||||||
return listFlags;
|
return listFlags;
|
||||||
}
|
}
|
||||||
//strcpy(currentPath, addrBarVal);
|
//wcscpy(currentPath, addrBarVal);
|
||||||
history->isAdditionTime = true;
|
history->isAdditionTime = true;
|
||||||
return (listFlags |= LIST_DIRECTORY);
|
return (listFlags |= LIST_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* errorDest, \
|
int handleFolderAccessResult(int listFlags, wchar_t* nextPath, bool* error, char* errorDest, \
|
||||||
const char* errorContent, History* history, bool isAdditionTime){
|
const char* errorContent, History* history, bool isAdditionTime){
|
||||||
*error = false;
|
*error = false;
|
||||||
if(!moveDirectory(nextPath)) {
|
if(!moveDirectory(nextPath)) {
|
||||||
|
|
@ -386,21 +455,27 @@ int handleFolderAccessResult(int listFlags, char* nextPath, bool* error, char* e
|
||||||
|
|
||||||
/* HISTORIAL */
|
/* HISTORIAL */
|
||||||
|
|
||||||
void addPathToHistory(History *history, char* pathToAdd){
|
void addPathToHistory(History *history, wchar_t* pathToAdd){
|
||||||
char* path;
|
wchar_t* path;
|
||||||
|
char* pathUTF8;
|
||||||
if (history->historyTraversalPos + 1 >= history->previousPaths.size()){
|
if (history->historyTraversalPos + 1 >= history->previousPaths.size()){
|
||||||
path = (char*)calloc(1, MAX_PATH);
|
path = (wchar_t*)calloc(2, MAX_PATH);
|
||||||
history->previousPaths.push_back(path);
|
history->previousPaths.push_back(path);
|
||||||
|
pathUTF8 = (char*)calloc(4, MAX_PATH);
|
||||||
|
WideCharToMultiByte(CP_UTF8, NULL, path, -1, pathUTF8,
|
||||||
|
4 * MAX_PATH, NULL, NULL);
|
||||||
|
history->previousPathsUTF8.push_back(pathUTF8);
|
||||||
} else {
|
} else {
|
||||||
path = history->previousPaths.at(history->historyTraversalPos + 1);
|
path = history->previousPaths.at(history->historyTraversalPos + 1);
|
||||||
|
pathUTF8 = history->previousPathsUTF8.at(history->historyTraversalPos + 1);
|
||||||
}
|
}
|
||||||
strncpy(path, pathToAdd, MAX_PATH);
|
wcsncpy(path, pathToAdd, MAX_PATH);
|
||||||
history->historyTraversalPos++;
|
history->historyTraversalPos++;
|
||||||
history->historyDepth = history->historyTraversalPos;
|
history->historyDepth = history->historyTraversalPos;
|
||||||
history->isAdditionTime = false;
|
history->isAdditionTime = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* moveThroughHistory(History *history, HistoryMovement movement) {
|
wchar_t* 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:
|
||||||
|
|
@ -418,25 +493,60 @@ char* moveThroughHistory(History *history, HistoryMovement movement) {
|
||||||
return history->previousPaths.at(history->historyTraversalPos);
|
return history->previousPaths.at(history->historyTraversalPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* RENDERING */
|
||||||
|
|
||||||
/* FIN FILE PICKER MOMENTO */
|
int windowRendering(wchar_t*, bool*, int);
|
||||||
|
int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
|
||||||
|
//TODO filesystem watcher
|
||||||
void filePickerMomento(bool isFullViewport = false){
|
//TODO let user handle memory management
|
||||||
if (isFullViewport){
|
//TODO use local val to create actual windowFlags when expanding functionality
|
||||||
|
if (!windowConfigured) {
|
||||||
|
listFlags = LIST_DIRECTORY | LIST_VOLUME;
|
||||||
|
history = new History();
|
||||||
|
if (windowFlags & FP_FULLSCREEN){
|
||||||
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
||||||
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
|
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
||||||
windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize;
|
windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize;
|
||||||
|
} else {
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(50.0f, 50.0f));
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(500.0f, 500.0f));
|
||||||
|
windowFlags = ImGuiWindowFlags_None;
|
||||||
|
//const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
|
}
|
||||||
|
windowConfigured = true;
|
||||||
|
} else windowFlags = 0;
|
||||||
|
return windowRendering(userPath, windowOpen, 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
|
||||||
|
windowConfigured = false;
|
||||||
|
for (int i = 0; i < history->previousPaths.size(); i++){
|
||||||
|
free(history->previousPaths.at(i));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < onPresentPaths.size(); i++){
|
||||||
|
free(onPresentPaths.at(i));
|
||||||
|
}
|
||||||
|
onPresentPaths.resize(0);
|
||||||
|
std::vector<wchar_t*> previousPaths;
|
||||||
|
delete history;
|
||||||
|
return exitFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Begin("File Picker in 4K", NULL, windowFlags);
|
int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
|
||||||
if (isFullViewport) ImGui::PopStyleVar(1);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||||
|
ImGui::Begin("File picker", windowOpen, windowFlags);
|
||||||
|
ImGui::PopStyleVar(1);
|
||||||
|
//log_debugcpp(*windowOpen);
|
||||||
//Listar UNA VEZ volumenes
|
//Listar UNA VEZ volumenes
|
||||||
if (listFlags & LIST_VOLUME) {
|
if (listFlags & LIST_VOLUME) {
|
||||||
listFlags &= ~LIST_VOLUME;
|
listFlags &= ~LIST_VOLUME;
|
||||||
numVolumes = listVolumes(&onPresentPaths);
|
numVolumes = listVolumes(&onPresentPaths, &onPresentPathsUTF8);
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,68 +554,52 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
//ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath);
|
//ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath);
|
||||||
if (listFlags & LIST_DIRECTORY) {
|
if (listFlags & LIST_DIRECTORY) {
|
||||||
listFlags &= ~LIST_DIRECTORY;
|
listFlags &= ~LIST_DIRECTORY;
|
||||||
|
chosenPath[0] = '\0';
|
||||||
log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
|
log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
|
||||||
if(!retrieveCurrentDirectory(currentPath)) {
|
if(!retrieveCurrentDirectory(currentPath)) {
|
||||||
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
|
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE
|
//TODO Expand extension filter
|
||||||
|
|
||||||
numFiles = listDirectory(std::string(currentPath), &directoryContents);
|
numFiles = listDirectory(std::wstring(currentPath), &directoryContents);
|
||||||
//std::cout << numFiles;
|
//std::cout << numFiles;
|
||||||
if (numFiles < 0) {
|
if (numFiles < 0) {
|
||||||
//TODO quitar GetLastError() de aqui
|
|
||||||
long directoryErrorCode;
|
long directoryErrorCode;
|
||||||
log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles));
|
log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO " + std::to_string(numFiles));
|
||||||
if (numFiles == DIRECTORY_ERROR_ACCESSING_CONTENT) directoryErrorCode = getLastDirectorySystemError();
|
if (numFiles == DIRECTORY_ERROR_ACCESSING_CONTENT) directoryErrorCode = getLastSystemError();
|
||||||
showError = true;
|
showError = true;
|
||||||
switch(directoryErrorCode) {
|
switch(directoryErrorCode) {
|
||||||
case AGDIR_ERROR_ACCESS_DENIED:
|
case AGDIR_ERROR_ACCESS_DENIED:
|
||||||
strcpy(error, ErrorMessages::accessDeniedError);
|
strcpy(error, ErrorMessages::accessDeniedError);
|
||||||
strcpy(addrBarVal, history->previousPaths.at(history->historyTraversalPos));
|
wcscpy(addrBarVal, history->previousPaths.at(history->historyTraversalPos));
|
||||||
strcpy(currentPath, history->previousPaths.at(history->historyTraversalPos));
|
wcscpy(currentPath, history->previousPaths.at(history->historyTraversalPos));
|
||||||
numFiles = listDirectory(history->previousPaths.at(history->historyTraversalPos), &directoryContents);
|
numFiles = listDirectory(history->previousPaths.at(history->historyTraversalPos), &directoryContents);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strcpy(error, ErrorMessages::listDirectoryError);
|
strcpy(error, ErrorMessages::listDirectoryError);
|
||||||
strcpy(currentPath, addrBarVal);
|
wcscpy(currentPath, addrBarVal);
|
||||||
numFiles = listDirectory(std::string(currentPath), &directoryContents);
|
numFiles = listDirectory(std::wstring(currentPath), &directoryContents);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
history->isAdditionTime = false;
|
history->isAdditionTime = false;
|
||||||
} else {
|
} else {
|
||||||
showError = false;
|
showError = false;
|
||||||
strcpy(addrBarVal, currentPath);
|
wcscpy(addrBarVal, currentPath);
|
||||||
if(history->isAdditionTime) addPathToHistory(history, addrBarVal);
|
if(history->isAdditionTime) addPathToHistory(history, addrBarVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* It's renderin' time */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
It's renderin' time
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(showError){
|
|
||||||
ImGui::Text(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(showError) ImGui::Text(error);
|
||||||
ImGui::Text("Select a file:");
|
ImGui::Text("Select a file:");
|
||||||
|
|
||||||
//Permanentes e increiblemente utilitarios botones en Cuatro K: BACK
|
//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);
|
wchar_t* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_BACKWARD);
|
||||||
//TODO: ERROR
|
|
||||||
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
||||||
&showError, error, ErrorMessages::moveUpError, history, false);
|
&showError, error, ErrorMessages::moveUpError, history, false);
|
||||||
}
|
}
|
||||||
|
|
@ -514,8 +608,7 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::BeginDisabled(MAX_HISTORY_POS);
|
ImGui::BeginDisabled(MAX_HISTORY_POS);
|
||||||
if(ImGui::Button("Forward")) {
|
if(ImGui::Button("Forward")) {
|
||||||
//TODO david????????????????????????????????????
|
wchar_t* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD);
|
||||||
char* interfaceMovementButtonsPath = moveThroughHistory(history, HISTORY_FORWARD);
|
|
||||||
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
listFlags = handleFolderAccessResult(listFlags, interfaceMovementButtonsPath,
|
||||||
&showError, error, ErrorMessages::moveUpError, history, false);
|
&showError, error, ErrorMessages::moveUpError, history, false);
|
||||||
}
|
}
|
||||||
|
|
@ -531,11 +624,13 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
//BARRA DE DIRECCIONES
|
//BARRA DE DIRECCIONES
|
||||||
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 )){
|
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_debugcpp(currentPath <<" ADDRBAR INTENTO");
|
||||||
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError,
|
MultiByteToWideChar(CP_UTF8, NULL, addrBarValUTF8, -1, addrBarVal, 2 * MAX_PATH);
|
||||||
history, currentPath, addrBarVal);
|
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError, history, currentPath, addrBarVal);
|
||||||
};
|
}
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if(ImGui::Button("Enter")){
|
if(ImGui::Button("Enter")){
|
||||||
|
|
@ -567,8 +662,7 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, 0.6f, 0.6f));
|
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, 0.6f, 0.6f));
|
||||||
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(onPresentPathsUTF8.at(i))){
|
||||||
//TODO xdddddddd
|
|
||||||
listFlags = handleFolderAccessResult(listFlags, onPresentPaths.at(i), &showError, error,
|
listFlags = handleFolderAccessResult(listFlags, onPresentPaths.at(i), &showError, error,
|
||||||
ErrorMessages::moveUpError, history, true);
|
ErrorMessages::moveUpError, history, true);
|
||||||
}
|
}
|
||||||
|
|
@ -582,7 +676,7 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
|
||||||
//DIRECTORIOS ENCONTRADOS bien pinta2
|
//DRAW DIRECTORIOS ENCONTRADOS
|
||||||
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()))){
|
||||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoHide);
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoHide);
|
||||||
|
|
@ -596,10 +690,10 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
for (; idx < numFiles; idx++) {
|
for (; idx < numFiles; idx++) {
|
||||||
if(directoryContents.at(idx)->isHidden && !showHidden) continue;
|
if(directoryContents.at(idx)->isHidden && !showHidden) continue;
|
||||||
if(filterByExtension && !directoryContents.at(idx)->isFile) {
|
if(filterByExtension && !directoryContents.at(idx)->isFile) {
|
||||||
//TODO XAPUSITA
|
//TODO Expand extensions filter
|
||||||
extensions.clear();
|
extensions.clear();
|
||||||
extensions.push_back("exe");
|
extensions.push_back(L"exe");
|
||||||
if (!compareLastChar(&extensions, directoryContents.at(idx)->name)) continue;
|
if (!compareLastWchar(&extensions, directoryContents.at(idx)->name)) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
|
|
@ -607,11 +701,21 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
|
|
||||||
//NAME
|
//NAME
|
||||||
bool isSelected = false;
|
bool isSelected = false;
|
||||||
if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){
|
WideCharToMultiByte(CP_UTF8, NULL, addrBarVal, -1, addrBarValUTF8,
|
||||||
strcat(addrBarVal, "\\");
|
4 * MAX_PATH, NULL, NULL);
|
||||||
strcat(addrBarVal, directoryContents.at(idx)->name);
|
if (ImGui::Selectable(directoryContents.at(idx)->nameUTF8, &isSelected)){
|
||||||
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error,
|
if(!directoryContents.at(idx)->isFile) {
|
||||||
|
wcscpy(chosenPath, addrBarVal);
|
||||||
|
wcscat(chosenPath, L"\\");
|
||||||
|
wcscat(chosenPath, directoryContents.at(idx)->name);
|
||||||
|
log_wdebugcpp(chosenPath << L" selected");
|
||||||
|
} else {
|
||||||
|
wcscat(addrBarVal, L"\\");
|
||||||
|
wcscat(addrBarVal, directoryContents.at(idx)->name);
|
||||||
|
log_debugcpp("directo selected");
|
||||||
|
listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error,
|
||||||
ErrorMessages::tableElementError, history, currentPath, addrBarVal);
|
ErrorMessages::tableElementError, history, currentPath, addrBarVal);
|
||||||
|
}
|
||||||
//currentItemIdx = -1;
|
//currentItemIdx = -1;
|
||||||
}
|
}
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
|
@ -639,14 +743,37 @@ void filePickerMomento(bool isFullViewport = false){
|
||||||
|
|
||||||
|
|
||||||
//ImGui::TreePop();
|
//ImGui::TreePop();
|
||||||
|
//BOTTOM ROW
|
||||||
ImGui::Checkbox("Show hidden", &showHidden);
|
ImGui::Checkbox("Show hidden", &showHidden);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Filter by .exe", &filterByExtension);
|
ImGui::Checkbox("Filter by .exe", &filterByExtension);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Button("Select");
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize("Select").x + ImGui::GetStyle().ItemSpacing.x * 2) );
|
||||||
|
|
||||||
|
ImGui::BeginDisabled();
|
||||||
|
WideCharToMultiByte(CP_UTF8, NULL, chosenPath, -1, chosenPathUTF8,
|
||||||
|
4 * MAX_PATH, NULL, NULL);
|
||||||
|
ImGui::InputText("##chosenbar", chosenPathUTF8, IM_ARRAYSIZE(chosenPathUTF8), ImGuiInputTextFlags_EnterReturnsTrue );
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if(ImGui::Button("Select")) {
|
||||||
|
log_wdebugcpp(chosenPath << " TRIED TO RETURN");
|
||||||
|
ImGui::End();
|
||||||
|
return exitWindow(userPath, windowOpen, exitFlags::EXIT_SELECTED);
|
||||||
|
}
|
||||||
|
//listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError, history, currentPath, addrBarVal);
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
|
||||||
|
if(windowOpen) return EXIT_CONTINUE;
|
||||||
|
else return exitWindow(userPath, windowOpen, exitFlags::EXIT_CLOSED);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
BIN
glfw3.dll
Normal file
BIN
glfw3.dll
Normal file
Binary file not shown.
26
main.cpp
26
main.cpp
|
|
@ -6,7 +6,7 @@
|
||||||
#define IMGUI_IMPLEMENTATION
|
#define IMGUI_IMPLEMENTATION
|
||||||
#define GL_SILENCE_DEPRECATION
|
#define GL_SILENCE_DEPRECATION
|
||||||
|
|
||||||
#include "imgui/misc/single_file/imgui_single_file.h"
|
#include "unityBuild.h"
|
||||||
#include "filepicker.hpp"
|
#include "filepicker.hpp"
|
||||||
|
|
||||||
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
|
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
|
||||||
|
|
@ -80,13 +80,13 @@ int main(int, char**) {
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//IM_ASSERT(font != NULL);
|
||||||
|
|
||||||
// Our state
|
// Our state
|
||||||
bool show_demo_window = true;
|
bool show_demo_window = true;
|
||||||
|
|
@ -107,10 +107,14 @@ int main(int, char**) {
|
||||||
ImGui::NewFrame();
|
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!).
|
// 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!).
|
||||||
if (show_demo_window)
|
static wchar_t path[MAX_PATH];// = malloc(MAX_PATH * sizeof(char));
|
||||||
|
static bool windowOpen = true;
|
||||||
|
if(windowOpen)
|
||||||
|
fp::renderFilePicker(&path[0], &windowOpen, 0);
|
||||||
|
|
||||||
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
|
|
||||||
fp::filePickerMomento(true);
|
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
@ -120,7 +124,7 @@ int main(int, char**) {
|
||||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
ImGui::EndFrame();
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
25
unityBuild.h
Normal file
25
unityBuild.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
// dear imgui: single-file wrapper include
|
||||||
|
// We use this to validate compiling all *.cpp files in a same compilation unit.
|
||||||
|
// Users of that technique (also called "Unity builds") can generally provide this themselves,
|
||||||
|
// so we don't really recommend you use this in your projects.
|
||||||
|
|
||||||
|
// Do this:
|
||||||
|
// #define IMGUI_IMPLEMENTATION
|
||||||
|
// Before you include this file in *one* C++ file to create the implementation.
|
||||||
|
// Using this in your project will leak the contents of imgui_internal.h and ImVec2 operators in this compilation unit.
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#define UNICODE
|
||||||
|
#define _UNICODE
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPLEMENTATION
|
||||||
|
#include "imgui/imgui.cpp"
|
||||||
|
#include "imgui/imgui_demo.cpp"
|
||||||
|
#include "imgui/imgui_draw.cpp"
|
||||||
|
#include "imgui/imgui_tables.cpp"
|
||||||
|
#include "imgui/imgui_widgets.cpp"
|
||||||
|
#include "imgui/backends/imgui_impl_glfw.h"
|
||||||
|
#include "imgui/backends/imgui_impl_opengl3.h"
|
||||||
|
#include "imgui/backends/imgui_impl_opengl3.cpp"
|
||||||
|
#include "imgui/backends/imgui_impl_glfw.cpp"
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue