Skip to content

Commit

Permalink
Merge pull request #1 from Anton-V-K/develop
Browse files Browse the repository at this point in the history
Logon Hours Manager
  • Loading branch information
Anton-V-K authored May 9, 2023
2 parents 0df4a00 + e8ce988 commit 59b4e89
Show file tree
Hide file tree
Showing 39 changed files with 1,859 additions and 219 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs

# All files
[*]
indent_size = 4
indent_style = space
tab_width = 4

[*.{xml,xsd,xsl}]
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v1.1

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
/packages
/_crashes
/_releases

*.aps
*.vcxproj.user
17 changes: 15 additions & 2 deletions ClassicParentalControl.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.779
# Visual Studio Version 16
VisualStudioVersion = 16.0.33130.400
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LogonHoursService", "LogonHoursService\LogonHoursService.vcxproj", "{D6E78055-7BC4-4301-BDFC-C4DDA35E959C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LogonHoursManager", "LogonHoursManager\LogonHoursManager.vcxproj", "{1FB09AD5-5BEA-427A-9862-6884A60AA97A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcxitems", "{2665D681-30A9-4760-9648-25AB585A19B3}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Common\Common.vcxitems*{1fb09ad5-5bea-427a-9862-6884a60aa97a}*SharedItemsImports = 4
Common\Common.vcxitems*{2665d681-30a9-4760-9648-25ab585a19b3}*SharedItemsImports = 9
Common\Common.vcxitems*{d6e78055-7bc4-4301-bdfc-c4dda35e959c}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
Expand All @@ -15,6 +24,10 @@ Global
{D6E78055-7BC4-4301-BDFC-C4DDA35E959C}.Debug|x86.Build.0 = Debug|Win32
{D6E78055-7BC4-4301-BDFC-C4DDA35E959C}.Release|x86.ActiveCfg = Release|Win32
{D6E78055-7BC4-4301-BDFC-C4DDA35E959C}.Release|x86.Build.0 = Release|Win32
{1FB09AD5-5BEA-427A-9862-6884A60AA97A}.Debug|x86.ActiveCfg = Debug|Win32
{1FB09AD5-5BEA-427A-9862-6884A60AA97A}.Debug|x86.Build.0 = Debug|Win32
{1FB09AD5-5BEA-427A-9862-6884A60AA97A}.Release|x86.ActiveCfg = Release|Win32
{1FB09AD5-5BEA-427A-9862-6884A60AA97A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 27 additions & 0 deletions Common/Common.vcxitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{2665d681-30a9-4760-9648-25ab585a19b3}</ItemsProjectGuid>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)Logger.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)LogonHours.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)Logger.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)LogonHours.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)REPEAT.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)version.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)WeekHours.h" />
</ItemGroup>
</Project>
105 changes: 105 additions & 0 deletions Common/Logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "stdafx.h"
#include "Logger.h"

#include <log4cpp/DailyRollingFileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/PropertyConfigurator.hh>
#include <log4cpp/Win32DebugAppender.hh>

#include "version.h"

#pragma comment(lib, "ws2_32.lib") // Needed for log4cpp if PropertyConfigurator is used

void LogMain(const char* appname)
{
log4cpp::Category& root = log4cpp::Category::getRoot();

////////////////////////////////////////
// Configure log4cpp
////////////////////////////////////////
char config_path[_MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, config_path, _countof(config_path));
strcat_s(config_path, ".log4cpp");
try
{
log4cpp::PropertyConfigurator::configure(config_path);
}
catch (const log4cpp::ConfigureFailure& /*ex*/)
{
config_path[0] = 0;

// Default configuration for log4cpp
#ifdef _DEBUG
root.setPriority(log4cpp::Priority::DEBUG);
#else
root.setPriority(log4cpp::Priority::INFO);
#endif

}

const log4cpp::AppenderSet& set = root.getAllAppenders();
if (set.empty()) // if no appenders are specified in the config file ...
{
char log_path_format[MAX_PATH];
ExpandEnvironmentStringsA("%TEMP%\\%s.log", log_path_format, _countof(log_path_format));

char log_path[MAX_PATH];
if (appname)
sprintf_s(log_path, log_path_format, appname);
else
{
char module_path[_MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, module_path, _countof(module_path));

char filename[MAX_PATH] = { 0 };
_splitpath_s(module_path, NULL, 0, NULL, 0, filename, _countof(filename), NULL, 0);
sprintf_s(log_path, log_path_format, filename);
}

#if 1
if (log4cpp::Appender* const appender = new log4cpp::DailyRollingFileAppender("logfile", log_path, 14))
#else
if (log4cpp::Appender* const appender = new log4cpp::RollingFileAppender("logfile", log_path, 10*1024*1024, 10))
//#else
if (log4cpp::Appender* const appender = new log4cpp::FileAppender("logfile", log_path))
#endif
{
log4cpp::PatternLayout* const layout = new log4cpp::PatternLayout();
// Refer to http://www.cplusplus.com/reference/ctime/strftime/ for format specification
layout->setConversionPattern("%d{%Y.%m.%d %H:%M:%S,%l} [%p] [%t] %c: %m%n");
appender->setLayout(layout);
root.addAppender(appender);
}
if (log4cpp::Appender* const appender = new log4cpp::Win32DebugAppender("debugger"))
{
log4cpp::PatternLayout* const layout = new log4cpp::PatternLayout();
// Refer to http://www.cplusplus.com/reference/ctime/strftime/ for format specification
layout->setConversionPattern("%d{%H:%M:%S,%l} [%p] [%t] %c: %m%n");
appender->setLayout(layout);
root.addAppender(appender);
}
}

LOG_INFO(__func__) << "========================================";
LOG_INFO(__func__) << "Log initialized successfully";
if (*config_path)
LOG_INFO(__func__) << "Loaded " << config_path;

#ifndef _CONSOLE
LOG_INFO(__func__) << "Length of command line: " << _tcslen(GetCommandLine());
#endif

LOG_INFO(__func__) << "Version: " << VERSION_STRING;
LOG_INFO(__func__) << "Build : " << __DATE__ << ' ' << __TIME__;
#if defined(_MSC_FULL_VER)
LOG_INFO(__func__) << "_MSC_FULL_VER: "
<< _MSC_FULL_VER / 10000000 << '.'
<< (_MSC_FULL_VER % 10000000) / 100000 << '.'
<< _MSC_FULL_VER % 100000;
#elif defined(_MSC_VER)
LOG_INFO(__func__) << "_MSC_VER: "
<< _MSC_VER / 100 << '.'
<< _MSC_VER % 100;
#endif

}
2 changes: 2 additions & 0 deletions LogonHoursService/Logger.h → Common/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ inline log4cpp::Category& Logger(const void* p = NULL)
{
return log4cpp::Category::getRoot();
}

void LogMain(const char* appname = nullptr);
Loading

0 comments on commit 59b4e89

Please sign in to comment.