Skip to content
Permalink
Browse files

Minor Refactoring

- enum class partial
- .clang-format windows-friendly
- really minor things

Change-Id: Ie5068f720e882e763a768b6a4b16340fa5cacb6f
  • Loading branch information...
s-kipnis committed Apr 16, 2019
1 parent 244ec35 commit c50e686a4547fb1b549feb7d2ccbd8db0a5a4068
@@ -4,6 +4,10 @@ BasedOnStyle: Google
AccessModifierOffset: -4
BreakConstructorInitializersBeforeComma: true
IncludeCategories:
- Regex: '^"stdafx.h"'
Priority: -1
- Regex: '^"pch.h"'
Priority: -1
- Regex: '^"config.h"'
Priority: 1
- Regex: '^<winsock2.h>'
@@ -18,11 +18,11 @@ namespace XLOG {

// windows specific Event Log
enum class EventLevel : int {
kLogCritical = 1,
kLogError = 2,
kLogWarning = 3,
kLogInformation = 4,
kLogSuccess = 99
critical = 1,
error = 2,
warning = 3,
information = 4,
success = 99
};

// recommended but not obligatory to use
@@ -1,26 +1,23 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <WinSock2.h>

#include <iostream>

#include <stdio.h>
#include <windows.h>

#include <cstdint>
#include <iostream>
#include <string>

#include "tools/_raii.h"
#include "tools/_xlog.h"

#include "cap.h"
#include "cfg.h"
#include "logger.h"
#include "wtools.h"

#include "tools/_raii.h"
#include "tools/_xlog.h"
#include "upgrade.h"
#include "wtools.h"

#pragma comment(lib, "wbemuuid.lib") /// Microsoft Specific

@@ -1,19 +1,19 @@
// Windows Tools
#include <stdafx.h>

#include "stdafx.h"

#include "cap.h"

#include <cstdint>
#include <filesystem>
#include <string>
#include <unordered_set>

#include "tools/_raii.h"
#include "tools/_xlog.h"

#include "logger.h"

#include "cap.h"
#include "cfg.h"
#include "cvt.h"
#include "logger.h"
#include "tools/_raii.h"
#include "tools/_xlog.h"
#include "upgrade.h"

namespace cma::cfg::cap {
@@ -211,19 +211,19 @@ bool Process(const std::string CapFileName, ProcMode Mode,
}
const auto full_path = ProcessPluginPath(name);

if (Mode == ProcMode::kInstall) {
if (Mode == ProcMode::install) {
StoreFile(full_path, data);
std::error_code ec;
if (fs::exists(full_path, ec)) FilesLeftOnDisk.push_back(full_path);
} else if ((Mode == ProcMode::kRemove)) {
} else if ((Mode == ProcMode::remove)) {
std::error_code ec;
if (fs::remove(full_path, ec))
FilesLeftOnDisk.push_back(full_path);
else {
XLOG::l("Cannot remove '{}' error {}",
wtools::ConvertToUTF8(full_path), ec.value());
}
} else if ((Mode == ProcMode::kList)) {
} else if ((Mode == ProcMode::list)) {
FilesLeftOnDisk.push_back(full_path);
}
}
@@ -267,7 +267,7 @@ bool ReinstallCaps(const std::filesystem::path TargetCap,
std::vector<std::wstring> files_left;
if (fs::exists(TargetCap, ec)) {
if (true ==
Process(TargetCap.u8string(), ProcMode::kRemove, files_left)) {
Process(TargetCap.u8string(), ProcMode::remove, files_left)) {
XLOG::l.t("File '{}' uninstall-ed", TargetCap.u8string());
fs::remove(TargetCap, ec);
for (auto &name : files_left)
@@ -281,7 +281,7 @@ bool ReinstallCaps(const std::filesystem::path TargetCap,
files_left.clear();
if (fs::exists(SourceCap, ec)) {
if (true ==
Process(SourceCap.u8string(), ProcMode::kInstall, files_left)) {
Process(SourceCap.u8string(), ProcMode::install, files_left)) {
XLOG::l.t("File {} installed", SourceCap.u8string());
fs::copy_file(SourceCap, TargetCap, ec);
for (auto &name : files_left)
@@ -30,7 +30,7 @@ bool ReinstallIni(const std::filesystem::path TargetIni,
const std::filesystem::path SrcIni);

// data structures to use
enum class ProcMode { kInstall, kRemove, kList };
enum class ProcMode { install, remove, list };

// valid eof is {empty, empty, true}
// valid NOT eod if {name, data, false}
@@ -594,9 +594,7 @@ const int GetCurrentDebugLevel() {
return kDefaultLogLevel;
}

XLOG::EventLevel GetCurrentEventLevel() {
return XLOG::EventLevel::kLogCritical;
}
XLOG::EventLevel GetCurrentEventLevel() { return XLOG::EventLevel::critical; }

const bool GetCurrentWinDbg() {
if (ConfigLoaded()) return groups::global.windbgLog();
@@ -1,17 +1,18 @@
// cma_core.cpp :
//
#include <time.h>
#include "stdafx.h"

#include "cma_core.h"

#include <time.h>

#include <chrono>
#include <filesystem>
#include <string>
#include <unordered_set>
#include <vector>

#include "glob_match.h"

#include "cma_core.h"
#include "section_header.h" // we have logging here

namespace cma {
@@ -1,5 +1,5 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#include <cstdint>
#include <filesystem>
@@ -1,15 +1,14 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#include "encryption.h"

#include <string>
#include <string_view>

#include "tools/_raii.h"

#include "cfg.h"
#include "logger.h"

#include "encryption.h"
#include "tools/_raii.h"

namespace cma::encrypt {
Commander::Commander() : algorithm_(Algorithm::kDefault) {
@@ -15,12 +15,12 @@ namespace cma::evl {
class EventLogRecordBase {
public:
enum class Level {
Error,
Warning,
Information,
AuditFailure,
AuditSuccess,
Success
error,
warning,
information,
audit_failure,
audit_success,
success
};

EventLogRecordBase() = default;
@@ -63,18 +63,18 @@ class EventLogRecordBase {
// for output in port
char getEventSymbol(cma::cfg::EventLevels Required) const {
switch (eventLevel()) {
case Level::Error:
case Level::error:
return 'C';
case Level::Warning:
case Level::warning:
return 'W';
case Level::Information:
case Level::AuditSuccess:
case Level::Success:
if (Required == cma::cfg::EventLevels::kAll)
case Level::information:
case Level::audit_success:
case Level::success:
if (Required == cma::cfg::kAll)
return 'O';
else
return '.'; // potential drop of context
case Level::AuditFailure:
case Level::audit_failure:
return 'C';
default:
return 'u';
@@ -84,15 +84,15 @@ class EventLogRecordBase {
// decode windows level to universal
cma::cfg::EventLevels calcEventLevel(cma::cfg::EventLevels Required) const {
switch (eventLevel()) {
case Level::Error:
case Level::error:
return cma::cfg::EventLevels::kCrit;
case Level::Warning:
case Level::warning:
return cma::cfg::EventLevels::kWarn;
case Level::Information:
case Level::AuditSuccess:
case Level::Success:
case Level::information:
case Level::audit_success:
case Level::success:
return cma::cfg::EventLevels::kAll;
case Level::AuditFailure:
case Level::audit_failure:
return cma::cfg::EventLevels::kCrit;
default:
return cma::cfg::EventLevels::kWarn;
@@ -154,19 +154,19 @@ class EventLogRecord : public EventLogRecordBase {
virtual Level eventLevel() const override {
switch (_record->EventType) {
case EVENTLOG_ERROR_TYPE:
return Level::Error;
return Level::error;
case EVENTLOG_WARNING_TYPE:
return Level::Warning;
return Level::warning;
case EVENTLOG_INFORMATION_TYPE:
return Level::Information;
return Level::information;
case EVENTLOG_AUDIT_SUCCESS:
return Level::AuditSuccess;
return Level::audit_success;
case EVENTLOG_SUCCESS:
return Level::Success;
return Level::success;
case EVENTLOG_AUDIT_FAILURE:
return Level::AuditFailure;
return Level::audit_failure;
default:
return Level::Error;
return Level::error;
}
}

@@ -128,17 +128,17 @@ class EventLogRecordVista : public EventLogRecordBase {
switch (b) {
case WinEventLevel::Error:
case WinEventLevel::Critical:
return Level::Error;
return Level::error;
case WinEventLevel::Warning:
return Level::Warning;
return Level::warning;
case WinEventLevel::Information:
return Level::Information;
return Level::information;
case WinEventLevel::Audit:
return Level::AuditSuccess;
return Level::audit_success;
case WinEventLevel::Verbose:
return Level::Success;
return Level::success;
default:
return Level::Error;
return Level::error;
}
}

Oops, something went wrong.

0 comments on commit c50e686

Please sign in to comment.
You can’t perform that action at this time.