#ifndef ENV_ENV_H
#define ENV_ENV_H
class Settings;
namespace env
{
class Module;
class Process;
class SecurityProduct;
class WindowsInfo;
class Metrics;
struct DesktopDCReleaser
{
using pointer = HDC;
void operator()(HDC dc)
{
if (dc != 0) {
::ReleaseDC(0, dc);
}
}
};
using DesktopDCPtr = std::unique_ptr<HDC, DesktopDCReleaser>;
struct HMenuFreer
{
using pointer = HMENU;
void operator()(HMENU h)
{
if (h != 0) {
::DestroyMenu(h);
}
}
};
using HMenuPtr = std::unique_ptr<HMENU, HMenuFreer>;
struct LibraryFreer
{
using pointer = HINSTANCE;
void operator()(HINSTANCE h)
{
if (h != 0) {
::FreeLibrary(h);
}
}
};
using LibraryPtr = std::unique_ptr<HINSTANCE, LibraryFreer>;
struct COMReleaser
{
void operator()(IUnknown* p)
{
if (p) {
p->Release();
}
}
};
template <class T>
using COMPtr = std::unique_ptr<T, COMReleaser>;
struct MallocFreer
{
void operator()(void* p) { std::free(p); }
};
template <class T>
using MallocPtr = std::unique_ptr<T, MallocFreer>;
template <class T>
struct LocalFreer
{
using pointer = T;
void operator()(T p) { ::LocalFree(p); }
};
template <class T>
using LocalPtr = std::unique_ptr<T, LocalFreer<T>>;
template <class T>
struct CoTaskMemFreer
{
using pointer = T;
void operator()(T p) { ::CoTaskMemFree(p); }
};
template <class T>
using CoTaskMemPtr = std::unique_ptr<T, CoTaskMemFreer<T>>;
class Console
{
public:
Console();
~Console();
private:
bool m_hasConsole;
FILE* m_in;
FILE* m_out;
FILE* m_err;
};
class ModuleNotification
{
public:
ModuleNotification(QObject* o, std::function<void(Module)> f);
~ModuleNotification();
ModuleNotification(const ModuleNotification&) = delete;
ModuleNotification& operator=(const ModuleNotification&) = delete;
ModuleNotification(ModuleNotification&&) = default;
ModuleNotification& operator=(ModuleNotification&&) = default;
void setCookie(void* c);
void fire(QString path, std::size_t fileSize);
private:
void* m_cookie;
QObject* m_object;
std::set<QString> m_loaded;
std::function<void(Module)> m_f;
};
class Environment
{
public:
Environment();
~Environment();
const std::vector<Module>& loadedModules() const;
std::vector<Process> runningProcesses() const;
const WindowsInfo& windowsInfo() const;
const std::vector<SecurityProduct>& securityProducts() const;
const Metrics& metrics() const;
QString timezone() const;
std::unique_ptr<ModuleNotification> onModuleLoaded(QObject* o,
std::function<void(Module)> f);
void dump(const Settings& s) const;
private:
mutable std::vector<Module> m_modules;
mutable std::unique_ptr<WindowsInfo> m_windows;
mutable std::vector<SecurityProduct> m_security;
mutable std::unique_ptr<Metrics> m_metrics;
void dumpDisks(const Settings& s) const;
};
QString get(const QString& name);
void set(const QString& name, const QString& value);
QString path();
QString appendToPath(const QString& s);
QString prependToPath(const QString& s);
void setPath(const QString& s);
class Service
{
public:
enum class StartType
{
None = 0,
Disabled,
Enabled
};
enum class Status
{
None = 0,
Stopped,
Running
};
explicit Service(QString name);
Service(QString name, StartType st, Status s);
bool isValid() const;
const QString& name() const;
StartType startType() const;
Status status() const;
QString toString() const;
private:
QString m_name;
StartType m_startType;
Status m_status;
};
Service getService(const QString& name);
QString toString(Service::StartType st);
QString toString(Service::Status st);
struct Association
{
QFileInfo executable;
QString commandLine;
QString formattedCommandLine;
};
Association getAssociation(const QFileInfo& file);
bool registryValueExists(const QString& key, const QString& value);
void deleteRegistryKeyIfEmpty(const QString& name);
std::filesystem::path thisProcessPath();
}
#endif