Compare commits

...

1 Commits
master ... lab1

Author SHA1 Message Date
Ivan2567
0db1c556d4 lab1 2023-11-23 01:32:06 +03:00
7 changed files with 411 additions and 0 deletions

31
Project1/Project1.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32602.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}"
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
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x64.ActiveCfg = Debug|x64
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x64.Build.0 = Debug|x64
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x86.ActiveCfg = Debug|Win32
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x86.Build.0 = Debug|Win32
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x64.ActiveCfg = Release|x64
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x64.Build.0 = Release|x64
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x86.ActiveCfg = Release|Win32
{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {02C511CF-3283-4A24-ABEE-DB5811E8294C}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1 @@
old

View File

@ -0,0 +1,136 @@
<?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>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{73fd34d1-9a70-4ec7-bb6c-61b4e6503125}</ProjectGuid>
<RootNamespace>Project1</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" />
<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>
</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>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</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>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="hello.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="hello.c">
<Filter>Файлы ресурсов</Filter>
</ClCompile>
</ItemGroup>
</Project>

221
Project1/Project1/hello.c Normal file
View File

@ -0,0 +1,221 @@
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
TCHAR szDrive[] = _T(" A:");
int main()
{
setlocale(LC_ALL, "ru_RU.UTF8");
SetConsoleOutputCP(65001);
SetConsoleCP(65001);
//getLogicalDrives();
//getDiskFreeSpaceExA();
//get_file_list();
//getfiletime();
//createDir();
//removeDir();
//compareFileTime();
//setVolumeLabel();
//moveFile();
//deleteFile();
return 0;
}
int getLogicalDrives() {
DWORD uDriveMask = GetLogicalDrives();
// printf("The bitmask of the logical drives in hex: %0X\n", uDriveMask);
// printf("The bitmask of the logical drives in decimal: %d\n", uDriveMask);
if (uDriveMask == 0)
printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError());
else
{
printf("This machine has the following logical drives:\n");
while (uDriveMask)
{
// Use the bitwise AND, 1â€"available, 0-not available
if (uDriveMask & 1)
printf("%S ", (const char*)szDrive);
// increment, check next drive
++szDrive[1];
// shift the bitmask binary right
uDriveMask >>= 1;
}
printf("\n ");
}
return 0;
}
int getDiskFreeSpaceExA() {
char n[10] = "";
printf("Enter disc name\n");
scanf(" %s", n);
LPCWSTR pszDrive = n;
BOOL test, fResult;
// 64 bits integer, low and high bytes
__int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
// If the function succeeds, the return value is nonzero. If the function fails, the return value is 0 (zero).
test = GetDiskFreeSpaceExA(
pszDrive,
(PULARGE_INTEGER)&lpFreeBytesAvailable,
(PULARGE_INTEGER)&lpTotalNumberOfBytes,
(PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
);
printf("\nUsing GetDiskFreeSpaceEx()...\n");
// Check the return value
printf("The return value: %d, error code: %d\n", test, GetLastError());
printf("Total number of free bytes available for user-caller: %ul\n", lpFreeBytesAvailable);
printf("Total number of bytes available for user: %ul\n", lpTotalNumberOfBytes);
printf("Total number of free bytes on disk: %ul\n", lpTotalNumberOfFreeBytes);
return 0;
}
int get_file_list()
{
char n[8] = "";
printf("Enter disc name\n");
scanf("%s:", n);
HANDLE hFind, hFile;
WIN32_FIND_DATA data;
FILETIME ftCreate;
SYSTEMTIME systime, sysLocal;
hFind = FindFirstFileA(n, &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
printf("%s\n ", data.cFileName);
//GetFileTime(&hFind, &ftCreate, NULL, NULL);
//FileTimeToSystemTime(&ftCreate, &systime);
//SystemTimeToTzSpecificLocalTime(NULL, &systime, &sysLocal);
//wprintf(L"CreationTime: %lu:%lu:%lu\n", sysLocal.wHour, sysLocal.wMinute, sysLocal.wSecond);
//printf("Created on: %02d/%02d/%d %02d:%02d\n", ssystimeystime.wDay, systime.wMonth, systime.wYear, systime.wHour, systime.wMinute);
} while (FindNextFileA(hFind, &data));
FindClose(hFind);
}
return 0;
}
int getfiletime()
{
HANDLE hFile1;
FILETIME ftCreate;
SYSTEMTIME stUTC, stLocal;
hFile1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile1 == INVALID_HANDLE_VALUE)
{
printf("Could not open file, error %ul\n", GetLastError());
return -1;
}
if (!GetFileTime(hFile1, &ftCreate, NULL, NULL))
{
printf("Something wrong!\n");
return FALSE;
}
FileTimeToSystemTime(&ftCreate, &stUTC);
printf("UTC System Time format:\n");
printf("text.txt Created on: %02d/%02d/%d %02d:%02d\n",stUTC.wDay, stUTC.wMonth, stUTC.wYear, stUTC.wHour, stUTC.wMinute);
return 0;
}
int createDir()
{
BOOL createD = CreateDirectory(L"NewFolder", NULL);
if (createD)
{
printf("Directory Created\n");
}
return 0;
}
int removeDir()
{
BOOL removeD = RemoveDirectory(L"NewFolder", NULL);
if (removeD)
{
printf("Directory Deleted\n");
}
return 0;
}
int compareFileTime() {
FILETIME fileTime1, fileTime2;
// первый файл
HANDLE file1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
// время изменения первого файла
GetFileTime(file1, NULL, NULL, &fileTime1);
// закрываем первый файл
CloseHandle(file1);
// Открываем второй файл
HANDLE file2 = CreateFile(TEXT("text2.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
// Получаем время изменения второго файла
GetFileTime(file2, NULL, NULL, &fileTime2);
// Закрываем второй файл
CloseHandle(file2);
// Сравниваем время изменения файлов
int comparisonResult = CompareFileTime(&fileTime1, &fileTime2);
if (comparisonResult == -1) {
wprintf(L"Файл 1 был изменен раньше файла 2\n");
}
else if (comparisonResult == 1) {
wprintf(L"Файл 2 был изменен раньше файла 1\n");
}
else {
wprintf(L"Время изменения файлов одинаково\n");
}
return 0;
}
int setVolumeLabel(){
LPSTR dirch = "S:\\";
LPSTR dirn = "Storage";
//LPSTR dirn = "Test";
BOOL bbb = SetVolumeLabelA(dirch, dirn);
//if(bbb){wprintf("%b",bbb);}
return 0;
}
int moveFile(){
if (MoveFile(L"Old.txt",L"New.txt")){
wprintf(L"Файл перемещён\n");
}
else {
wprintf(L"Ошибка\n");
}
return 0;
}
int deleteFile() {
if (DeleteFile(L"New.txt")) {
wprintf(L"Файл удалён\n");
}
else {
wprintf(L"Ошибка\n");
}
return 0;
}
/*
GetLogicalDrivesFindFistFile +
GetDiskFreeSpaceExA+
FindFirstFile +
FindNextFile +
GetFileTime+
CompareFileTime+
SetVolumeLabel+
CreatDirectory+
RemoveDirectory+
MoveFile +
DeleteFile +
*/

View File

View File