W MoveUp pero random bug al entrar en carpeta

This commit is contained in:
OugonNoHane 2022-10-30 03:08:19 +01:00 committed by Hane
commit 0fa6d6b056

View file

@ -47,10 +47,11 @@ bool moveDirectory(char** currentPath){
return false;
}
int listDirectory(std::string path, std::vector<char*> *directoryContents){
int listDirectory(std::string path, std::vector<char*> *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;
@ -58,6 +59,42 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
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;
//Codigo pa saltarse arxibus k no estiendan
/*if(desiredExtensions != nullptr){
TCHAR* fileExtension = strrchr(ffd.cFileName, '.');
if (debug && fileExtension != NULL) { std::cout << fileExtension; std::cout << " <- FILTERING EXTENSION" << std::endl; }
std::cout << ffd.cFileName << std::endl;
//TODO tabien no???
if (fileExtension == NULL) continue;
for (int i = 0; i < desiredExtensions->size(); i++) {
if (debug) { std::cout << std::to_string(strcmp(desiredExtensions->at(i).c_str(), fileExtension)) << std::endl; }
if (strcmp(desiredExtensions->at(i).c_str(), fileExtension)){
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);
}
char* itemPath;
if (directoryContents->size() <= numFiles){
itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR));
@ -65,21 +102,12 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
} else {
itemPath = directoryContents->at(numFiles);
}
uint64_t idx = 0;
do {
itemPath[idx] = ffd.cFileName[idx];
idx++;
} while (ffd.cFileName[idx]);
//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);
}
numFiles++;
} while (FindNextFile(hFind, &ffd) != 0);
@ -89,7 +117,6 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
/* VOLUMES */
//new char*[CharCount * sizeof(WCHAR)
/*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
@ -97,7 +124,6 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
char separator, std::vector<char*> *dest, , int startingFrom = 0);
if (nextOcurrence == NULL) return 0;
*/
int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector<char*> *dest, int depth = 1){
//Por alguna razon esta puta mierda que dice acabar con 2 NULL acaba con 3; de locos.
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumepathnamesforvolumenamew
@ -176,7 +202,7 @@ int listVolumes(std::vector<char*> *onPresentPaths){
if (debug) std::cout << "THE END" << std::endl;
}else{
if (debug) std::cout << "cagaste" << std::endl;
if (debug) std::cout << "no volumes found wtf" << std::endl;
}
//TODO necesario? di CAMBIAR 4 A NUL
@ -191,7 +217,6 @@ int listVolumes(std::vector<char*> *onPresentPaths){
/* FIN FILE PICKER MOMENTO */
int main(int, char**)
{
// Setup window
@ -345,7 +370,9 @@ int main(int, char**)
goto filepickerFailure;
}
//
numFiles = (listDirectory(std::string(currentPath), &directoryContents));
//TODO ELIMINAR RESTRICCION EXE; PRUEBITA DEL SIGNIORE
static std::vector<std::string> restrictToExe = { "exe" };
numFiles = (listDirectory(std::string(currentPath), &directoryContents));//, &restrictToExe));
//std::cout << numFiles;
if (numFiles < 0) {
if (debug) std::cout << "pencaste 2 el repencazo";
@ -361,10 +388,11 @@ int main(int, char**)
//Y a que los VOLUMENES pinta2 pa100pre
//if (debug) std::cout << std::to_string(onPresentPaths.size()) + "<- numvols" << std::endl;
if (numVolumes > 0){
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;
//TODO dabid aiuda
// 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));
@ -374,10 +402,18 @@ int main(int, char**)
isListDirectoriesAdequate = true;
}
ImGui::PopStyleColor(3);
// ImGui::PopID();
}
}
//Permanentes e increiblemente utilitarios botones en Cuatro K
//c pervirtio con unicode std::wstring s(L"←→↑↓");
//TODO TREMENDA MANDING DICK
static char moveUp[2] = {'.', '.'};
static char* moveUpPtr = &moveUp[0];
if(ImGui::Button("Move Up")){
moveDirectory(&moveUpPtr);
isListDirectoriesAdequate = true;
}
//DIRECTORIOS ENCONTRADOS bien pinta2