Cambio de volumen funcional VAMOS CONIO
This commit is contained in:
parent
545e7b53d1
commit
571bb45b27
1 changed files with 57 additions and 39 deletions
92
main.cpp
92
main.cpp
|
|
@ -42,6 +42,7 @@ bool retrieveCurrentDirectory(char** currentPath){
|
|||
}
|
||||
|
||||
bool moveDirectory(char** currentPath){
|
||||
if (debug) std::cout << *currentPath << std::endl;
|
||||
if(SetCurrentDirectory(*currentPath)) return true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -70,7 +71,7 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
|||
itemPath[idx] = ffd.cFileName[idx];
|
||||
idx++;
|
||||
} while (ffd.cFileName[idx]);
|
||||
|
||||
//TODO multi info Struct
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
//strcat(itemPath, " <DIR>");
|
||||
} else {
|
||||
|
|
@ -97,47 +98,31 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
|||
if (nextOcurrence == NULL) return 0;
|
||||
*/
|
||||
|
||||
int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector<char*> *dest, int depth = 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
|
||||
|
||||
static int lmao = 0;
|
||||
char* nextOcurrence = strchr(volumePaths, separator);
|
||||
//TODO Test de cadena original;
|
||||
// if (debug && lmao) {
|
||||
// std::cout << std::to_string(lmao) + ":lmao " << std::endl;
|
||||
// for (int i = 0; i < volumePathsBufferSize; i++){
|
||||
// std::cout << std::to_string(i) + ": ";
|
||||
// std::cout << volumePaths[i];
|
||||
// std::cout << " | ";
|
||||
// }
|
||||
// std::cout << std::endl << "I IA" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// if (debug && volumePaths[0] == 'E') lmao = 1;
|
||||
|
||||
char* itemPath;
|
||||
itemPath = (char*)calloc(1, volumePathsBufferSize);
|
||||
//for (int i = 0; &volumePaths[i] == nextOcurrence; i++) {
|
||||
|
||||
int pathLengthIdx = 0;
|
||||
for (; volumePaths[pathLengthIdx] != nextOcurrence[0]; pathLengthIdx++) {
|
||||
if (debug) { std::cout << volumePaths[0]; std::cout << " ENTERS " + std::to_string(pathLengthIdx) << std::endl; }
|
||||
itemPath[pathLengthIdx] = volumePaths[pathLengthIdx];
|
||||
}
|
||||
itemPath[pathLengthIdx + 1] = '\0';
|
||||
dest->push_back(itemPath);
|
||||
if (debug) {
|
||||
|
||||
if (debug) {
|
||||
std::cout << dest->at(dest->size() - 1);
|
||||
std::cout << " EXPLODEPATH" << std::endl;
|
||||
|
||||
}
|
||||
//TODO Test de recursividad
|
||||
//if (debug) { std::cout << dest->at(0) << std::endl; exit(1); }
|
||||
//if (debug && lmao == 3) { std::cout << volumePaths << std::endl; exit(1); }
|
||||
//lmao++;
|
||||
depth++;
|
||||
|
||||
if (nextOcurrence[0] == nextOcurrence[1]) return depth;
|
||||
return explodePaths(nextOcurrence + sizeof(TCHAR), (volumePathsBufferSize - pathLengthIdx), separator, dest);
|
||||
depth++;
|
||||
return explodePaths(nextOcurrence + sizeof(TCHAR), (volumePathsBufferSize - pathLengthIdx), separator, dest, depth);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -167,6 +152,7 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; }
|
||||
if (debug) std::cout << volumeName;
|
||||
if (debug) {
|
||||
//pathSchecker
|
||||
// if (debug && volumePaths[0] == 'E') {
|
||||
// std::cout << volumePathLength << std::endl;
|
||||
// /*exit(1);*/
|
||||
|
|
@ -178,10 +164,11 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
// std::cout << std::endl << "I IA" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
if(explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
||||
if(numVolumes += explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
||||
for (int i = 0; i < onPresentPaths->size(); i++){
|
||||
std::cout << onPresentPaths->at(i) << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
//std::cout << volumePaths << std::endl;
|
||||
}
|
||||
|
|
@ -192,11 +179,11 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
|||
if (debug) std::cout << "cagaste" << std::endl;
|
||||
}
|
||||
|
||||
numVolumes++;
|
||||
//TODO necesario? di CAMBIAR 4 A NUL
|
||||
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '4');
|
||||
} while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0);
|
||||
|
||||
if (debug) std::cout << std::to_string(onPresentPaths->size()) + " JUST BEFORE MAIN" << std::endl;
|
||||
FindVolumeClose(hFind);
|
||||
return numVolumes;
|
||||
}
|
||||
|
|
@ -321,20 +308,27 @@ int main(int, char**)
|
|||
|
||||
{
|
||||
ImGui::Begin("File Picker in 4K");
|
||||
//TODO test listar volumenes
|
||||
|
||||
static bool isListVolumesAdequate = true;
|
||||
static bool isListDirectoriesAdequate = true;
|
||||
//Listar UNA VEZ volumenes
|
||||
|
||||
static int numVolumes;
|
||||
static std::vector<char*> onPresentPaths;
|
||||
|
||||
if (debug && isListVolumesAdequate) {
|
||||
isListVolumesAdequate = false;
|
||||
//std::cout << isListVolumesAdequate << std::endl;
|
||||
std::vector<char*> onPresentPaths;
|
||||
listVolumes(&onPresentPaths);
|
||||
numVolumes = listVolumes(&onPresentPaths);
|
||||
if (debug) std::cout << std::to_string(numVolumes) + "<- depth MAIN size() ->" + std::to_string(onPresentPaths.size()) << std::endl;
|
||||
//TODO tiyuria
|
||||
}
|
||||
//
|
||||
|
||||
static bool renderListbox = true;
|
||||
|
||||
//Listar UNA VEZ directorios
|
||||
//cursed C momento: necesario ptr en otra var para mandar a char** de firma
|
||||
static char currentPath[MAX_PATH];
|
||||
static char* ptr = ¤tPath[0];
|
||||
static char* currentPathPtr = ¤tPath[0];
|
||||
|
||||
static int currentItemIdx = -1;
|
||||
static std::vector<char*> displayContents;
|
||||
|
|
@ -343,10 +337,10 @@ int main(int, char**)
|
|||
|
||||
if (debug) ImGui::Text("%s primir", currentPath);
|
||||
|
||||
if(renderListbox) {
|
||||
if(isListDirectoriesAdequate) {
|
||||
if (debug) std::cout << "renderiso" << std::endl;
|
||||
renderListbox = false;
|
||||
if(!retrieveCurrentDirectory(&ptr)) {
|
||||
isListDirectoriesAdequate = false;
|
||||
if(!retrieveCurrentDirectory(¤tPathPtr)) {
|
||||
if (debug) std::cout << "pencaste";
|
||||
goto filepickerFailure;
|
||||
}
|
||||
|
|
@ -360,9 +354,33 @@ int main(int, char**)
|
|||
displayContents = std::move(directoryContents);
|
||||
}
|
||||
|
||||
//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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//DIRECTORIOS ENCONTRADOS bien pinta2
|
||||
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
|
||||
|
|
@ -373,9 +391,9 @@ int main(int, char**)
|
|||
if (isSelected) {
|
||||
strcat(currentPath, "\\");
|
||||
strcat(currentPath, displayContents.at(i));
|
||||
moveDirectory(&ptr);
|
||||
moveDirectory(¤tPathPtr);
|
||||
currentItemIdx = -1;
|
||||
renderListbox = true;
|
||||
isListDirectoriesAdequate = true;
|
||||
}
|
||||
//ImGui::SetItemDefaultFocus();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue