Lectura directorio escindida main
This commit is contained in:
parent
4585771168
commit
564f840936
1 changed files with 75 additions and 36 deletions
105
main.cpp
105
main.cpp
|
|
@ -7,7 +7,10 @@
|
|||
#define GL_SILENCE_DEPRECATION
|
||||
#include "imgui/misc/single_file/imgui_single_file.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
|
||||
// To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma.
|
||||
|
|
@ -20,6 +23,52 @@ static void glfw_error_callback(int error, const char* description)
|
|||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
||||
}
|
||||
|
||||
bool retrieveCurrentDirectory(char** currentPath){
|
||||
if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
WIN32_FIND_DATA ffd;
|
||||
LARGE_INTEGER filesize;
|
||||
int numFiles = 0;
|
||||
|
||||
if (path.length() > (MAX_PATH - 3)) return -1;
|
||||
path = path + "\\*";
|
||||
hFind = FindFirstFile(path.c_str(), &ffd);
|
||||
if (INVALID_HANDLE_VALUE == hFind) return -2;
|
||||
do {
|
||||
char* itemPath;
|
||||
if (directoryContents->size() <= numFiles){
|
||||
itemPath = (char*)calloc(1, MAX_PATH * sizeof(WCHAR));
|
||||
directoryContents->push_back(itemPath);
|
||||
} else {
|
||||
itemPath = directoryContents->at(numFiles);
|
||||
}
|
||||
|
||||
uint64_t idx = 0;
|
||||
do {
|
||||
itemPath[idx] = ffd.cFileName[idx];
|
||||
idx++;
|
||||
} while (ffd.cFileName[idx]);
|
||||
|
||||
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);
|
||||
FindClose(hFind);
|
||||
return numFiles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
|
|
@ -139,52 +188,42 @@ int main(int, char**)
|
|||
{
|
||||
ImGui::Begin("File Picker in 4K");
|
||||
|
||||
//TODO Win32
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
WIN32_FIND_DATA ffd;
|
||||
LARGE_INTEGER filesize;
|
||||
static char* debug32;
|
||||
//
|
||||
//cursed C momento
|
||||
static char currentPath[MAX_PATH];
|
||||
char* ptr = ¤tPath[0];
|
||||
|
||||
static int currentItemIdx = 0;
|
||||
std::vector<char*> directoryContents;
|
||||
|
||||
if(!retrieveCurrentDirectory(&ptr)) goto filepickerFailure;
|
||||
|
||||
if(int numFiles = (listDirectory(".", &directoryContents))){
|
||||
ImGui::Text("Select a file:");
|
||||
hFind = FindFirstFile("C:\\Users\\Fabio\\Downloads\\Street Fighter 6 - Closed Beta\\*", &ffd);
|
||||
if (INVALID_HANDLE_VALUE != hFind) {
|
||||
if (ImGui::BeginListBox("fpLb", ImVec2(FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||
for (int n = 0; FindNextFile(hFind, &ffd) != 0; n++) {
|
||||
static std::string seleciable;
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
seleciable = " " + std::string(ffd.cFileName) + "<DIR>";
|
||||
ImGui::Selectable(seleciable.c_str(), false);
|
||||
} else {
|
||||
filesize.QuadPart = (long long)(ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow;
|
||||
seleciable = " " + std::string(ffd.cFileName) + " " + std::to_string(filesize.QuadPart);
|
||||
ImGui::Selectable(seleciable.c_str(), false);
|
||||
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
// ImGui::Selectable(directoryContents.at(i), false);
|
||||
|
||||
const bool isSelected = (currentItemIdx == i);
|
||||
if (ImGui::Selectable(directoryContents.at(i), isSelected))
|
||||
currentItemIdx = i;
|
||||
|
||||
//Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (isSelected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
}
|
||||
|
||||
//const bool isSelected = (currentItemIdx == n);
|
||||
//if (ImGui::Selectable(items[n], is_selected))
|
||||
// item_current_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
//if (is_selected)
|
||||
// ImGui::SetItemDefaultFocus();
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
//if (is_selected) ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
FindClose(hFind);
|
||||
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("cagaste");
|
||||
}
|
||||
//ImGui::TreePop();
|
||||
|
||||
filepickerFailure:
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 3. Show another simple window.
|
||||
if (show_another_window)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue