Listar volumenes en consola WE ARE THE VOLUMES
This commit is contained in:
parent
7ad29f670d
commit
545e7b53d1
1 changed files with 50 additions and 34 deletions
84
main.cpp
84
main.cpp
|
|
@ -97,24 +97,47 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
||||||
if (nextOcurrence == NULL) return 0;
|
if (nextOcurrence == NULL) return 0;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector<char*> *dest){
|
int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector<char*> *dest, int depth = 0){
|
||||||
static int lmao = 0;
|
//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);
|
char* nextOcurrence = strchr(volumePaths, separator);
|
||||||
//TODO Test de cadena original
|
//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;
|
char* itemPath;
|
||||||
itemPath = (char*)calloc(1, volumePathsBufferSize);
|
itemPath = (char*)calloc(1, volumePathsBufferSize);
|
||||||
//for (int i = 0; &volumePaths[i] == nextOcurrence; i++) {
|
//for (int i = 0; &volumePaths[i] == nextOcurrence; i++) {
|
||||||
for (int i = 0; volumePaths[i] != nextOcurrence[0]; i++) {
|
int pathLengthIdx = 0;
|
||||||
itemPath[i] = volumePaths[i];
|
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];
|
||||||
}
|
}
|
||||||
dest->push_back(itemPath);
|
dest->push_back(itemPath);
|
||||||
|
if (debug) {
|
||||||
|
|
||||||
|
std::cout << dest->at(dest->size() - 1);
|
||||||
|
std::cout << " EXPLODEPATH" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
//TODO Test de recursividad
|
//TODO Test de recursividad
|
||||||
//if (debug) { std::cout << dest->at(0) << std::endl; exit(1); }
|
//if (debug) { std::cout << dest->at(0) << std::endl; exit(1); }
|
||||||
if (debug && lmao == 3) { std::cout << volumePaths << std::endl; exit(1); }
|
//if (debug && lmao == 3) { std::cout << volumePaths << std::endl; exit(1); }
|
||||||
lmao++;
|
//lmao++;
|
||||||
if (nextOcurrence[0] == nextOcurrence[sizeof(TCHAR)]) return 0;
|
depth++;
|
||||||
return explodePaths(nextOcurrence, volumePathsBufferSize, separator, dest);
|
if (nextOcurrence[0] == nextOcurrence[1]) return depth;
|
||||||
|
return explodePaths(nextOcurrence + sizeof(TCHAR), (volumePathsBufferSize - pathLengthIdx), separator, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -131,17 +154,10 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(TCHAR);
|
int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(TCHAR);
|
||||||
unsigned long volumePathLength;
|
unsigned long volumePathLength;
|
||||||
TCHAR volumePaths[volumePathsBufferSize];
|
TCHAR volumePaths[volumePathsBufferSize];
|
||||||
//TODO BORRAR
|
//TODO necesario? di
|
||||||
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '4');
|
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '\0');
|
||||||
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;
|
|
||||||
|
|
||||||
hFind = FindFirstVolume(volumeName, volumeNameSize);
|
hFind = FindFirstVolume(volumeName, volumeNameSize); //if (debug) std::cout << volumeNameSize << std::endl;
|
||||||
//if (debug) std::cout << volumeNameSize << std::endl;
|
|
||||||
if (INVALID_HANDLE_VALUE == hFind) return -2;
|
if (INVALID_HANDLE_VALUE == hFind) return -2;
|
||||||
do {
|
do {
|
||||||
//if (debug) std::cout << volumeName << std::endl;
|
//if (debug) std::cout << volumeName << std::endl;
|
||||||
|
|
@ -150,20 +166,19 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
|
|
||||||
if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; }
|
if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; }
|
||||||
if (debug) std::cout << volumeName;
|
if (debug) std::cout << volumeName;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
if (debug && volumePaths[0] == 'E') {
|
// if (debug && volumePaths[0] == 'E') {
|
||||||
std::cout << volumePathLength << std::endl;
|
// std::cout << volumePathLength << std::endl;
|
||||||
/*exit(1);*/
|
// /*exit(1);*/
|
||||||
for (int i = 0; i < volumePathsBufferSize; i++){
|
// for (int i = 0; i < volumePathsBufferSize; i++){
|
||||||
std::cout << std::to_string(i) + ": ";
|
// std::cout << std::to_string(i) + ": ";
|
||||||
std::cout << volumePaths[i];
|
// std::cout << volumePaths[i];
|
||||||
std::cout << " | ";
|
// std::cout << " | ";
|
||||||
}
|
// }
|
||||||
std::cout << std::endl << "I IA" << std::endl;
|
// std::cout << std::endl << "I IA" << std::endl;
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
if(explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
if(explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){
|
||||||
if (debug) std::cout << volumePaths << std::endl;
|
|
||||||
for (int i = 0; i < onPresentPaths->size(); i++){
|
for (int i = 0; i < onPresentPaths->size(); i++){
|
||||||
std::cout << onPresentPaths->at(i) << std::endl;
|
std::cout << onPresentPaths->at(i) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +193,8 @@ int listVolumes(std::vector<char*> *onPresentPaths){
|
||||||
}
|
}
|
||||||
|
|
||||||
numVolumes++;
|
numVolumes++;
|
||||||
|
//TODO necesario? di CAMBIAR 4 A NUL
|
||||||
|
std::fill(volumePaths, volumePaths + volumePathsBufferSize, '4');
|
||||||
} while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0);
|
} while (FindNextVolume(hFind, volumeName, volumeNameSize) != 0);
|
||||||
|
|
||||||
FindVolumeClose(hFind);
|
FindVolumeClose(hFind);
|
||||||
|
|
@ -309,7 +325,7 @@ int main(int, char**)
|
||||||
static bool isListVolumesAdequate = true;
|
static bool isListVolumesAdequate = true;
|
||||||
if (debug && isListVolumesAdequate) {
|
if (debug && isListVolumesAdequate) {
|
||||||
isListVolumesAdequate = false;
|
isListVolumesAdequate = false;
|
||||||
std::cout << isListVolumesAdequate << std::endl;
|
//std::cout << isListVolumesAdequate << std::endl;
|
||||||
std::vector<char*> onPresentPaths;
|
std::vector<char*> onPresentPaths;
|
||||||
listVolumes(&onPresentPaths);
|
listVolumes(&onPresentPaths);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue