Lectura directorio escindida main
This commit is contained in:
parent
4585771168
commit
564f840936
1 changed files with 75 additions and 36 deletions
97
main.cpp
97
main.cpp
|
|
@ -7,7 +7,10 @@
|
||||||
#define GL_SILENCE_DEPRECATION
|
#define GL_SILENCE_DEPRECATION
|
||||||
#include "imgui/misc/single_file/imgui_single_file.h"
|
#include "imgui/misc/single_file/imgui_single_file.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
#include <Windows.h>
|
#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.
|
// [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.
|
// 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);
|
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**)
|
int main(int, char**)
|
||||||
|
|
@ -139,52 +188,42 @@ int main(int, char**)
|
||||||
{
|
{
|
||||||
ImGui::Begin("File Picker in 4K");
|
ImGui::Begin("File Picker in 4K");
|
||||||
|
|
||||||
//TODO Win32
|
//cursed C momento
|
||||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
static char currentPath[MAX_PATH];
|
||||||
WIN32_FIND_DATA ffd;
|
char* ptr = ¤tPath[0];
|
||||||
LARGE_INTEGER filesize;
|
|
||||||
static char* debug32;
|
|
||||||
//
|
|
||||||
static int currentItemIdx = 0;
|
static int currentItemIdx = 0;
|
||||||
|
std::vector<char*> directoryContents;
|
||||||
|
|
||||||
|
if(!retrieveCurrentDirectory(&ptr)) goto filepickerFailure;
|
||||||
|
|
||||||
|
if(int numFiles = (listDirectory(".", &directoryContents))){
|
||||||
ImGui::Text("Select a file:");
|
ImGui::Text("Select a file:");
|
||||||
hFind = FindFirstFile("C:\\Users\\Fabio\\Downloads\\Street Fighter 6 - Closed Beta\\*", &ffd);
|
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||||
if (INVALID_HANDLE_VALUE != hFind) {
|
for (int i = 0; i < numFiles; i++) {
|
||||||
if (ImGui::BeginListBox("fpLb", ImVec2(FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
// ImGui::Selectable(directoryContents.at(i), false);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//const bool isSelected = (currentItemIdx == n);
|
const bool isSelected = (currentItemIdx == i);
|
||||||
//if (ImGui::Selectable(items[n], is_selected))
|
if (ImGui::Selectable(directoryContents.at(i), isSelected))
|
||||||
// item_current_idx = n;
|
currentItemIdx = i;
|
||||||
|
|
||||||
//Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
//Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||||
//if (is_selected)
|
if (isSelected)
|
||||||
// ImGui::SetItemDefaultFocus();
|
ImGui::SetItemDefaultFocus();
|
||||||
|
|
||||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
|
||||||
//if (is_selected) ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
}
|
||||||
FindClose(hFind);
|
|
||||||
|
|
||||||
ImGui::EndListBox();
|
ImGui::EndListBox();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("cagaste");
|
ImGui::Text("cagaste");
|
||||||
}
|
}
|
||||||
//ImGui::TreePop();
|
//ImGui::TreePop();
|
||||||
|
filepickerFailure:
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 3. Show another simple window.
|
// 3. Show another simple window.
|
||||||
if (show_another_window)
|
if (show_another_window)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue