1
0
This commit is contained in:
2025-10-10 02:17:07 +02:00
commit ee9f86004b
48 changed files with 2161 additions and 0 deletions

31
P4/P4.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smt4497-P4", "smt4497-P4\smt4497-P4.vcxproj", "{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Debug|x64.ActiveCfg = Debug|x64
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Debug|x64.Build.0 = Debug|x64
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Debug|x86.ActiveCfg = Debug|Win32
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Debug|x86.Build.0 = Debug|Win32
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Release|x64.ActiveCfg = Release|x64
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Release|x64.Build.0 = Release|x64
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Release|x86.ActiveCfg = Release|Win32
{26268DC2-B4EF-4EB4-A028-7FCE3264D50D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03E5163E-88C0-4721-A68B-5902660D19FD}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,180 @@
#include "smt4497-P4.h"
using namespace ss;
using namespace std;
extern Dbg _dbg(true);
static size_t accSize = 0;
int main(int argc, char* argv[], char* envp[])
{
setlocale(LC_ALL, "spanish");
const char* pDir = argv[1];
int found;
char** pfileList;
static FileSys fs;
pfileList = fs.ArchivosEnDirectorio(&found, pDir, false);
_dbg.CheckError(argc < 2, 1, "Error en argumentos\n");
SearchTextInFile(argv[1], argv[2]);
printf("\nPor favor, pulse la tecla ENTRAR para terminar...\n");
(void)getchar();
return 0;
}
BOOL ShowFilesInDirectory(int found, char* pName)
{
BOOL res = FALSE;
CHAR buffer[MAX_PATH];
DWORD win32APIResponse = GetFullPathNameA(pName, sizeof(buffer), buffer, NULL);
if (!_dbg.CheckError(win32APIResponse == 0, "Error al llamar a GetFullPathNameA()"))
{
res = TRUE;
printf("Se han encontrado %d archivos en la carpeta %s\n", found, buffer);
}
return res;
}
size_t GetFileSize(char* pfileName)
{
WIN32_FILE_ATTRIBUTE_DATA info;
BOOL attrs = GetFileAttributesExA(pfileName, GetFileExInfoStandard, &info);
return info.nFileSizeLow + ((int64_t)info.nFileSizeHigh << 32);
}
VOID PrintFilesInDirectory(char* pfileList[])
{
int i = 0;
// prints file list while a null pointer isn't found
while (pfileList[i] != nullptr)
{
CHAR buffer[64];
PSTR formatted = StrFormatByteSize64A(GetFileSize(pfileList[i]), buffer, sizeof(buffer));
printf("#%d: %s (%s)\n", i, pfileList[i], formatted);
i++;
}
}
static size_t BytesInFile(char* listaArchivos[], int nroArchivos)
{
size_t total = 0;
int i = 0;
WIN32_FILE_ATTRIBUTE_DATA info;
for (i = 0; i < nroArchivos; i++) {
if (_dbg.CheckError(FALSE ==
GetFileAttributesExA(listaArchivos[i], GetFileExInfoStandard, &info),
"Error en GetFileAttributesExA para el archivo %s\n", listaArchivos[i]))
continue; // Salta a la siguiente iteraci<63>n del bucle si hay error
int64_t tam = ((int64_t)info.nFileSizeHigh >> 32) + info.nFileSizeLow;
total += tam;
}
return total;
}
static size_t BytesInFileThread(char* listaArchivos[], int nroArchivos, size_t* pTotal)
{
size_t total = 0;
int i = 0;
WIN32_FILE_ATTRIBUTE_DATA info;
for (i = 0; i < nroArchivos; i++) {
if (_dbg.CheckError(FALSE ==
GetFileAttributesExA(listaArchivos[i], GetFileExInfoStandard, &info),
"Error en GetFileAttributesExA para el archivo %s\n", listaArchivos[i]))
continue; // Salta a la siguiente iteraci<63>n del bucle si hay error
int64_t tam = ((int64_t)info.nFileSizeHigh >> 32) + info.nFileSizeLow;
total += tam;
}
*pTotal += total;
return total;
}
static size_t BytesInFileMultithread(char* path,
unsigned int additionalThreads, bool useLastSearch)
{
static FileSys fs;
static int found = 0;
static char** pfileList = nullptr;
if (!useLastSearch)
{
pfileList = fs.ArchivosEnDirectorio(&found, path, false);
if (!ShowFilesInDirectory(found, path))
{
return 0;
printf("\t\tLa b<>squeda de archivos ha tardado %f segs\n", fs.TiempoUltimoMetodo());
}
}
_dbg.CronoInicio();
size_t totalSize = 0;
if (additionalThreads == 0)
{
totalSize = BytesInFile(pfileList, found);
}
else
{
thread* threads = new thread[additionalThreads];
for (int i = 0; i < additionalThreads; i++)
{
threads[i] = thread(BytesInFileThread, pfileList, found, &totalSize);
_dbg.CheckError(threads[i].native_handle() == NULL, "Error creando hilo %d", i);
}
for (int i = 0; i < additionalThreads; i++)
{
threads[i].join();
}
delete[] threads;
}
auto secs = _dbg.CronoLee();
printf("\tCalculados %lld bytes\n", totalSize);
printf("\t\tCalculado en: %f segs por %s (%d hilos adicionales).\n\n", secs, __FUNCTION__, additionalThreads);
return totalSize;
}
static int SearchTextInFile(const char* dirBusqueda, const char* textoABuscar) {
Dbg dbg;
FileSys fs;
int ocurrencias, encontrados = 0, nroArchivos, idxMarca = 0;
char** listaArchivos = fs.ArchivosEnDirectorio(&nroArchivos, dirBusqueda, false);
if (dbg.CheckError(listaArchivos == nullptr, "No se han encontrado archivos en la carpeta %s\n", dirBusqueda)) {
return -1;
}
char marcasAvance[] = "-\\|/"; // Para animaci<63>n simple
size_t bytesTotal, bytesAcumulados = 0;
bytesTotal = BytesInFile(listaArchivos, nroArchivos);
if (dbg.CheckError(bytesTotal == 0, "No se han encontrado archivos en la carpeta %s\n", dirBusqueda)) {
return -1;
}
ShowFilesInDirectory(nroArchivos, (char*)dirBusqueda);
printf("\nBuscando texto \"%s\" en %lld bytes\n", textoABuscar, bytesTotal);
dbg.CronoInicio();
for (int i = 0; i < nroArchivos; i++) {
// Busca el texto en el archivo usando un m<>todo de FileSys
ocurrencias = fs.BuscaDatoEnArchivo(textoABuscar, strlen(textoABuscar),
listaArchivos[i], &bytesAcumulados, 10000);
if (ocurrencias > 0) {
encontrados++;
dbg.DbgPrint("#%d: %d ocurrencias en %s\n", encontrados, ocurrencias, listaArchivos[i]);
}
else if (ocurrencias < 0) {
dbg.DbgPrint("Error %s\n", listaArchivos[i]);
}
// Muestra el avance del proceso
if (i == nroArchivos - 1)
bytesAcumulados = bytesTotal; // Para que muestre 100% al final, aunque no sea exacto
printf("\r%c %.02f %% %d/%d ", marcasAvance[idxMarca++ % (sizeof(marcasAvance) - 1)],
(double)bytesAcumulados * 100 / bytesTotal, i + 1, nroArchivos);
}
double segs = dbg.CronoLee();
printf("\nSe han encontrado %d archivos con el texto\n", encontrados, textoABuscar, dirBusqueda);
printf("\t\tCalculado en: %f segs por %s\n", segs, __FUNCTION__);
return encontrados;
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <stdio.h>
#include <locale.h>
#include <Shlwapi.h>
#include <thread>
#include <sslib\SSLib.h>
#pragma comment(lib, "Shlwapi.lib") // Link against Shlwapi.lib
static BOOL ShowFilesInDirectory(int found, char* pdirName);
static void PrintFilesInDirectory(char* fileList[]);
static size_t GetFileSize(char* pfileName);
static size_t BytesInFile(char* listaArchivos[], int nroArchivos);
static size_t BytesInFileThread(char* listaArchivos[], int nroArchivos, size_t* pTotal);
static size_t BytesInFileMultithread(char* path, unsigned int additionalThreads, bool useLastSearch);
static int SearchTextInFile(const char* dirBusqueda, const char* textoABuscar);

View File

@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{26268dc2-b4ef-4eb4-a028-7fce3264d50d}</ProjectGuid>
<RootNamespace>smt4497P4</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(AAComm)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(AAComm)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(AAComm)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(AAComm)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(AAComm)lib\sslib\x86\SSLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(AAComm)lib\sslib\x86\SSLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(AAComm)lib\sslib\x64\SSLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(AAComm)lib\sslib\x64\SSLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="smt4497-P4.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="smt4497-P4.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="smt4497-P4.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="smt4497-P4.h" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerEnvironment>PATH=$(AAComm)bin\sslib\$(PlatformTarget);%PATH%</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>. BuscaTextoEnArchivos</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerEnvironment>PATH=$(AAComm)bin\sslib\$(PlatformTarget);%PATH%</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>. BuscaTextoEnArchivos</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerEnvironment>PATH=$(AAComm)bin\sslib\$(PlatformTarget);%PATH%</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>. BuscaTextoEnArchivos</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerEnvironment>PATH=$(AAComm)bin\sslib\$(PlatformTarget);%PATH%</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>. BuscaTextoEnArchivos</LocalDebuggerCommandArguments>
</PropertyGroup>
</Project>