Compare commits
2 commits
4b7cc08f8e
...
c51fbcd156
| Author | SHA1 | Date | |
|---|---|---|---|
| c51fbcd156 | |||
| c52687450e |
2 changed files with 124 additions and 113 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
*.ini
|
||||
*.exe
|
||||
*.exe
|
||||
*.rdbg
|
||||
*.pdb
|
||||
237
main.cpp
237
main.cpp
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#define IMGUI_IMPLEMENTATION
|
||||
#define GL_SILENCE_DEPRECATION
|
||||
|
||||
#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; \
|
||||
|
|
@ -13,6 +14,9 @@
|
|||
#define log_volume(str) if(debugVerbosity & DEBUG_VOLUME) log_debugcpp((str))
|
||||
#define log_extension(str) if(debugVerbosity & DEBUG_EXTENSION) log_debugcpp((str))
|
||||
|
||||
|
||||
#define MAX_LISTDIR_PATH_LENGTH (MAX_PATH - 3)
|
||||
|
||||
#include "imgui/misc/single_file/imgui_single_file.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
|
@ -45,9 +49,16 @@ bool debug = true;
|
|||
|
||||
|
||||
typedef struct {
|
||||
std::vector<uint64_t> size;
|
||||
std::vector<char*> name;
|
||||
} directoriesInfo, volumesInfo;
|
||||
long long size;
|
||||
//TODO yel spacsio NELLA MEMoria
|
||||
TCHAR name[MAX_LISTDIR_PATH_LENGTH];
|
||||
SYSTEMTIME createTime;
|
||||
SYSTEMTIME lastAccessTime;
|
||||
SYSTEMTIME lastWriteTime;
|
||||
bool isFile;
|
||||
bool isHidden;
|
||||
|
||||
} directoriesInfo;
|
||||
|
||||
//TODO UNICORDEO
|
||||
/* FILE PICKER MOMENTO */
|
||||
|
|
@ -61,27 +72,25 @@ bool retrieveCurrentDirectory(char** currentPath){
|
|||
}
|
||||
|
||||
bool moveDirectory(char** currentPath){
|
||||
if (debug) std::cout << *currentPath << std::endl;
|
||||
log_debugcpp(*currentPath);
|
||||
if(SetCurrentDirectory(*currentPath)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int listDirectory(std::string path, std::vector<char*> *directoryContents, std::vector<std::string> *desiredExtensions = nullptr){
|
||||
int listDirectory(std::string path, std::vector<directoriesInfo*> *directoryContents, std::vector<std::string> *desiredExtensions = nullptr){
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
WIN32_FIND_DATA ffd;
|
||||
LARGE_INTEGER filesize;
|
||||
bool skipDueToExtension = false;
|
||||
int numFiles = 0;
|
||||
|
||||
if (path.length() > (MAX_PATH - 3)) return -1;
|
||||
if (path.length() > (MAX_LISTDIR_PATH_LENGTH)) return -1;
|
||||
path = path + "\\*";
|
||||
hFind = FindFirstFile(path.c_str(), &ffd);
|
||||
if (INVALID_HANDLE_VALUE == hFind) return -2;
|
||||
do {
|
||||
|
||||
//TODO laberga k momento educativo
|
||||
if(!strcmp(ffd.cFileName, ".") || !strcmp(ffd.cFileName, "..")) continue;
|
||||
|
||||
log_debugcpp("BUCLE listDirectory iteracion " + std::to_string(numFiles));
|
||||
//Codigo pa saltarse arxibus k no estiendan
|
||||
/*if(desiredExtensions != nullptr){
|
||||
TCHAR* fileExtension = strrchr(ffd.cFileName, '.');
|
||||
|
|
@ -97,37 +106,45 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents, std::
|
|||
skipDueToExtension = true;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue;
|
||||
|
||||
//TODO multi info Struct
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
//strcat(itemPath, " <DIR>");
|
||||
} else {
|
||||
|
||||
// filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow);
|
||||
// char buf[16]; buf[0] = ' ';
|
||||
// itoa(filesize.QuadPart, buf + 1 , 10 );
|
||||
// strcat(itemPath, buf);
|
||||
}
|
||||
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && skipDueToExtension) continue;*/
|
||||
|
||||
|
||||
char* itemPath;
|
||||
//TODO Borrar legado
|
||||
// char* itemPath;
|
||||
// if (directoryContents->size() <= numFiles){
|
||||
// itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR));
|
||||
// directoryContents->push_back(itemPath);
|
||||
// } else {
|
||||
// itemPath = directoryContents->at(numFiles);
|
||||
// }
|
||||
directoriesInfo* itemInfo;
|
||||
if (directoryContents->size() <= numFiles){
|
||||
itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR));
|
||||
directoryContents->push_back(itemPath);
|
||||
itemInfo = new directoriesInfo();
|
||||
directoryContents->push_back(itemInfo);
|
||||
} else {
|
||||
itemPath = directoryContents->at(numFiles);
|
||||
itemInfo = directoryContents->at(numFiles);
|
||||
}
|
||||
|
||||
log_debugcpp("MEMORIA ASIGNADA iteracion " + std::to_string(numFiles));
|
||||
|
||||
//A registrar info, fiera
|
||||
itemInfo->isFile = (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false;
|
||||
itemInfo->isHidden = (ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false;
|
||||
//Tamaño
|
||||
filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow);
|
||||
itemInfo->size = filesize.QuadPart;
|
||||
//Fechitssss
|
||||
FileTimeToSystemTime(&ffd.ftCreationTime, &itemInfo->createTime);
|
||||
FileTimeToSystemTime(&ffd.ftLastAccessTime, &itemInfo->lastAccessTime);
|
||||
FileTimeToSystemTime(&ffd.ftLastWriteTime, &itemInfo->lastWriteTime);
|
||||
//Nombre de la cosita
|
||||
uint64_t idx = 0;
|
||||
do {
|
||||
itemPath[idx] = ffd.cFileName[idx];
|
||||
itemInfo->name[idx] = ffd.cFileName[idx];
|
||||
idx++;
|
||||
} while (ffd.cFileName[idx]);
|
||||
|
||||
itemInfo->name[idx] = '\0';
|
||||
log_debugcpp("INFORMACION ALMACENADA iteracion " + std::to_string(numFiles));
|
||||
|
||||
numFiles++;
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
FindClose(hFind);
|
||||
|
|
@ -215,17 +232,16 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
}
|
||||
//std::cout << volumePaths << std::endl;
|
||||
|
||||
if (debug) std::cout << std::to_string(volumePathLength) + " " ;
|
||||
if (debug) std::cout << "THE END" << std::endl;
|
||||
log_debugcpp(std::to_string(volumePathLength) + "<- VOLUME PATH LENGTH");
|
||||
log_debugcpp("THE END");
|
||||
|
||||
}else{
|
||||
if (debug) std::cout << "no volumes found wtf" << std::endl;
|
||||
log_debugcpp("no volumes found wtf");
|
||||
}
|
||||
|
||||
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
||||
} while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0);
|
||||
|
||||
if (debug) std::cout << std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN" << std::endl;
|
||||
log_debugcpp(std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN");
|
||||
FindVolumeClose(hFind);
|
||||
return numVolumes;
|
||||
}
|
||||
|
|
@ -352,8 +368,8 @@ int main(int, char**)
|
|||
|
||||
static bool isListVolumesAdequate = true;
|
||||
static bool isListDirectoriesAdequate = true;
|
||||
//Listar UNA VEZ volumenes
|
||||
|
||||
//Listar UNA VEZ volumenes
|
||||
static int numVolumes;
|
||||
static std::vector<char*> onPresentPaths;
|
||||
|
||||
|
|
@ -361,7 +377,7 @@ int main(int, char**)
|
|||
isListVolumesAdequate = false;
|
||||
//std::cout << isListVolumesAdequate << std::endl;
|
||||
numVolumes = listVolumes(&onPresentPaths);
|
||||
if (debug) std::cout << std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()) << std::endl;
|
||||
log_debugcpp(std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -370,103 +386,96 @@ int main(int, char**)
|
|||
static char currentPath[MAX_PATH];
|
||||
static char* currentPathPtr = ¤tPath[0];
|
||||
|
||||
static int currentItemIdx = -1;
|
||||
//TODO David momento
|
||||
static std::vector<char*> displayContents;
|
||||
std::vector<char*> directoryContents;
|
||||
//static int currentItemIdx = -1;
|
||||
//static std::vector<char*> directoryContents;
|
||||
static std::vector<directoriesInfo*> directoryContents;
|
||||
static int numFiles = 0;
|
||||
|
||||
if (debug) ImGui::Text("%s primir", currentPath);
|
||||
ImGui::Text("%s PRE DIRECTORY TREATMENTO", currentPath);
|
||||
|
||||
if(isListDirectoriesAdequate) {
|
||||
log_debugcpp("renderiso");
|
||||
log_debugcpp("ADECUADO LISTAR DIRECTORIOS");
|
||||
isListDirectoriesAdequate = false;
|
||||
if(!retrieveCurrentDirectory(¤tPathPtr)) {
|
||||
if (debug) std::cout << "pencaste";
|
||||
log_debugcpp("NO HABIA DIRECTORIO GetCurrentPath()");
|
||||
goto filepickerFailure;
|
||||
}
|
||||
//
|
||||
//TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE
|
||||
static std::vector<std::string> restrictToExe{"exe", "DSDFD"};
|
||||
//static std::vector<std::string> restrictToExe{"exe", "DSDFD"};
|
||||
numFiles = (listDirectory(std::string(currentPath), &directoryContents));//, &restrictToExe));
|
||||
//std::cout << numFiles;
|
||||
if (numFiles < 0) {
|
||||
ImGui::Text("Path not valid");
|
||||
if (debug) std::cout << "pencaste 2 el repencazo";
|
||||
//ImGui::Text("Path not valid");
|
||||
log_debugcpp("FALLO LA FUNCION, VALOR NEGATIVO");
|
||||
goto filepickerFailure;
|
||||
}
|
||||
if (numFiles == 0) {
|
||||
if (debug) std::cout << std::to_string (numFiles) << "<- NUM FILES" << std::endl;
|
||||
char empty[] = "Empty";
|
||||
numFiles++;
|
||||
directoryContents.push_back(empty);
|
||||
}
|
||||
displayContents = std::move(directoryContents);
|
||||
directoryContents.clear();
|
||||
|
||||
//displayContents = std::move(directoryContents);
|
||||
//directoryContents.clear();
|
||||
}
|
||||
|
||||
//It's renderin' time
|
||||
if(numFiles > 0){
|
||||
ImGui::Text("Select a file:");
|
||||
if (debug) ImGui::Text("%s %d", currentPath, currentItemIdx);
|
||||
|
||||
//Y a que los VOLUMENES pinta2 pa100pre
|
||||
//if (debug) std::cout << std::to_string(onPresentPaths.size()) + "<- numvols" << std::endl;
|
||||
if (numVolumes > 0) {
|
||||
for (int i = 0; i < onPresentPaths.size(); i++) {
|
||||
if (i > 0) ImGui::SameLine();
|
||||
// if (debug) std::cout << std::to_string(i) + "<- WE IN" << std::endl;
|
||||
// ImGui::PushID(i);
|
||||
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_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f));
|
||||
if(ImGui::Button(onPresentPaths.at(i))){
|
||||
moveDirectory(&onPresentPaths.at(i));
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
// ImGui::PopID();
|
||||
ImGui::Text("Select a file:");
|
||||
if (debug) ImGui::Text("%s TEMPADDRBAR", currentPath);
|
||||
|
||||
//Y a que los VOLUMENES pinta2 pa100pre
|
||||
//if (debug) std::cout << std::to_string(onPresentPaths.size()) + "<- numvols" << std::endl;
|
||||
if (numVolumes > 0) {
|
||||
for (int i = 0; i < onPresentPaths.size(); i++) {
|
||||
if (i > 0) ImGui::SameLine();
|
||||
// if (debug) std::cout << std::to_string(i) + "<- WE IN" << std::endl;
|
||||
// ImGui::PushID(i);
|
||||
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_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, 0.8f, 0.8f));
|
||||
if(ImGui::Button(onPresentPaths.at(i))){
|
||||
moveDirectory(&onPresentPaths.at(i));
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
// ImGui::PopID();
|
||||
}
|
||||
|
||||
|
||||
//Permanentes e increiblemente utilitarios botones en Cuatro K
|
||||
//c pervirtio con unicode std::wstring s(L"←→↑↓");
|
||||
static char moveUp[] = "..";
|
||||
static char* moveUpPtr = &moveUp[0];
|
||||
if(ImGui::Button("Move Up")){
|
||||
moveDirectory(&moveUpPtr);
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
|
||||
|
||||
//DIRECTORIOS ENCONTRADOS bien pinta2
|
||||
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
|
||||
const bool isSelected = (currentItemIdx == i);
|
||||
if (ImGui::Selectable(displayContents.at(i), isSelected))
|
||||
currentItemIdx = i;
|
||||
|
||||
if (isSelected) {
|
||||
strcat(currentPath, "\\");
|
||||
strcat(currentPath, displayContents.at(i));
|
||||
moveDirectory(¤tPathPtr);
|
||||
currentItemIdx = -1;
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
//ImGui::SetItemDefaultFocus();
|
||||
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("cagaste");
|
||||
}
|
||||
//ImGui::TreePop();
|
||||
filepickerFailure:
|
||||
ImGui::End();
|
||||
|
||||
|
||||
|
||||
//Permanentes e increiblemente utilitarios botones en Cuatro K
|
||||
//c pervirtio con unicode std::wstring s(L"←→↑↓");
|
||||
static char moveUp[] = "..";
|
||||
static char* moveUpPtr = &moveUp[0];
|
||||
if(ImGui::Button("Move Up")){
|
||||
moveDirectory(&moveUpPtr);
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
|
||||
|
||||
//DIRECTORIOS ENCONTRADOS bien pinta2
|
||||
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||
int idx = 0;
|
||||
for (; idx < numFiles; idx++) {
|
||||
|
||||
//const bool isSelected = (currentItemIdx == i);
|
||||
bool isSelected = false;
|
||||
if (ImGui::Selectable(directoryContents.at(idx)->name, &isSelected)){
|
||||
//currentItemIdx = i;
|
||||
strcat(currentPath, "\\");
|
||||
strcat(currentPath, directoryContents.at(idx)->name);
|
||||
moveDirectory(¤tPathPtr);
|
||||
//currentItemIdx = -1;
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
|
||||
//ImGui::SetItemDefaultFocus();
|
||||
|
||||
}
|
||||
if (!idx) ImGui::Text("Folder is empty");
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
|
||||
//ImGui::TreePop();
|
||||
filepickerFailure:
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue