mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Work on exporting stuff, revert some changes for better diff
This commit is contained in:
parent
473f23378f
commit
69913fa251
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,262 +1,262 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2011 Birunthan Mohanathas, Peter Souza
|
Copyright (C) 2011 Birunthan Mohanathas, Peter Souza
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "Export.h"
|
#include "Export.h"
|
||||||
#include "MeterWindow.h"
|
#include "MeterWindow.h"
|
||||||
#include "Measure.h"
|
#include "Measure.h"
|
||||||
#include "MeasurePlugin.h"
|
#include "MeasurePlugin.h"
|
||||||
|
|
||||||
#define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } }
|
#define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } }
|
||||||
|
|
||||||
static std::wstring g_Buffer;
|
static std::wstring g_Buffer;
|
||||||
|
|
||||||
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
|
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
|
||||||
{
|
{
|
||||||
NULLCHECK(option);
|
NULLCHECK(option);
|
||||||
NULLCHECK(defValue);
|
NULLCHECK(defValue);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||||
return parser.ReadString(measure->GetName(), option, defValue, replaceMeasures != FALSE).c_str();
|
return parser.ReadString(measure->GetName(), option, defValue, replaceMeasures != FALSE).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
|
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
|
||||||
{
|
{
|
||||||
NULLCHECK(option);
|
NULLCHECK(option);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||||
return parser.ReadFloat(measure->GetName(), option, defValue);
|
return parser.ReadFloat(measure->GetName(), option, defValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
LPCWSTR __stdcall RmReplaceVariables(void* rm, LPCWSTR str)
|
LPCWSTR __stdcall RmReplaceVariables(void* rm, LPCWSTR str)
|
||||||
{
|
{
|
||||||
NULLCHECK(str);
|
NULLCHECK(str);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||||
g_Buffer = str;
|
g_Buffer = str;
|
||||||
parser.ReplaceVariables(g_Buffer);
|
parser.ReplaceVariables(g_Buffer);
|
||||||
parser.ReplaceMeasures(g_Buffer);
|
parser.ReplaceMeasures(g_Buffer);
|
||||||
return g_Buffer.c_str();
|
return g_Buffer.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
|
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
|
||||||
{
|
{
|
||||||
NULLCHECK(relativePath);
|
NULLCHECK(relativePath);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
g_Buffer = relativePath;
|
g_Buffer = relativePath;
|
||||||
measure->GetMeterWindow()->MakePathAbsolute(g_Buffer);
|
measure->GetMeterWindow()->MakePathAbsolute(g_Buffer);
|
||||||
return g_Buffer.c_str();
|
return g_Buffer.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* __stdcall RmGet(void* rm, int type)
|
void* __stdcall RmGet(void* rm, int type)
|
||||||
{
|
{
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case RMG_MEASURENAME:
|
case RMG_MEASURENAME:
|
||||||
{
|
{
|
||||||
return (void*)measure->GetName();
|
return (void*)measure->GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RMG_SKIN:
|
case RMG_SKIN:
|
||||||
{
|
{
|
||||||
return (void*)measure->GetMeterWindow();
|
return (void*)measure->GetMeterWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RMG_SETTINGSFILE:
|
case RMG_SETTINGSFILE:
|
||||||
{
|
{
|
||||||
return (void*)Rainmeter::GetInstance().GetDataFile().c_str();
|
return (void*)GetRainmeter().GetDataFile().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RMG_SKINNAME:
|
case RMG_SKINNAME:
|
||||||
{
|
{
|
||||||
MeterWindow* window = measure->GetMeterWindow();
|
MeterWindow* window = measure->GetMeterWindow();
|
||||||
if (!window) break;
|
if (!window) break;
|
||||||
return (void*)window->GetFolderPath().c_str();
|
return (void*)window->GetFolderPath().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RMG_SKINWINDOWHANDLE:
|
case RMG_SKINWINDOWHANDLE:
|
||||||
{
|
{
|
||||||
MeterWindow* window = measure->GetMeterWindow();
|
MeterWindow* window = measure->GetMeterWindow();
|
||||||
if (!window) break;
|
if (!window) break;
|
||||||
return (void*)window->GetWindow();
|
return (void*)window->GetWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __stdcall RmExecute(void* skin, LPCWSTR command)
|
void __stdcall RmExecute(void* skin, LPCWSTR command)
|
||||||
{
|
{
|
||||||
MeterWindow* mw = (MeterWindow*)skin;
|
MeterWindow* mw = (MeterWindow*)skin;
|
||||||
if (command)
|
if (command)
|
||||||
{
|
{
|
||||||
// WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety
|
// WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety
|
||||||
SendMessage(Rainmeter::GetInstance().GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)mw, (LPARAM)command);
|
SendMessage(GetRainmeter().GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)mw, (LPARAM)command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message)
|
BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message)
|
||||||
{
|
{
|
||||||
NULLCHECK(message);
|
NULLCHECK(message);
|
||||||
|
|
||||||
// Ignore Debug messages from plugins unless in debug mode.
|
// Ignore Debug messages from plugins unless in debug mode.
|
||||||
if (level != (int)Logger::Level::Debug || Rainmeter::GetInstance().GetDebug())
|
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
|
||||||
{
|
{
|
||||||
GetLogger().Log((Logger::Level)level, L"", message);
|
GetLogger().Log((Logger::Level)level, L"", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __stdcall RmLog(void* rm, int level, LPCWSTR message)
|
void __stdcall RmLog(void* rm, int level, LPCWSTR message)
|
||||||
{
|
{
|
||||||
NULLCHECK(message);
|
NULLCHECK(message);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
|
|
||||||
// Ignore Debug messages from plugins unless in debug mode.
|
// Ignore Debug messages from plugins unless in debug mode.
|
||||||
if (level != (int)Logger::Level::Debug || Rainmeter::GetInstance().GetDebug())
|
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
|
||||||
{
|
{
|
||||||
GetLogger().LogSection((Logger::Level)level, measure, message);
|
GetLogger().LogSection((Logger::Level)level, measure, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RmLogF(void* rm, int level, LPCWSTR format, ...)
|
void RmLogF(void* rm, int level, LPCWSTR format, ...)
|
||||||
{
|
{
|
||||||
NULLCHECK(format);
|
NULLCHECK(format);
|
||||||
|
|
||||||
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
||||||
|
|
||||||
// Ignore Debug messages from plugins unless in debug mode.
|
// Ignore Debug messages from plugins unless in debug mode.
|
||||||
if (level != (int)Logger::Level::Debug || Rainmeter::GetInstance().GetDebug())
|
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
GetLogger().LogSectionVF((Logger::Level)level, measure, format, args);
|
GetLogger().LogSectionVF((Logger::Level)level, measure, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated!
|
// Deprecated!
|
||||||
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
|
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
|
||||||
{
|
{
|
||||||
NULLCHECK(section);
|
NULLCHECK(section);
|
||||||
NULLCHECK(option);
|
NULLCHECK(option);
|
||||||
NULLCHECK(defValue);
|
NULLCHECK(defValue);
|
||||||
|
|
||||||
ConfigParser* parser = Rainmeter::GetInstance().GetCurrentParser();
|
ConfigParser* parser = GetRainmeter().GetCurrentParser();
|
||||||
if (parser)
|
if (parser)
|
||||||
{
|
{
|
||||||
return parser->ReadString(section, option, defValue, false).c_str();
|
return parser->ReadString(section, option, defValue, false).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated!
|
// Deprecated!
|
||||||
LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
|
LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
|
||||||
{
|
{
|
||||||
if (command == nullptr || *command == L'\0')
|
if (command == nullptr || *command == L'\0')
|
||||||
{
|
{
|
||||||
return L"noop";
|
return L"noop";
|
||||||
}
|
}
|
||||||
|
|
||||||
NULLCHECK(data);
|
NULLCHECK(data);
|
||||||
|
|
||||||
if (_wcsicmp(command, L"GetConfig") == 0)
|
if (_wcsicmp(command, L"GetConfig") == 0)
|
||||||
{
|
{
|
||||||
MeterWindow* meterWindow = Rainmeter::GetInstance().GetMeterWindowByINI(data);
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindowByINI(data);
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
g_Buffer = L"\"";
|
g_Buffer = L"\"";
|
||||||
g_Buffer += meterWindow->GetFolderPath();
|
g_Buffer += meterWindow->GetFolderPath();
|
||||||
g_Buffer += L"\"";
|
g_Buffer += L"\"";
|
||||||
return g_Buffer.c_str();
|
return g_Buffer.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
else if (_wcsicmp(command, L"GetWindow") == 0)
|
else if (_wcsicmp(command, L"GetWindow") == 0)
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
||||||
|
|
||||||
if (subStrings.size() >= 1)
|
if (subStrings.size() >= 1)
|
||||||
{
|
{
|
||||||
const std::wstring& config = subStrings[0];
|
const std::wstring& config = subStrings[0];
|
||||||
|
|
||||||
MeterWindow* meterWindow = Rainmeter::GetInstance().GetMeterWindow(config);
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
WCHAR buf1[64];
|
WCHAR buf1[64];
|
||||||
_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow()));
|
_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow()));
|
||||||
g_Buffer = buf1;
|
g_Buffer = buf1;
|
||||||
return g_Buffer.c_str();
|
return g_Buffer.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return L"error";
|
return L"error";
|
||||||
}
|
}
|
||||||
else if (_wcsicmp(command, L"GetVariable") == 0)
|
else if (_wcsicmp(command, L"GetVariable") == 0)
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
||||||
|
|
||||||
if (subStrings.size() >= 2)
|
if (subStrings.size() >= 2)
|
||||||
{
|
{
|
||||||
const std::wstring& config = subStrings[0];
|
const std::wstring& config = subStrings[0];
|
||||||
|
|
||||||
MeterWindow* meterWindow = Rainmeter::GetInstance().GetMeterWindow(config);
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
const std::wstring& variable = subStrings[1];
|
const std::wstring& variable = subStrings[1];
|
||||||
|
|
||||||
const std::wstring* value = meterWindow->GetParser().GetVariable(variable);
|
const std::wstring* value = meterWindow->GetParser().GetVariable(variable);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
return (*value).c_str();
|
return (*value).c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
else if (_wcsicmp(command, L"SetVariable") == 0)
|
else if (_wcsicmp(command, L"SetVariable") == 0)
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
||||||
|
|
||||||
if (subStrings.size() == 3)
|
if (subStrings.size() == 3)
|
||||||
{
|
{
|
||||||
MeterWindow* meterWindow = Rainmeter::GetInstance().GetMeterWindow(subStrings[0]);
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(subStrings[0]);
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
meterWindow->SetVariable(subStrings[1], subStrings[2]);
|
meterWindow->SetVariable(subStrings[1], subStrings[2]);
|
||||||
return L"success";
|
return L"success";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return L"error";
|
return L"error";
|
||||||
}
|
}
|
||||||
|
|
||||||
return L"noop";
|
return L"noop";
|
||||||
}
|
}
|
||||||
|
3
Library/Exports_Common.h
Normal file
3
Library/Exports_Common.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define EXPORT extern "C" _declspec(dllexport)
|
32
Library/Exports_Group.cpp
Normal file
32
Library/Exports_Group.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "StdAfx.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include "Group.h"
|
||||||
|
#include "HandleManager.h"
|
||||||
|
#include "Exports_Common.h"
|
||||||
|
|
||||||
|
EXPORT bool Group_BelongsToGroup (bool* result, int32_t handle, LPWSTR str)
|
||||||
|
{
|
||||||
|
Group* group = (Group*)handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (group != nullptr)
|
||||||
|
{
|
||||||
|
*result = group->BelongsToGroup (str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Group_Destroy (int32_t handle)
|
||||||
|
{
|
||||||
|
Group* group = (Group*)handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (group != nullptr)
|
||||||
|
{
|
||||||
|
handle_free (handle);
|
||||||
|
delete group;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
21
Library/Exports_Meter.cpp
Normal file
21
Library/Exports_Meter.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "StdAfx.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include "Meter.h"
|
||||||
|
#include "HandleManager.h"
|
||||||
|
#include "Exports_Common.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EXPORT bool Meter_Destroy (int handle)
|
||||||
|
{
|
||||||
|
Meter* meter = (Meter*)handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (meter != nullptr)
|
||||||
|
{
|
||||||
|
handle_free (handle);
|
||||||
|
delete meter;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
35
Library/Exports_MeterString.cpp
Normal file
35
Library/Exports_MeterString.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "StdAfx.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include "MeterString.h"
|
||||||
|
#include "HandleManager.h"
|
||||||
|
#include "Exports_Common.h"
|
||||||
|
|
||||||
|
EXPORT bool MeterString_Init (int* handle_result, int meterCanvasHandle, LPCWSTR name)
|
||||||
|
{
|
||||||
|
MeterWindow* w = (MeterWindow*) handle_get_resource (meterCanvasHandle);
|
||||||
|
|
||||||
|
if (w != nullptr)
|
||||||
|
{
|
||||||
|
MeterString* result = new MeterString (w, name);
|
||||||
|
*handle_result = handle_allocate (result);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool MeterString_Destroy (int handle)
|
||||||
|
{
|
||||||
|
MeterString* ms = (MeterString*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (ms != nullptr)
|
||||||
|
{
|
||||||
|
handle_free (handle);
|
||||||
|
delete ms;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
27
Library/Exports_Rainmeter.cpp
Normal file
27
Library/Exports_Rainmeter.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "Rainmeter.h"
|
||||||
|
#include "HandleManager.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Initializes Rainmeter.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
bool Rainmeter_Initialize()
|
||||||
|
{
|
||||||
|
int res = GetRainmeter().Initialize(nullptr, nullptr);
|
||||||
|
|
||||||
|
// Success?
|
||||||
|
if (res == 0)
|
||||||
|
return &GetRainmeter();
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Finalizes Rainmeter.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
void Rainmeter_Finalize(void* ptr)
|
||||||
|
{
|
||||||
|
Rainmeter* rainmeter = (Rainmeter*)ptr;
|
||||||
|
rainmeter->Finalize();
|
||||||
|
}
|
131
Library/Exports_Section.cpp
Normal file
131
Library/Exports_Section.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include "HandleManager.h"
|
||||||
|
#include "Exports_Common.h"
|
||||||
|
#include "Section.h"
|
||||||
|
|
||||||
|
EXPORT bool Section_GetName (LPCWCHAR* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->GetName();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_GetOriginalName (LPCWCHAR* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->GetOriginalName().c_str();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_HasDynamicVariables (bool* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->HasDynamicVariables();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_SetDynamicVariables (int32_t handle, bool value)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
section->SetDynamicVariables(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_ResetUpdateCounter (int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
section->ResetUpdateCounter();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_GetUpdateCounter (int* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->GetUpdateCounter();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EXPORT bool Section_GetUpdateDivider (int* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->GetUpdateDivider();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_GetOnUpdateAction (LPCWCHAR* result, int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
*result = section->GetOnUpdateAction().c_str();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_DoUpdateAction (int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
section->DoUpdateAction ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT bool Section_Destroy (int32_t handle)
|
||||||
|
{
|
||||||
|
Section* section = (Section*) handle_get_resource (handle);
|
||||||
|
if (section != nullptr)
|
||||||
|
{
|
||||||
|
handle_free (handle);
|
||||||
|
delete section;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
28
Library/HandleManager.cpp
Normal file
28
Library/HandleManager.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <cstdint>
|
||||||
|
#include "HandleManager.h"
|
||||||
|
|
||||||
|
std::map<int32_t, void*> handles;
|
||||||
|
|
||||||
|
int32_t handle_allocate (void* resource)
|
||||||
|
{
|
||||||
|
static int32_t handle = 1;
|
||||||
|
|
||||||
|
handles.insert (std::make_pair(handle, resource));
|
||||||
|
return handle++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* handle_get_resource (int32_t handle)
|
||||||
|
{
|
||||||
|
if (handles.count (handle) != 0)
|
||||||
|
return handles.at (handle);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_free (int32_t handle)
|
||||||
|
{
|
||||||
|
handles.erase (handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
7
Library/HandleManager.h
Normal file
7
Library/HandleManager.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
int32_t handle_allocate (void* resource);
|
||||||
|
void* handle_get_resource (int32_t handle);
|
||||||
|
void handle_free (int32_t handle);
|
@ -1,367 +1,367 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2013 Brian Ferguson
|
Copyright (C) 2013 Brian Ferguson
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Measure.h"
|
#include "Measure.h"
|
||||||
#include "IfActions.h"
|
#include "IfActions.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "../Common/MathParser.h"
|
#include "../Common/MathParser.h"
|
||||||
#include "pcre-8.10/config.h"
|
#include "pcre-8.10/config.h"
|
||||||
#include "pcre-8.10/pcre.h"
|
#include "pcre-8.10/pcre.h"
|
||||||
|
|
||||||
IfActions::IfActions() :
|
IfActions::IfActions() :
|
||||||
m_AboveValue(0.0f),
|
m_AboveValue(0.0f),
|
||||||
m_BelowValue(0.0f),
|
m_BelowValue(0.0f),
|
||||||
m_EqualValue(0),
|
m_EqualValue(0),
|
||||||
m_AboveAction(),
|
m_AboveAction(),
|
||||||
m_BelowAction(),
|
m_BelowAction(),
|
||||||
m_EqualAction(),
|
m_EqualAction(),
|
||||||
m_AboveCommitted(false),
|
m_AboveCommitted(false),
|
||||||
m_BelowCommitted(false),
|
m_BelowCommitted(false),
|
||||||
m_EqualCommitted(false),
|
m_EqualCommitted(false),
|
||||||
m_Conditions(),
|
m_Conditions(),
|
||||||
m_ConditionMode(false),
|
m_ConditionMode(false),
|
||||||
m_Matches(),
|
m_Matches(),
|
||||||
m_MatchMode(false)
|
m_MatchMode(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IfActions::~IfActions()
|
IfActions::~IfActions()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfActions::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
void IfActions::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
m_AboveAction = parser.ReadString(section, L"IfAboveAction", L"", false);
|
m_AboveAction = parser.ReadString(section, L"IfAboveAction", L"", false);
|
||||||
m_AboveValue = parser.ReadFloat(section, L"IfAboveValue", 0.0f);
|
m_AboveValue = parser.ReadFloat(section, L"IfAboveValue", 0.0f);
|
||||||
|
|
||||||
m_BelowAction = parser.ReadString(section, L"IfBelowAction", L"", false);
|
m_BelowAction = parser.ReadString(section, L"IfBelowAction", L"", false);
|
||||||
m_BelowValue = parser.ReadFloat(section, L"IfBelowValue", 0.0f);
|
m_BelowValue = parser.ReadFloat(section, L"IfBelowValue", 0.0f);
|
||||||
|
|
||||||
m_EqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
|
m_EqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
|
||||||
m_EqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0f);
|
m_EqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section)
|
void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
// IfCondition options
|
// IfCondition options
|
||||||
m_ConditionMode = parser.ReadBool(section, L"IfConditionMode", false);
|
m_ConditionMode = parser.ReadBool(section, L"IfConditionMode", false);
|
||||||
|
|
||||||
std::wstring condition = parser.ReadString(section, L"IfCondition", L"");
|
std::wstring condition = parser.ReadString(section, L"IfCondition", L"");
|
||||||
if (!condition.empty())
|
if (!condition.empty())
|
||||||
{
|
{
|
||||||
std::wstring tAction = parser.ReadString(section, L"IfTrueAction", L"", false);
|
std::wstring tAction = parser.ReadString(section, L"IfTrueAction", L"", false);
|
||||||
std::wstring fAction = parser.ReadString(section, L"IfFalseAction", L"", false);
|
std::wstring fAction = parser.ReadString(section, L"IfFalseAction", L"", false);
|
||||||
if (!tAction.empty() || !fAction.empty())
|
if (!tAction.empty() || !fAction.empty())
|
||||||
{
|
{
|
||||||
size_t i = 1;
|
size_t i = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (m_Conditions.size() > (i - 1))
|
if (m_Conditions.size() > (i - 1))
|
||||||
{
|
{
|
||||||
m_Conditions[i - 1].Set(condition, tAction, fAction);
|
m_Conditions[i - 1].Set(condition, tAction, fAction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Conditions.emplace_back(condition, tAction, fAction);
|
m_Conditions.emplace_back(condition, tAction, fAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for IfCondition2/IfTrueAction2/IfFalseAction2 ... etc.
|
// Check for IfCondition2/IfTrueAction2/IfFalseAction2 ... etc.
|
||||||
const std::wstring num = std::to_wstring(++i);
|
const std::wstring num = std::to_wstring(++i);
|
||||||
|
|
||||||
std::wstring key = L"IfCondition" + num;
|
std::wstring key = L"IfCondition" + num;
|
||||||
condition = parser.ReadString(section, key.c_str(), L"");
|
condition = parser.ReadString(section, key.c_str(), L"");
|
||||||
if (condition.empty()) break;
|
if (condition.empty()) break;
|
||||||
|
|
||||||
key = L"IfTrueAction" + num;
|
key = L"IfTrueAction" + num;
|
||||||
tAction = parser.ReadString(section, key.c_str(), L"", false);
|
tAction = parser.ReadString(section, key.c_str(), L"", false);
|
||||||
key = L"IfFalseAction" + num;
|
key = L"IfFalseAction" + num;
|
||||||
fAction = parser.ReadString(section, key.c_str(), L"", false);
|
fAction = parser.ReadString(section, key.c_str(), L"", false);
|
||||||
}
|
}
|
||||||
while (!tAction.empty() || !fAction.empty());
|
while (!tAction.empty() || !fAction.empty());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Conditions.clear();
|
m_Conditions.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Conditions.clear();
|
m_Conditions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfMatch options
|
// IfMatch options
|
||||||
m_MatchMode = parser.ReadBool(section, L"IfMatchMode", false);
|
m_MatchMode = parser.ReadBool(section, L"IfMatchMode", false);
|
||||||
|
|
||||||
std::wstring match = parser.ReadString(section, L"IfMatch", L"");
|
std::wstring match = parser.ReadString(section, L"IfMatch", L"");
|
||||||
if (!match.empty())
|
if (!match.empty())
|
||||||
{
|
{
|
||||||
std::wstring tAction = parser.ReadString(section, L"IfMatchAction", L"", false);
|
std::wstring tAction = parser.ReadString(section, L"IfMatchAction", L"", false);
|
||||||
std::wstring fAction = parser.ReadString(section, L"IfNotMatchAction", L"", false);
|
std::wstring fAction = parser.ReadString(section, L"IfNotMatchAction", L"", false);
|
||||||
if (!tAction.empty() || !fAction.empty())
|
if (!tAction.empty() || !fAction.empty())
|
||||||
{
|
{
|
||||||
size_t i = 1;
|
size_t i = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (m_Matches.size() > (i - 1))
|
if (m_Matches.size() > (i - 1))
|
||||||
{
|
{
|
||||||
m_Matches[i - 1].Set(match, tAction, fAction);
|
m_Matches[i - 1].Set(match, tAction, fAction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Matches.emplace_back(match, tAction, fAction);
|
m_Matches.emplace_back(match, tAction, fAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for IfMatch2/IfMatchAction2/IfNotMatchAction2 ... etc.
|
// Check for IfMatch2/IfMatchAction2/IfNotMatchAction2 ... etc.
|
||||||
const std::wstring num = std::to_wstring(++i);
|
const std::wstring num = std::to_wstring(++i);
|
||||||
|
|
||||||
std::wstring key = L"IfMatch" + num;
|
std::wstring key = L"IfMatch" + num;
|
||||||
match = parser.ReadString(section, key.c_str(), L"");
|
match = parser.ReadString(section, key.c_str(), L"");
|
||||||
if (match.empty()) break;
|
if (match.empty()) break;
|
||||||
|
|
||||||
key = L"IfMatchAction" + num;
|
key = L"IfMatchAction" + num;
|
||||||
tAction = parser.ReadString(section, key.c_str(), L"", false);
|
tAction = parser.ReadString(section, key.c_str(), L"", false);
|
||||||
key = L"IfNotMatchAction" + num;
|
key = L"IfNotMatchAction" + num;
|
||||||
fAction = parser.ReadString(section, key.c_str(), L"", false);
|
fAction = parser.ReadString(section, key.c_str(), L"", false);
|
||||||
} while (!tAction.empty() || !fAction.empty());
|
} while (!tAction.empty() || !fAction.empty());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Matches.clear();
|
m_Matches.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Matches.clear();
|
m_Matches.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfActions::DoIfActions(Measure& measure, double value)
|
void IfActions::DoIfActions(Measure& measure, double value)
|
||||||
{
|
{
|
||||||
// IfEqual
|
// IfEqual
|
||||||
if (!m_EqualAction.empty())
|
if (!m_EqualAction.empty())
|
||||||
{
|
{
|
||||||
if ((int64_t)value == m_EqualValue)
|
if ((int64_t)value == m_EqualValue)
|
||||||
{
|
{
|
||||||
if (!m_EqualCommitted)
|
if (!m_EqualCommitted)
|
||||||
{
|
{
|
||||||
m_EqualCommitted = true; // To avoid infinite loop from !Update
|
m_EqualCommitted = true; // To avoid infinite loop from !Update
|
||||||
Rainmeter::GetInstance().ExecuteCommand(m_EqualAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(m_EqualAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_EqualCommitted = false;
|
m_EqualCommitted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfAbove
|
// IfAbove
|
||||||
if (!m_AboveAction.empty())
|
if (!m_AboveAction.empty())
|
||||||
{
|
{
|
||||||
if (value > m_AboveValue)
|
if (value > m_AboveValue)
|
||||||
{
|
{
|
||||||
if (!m_AboveCommitted)
|
if (!m_AboveCommitted)
|
||||||
{
|
{
|
||||||
m_AboveCommitted = true; // To avoid infinite loop from !Update
|
m_AboveCommitted = true; // To avoid infinite loop from !Update
|
||||||
Rainmeter::GetInstance().ExecuteCommand(m_AboveAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(m_AboveAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_AboveCommitted = false;
|
m_AboveCommitted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfBelow
|
// IfBelow
|
||||||
if (!m_BelowAction.empty())
|
if (!m_BelowAction.empty())
|
||||||
{
|
{
|
||||||
if (value < m_BelowValue)
|
if (value < m_BelowValue)
|
||||||
{
|
{
|
||||||
if (!m_BelowCommitted)
|
if (!m_BelowCommitted)
|
||||||
{
|
{
|
||||||
m_BelowCommitted = true; // To avoid infinite loop from !Update
|
m_BelowCommitted = true; // To avoid infinite loop from !Update
|
||||||
Rainmeter::GetInstance().ExecuteCommand(m_BelowAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(m_BelowAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_BelowCommitted = false;
|
m_BelowCommitted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfCondition
|
// IfCondition
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& item : m_Conditions)
|
for (auto& item : m_Conditions)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
if (!item.value.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
if (!item.value.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
||||||
{
|
{
|
||||||
double result = 0.0f;
|
double result = 0.0f;
|
||||||
const WCHAR* errMsg = MathParser::Parse(
|
const WCHAR* errMsg = MathParser::Parse(
|
||||||
item.value.c_str(), &result, measure.GetCurrentMeasureValue, &measure);
|
item.value.c_str(), &result, measure.GetCurrentMeasureValue, &measure);
|
||||||
if (errMsg != nullptr)
|
if (errMsg != nullptr)
|
||||||
{
|
{
|
||||||
if (!item.parseError)
|
if (!item.parseError)
|
||||||
{
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
LogErrorF(&measure, L"%s: IfCondition=%s", errMsg, item.value.c_str());
|
LogErrorF(&measure, L"%s: IfCondition=%s", errMsg, item.value.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogErrorF(&measure, L"%s: IfCondition%i=%s", errMsg, i, item.value.c_str());
|
LogErrorF(&measure, L"%s: IfCondition%i=%s", errMsg, i, item.value.c_str());
|
||||||
}
|
}
|
||||||
item.parseError = true;
|
item.parseError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.parseError = false;
|
item.parseError = false;
|
||||||
|
|
||||||
if (result == 1.0f) // "True"
|
if (result == 1.0f) // "True"
|
||||||
{
|
{
|
||||||
item.fCommitted = false;
|
item.fCommitted = false;
|
||||||
|
|
||||||
if (m_ConditionMode || !item.tCommitted)
|
if (m_ConditionMode || !item.tCommitted)
|
||||||
{
|
{
|
||||||
item.tCommitted = true;
|
item.tCommitted = true;
|
||||||
Rainmeter::GetInstance().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result == 0.0f) // "False"
|
else if (result == 0.0f) // "False"
|
||||||
{
|
{
|
||||||
item.tCommitted = false;
|
item.tCommitted = false;
|
||||||
|
|
||||||
if (m_ConditionMode || !item.fCommitted)
|
if (m_ConditionMode || !item.fCommitted)
|
||||||
{
|
{
|
||||||
item.fCommitted = true;
|
item.fCommitted = true;
|
||||||
Rainmeter::GetInstance().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfMatch
|
// IfMatch
|
||||||
i = 0;
|
i = 0;
|
||||||
for (auto& item : m_Matches)
|
for (auto& item : m_Matches)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
if (!item.value.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
if (!item.value.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
||||||
{
|
{
|
||||||
const char* error;
|
const char* error;
|
||||||
int errorOffset;
|
int errorOffset;
|
||||||
|
|
||||||
pcre* re = pcre_compile(
|
pcre* re = pcre_compile(
|
||||||
StringUtil::NarrowUTF8(item.value).c_str(),
|
StringUtil::NarrowUTF8(item.value).c_str(),
|
||||||
PCRE_UTF8,
|
PCRE_UTF8,
|
||||||
&error,
|
&error,
|
||||||
&errorOffset,
|
&errorOffset,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
if (!re)
|
if (!re)
|
||||||
{
|
{
|
||||||
if (!item.parseError)
|
if (!item.parseError)
|
||||||
{
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
LogErrorF(&measure, L"Error: \"%S\" in IfMatch=%s", error, item.value.c_str());
|
LogErrorF(&measure, L"Error: \"%S\" in IfMatch=%s", error, item.value.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogErrorF(&measure, L"Error: \"%S\" in IfMatch%i=%s", error, i, item.value.c_str());
|
LogErrorF(&measure, L"Error: \"%S\" in IfMatch%i=%s", error, i, item.value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
item.parseError = true;
|
item.parseError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.parseError = false;
|
item.parseError = false;
|
||||||
|
|
||||||
std::string utf8str = StringUtil::NarrowUTF8(measure.GetStringValue());
|
std::string utf8str = StringUtil::NarrowUTF8(measure.GetStringValue());
|
||||||
int ovector[300];
|
int ovector[300];
|
||||||
|
|
||||||
int rc = pcre_exec(
|
int rc = pcre_exec(
|
||||||
re,
|
re,
|
||||||
nullptr,
|
nullptr,
|
||||||
utf8str.c_str(),
|
utf8str.c_str(),
|
||||||
(int)utf8str.length(),
|
(int)utf8str.length(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
ovector,
|
ovector,
|
||||||
(int)_countof(ovector));
|
(int)_countof(ovector));
|
||||||
|
|
||||||
if (rc > 0) // Match
|
if (rc > 0) // Match
|
||||||
{
|
{
|
||||||
item.fCommitted = false;
|
item.fCommitted = false;
|
||||||
|
|
||||||
if (m_MatchMode || !item.tCommitted)
|
if (m_MatchMode || !item.tCommitted)
|
||||||
{
|
{
|
||||||
item.tCommitted = true;
|
item.tCommitted = true;
|
||||||
Rainmeter::GetInstance().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Not Match
|
else // Not Match
|
||||||
{
|
{
|
||||||
item.tCommitted = false;
|
item.tCommitted = false;
|
||||||
|
|
||||||
if (m_MatchMode || !item.fCommitted)
|
if (m_MatchMode || !item.fCommitted)
|
||||||
{
|
{
|
||||||
item.fCommitted = true;
|
item.fCommitted = true;
|
||||||
Rainmeter::GetInstance().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow());
|
GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release memory used for the compiled pattern
|
// Release memory used for the compiled pattern
|
||||||
pcre_free(re);
|
pcre_free(re);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfActions::SetState(double& value)
|
void IfActions::SetState(double& value)
|
||||||
{
|
{
|
||||||
// Set IfAction committed state to false if condition is not met with value = 0
|
// Set IfAction committed state to false if condition is not met with value = 0
|
||||||
if (m_EqualValue != (int64_t)value)
|
if (m_EqualValue != (int64_t)value)
|
||||||
{
|
{
|
||||||
m_EqualCommitted = false;
|
m_EqualCommitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_AboveValue <= value)
|
if (m_AboveValue <= value)
|
||||||
{
|
{
|
||||||
m_AboveCommitted = false;
|
m_AboveCommitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_BelowValue >= value)
|
if (m_BelowValue >= value)
|
||||||
{
|
{
|
||||||
m_BelowCommitted = false;
|
m_BelowCommitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& item : m_Conditions)
|
for (auto& item : m_Conditions)
|
||||||
{
|
{
|
||||||
item.tCommitted = false;
|
item.tCommitted = false;
|
||||||
item.fCommitted = false;
|
item.fCommitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& item : m_Matches)
|
for (auto& item : m_Matches)
|
||||||
{
|
{
|
||||||
item.tCommitted = false;
|
item.tCommitted = false;
|
||||||
item.fCommitted = false;
|
item.fCommitted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,90 +1,90 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2002 Kimmo Pekkola + few lsapi developers
|
Copyright (C) 2002 Kimmo Pekkola + few lsapi developers
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Litestep.h"
|
#include "Litestep.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "DialogAbout.h"
|
#include "DialogAbout.h"
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
|
||||||
UINT GetUniqueID()
|
UINT GetUniqueID()
|
||||||
{
|
{
|
||||||
static UINT id = 0;
|
static UINT id = 0;
|
||||||
return id++;
|
return id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR* GetString(UINT id)
|
WCHAR* GetString(UINT id)
|
||||||
{
|
{
|
||||||
LPWSTR pData;
|
LPWSTR pData;
|
||||||
int len = LoadString(Rainmeter::GetInstance().GetResourceInstance(), id, (LPWSTR)&pData, 0);
|
int len = LoadString(GetRainmeter().GetResourceInstance(), id, (LPWSTR)&pData, 0);
|
||||||
return len ? pData : L"";
|
return len ? pData : L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetFormattedString(UINT id, ...)
|
std::wstring GetFormattedString(UINT id, ...)
|
||||||
{
|
{
|
||||||
LPWSTR pBuffer = nullptr;
|
LPWSTR pBuffer = nullptr;
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, id);
|
va_start(args, id);
|
||||||
|
|
||||||
DWORD len = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
DWORD len = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||||
GetString(id),
|
GetString(id),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(LPWSTR)&pBuffer,
|
(LPWSTR)&pBuffer,
|
||||||
0,
|
0,
|
||||||
&args);
|
&args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
std::wstring tmpSz(len ? pBuffer : L"", len);
|
std::wstring tmpSz(len ? pBuffer : L"", len);
|
||||||
if (pBuffer) LocalFree(pBuffer);
|
if (pBuffer) LocalFree(pBuffer);
|
||||||
return tmpSz;
|
return tmpSz;
|
||||||
}
|
}
|
||||||
|
|
||||||
HICON GetIcon(UINT id, bool large)
|
HICON GetIcon(UINT id, bool large)
|
||||||
{
|
{
|
||||||
HINSTANCE hExe = GetModuleHandle(nullptr);
|
HINSTANCE hExe = GetModuleHandle(nullptr);
|
||||||
HINSTANCE hComctl = GetModuleHandle(L"Comctl32");
|
HINSTANCE hComctl = GetModuleHandle(L"Comctl32");
|
||||||
if (hComctl)
|
if (hComctl)
|
||||||
{
|
{
|
||||||
// Try LoadIconMetric for better quality with high DPI
|
// Try LoadIconMetric for better quality with high DPI
|
||||||
auto loadIconMetric = (decltype(LoadIconMetric)*)GetProcAddress(hComctl, "LoadIconMetric");
|
auto loadIconMetric = (decltype(LoadIconMetric)*)GetProcAddress(hComctl, "LoadIconMetric");
|
||||||
if (loadIconMetric)
|
if (loadIconMetric)
|
||||||
{
|
{
|
||||||
HICON icon;
|
HICON icon;
|
||||||
HRESULT hr = loadIconMetric(hExe, MAKEINTRESOURCE(id), large ? LIM_LARGE : LIM_SMALL, &icon);
|
HRESULT hr = loadIconMetric(hExe, MAKEINTRESOURCE(id), large ? LIM_LARGE : LIM_SMALL, &icon);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (HICON)LoadImage(
|
return (HICON)LoadImage(
|
||||||
hExe,
|
hExe,
|
||||||
MAKEINTRESOURCE(id),
|
MAKEINTRESOURCE(id),
|
||||||
IMAGE_ICON,
|
IMAGE_ICON,
|
||||||
GetSystemMetrics(large ? SM_CXICON : SM_CXSMICON),
|
GetSystemMetrics(large ? SM_CXICON : SM_CXSMICON),
|
||||||
GetSystemMetrics(large ? SM_CYICON : SM_CYSMICON),
|
GetSystemMetrics(large ? SM_CYICON : SM_CYSMICON),
|
||||||
LR_SHARED);
|
LR_SHARED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
|
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
|
||||||
{
|
{
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
@ -1,276 +1,276 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2013 Birunthan Mohanathas
|
Copyright (C) 2013 Birunthan Mohanathas
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "DialogAbout.h"
|
#include "DialogAbout.h"
|
||||||
#include "Litestep.h"
|
#include "Litestep.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "Section.h"
|
#include "Section.h"
|
||||||
#include "MeterWindow.h"
|
#include "MeterWindow.h"
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const size_t MAX_LOG_ENTIRES = 20;
|
const size_t MAX_LOG_ENTIRES = 20;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Logger::Logger() :
|
Logger::Logger() :
|
||||||
m_LogToFile(false)
|
m_LogToFile(false)
|
||||||
{
|
{
|
||||||
System::InitializeCriticalSection(&m_CsLog);
|
System::InitializeCriticalSection(&m_CsLog);
|
||||||
System::InitializeCriticalSection(&m_CsLogDelay);
|
System::InitializeCriticalSection(&m_CsLogDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::~Logger()
|
Logger::~Logger()
|
||||||
{
|
{
|
||||||
DeleteCriticalSection(&m_CsLog);
|
DeleteCriticalSection(&m_CsLog);
|
||||||
DeleteCriticalSection(&m_CsLogDelay);
|
DeleteCriticalSection(&m_CsLogDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger& Logger::GetInstance()
|
Logger& Logger::GetInstance()
|
||||||
{
|
{
|
||||||
static Logger s_Logger;
|
static Logger s_Logger;
|
||||||
return s_Logger;
|
return s_Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::StartLogFile()
|
void Logger::StartLogFile()
|
||||||
{
|
{
|
||||||
const WCHAR* filePath = m_LogFilePath.c_str();
|
const WCHAR* filePath = m_LogFilePath.c_str();
|
||||||
if (_waccess(filePath, 0) == -1)
|
if (_waccess(filePath, 0) == -1)
|
||||||
{
|
{
|
||||||
// Create empty log file.
|
// Create empty log file.
|
||||||
HANDLE file = CreateFile(filePath, GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
HANDLE file = CreateFile(filePath, GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
if (file != INVALID_HANDLE_VALUE)
|
if (file != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
CloseHandle(file);
|
CloseHandle(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, filePath);
|
const std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, filePath);
|
||||||
Rainmeter::GetInstance().ShowMessage(nullptr, text.c_str(), MB_OK | MB_ICONERROR);
|
GetRainmeter().ShowMessage(nullptr, text.c_str(), MB_OK | MB_ICONERROR);
|
||||||
SetLogToFile(false);
|
SetLogToFile(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLogToFile(true);
|
SetLogToFile(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::StopLogFile()
|
void Logger::StopLogFile()
|
||||||
{
|
{
|
||||||
SetLogToFile(false);
|
SetLogToFile(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::DeleteLogFile()
|
void Logger::DeleteLogFile()
|
||||||
{
|
{
|
||||||
const WCHAR* filePath = m_LogFilePath.c_str();
|
const WCHAR* filePath = m_LogFilePath.c_str();
|
||||||
if (_waccess(filePath, 0) != -1)
|
if (_waccess(filePath, 0) != -1)
|
||||||
{
|
{
|
||||||
const std::wstring text = GetFormattedString(ID_STR_LOGFILEDELETE, filePath);
|
const std::wstring text = GetFormattedString(ID_STR_LOGFILEDELETE, filePath);
|
||||||
const int res = Rainmeter::GetInstance().ShowMessage(nullptr, text.c_str(), MB_YESNO | MB_ICONQUESTION);
|
const int res = GetRainmeter().ShowMessage(nullptr, text.c_str(), MB_YESNO | MB_ICONQUESTION);
|
||||||
if (res == IDYES)
|
if (res == IDYES)
|
||||||
{
|
{
|
||||||
SetLogToFile(false);
|
SetLogToFile(false);
|
||||||
System::RemoveFile(m_LogFilePath);
|
System::RemoveFile(m_LogFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::SetLogToFile(bool logToFile)
|
void Logger::SetLogToFile(bool logToFile)
|
||||||
{
|
{
|
||||||
m_LogToFile = logToFile;
|
m_LogToFile = logToFile;
|
||||||
WritePrivateProfileString(
|
WritePrivateProfileString(
|
||||||
L"Rainmeter", L"Logging", logToFile ? L"1" : L"0", Rainmeter::GetInstance().GetIniFile().c_str());
|
L"Rainmeter", L"Logging", logToFile ? L"1" : L"0", GetRainmeter().GetIniFile().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::LogInternal(Level level, ULONGLONG timestamp, const WCHAR* source, const WCHAR* msg)
|
void Logger::LogInternal(Level level, ULONGLONG timestamp, const WCHAR* source, const WCHAR* msg)
|
||||||
{
|
{
|
||||||
WCHAR timestampSz[128];
|
WCHAR timestampSz[128];
|
||||||
size_t len = _snwprintf_s(
|
size_t len = _snwprintf_s(
|
||||||
timestampSz,
|
timestampSz,
|
||||||
_TRUNCATE,
|
_TRUNCATE,
|
||||||
L"%02llu:%02llu:%02llu.%03llu",
|
L"%02llu:%02llu:%02llu.%03llu",
|
||||||
timestamp / (1000 * 60 * 60),
|
timestamp / (1000 * 60 * 60),
|
||||||
(timestamp / (1000 * 60)) % 60,
|
(timestamp / (1000 * 60)) % 60,
|
||||||
(timestamp / 1000) % 60,
|
(timestamp / 1000) % 60,
|
||||||
timestamp % 1000);
|
timestamp % 1000);
|
||||||
|
|
||||||
// Store up to MAX_LOG_ENTIRES entries.
|
// Store up to MAX_LOG_ENTIRES entries.
|
||||||
Entry entry = {level, std::wstring(timestampSz, len), source, msg};
|
Entry entry = {level, std::wstring(timestampSz, len), source, msg};
|
||||||
m_Entries.push_back(entry);
|
m_Entries.push_back(entry);
|
||||||
if (m_Entries.size() > MAX_LOG_ENTIRES)
|
if (m_Entries.size() > MAX_LOG_ENTIRES)
|
||||||
{
|
{
|
||||||
m_Entries.pop_front();
|
m_Entries.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogAbout::AddLogItem(level, timestampSz, source, msg);
|
DialogAbout::AddLogItem(level, timestampSz, source, msg);
|
||||||
WriteToLogFile(entry);
|
WriteToLogFile(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::WriteToLogFile(Entry& entry)
|
void Logger::WriteToLogFile(Entry& entry)
|
||||||
{
|
{
|
||||||
#ifndef _DEBUG
|
#ifndef _DEBUG
|
||||||
if (!m_LogToFile) return;
|
if (!m_LogToFile) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const WCHAR* levelSz =
|
const WCHAR* levelSz =
|
||||||
(entry.level == Level::Error) ? L"ERRO" :
|
(entry.level == Level::Error) ? L"ERRO" :
|
||||||
(entry.level == Level::Warning) ? L"WARN" :
|
(entry.level == Level::Warning) ? L"WARN" :
|
||||||
(entry.level == Level::Notice) ? L"NOTE" :
|
(entry.level == Level::Notice) ? L"NOTE" :
|
||||||
L"DBUG";
|
L"DBUG";
|
||||||
|
|
||||||
std::wstring message = levelSz;
|
std::wstring message = levelSz;
|
||||||
message += L" (";
|
message += L" (";
|
||||||
message.append(entry.timestamp);
|
message.append(entry.timestamp);
|
||||||
message += L") ";
|
message += L") ";
|
||||||
message += entry.source;
|
message += entry.source;
|
||||||
message += L": ";
|
message += L": ";
|
||||||
message += entry.message;
|
message += entry.message;
|
||||||
message += L'\n';
|
message += L'\n';
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
_RPTW0(_CRT_WARN, message.c_str());
|
_RPTW0(_CRT_WARN, message.c_str());
|
||||||
if (!m_LogToFile) return;
|
if (!m_LogToFile) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const WCHAR* filePath = m_LogFilePath.c_str();
|
const WCHAR* filePath = m_LogFilePath.c_str();
|
||||||
if (_waccess(filePath, 0) == -1)
|
if (_waccess(filePath, 0) == -1)
|
||||||
{
|
{
|
||||||
// The file has been deleted manually.
|
// The file has been deleted manually.
|
||||||
StopLogFile();
|
StopLogFile();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FILE* file = _wfopen(filePath, L"a+, ccs=UTF-8");
|
FILE* file = _wfopen(filePath, L"a+, ccs=UTF-8");
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
fputws(message.c_str(), file);
|
fputws(message.c_str(), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::Log(Level level, const WCHAR* source, const WCHAR* msg)
|
void Logger::Log(Level level, const WCHAR* source, const WCHAR* msg)
|
||||||
{
|
{
|
||||||
struct DelayedEntry
|
struct DelayedEntry
|
||||||
{
|
{
|
||||||
Level level;
|
Level level;
|
||||||
ULONGLONG elapsed;
|
ULONGLONG elapsed;
|
||||||
std::wstring message;
|
std::wstring message;
|
||||||
};
|
};
|
||||||
static std::list<DelayedEntry> s_DelayedEntries;
|
static std::list<DelayedEntry> s_DelayedEntries;
|
||||||
|
|
||||||
static ULONGLONG s_StartTime = System::GetTickCount64();
|
static ULONGLONG s_StartTime = System::GetTickCount64();
|
||||||
ULONGLONG elapsed = System::GetTickCount64() - s_StartTime;
|
ULONGLONG elapsed = System::GetTickCount64() - s_StartTime;
|
||||||
|
|
||||||
if (TryEnterCriticalSection(&m_CsLog))
|
if (TryEnterCriticalSection(&m_CsLog))
|
||||||
{
|
{
|
||||||
// Log queued messages first.
|
// Log queued messages first.
|
||||||
EnterCriticalSection(&m_CsLogDelay);
|
EnterCriticalSection(&m_CsLogDelay);
|
||||||
|
|
||||||
while (!s_DelayedEntries.empty())
|
while (!s_DelayedEntries.empty())
|
||||||
{
|
{
|
||||||
DelayedEntry& entry = s_DelayedEntries.front();
|
DelayedEntry& entry = s_DelayedEntries.front();
|
||||||
LogInternal(entry.level, entry.elapsed, source, entry.message.c_str());
|
LogInternal(entry.level, entry.elapsed, source, entry.message.c_str());
|
||||||
|
|
||||||
s_DelayedEntries.erase(s_DelayedEntries.begin());
|
s_DelayedEntries.erase(s_DelayedEntries.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaveCriticalSection(&m_CsLogDelay);
|
LeaveCriticalSection(&m_CsLogDelay);
|
||||||
|
|
||||||
// Log the actual message.
|
// Log the actual message.
|
||||||
LogInternal(level, elapsed, source, msg);
|
LogInternal(level, elapsed, source, msg);
|
||||||
|
|
||||||
LeaveCriticalSection(&m_CsLog);
|
LeaveCriticalSection(&m_CsLog);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Queue message.
|
// Queue message.
|
||||||
EnterCriticalSection(&m_CsLogDelay);
|
EnterCriticalSection(&m_CsLogDelay);
|
||||||
|
|
||||||
DelayedEntry entry = {level, elapsed, msg};
|
DelayedEntry entry = {level, elapsed, msg};
|
||||||
s_DelayedEntries.push_back(entry);
|
s_DelayedEntries.push_back(entry);
|
||||||
|
|
||||||
LeaveCriticalSection(&m_CsLogDelay);
|
LeaveCriticalSection(&m_CsLogDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args)
|
void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args)
|
||||||
{
|
{
|
||||||
WCHAR* buffer = new WCHAR[1024];
|
WCHAR* buffer = new WCHAR[1024];
|
||||||
|
|
||||||
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
|
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
|
||||||
_CrtSetReportMode(_CRT_ASSERT, 0);
|
_CrtSetReportMode(_CRT_ASSERT, 0);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
_vsnwprintf_s(buffer, 1024, _TRUNCATE, format, args);
|
_vsnwprintf_s(buffer, 1024, _TRUNCATE, format, args);
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
{
|
{
|
||||||
level = Level::Error;
|
level = Level::Error;
|
||||||
_snwprintf_s(buffer, 1024, _TRUNCATE, L"Internal error: %s", format);
|
_snwprintf_s(buffer, 1024, _TRUNCATE, L"Internal error: %s", format);
|
||||||
}
|
}
|
||||||
|
|
||||||
_set_invalid_parameter_handler(oldHandler);
|
_set_invalid_parameter_handler(oldHandler);
|
||||||
|
|
||||||
Log(level, source, buffer);
|
Log(level, source, buffer);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetSectionSourceString(Section* section)
|
std::wstring GetSectionSourceString(Section* section)
|
||||||
{
|
{
|
||||||
std::wstring source;
|
std::wstring source;
|
||||||
if (section)
|
if (section)
|
||||||
{
|
{
|
||||||
MeterWindow* meterWindow = section->GetMeterWindow();
|
MeterWindow* meterWindow = section->GetMeterWindow();
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
source = meterWindow->GetSkinPath();
|
source = meterWindow->GetSkinPath();
|
||||||
source += L" - ";
|
source += L" - ";
|
||||||
}
|
}
|
||||||
|
|
||||||
source += L'[';
|
source += L'[';
|
||||||
source += section->GetOriginalName();
|
source += section->GetOriginalName();
|
||||||
source += L']';
|
source += L']';
|
||||||
}
|
}
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::LogSection(Logger::Level level, Section* section, const WCHAR* message)
|
void Logger::LogSection(Logger::Level level, Section* section, const WCHAR* message)
|
||||||
{
|
{
|
||||||
const std::wstring source = GetSectionSourceString(section);
|
const std::wstring source = GetSectionSourceString(section);
|
||||||
GetLogger().Log(level, source.c_str(), message);
|
GetLogger().Log(level, source.c_str(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args)
|
void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args)
|
||||||
{
|
{
|
||||||
const std::wstring source = GetSectionSourceString(section);
|
const std::wstring source = GetSectionSourceString(section);
|
||||||
GetLogger().LogVF(level, source.c_str(), format, args);
|
GetLogger().LogVF(level, source.c_str(), format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::LogMeterWindowVF(Logger::Level level, MeterWindow* meterWindow, const WCHAR* format, va_list args)
|
void Logger::LogMeterWindowVF(Logger::Level level, MeterWindow* meterWindow, const WCHAR* format, va_list args)
|
||||||
{
|
{
|
||||||
std::wstring source;
|
std::wstring source;
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
source = meterWindow->GetSkinPath();
|
source = meterWindow->GetSkinPath();
|
||||||
}
|
}
|
||||||
GetLogger().LogVF(level, source.c_str(), format, args);
|
GetLogger().LogVF(level, source.c_str(), format, args);
|
||||||
}
|
}
|
||||||
|
1676
Library/Measure.cpp
1676
Library/Measure.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,258 +1,258 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2001 Kimmo Pekkola
|
Copyright (C) 2001 Kimmo Pekkola
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "MeasurePlugin.h"
|
#include "MeasurePlugin.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "Export.h"
|
#include "Export.h"
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The constructor
|
** The constructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
MeasurePlugin::MeasurePlugin(MeterWindow* meterWindow, const WCHAR* name) : Measure(meterWindow, name),
|
MeasurePlugin::MeasurePlugin(MeterWindow* meterWindow, const WCHAR* name) : Measure(meterWindow, name),
|
||||||
m_Plugin(),
|
m_Plugin(),
|
||||||
m_ReloadFunc(),
|
m_ReloadFunc(),
|
||||||
m_ID(),
|
m_ID(),
|
||||||
m_Update2(false),
|
m_Update2(false),
|
||||||
m_PluginData(),
|
m_PluginData(),
|
||||||
m_UpdateFunc(),
|
m_UpdateFunc(),
|
||||||
m_GetStringFunc(),
|
m_GetStringFunc(),
|
||||||
m_ExecuteBangFunc()
|
m_ExecuteBangFunc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The destructor
|
** The destructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
MeasurePlugin::~MeasurePlugin()
|
MeasurePlugin::~MeasurePlugin()
|
||||||
{
|
{
|
||||||
if (m_Plugin)
|
if (m_Plugin)
|
||||||
{
|
{
|
||||||
FARPROC finalizeFunc = GetProcAddress(m_Plugin, "Finalize");
|
FARPROC finalizeFunc = GetProcAddress(m_Plugin, "Finalize");
|
||||||
if (finalizeFunc)
|
if (finalizeFunc)
|
||||||
{
|
{
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
((NEWFINALIZE)finalizeFunc)(m_PluginData);
|
((NEWFINALIZE)finalizeFunc)(m_PluginData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((FINALIZE)finalizeFunc)(m_Plugin, m_ID);
|
((FINALIZE)finalizeFunc)(m_Plugin, m_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeLibrary(m_Plugin);
|
FreeLibrary(m_Plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Gets the current value from the plugin
|
** Gets the current value from the plugin
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeasurePlugin::UpdateValue()
|
void MeasurePlugin::UpdateValue()
|
||||||
{
|
{
|
||||||
if (m_UpdateFunc)
|
if (m_UpdateFunc)
|
||||||
{
|
{
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
m_Value = ((NEWUPDATE)m_UpdateFunc)(m_PluginData);
|
m_Value = ((NEWUPDATE)m_UpdateFunc)(m_PluginData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_Update2)
|
if (m_Update2)
|
||||||
{
|
{
|
||||||
m_Value = ((UPDATE2)m_UpdateFunc)(m_ID);
|
m_Value = ((UPDATE2)m_UpdateFunc)(m_ID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Value = ((UPDATE)m_UpdateFunc)(m_ID);
|
m_Value = ((UPDATE)m_UpdateFunc)(m_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to default
|
// Reset to default
|
||||||
System::ResetWorkingDirectory();
|
System::ResetWorkingDirectory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Reads the options and loads the plugin
|
** Reads the options and loads the plugin
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeasurePlugin::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
void MeasurePlugin::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
static UINT id = 0;
|
static UINT id = 0;
|
||||||
|
|
||||||
Measure::ReadOptions(parser, section);
|
Measure::ReadOptions(parser, section);
|
||||||
|
|
||||||
if (m_Initialized)
|
if (m_Initialized)
|
||||||
{
|
{
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
|
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DynamicVariables doesn't work with old plugins
|
// DynamicVariables doesn't work with old plugins
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::wstring& plugin = parser.ReadString(section, L"Plugin", L"");
|
const std::wstring& plugin = parser.ReadString(section, L"Plugin", L"");
|
||||||
size_t pos = plugin.find_last_of(L"\\/");
|
size_t pos = plugin.find_last_of(L"\\/");
|
||||||
std::wstring pluginName;
|
std::wstring pluginName;
|
||||||
if (pos != std::wstring::npos)
|
if (pos != std::wstring::npos)
|
||||||
{
|
{
|
||||||
pluginName.assign(plugin, pos, plugin.length() - pos);
|
pluginName.assign(plugin, pos, plugin.length() - pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pluginName = plugin;
|
pluginName = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First try from program path
|
// First try from program path
|
||||||
std::wstring pluginFile = Rainmeter::GetInstance().GetPluginPath();
|
std::wstring pluginFile = GetRainmeter().GetPluginPath();
|
||||||
pluginFile += pluginName;
|
pluginFile += pluginName;
|
||||||
m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
|
m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
|
||||||
if (!m_Plugin)
|
if (!m_Plugin)
|
||||||
{
|
{
|
||||||
if (Rainmeter::GetInstance().HasUserPluginPath())
|
if (GetRainmeter().HasUserPluginPath())
|
||||||
{
|
{
|
||||||
// Try from settings path
|
// Try from settings path
|
||||||
pluginFile = Rainmeter::GetInstance().GetUserPluginPath();
|
pluginFile = GetRainmeter().GetUserPluginPath();
|
||||||
pluginFile += pluginName;
|
pluginFile += pluginName;
|
||||||
m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
|
m_Plugin = System::RmLoadLibrary(pluginFile.c_str());
|
||||||
}
|
}
|
||||||
if (!m_Plugin)
|
if (!m_Plugin)
|
||||||
{
|
{
|
||||||
LogErrorF(
|
LogErrorF(
|
||||||
this, L"Plugin: Unable to load \"%s\" (error %ld)",
|
this, L"Plugin: Unable to load \"%s\" (error %ld)",
|
||||||
pluginName.c_str(), GetLastError());
|
pluginName.c_str(), GetLastError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FARPROC initializeFunc = GetProcAddress(m_Plugin, "Initialize");
|
FARPROC initializeFunc = GetProcAddress(m_Plugin, "Initialize");
|
||||||
m_ReloadFunc = GetProcAddress(m_Plugin, "Reload");
|
m_ReloadFunc = GetProcAddress(m_Plugin, "Reload");
|
||||||
m_UpdateFunc = GetProcAddress(m_Plugin, "Update");
|
m_UpdateFunc = GetProcAddress(m_Plugin, "Update");
|
||||||
m_GetStringFunc = GetProcAddress(m_Plugin, "GetString");
|
m_GetStringFunc = GetProcAddress(m_Plugin, "GetString");
|
||||||
m_ExecuteBangFunc = GetProcAddress(m_Plugin, "ExecuteBang");
|
m_ExecuteBangFunc = GetProcAddress(m_Plugin, "ExecuteBang");
|
||||||
|
|
||||||
// Remove current directory from DLL search path
|
// Remove current directory from DLL search path
|
||||||
SetDllDirectory(L"");
|
SetDllDirectory(L"");
|
||||||
|
|
||||||
double maxValue = 0.0;
|
double maxValue = 0.0;
|
||||||
|
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
m_PluginData = (void*)id;
|
m_PluginData = (void*)id;
|
||||||
|
|
||||||
if (initializeFunc)
|
if (initializeFunc)
|
||||||
{
|
{
|
||||||
((NEWINITIALIZE)initializeFunc)(&m_PluginData, this);
|
((NEWINITIALIZE)initializeFunc)(&m_PluginData, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &maxValue);
|
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &maxValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_ID = id;
|
m_ID = id;
|
||||||
|
|
||||||
if (!m_UpdateFunc)
|
if (!m_UpdateFunc)
|
||||||
{
|
{
|
||||||
m_UpdateFunc = GetProcAddress(m_Plugin, "Update2");
|
m_UpdateFunc = GetProcAddress(m_Plugin, "Update2");
|
||||||
m_Update2 = true;
|
m_Update2 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initializeFunc)
|
if (initializeFunc)
|
||||||
{
|
{
|
||||||
maxValue = ((INITIALIZE)initializeFunc)(m_Plugin, m_MeterWindow->GetFilePath().c_str(), section, m_ID);
|
maxValue = ((INITIALIZE)initializeFunc)(m_Plugin, m_MeterWindow->GetFilePath().c_str(), section, m_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::wstring& szMaxValue = parser.ReadString(section, L"MaxValue", L"");
|
const std::wstring& szMaxValue = parser.ReadString(section, L"MaxValue", L"");
|
||||||
if (szMaxValue.empty())
|
if (szMaxValue.empty())
|
||||||
{
|
{
|
||||||
if (maxValue == 0.0)
|
if (maxValue == 0.0)
|
||||||
{
|
{
|
||||||
m_MaxValue = 1.0;
|
m_MaxValue = 1.0;
|
||||||
m_LogMaxValue = true;
|
m_LogMaxValue = true;
|
||||||
m_MedianValues.clear();
|
m_MedianValues.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_MaxValue = maxValue;
|
m_MaxValue = maxValue;
|
||||||
m_LogMaxValue = false;
|
m_LogMaxValue = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to default
|
// Reset to default
|
||||||
SetDllDirectory(L"");
|
SetDllDirectory(L"");
|
||||||
System::ResetWorkingDirectory();
|
System::ResetWorkingDirectory();
|
||||||
|
|
||||||
++id;
|
++id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Gets the string value from the plugin.
|
** Gets the string value from the plugin.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
const WCHAR* MeasurePlugin::GetStringValue()
|
const WCHAR* MeasurePlugin::GetStringValue()
|
||||||
{
|
{
|
||||||
if (m_GetStringFunc)
|
if (m_GetStringFunc)
|
||||||
{
|
{
|
||||||
const WCHAR* ret;
|
const WCHAR* ret;
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
ret = ((NEWGETSTRING)m_GetStringFunc)(m_PluginData);
|
ret = ((NEWGETSTRING)m_GetStringFunc)(m_PluginData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = ((GETSTRING)m_GetStringFunc)(m_ID, 0);
|
ret = ((GETSTRING)m_GetStringFunc)(m_ID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) return CheckSubstitute(ret);
|
if (ret) return CheckSubstitute(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Sends a bang to the plugin
|
** Sends a bang to the plugin
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeasurePlugin::Command(const std::wstring& command)
|
void MeasurePlugin::Command(const std::wstring& command)
|
||||||
{
|
{
|
||||||
if (m_ExecuteBangFunc)
|
if (m_ExecuteBangFunc)
|
||||||
{
|
{
|
||||||
const WCHAR* str = command.c_str();
|
const WCHAR* str = command.c_str();
|
||||||
if (IsNewApi())
|
if (IsNewApi())
|
||||||
{
|
{
|
||||||
((NEWEXECUTEBANG)m_ExecuteBangFunc)(m_PluginData, str);
|
((NEWEXECUTEBANG)m_ExecuteBangFunc)(m_PluginData, str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((EXECUTEBANG)m_ExecuteBangFunc)(str, m_ID);
|
((EXECUTEBANG)m_ExecuteBangFunc)(str, m_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Measure::Command(command);
|
Measure::Command(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1520
Library/Meter.cpp
1520
Library/Meter.cpp
File diff suppressed because it is too large
Load Diff
@ -1,330 +1,330 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2005 Kimmo Pekkola
|
Copyright (C) 2005 Kimmo Pekkola
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "MeterButton.h"
|
#include "MeterButton.h"
|
||||||
#include "Measure.h"
|
#include "Measure.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include "../Common/Gfx/Canvas.h"
|
#include "../Common/Gfx/Canvas.h"
|
||||||
|
|
||||||
using namespace Gdiplus;
|
using namespace Gdiplus;
|
||||||
|
|
||||||
enum BUTTON_STATE
|
enum BUTTON_STATE
|
||||||
{
|
{
|
||||||
BUTTON_STATE_NORMAL,
|
BUTTON_STATE_NORMAL,
|
||||||
BUTTON_STATE_DOWN,
|
BUTTON_STATE_DOWN,
|
||||||
BUTTON_STATE_HOVER
|
BUTTON_STATE_HOVER
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The constructor
|
** The constructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
MeterButton::MeterButton(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
|
MeterButton::MeterButton(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
|
||||||
m_Image(L"ButtonImage", nullptr, true, meterWindow),
|
m_Image(L"ButtonImage", nullptr, true, meterWindow),
|
||||||
m_NeedsReload(false),
|
m_NeedsReload(false),
|
||||||
m_Bitmaps(),
|
m_Bitmaps(),
|
||||||
m_State(BUTTON_STATE_NORMAL),
|
m_State(BUTTON_STATE_NORMAL),
|
||||||
m_Clicked(false),
|
m_Clicked(false),
|
||||||
m_Focus(false)
|
m_Focus(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The destructor
|
** The destructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
MeterButton::~MeterButton()
|
MeterButton::~MeterButton()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
||||||
{
|
{
|
||||||
delete m_Bitmaps[i];
|
delete m_Bitmaps[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Load the image and get the dimensions of the meter from it.
|
** Load the image and get the dimensions of the meter from it.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeterButton::Initialize()
|
void MeterButton::Initialize()
|
||||||
{
|
{
|
||||||
Meter::Initialize();
|
Meter::Initialize();
|
||||||
|
|
||||||
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
||||||
{
|
{
|
||||||
delete m_Bitmaps[i];
|
delete m_Bitmaps[i];
|
||||||
m_Bitmaps[i] = nullptr;
|
m_Bitmaps[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the bitmaps if defined
|
// Load the bitmaps if defined
|
||||||
if (!m_ImageName.empty())
|
if (!m_ImageName.empty())
|
||||||
{
|
{
|
||||||
m_Image.LoadImage(m_ImageName, m_NeedsReload);
|
m_Image.LoadImage(m_ImageName, m_NeedsReload);
|
||||||
|
|
||||||
if (m_Image.IsLoaded())
|
if (m_Image.IsLoaded())
|
||||||
{
|
{
|
||||||
Bitmap* bitmap = m_Image.GetImage();
|
Bitmap* bitmap = m_Image.GetImage();
|
||||||
|
|
||||||
int bitmapW = bitmap->GetWidth();
|
int bitmapW = bitmap->GetWidth();
|
||||||
int bitmapH = bitmap->GetHeight();
|
int bitmapH = bitmap->GetHeight();
|
||||||
|
|
||||||
m_W = bitmapW;
|
m_W = bitmapW;
|
||||||
m_H = bitmapH;
|
m_H = bitmapH;
|
||||||
|
|
||||||
if (m_H > m_W)
|
if (m_H > m_W)
|
||||||
{
|
{
|
||||||
m_H /= BUTTON_FRAMES;
|
m_H /= BUTTON_FRAMES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_W /= BUTTON_FRAMES;
|
m_W /= BUTTON_FRAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separate the frames
|
// Separate the frames
|
||||||
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
for (int i = 0; i < BUTTON_FRAMES; ++i)
|
||||||
{
|
{
|
||||||
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppPARGB);
|
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppPARGB);
|
||||||
Graphics graphics(&bitmapPart);
|
Graphics graphics(&bitmapPart);
|
||||||
Rect r(0, 0, m_W, m_H);
|
Rect r(0, 0, m_W, m_H);
|
||||||
|
|
||||||
if (bitmapH > bitmapW)
|
if (bitmapH > bitmapW)
|
||||||
{
|
{
|
||||||
graphics.DrawImage(bitmap, r, 0, m_H * i, m_W, m_H, UnitPixel);
|
graphics.DrawImage(bitmap, r, 0, m_H * i, m_W, m_H, UnitPixel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
graphics.DrawImage(bitmap, r, m_W * i, 0, m_W, m_H, UnitPixel);
|
graphics.DrawImage(bitmap, r, m_W * i, 0, m_W, m_H, UnitPixel);
|
||||||
}
|
}
|
||||||
m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics);
|
m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_W += GetWidthPadding();
|
m_W += GetWidthPadding();
|
||||||
m_H += GetHeightPadding();
|
m_H += GetHeightPadding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_Image.IsLoaded())
|
else if (m_Image.IsLoaded())
|
||||||
{
|
{
|
||||||
m_Image.DisposeImage();
|
m_Image.DisposeImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Read the options specified in the ini file.
|
** Read the options specified in the ini file.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeterButton::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
void MeterButton::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
// Store the current values so we know if the image needs to be updated
|
// Store the current values so we know if the image needs to be updated
|
||||||
std::wstring oldImageName = m_ImageName;
|
std::wstring oldImageName = m_ImageName;
|
||||||
int oldW = m_W;
|
int oldW = m_W;
|
||||||
int oldH = m_H;
|
int oldH = m_H;
|
||||||
|
|
||||||
Meter::ReadOptions(parser, section);
|
Meter::ReadOptions(parser, section);
|
||||||
|
|
||||||
m_ImageName = parser.ReadString(section, L"ButtonImage", L"");
|
m_ImageName = parser.ReadString(section, L"ButtonImage", L"");
|
||||||
if (!m_ImageName.empty())
|
if (!m_ImageName.empty())
|
||||||
{
|
{
|
||||||
// Read tinting options
|
// Read tinting options
|
||||||
m_Image.ReadOptions(parser, section);
|
m_Image.ReadOptions(parser, section);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Image.ClearOptionFlags();
|
m_Image.ClearOptionFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Command = parser.ReadString(section, L"ButtonCommand", L"", false);
|
m_Command = parser.ReadString(section, L"ButtonCommand", L"", false);
|
||||||
|
|
||||||
if (m_Initialized)
|
if (m_Initialized)
|
||||||
{
|
{
|
||||||
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
|
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
|
||||||
|
|
||||||
if (m_NeedsReload ||
|
if (m_NeedsReload ||
|
||||||
m_Image.IsOptionsChanged())
|
m_Image.IsOptionsChanged())
|
||||||
{
|
{
|
||||||
Initialize(); // Reload the image
|
Initialize(); // Reload the image
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Reset to old dimensions
|
// Reset to old dimensions
|
||||||
m_W = oldW;
|
m_W = oldW;
|
||||||
m_H = oldH;
|
m_H = oldH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Updates the value(s) from the measures.
|
** Updates the value(s) from the measures.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
bool MeterButton::Update()
|
bool MeterButton::Update()
|
||||||
{
|
{
|
||||||
return Meter::Update();
|
return Meter::Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Draws the meter on the double buffer
|
** Draws the meter on the double buffer
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
bool MeterButton::Draw(Gfx::Canvas& canvas)
|
bool MeterButton::Draw(Gfx::Canvas& canvas)
|
||||||
{
|
{
|
||||||
if (!Meter::Draw(canvas)) return false;
|
if (!Meter::Draw(canvas)) return false;
|
||||||
|
|
||||||
if (m_Bitmaps[m_State] == nullptr) return false; // Unable to continue
|
if (m_Bitmaps[m_State] == nullptr) return false; // Unable to continue
|
||||||
|
|
||||||
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
|
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
|
||||||
|
|
||||||
Gdiplus::Rect meterRect = GetMeterRectPadding();
|
Gdiplus::Rect meterRect = GetMeterRectPadding();
|
||||||
|
|
||||||
// Blit the image
|
// Blit the image
|
||||||
graphics.DrawCachedBitmap(m_Bitmaps[m_State], meterRect.X, meterRect.Y);
|
graphics.DrawCachedBitmap(m_Bitmaps[m_State], meterRect.X, meterRect.Y);
|
||||||
|
|
||||||
canvas.EndGdiplusContext();
|
canvas.EndGdiplusContext();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Overridden method. The meters need not to be bound on anything
|
** Overridden method. The meters need not to be bound on anything
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MeterButton::BindMeasures(ConfigParser& parser, const WCHAR* section)
|
void MeterButton::BindMeasures(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
BindPrimaryMeasure(parser, section, true);
|
BindPrimaryMeasure(parser, section, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Checks if the given point is inside the button.
|
** Checks if the given point is inside the button.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
bool MeterButton::HitTest2(int px, int py)
|
bool MeterButton::HitTest2(int px, int py)
|
||||||
{
|
{
|
||||||
int x = GetX();
|
int x = GetX();
|
||||||
int y = GetY();
|
int y = GetY();
|
||||||
|
|
||||||
if (m_MouseOver &&
|
if (m_MouseOver &&
|
||||||
px >= x && px < x + m_W &&
|
px >= x && px < x + m_W &&
|
||||||
py >= y && py < y + m_H)
|
py >= y && py < y + m_H)
|
||||||
{
|
{
|
||||||
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check transparent pixels
|
// Check transparent pixels
|
||||||
if (m_Image.IsLoaded())
|
if (m_Image.IsLoaded())
|
||||||
{
|
{
|
||||||
Rect meterRect = GetMeterRectPadding();
|
Rect meterRect = GetMeterRectPadding();
|
||||||
int ix = meterRect.Width * m_State;
|
int ix = meterRect.Width * m_State;
|
||||||
px = px - meterRect.X + ix;
|
px = px - meterRect.X + ix;
|
||||||
py = py - meterRect.Y;
|
py = py - meterRect.Y;
|
||||||
if (px >= ix && px < ix + meterRect.Width &&
|
if (px >= ix && px < ix + meterRect.Width &&
|
||||||
py >= 0 && py < meterRect.Height)
|
py >= 0 && py < meterRect.Height)
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
Status status = m_Image.GetImage()->GetPixel(px, py, &color);
|
Status status = m_Image.GetImage()->GetPixel(px, py, &color);
|
||||||
if (status != Ok || color.GetA() != 0)
|
if (status != Ok || color.GetA() != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeterButton::MouseUp(POINT pos, bool execute)
|
bool MeterButton::MouseUp(POINT pos, bool execute)
|
||||||
{
|
{
|
||||||
if (m_State == BUTTON_STATE_DOWN)
|
if (m_State == BUTTON_STATE_DOWN)
|
||||||
{
|
{
|
||||||
if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y))
|
if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y))
|
||||||
{
|
{
|
||||||
Rainmeter::GetInstance().ExecuteCommand(m_Command.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(m_Command.c_str(), m_MeterWindow);
|
||||||
}
|
}
|
||||||
m_State = BUTTON_STATE_NORMAL;
|
m_State = BUTTON_STATE_NORMAL;
|
||||||
m_Clicked = false;
|
m_Clicked = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_Clicked = false;
|
m_Clicked = false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeterButton::MouseDown(POINT pos)
|
bool MeterButton::MouseDown(POINT pos)
|
||||||
{
|
{
|
||||||
if (m_Focus && HitTest2(pos.x, pos.y))
|
if (m_Focus && HitTest2(pos.x, pos.y))
|
||||||
{
|
{
|
||||||
m_State = BUTTON_STATE_DOWN;
|
m_State = BUTTON_STATE_DOWN;
|
||||||
m_Clicked = true;
|
m_Clicked = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeterButton::MouseMove(POINT pos)
|
bool MeterButton::MouseMove(POINT pos)
|
||||||
{
|
{
|
||||||
if (m_Clicked)
|
if (m_Clicked)
|
||||||
{
|
{
|
||||||
if (HitTest2(pos.x, pos.y))
|
if (HitTest2(pos.x, pos.y))
|
||||||
{
|
{
|
||||||
if (m_State == BUTTON_STATE_NORMAL)
|
if (m_State == BUTTON_STATE_NORMAL)
|
||||||
{
|
{
|
||||||
m_State = BUTTON_STATE_DOWN;
|
m_State = BUTTON_STATE_DOWN;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the left button is not down anymore the clicked state needs to be set false
|
// If the left button is not down anymore the clicked state needs to be set false
|
||||||
if (!IsLButtonDown())
|
if (!IsLButtonDown())
|
||||||
{
|
{
|
||||||
m_Clicked = false;
|
m_Clicked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_State == BUTTON_STATE_DOWN)
|
if (m_State == BUTTON_STATE_DOWN)
|
||||||
{
|
{
|
||||||
m_State = BUTTON_STATE_NORMAL;
|
m_State = BUTTON_STATE_NORMAL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (HitTest2(pos.x, pos.y))
|
if (HitTest2(pos.x, pos.y))
|
||||||
{
|
{
|
||||||
if (m_State == BUTTON_STATE_NORMAL)
|
if (m_State == BUTTON_STATE_NORMAL)
|
||||||
{
|
{
|
||||||
m_State = BUTTON_STATE_HOVER;
|
m_State = BUTTON_STATE_HOVER;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_State == BUTTON_STATE_HOVER)
|
if (m_State == BUTTON_STATE_HOVER)
|
||||||
{
|
{
|
||||||
m_State = BUTTON_STATE_NORMAL;
|
m_State = BUTTON_STATE_NORMAL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,285 +1,286 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2001 Kimmo Pekkola
|
Copyright (C) 2001 Kimmo Pekkola
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __RAINMETER_H__
|
#ifndef __RAINMETER_H__
|
||||||
#define __RAINMETER_H__
|
#define __RAINMETER_H__
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CommandHandler.h"
|
#include "CommandHandler.h"
|
||||||
#include "ContextMenu.h"
|
#include "ContextMenu.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "MeterWindow.h"
|
#include "MeterWindow.h"
|
||||||
#include "SkinRegistry.h"
|
#include "SkinRegistry.h"
|
||||||
|
|
||||||
#define MAX_LINE_LENGTH 4096
|
#define MAX_LINE_LENGTH 4096
|
||||||
|
|
||||||
#define APPNAME L"Rainmeter"
|
#define APPNAME L"Rainmeter"
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
#define APPBITS L"64-bit"
|
#define APPBITS L"64-bit"
|
||||||
#else
|
#else
|
||||||
#define APPBITS L"32-bit"
|
#define APPBITS L"32-bit"
|
||||||
#endif
|
#endif
|
||||||
#define WIDEN2(x) L ## x
|
#define WIDEN2(x) L ## x
|
||||||
#define WIDEN(x) WIDEN2(x)
|
#define WIDEN(x) WIDEN2(x)
|
||||||
#define APPDATE WIDEN(__DATE__)
|
#define APPDATE WIDEN(__DATE__)
|
||||||
|
|
||||||
#define RAINMETER_CLASS_NAME L"DummyRainWClass"
|
#define RAINMETER_CLASS_NAME L"DummyRainWClass"
|
||||||
#define RAINMETER_WINDOW_NAME L"Rainmeter control window"
|
#define RAINMETER_WINDOW_NAME L"Rainmeter control window"
|
||||||
|
|
||||||
#define WM_RAINMETER_DELAYED_REFRESH_ALL WM_APP + 0
|
#define WM_RAINMETER_DELAYED_REFRESH_ALL WM_APP + 0
|
||||||
#define WM_RAINMETER_DELAYED_EXECUTE WM_APP + 1
|
#define WM_RAINMETER_DELAYED_EXECUTE WM_APP + 1
|
||||||
#define WM_RAINMETER_EXECUTE WM_APP + 2
|
#define WM_RAINMETER_EXECUTE WM_APP + 2
|
||||||
|
|
||||||
struct GlobalOptions
|
struct GlobalOptions
|
||||||
{
|
{
|
||||||
double netInSpeed;
|
double netInSpeed;
|
||||||
double netOutSpeed;
|
double netOutSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigParser;
|
class ConfigParser;
|
||||||
class TrayWindow;
|
class TrayWindow;
|
||||||
|
|
||||||
class Rainmeter
|
class Rainmeter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Rainmeter& GetInstance();
|
static Rainmeter& GetInstance();
|
||||||
|
|
||||||
int Initialize(LPCWSTR iniPath, LPCWSTR layout);
|
int Initialize(LPCWSTR iniPath, LPCWSTR layout);
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
int MessagePump();
|
int MessagePump();
|
||||||
|
|
||||||
void SetNetworkStatisticsTimer();
|
void SetNetworkStatisticsTimer();
|
||||||
|
|
||||||
ConfigParser* GetCurrentParser() { return m_CurrentParser; }
|
ConfigParser* GetCurrentParser() { return m_CurrentParser; }
|
||||||
void SetCurrentParser(ConfigParser* parser) { m_CurrentParser = parser; }
|
void SetCurrentParser(ConfigParser* parser) { m_CurrentParser = parser; }
|
||||||
|
|
||||||
TrayWindow* GetTrayWindow() { return m_TrayWindow; }
|
TrayWindow* GetTrayWindow() { return m_TrayWindow; }
|
||||||
|
|
||||||
bool HasMeterWindow(const MeterWindow* meterWindow) const;
|
bool HasMeterWindow(const MeterWindow* meterWindow) const;
|
||||||
|
|
||||||
MeterWindow* GetMeterWindow(const std::wstring& folderPath);
|
MeterWindow* GetMeterWindow(const std::wstring& folderPath);
|
||||||
MeterWindow* GetMeterWindowByINI(const std::wstring& ini_searching);
|
MeterWindow* GetMeterWindowByINI(const std::wstring& ini_searching);
|
||||||
|
|
||||||
MeterWindow* GetMeterWindow(HWND hwnd);
|
MeterWindow* GetMeterWindow(HWND hwnd);
|
||||||
void GetMeterWindowsByLoadOrder(std::multimap<int, MeterWindow*>& windows, const std::wstring& group = std::wstring());
|
void GetMeterWindowsByLoadOrder(std::multimap<int, MeterWindow*>& windows, const std::wstring& group = std::wstring());
|
||||||
std::map<std::wstring, MeterWindow*>& GetAllMeterWindows() { return m_MeterWindows; }
|
std::map<std::wstring, MeterWindow*>& GetAllMeterWindows() { return m_MeterWindows; }
|
||||||
|
|
||||||
const std::vector<std::wstring>& GetAllLayouts() { return m_Layouts; }
|
const std::vector<std::wstring>& GetAllLayouts() { return m_Layouts; }
|
||||||
|
|
||||||
void RemoveMeterWindow(MeterWindow* meterWindow);
|
void RemoveMeterWindow(MeterWindow* meterWindow);
|
||||||
void AddUnmanagedMeterWindow(MeterWindow* meterWindow);
|
void AddUnmanagedMeterWindow(MeterWindow* meterWindow);
|
||||||
void RemoveUnmanagedMeterWindow(MeterWindow* meterWindow);
|
void RemoveUnmanagedMeterWindow(MeterWindow* meterWindow);
|
||||||
|
|
||||||
bool ActivateSkin(const std::wstring& folderPath);
|
bool ActivateSkin(const std::wstring& folderPath);
|
||||||
bool ActivateSkin(const std::wstring& folderPath, const std::wstring& file);
|
bool ActivateSkin(const std::wstring& folderPath, const std::wstring& file);
|
||||||
void ActivateSkin(int folderIndex, int fileIndex);
|
void ActivateSkin(int folderIndex, int fileIndex);
|
||||||
void DeactivateSkin(MeterWindow* meterWindow, int folderIndex, bool save = true);
|
void DeactivateSkin(MeterWindow* meterWindow, int folderIndex, bool save = true);
|
||||||
void ToggleSkin(int folderIndex, int fileIndex);
|
void ToggleSkin(int folderIndex, int fileIndex);
|
||||||
void ToggleSkinWithID(UINT id);
|
void ToggleSkinWithID(UINT id);
|
||||||
|
|
||||||
const std::wstring& GetPath() { return m_Path; }
|
const std::wstring& GetPath() { return m_Path; }
|
||||||
const std::wstring& GetIniFile() { return m_IniFile; }
|
const std::wstring& GetIniFile() { return m_IniFile; }
|
||||||
const std::wstring& GetDataFile() { return m_DataFile; }
|
const std::wstring& GetDataFile() { return m_DataFile; }
|
||||||
const std::wstring& GetSettingsPath() { return m_SettingsPath; }
|
const std::wstring& GetSettingsPath() { return m_SettingsPath; }
|
||||||
const std::wstring& GetSkinPath() { return m_SkinPath; }
|
const std::wstring& GetSkinPath() { return m_SkinPath; }
|
||||||
void SetSkinPath(const std::wstring& skinPath);
|
void SetSkinPath(const std::wstring& skinPath);
|
||||||
std::wstring GetLayoutPath() { return m_SettingsPath + L"Layouts\\"; }
|
std::wstring GetLayoutPath() { return m_SettingsPath + L"Layouts\\"; }
|
||||||
std::wstring GetPluginPath() { return m_Path + L"Plugins\\"; }
|
std::wstring GetPluginPath() { return m_Path + L"Plugins\\"; }
|
||||||
std::wstring GetUserPluginPath() { return m_SettingsPath + L"Plugins\\"; }
|
std::wstring GetUserPluginPath() { return m_SettingsPath + L"Plugins\\"; }
|
||||||
std::wstring GetAddonPath() { return m_SettingsPath + L"Addons\\"; }
|
std::wstring GetAddonPath() { return m_SettingsPath + L"Addons\\"; }
|
||||||
|
|
||||||
bool HasUserPluginPath() { return (_wcsicmp(m_Path.c_str(), m_SettingsPath.c_str()) != 0); }
|
bool HasUserPluginPath() { return (_wcsicmp(m_Path.c_str(), m_SettingsPath.c_str()) != 0); }
|
||||||
|
|
||||||
std::wstring GetDefaultSkinPath() { return m_Path + L"Defaults\\Skins\\"; }
|
std::wstring GetDefaultSkinPath() { return m_Path + L"Defaults\\Skins\\"; }
|
||||||
std::wstring GetDefaultLayoutPath() { return m_Path + L"Defaults\\Layouts\\"; }
|
std::wstring GetDefaultLayoutPath() { return m_Path + L"Defaults\\Layouts\\"; }
|
||||||
std::wstring GetDefaultPluginPath() { return m_Path + L"Defaults\\Plugins\\"; }
|
std::wstring GetDefaultPluginPath() { return m_Path + L"Defaults\\Plugins\\"; }
|
||||||
std::wstring GetDefaultAddonPath() { return m_Path + L"Defaults\\Addons\\"; }
|
std::wstring GetDefaultAddonPath() { return m_Path + L"Defaults\\Addons\\"; }
|
||||||
|
|
||||||
const std::wstring& GetDrive() { return m_Drive; }
|
const std::wstring& GetDrive() { return m_Drive; }
|
||||||
|
|
||||||
const std::wstring& GetSkinEditor() { return m_SkinEditor; }
|
const std::wstring& GetSkinEditor() { return m_SkinEditor; }
|
||||||
void SetSkinEditor(const std::wstring& path);
|
void SetSkinEditor(const std::wstring& path);
|
||||||
const std::wstring& GetStatsDate() { return m_StatsDate; }
|
const std::wstring& GetStatsDate() { return m_StatsDate; }
|
||||||
|
|
||||||
HWND GetWindow() { return m_Window; }
|
HWND GetWindow() { return m_Window; }
|
||||||
|
|
||||||
HINSTANCE GetModuleInstance() { return m_Instance; }
|
HINSTANCE GetModuleInstance() { return m_Instance; }
|
||||||
HINSTANCE GetResourceInstance() { return m_ResourceInstance; }
|
HINSTANCE GetResourceInstance() { return m_ResourceInstance; }
|
||||||
LCID GetResourceLCID() { return m_ResourceLCID; }
|
LCID GetResourceLCID() { return m_ResourceLCID; }
|
||||||
|
|
||||||
bool GetUseD2D() const { return m_UseD2D; }
|
bool GetUseD2D() const { return m_UseD2D; }
|
||||||
void SetUseD2D(bool enabled);
|
void SetUseD2D(bool enabled);
|
||||||
|
|
||||||
bool GetDebug() { return m_Debug; }
|
bool GetDebug() { return m_Debug; }
|
||||||
|
|
||||||
GlobalOptions& GetGlobalOptions() { return m_GlobalOptions; }
|
GlobalOptions& GetGlobalOptions() { return m_GlobalOptions; }
|
||||||
|
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
void EditSettings();
|
void EditSettings();
|
||||||
void EditSkinFile(const std::wstring& name, const std::wstring& iniFile);
|
void EditSkinFile(const std::wstring& name, const std::wstring& iniFile);
|
||||||
void OpenSkinFolder(const std::wstring& name = std::wstring());
|
void OpenSkinFolder(const std::wstring& name = std::wstring());
|
||||||
|
|
||||||
void UpdateStats();
|
void UpdateStats();
|
||||||
void ReadStats();
|
void ReadStats();
|
||||||
void WriteStats(bool bForce);
|
void WriteStats(bool bForce);
|
||||||
void ResetStats();
|
void ResetStats();
|
||||||
|
|
||||||
bool GetDisableVersionCheck() { return m_DisableVersionCheck; }
|
bool GetDisableVersionCheck() { return m_DisableVersionCheck; }
|
||||||
void SetDisableVersionCheck(bool check);
|
void SetDisableVersionCheck(bool check);
|
||||||
bool GetNewVersion() { return m_NewVersion; }
|
bool GetNewVersion() { return m_NewVersion; }
|
||||||
void SetNewVersion() { m_NewVersion = true; }
|
void SetNewVersion() { m_NewVersion = true; }
|
||||||
|
|
||||||
void ShowLogFile();
|
void ShowLogFile();
|
||||||
|
|
||||||
bool GetDisableRDP() { return m_DisableRDP; }
|
bool GetDisableRDP() { return m_DisableRDP; }
|
||||||
bool IsRedrawable() { return (!GetDisableRDP() || !GetSystemMetrics(SM_REMOTESESSION)); }
|
bool IsRedrawable() { return (!GetDisableRDP() || !GetSystemMetrics(SM_REMOTESESSION)); }
|
||||||
|
|
||||||
bool GetDisableDragging() { return m_DisableDragging; }
|
bool GetDisableDragging() { return m_DisableDragging; }
|
||||||
void SetDisableDragging(bool dragging);
|
void SetDisableDragging(bool dragging);
|
||||||
|
|
||||||
bool IsNormalStayDesktop() { return m_NormalStayDesktop; }
|
bool IsNormalStayDesktop() { return m_NormalStayDesktop; }
|
||||||
|
|
||||||
void SetDebug(bool debug);
|
void SetDebug(bool debug);
|
||||||
|
|
||||||
int ShowMessage(HWND parent, const WCHAR* text, UINT type);
|
int ShowMessage(HWND parent, const WCHAR* text, UINT type);
|
||||||
|
|
||||||
bool IsMenuActive() { return m_ContextMenu.IsMenuActive(); }
|
bool IsMenuActive() { return m_ContextMenu.IsMenuActive(); }
|
||||||
void ShowContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowMenu(pos, mw); }
|
void ShowContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowMenu(pos, mw); }
|
||||||
void ShowSkinCustomContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowSkinCustomMenu(pos, mw); }
|
void ShowSkinCustomContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowSkinCustomMenu(pos, mw); }
|
||||||
|
|
||||||
const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
|
const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
|
||||||
const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }
|
const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }
|
||||||
const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; }
|
const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; }
|
||||||
const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; }
|
const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; }
|
||||||
|
|
||||||
void ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, MeterWindow* meterWindow);
|
void ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, MeterWindow* meterWindow);
|
||||||
void ExecuteCommand(const WCHAR* command, MeterWindow* meterWindow, bool multi = true);
|
void ExecuteCommand(const WCHAR* command, MeterWindow* meterWindow, bool multi = true);
|
||||||
void DelayedExecuteCommand(const WCHAR* command);
|
void DelayedExecuteCommand(const WCHAR* command);
|
||||||
|
|
||||||
void RefreshAll();
|
void RefreshAll();
|
||||||
|
|
||||||
bool LoadLayout(const std::wstring& name);
|
bool LoadLayout(const std::wstring& name);
|
||||||
void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true);
|
void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true);
|
||||||
|
|
||||||
friend class CommandHandler;
|
friend class CommandHandler;
|
||||||
friend class ContextMenu;
|
friend class ContextMenu;
|
||||||
friend class DialogManage;
|
friend class DialogManage;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Rainmeter();
|
Rainmeter();
|
||||||
~Rainmeter();
|
~Rainmeter();
|
||||||
|
|
||||||
Rainmeter(const Rainmeter& other) = delete;
|
Rainmeter(const Rainmeter& other) = delete;
|
||||||
Rainmeter& operator=(Rainmeter other) = delete;
|
Rainmeter& operator=(Rainmeter other) = delete;
|
||||||
|
|
||||||
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
void ActivateActiveSkins();
|
void ActivateActiveSkins();
|
||||||
void CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file);
|
void CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file);
|
||||||
void DeleteAllMeterWindows();
|
void DeleteAllMeterWindows();
|
||||||
void DeleteAllUnmanagedMeterWindows();
|
void DeleteAllUnmanagedMeterWindows();
|
||||||
void WriteActive(const std::wstring& folderPath, int fileIndex);
|
void WriteActive(const std::wstring& folderPath, int fileIndex);
|
||||||
void ScanForSkins();
|
void ScanForSkins();
|
||||||
void ScanForLayouts();
|
void ScanForLayouts();
|
||||||
void ReadGeneralSettings(const std::wstring& iniFile);
|
void ReadGeneralSettings(const std::wstring& iniFile);
|
||||||
void SetLoadOrder(int folderIndex, int order);
|
void SetLoadOrder(int folderIndex, int order);
|
||||||
int GetLoadOrder(const std::wstring& folderPath);
|
int GetLoadOrder(const std::wstring& folderPath);
|
||||||
void UpdateDesktopWorkArea(bool reset);
|
void UpdateDesktopWorkArea(bool reset);
|
||||||
|
|
||||||
void CreateOptionsFile();
|
void CreateOptionsFile();
|
||||||
void CreateDataFile();
|
void CreateDataFile();
|
||||||
void CreateComponentFolders(bool defaultIniLocation);
|
void CreateComponentFolders(bool defaultIniLocation);
|
||||||
void TestSettingsFile(bool bDefaultIniLocation);
|
void TestSettingsFile(bool bDefaultIniLocation);
|
||||||
|
|
||||||
TrayWindow* m_TrayWindow;
|
TrayWindow* m_TrayWindow;
|
||||||
|
|
||||||
std::multimap<int, int> m_SkinOrders;
|
std::multimap<int, int> m_SkinOrders;
|
||||||
std::map<std::wstring, MeterWindow*> m_MeterWindows;
|
std::map<std::wstring, MeterWindow*> m_MeterWindows;
|
||||||
std::list<MeterWindow*> m_UnmanagedMeterWindows;
|
std::list<MeterWindow*> m_UnmanagedMeterWindows;
|
||||||
std::vector<std::wstring> m_Layouts;
|
std::vector<std::wstring> m_Layouts;
|
||||||
|
|
||||||
std::wstring m_Path;
|
std::wstring m_Path;
|
||||||
std::wstring m_IniFile;
|
std::wstring m_IniFile;
|
||||||
std::wstring m_DataFile;
|
std::wstring m_DataFile;
|
||||||
std::wstring m_StatsFile;
|
std::wstring m_StatsFile;
|
||||||
std::wstring m_SettingsPath;
|
std::wstring m_SettingsPath;
|
||||||
std::wstring m_SkinPath;
|
std::wstring m_SkinPath;
|
||||||
|
|
||||||
std::wstring m_Drive;
|
std::wstring m_Drive;
|
||||||
|
|
||||||
std::wstring m_StatsDate;
|
std::wstring m_StatsDate;
|
||||||
|
|
||||||
std::wstring m_TrayExecuteR;
|
std::wstring m_TrayExecuteR;
|
||||||
std::wstring m_TrayExecuteM;
|
std::wstring m_TrayExecuteM;
|
||||||
std::wstring m_TrayExecuteDR;
|
std::wstring m_TrayExecuteDR;
|
||||||
std::wstring m_TrayExecuteDM;
|
std::wstring m_TrayExecuteDM;
|
||||||
|
|
||||||
bool m_UseD2D;
|
bool m_UseD2D;
|
||||||
|
|
||||||
bool m_Debug;
|
bool m_Debug;
|
||||||
|
|
||||||
bool m_DisableVersionCheck;
|
bool m_DisableVersionCheck;
|
||||||
bool m_NewVersion;
|
bool m_NewVersion;
|
||||||
|
|
||||||
bool m_DesktopWorkAreaChanged;
|
bool m_DesktopWorkAreaChanged;
|
||||||
bool m_DesktopWorkAreaType;
|
bool m_DesktopWorkAreaType;
|
||||||
std::map<UINT, RECT> m_DesktopWorkAreas;
|
std::map<UINT, RECT> m_DesktopWorkAreas;
|
||||||
std::vector<RECT> m_OldDesktopWorkAreas;
|
std::vector<RECT> m_OldDesktopWorkAreas;
|
||||||
|
|
||||||
bool m_NormalStayDesktop;
|
bool m_NormalStayDesktop;
|
||||||
|
|
||||||
bool m_DisableRDP;
|
bool m_DisableRDP;
|
||||||
|
|
||||||
bool m_DisableDragging;
|
bool m_DisableDragging;
|
||||||
|
|
||||||
std::wstring m_SkinEditor;
|
std::wstring m_SkinEditor;
|
||||||
|
|
||||||
CommandHandler m_CommandHandler;
|
CommandHandler m_CommandHandler;
|
||||||
ContextMenu m_ContextMenu;
|
ContextMenu m_ContextMenu;
|
||||||
SkinRegistry m_SkinRegistry;
|
SkinRegistry m_SkinRegistry;
|
||||||
|
|
||||||
ConfigParser* m_CurrentParser;
|
ConfigParser* m_CurrentParser;
|
||||||
|
|
||||||
HWND m_Window;
|
HWND m_Window;
|
||||||
|
|
||||||
HANDLE m_Mutex;
|
HANDLE m_Mutex;
|
||||||
HINSTANCE m_Instance;
|
HINSTANCE m_Instance;
|
||||||
HMODULE m_ResourceInstance;
|
HMODULE m_ResourceInstance;
|
||||||
LCID m_ResourceLCID;
|
LCID m_ResourceLCID;
|
||||||
|
|
||||||
ULONG_PTR m_GDIplusToken;
|
ULONG_PTR m_GDIplusToken;
|
||||||
|
|
||||||
GlobalOptions m_GlobalOptions;
|
GlobalOptions m_GlobalOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LIBRARY_EXPORTS
|
// Convenience function.
|
||||||
#define EXPORT_PLUGIN EXTERN_C __declspec(dllexport)
|
inline Rainmeter& GetRainmeter() { return Rainmeter::GetInstance(); }
|
||||||
#else
|
|
||||||
#define EXPORT_PLUGIN EXTERN_C __declspec(dllimport)
|
#ifdef LIBRARY_EXPORTS
|
||||||
#endif
|
#define EXPORT_PLUGIN EXTERN_C
|
||||||
|
#else
|
||||||
EXPORT_PLUGIN int RainmeterMain(LPWSTR cmdLine);
|
#define EXPORT_PLUGIN EXTERN_C __declspec(dllimport)
|
||||||
EXPORT_PLUGIN void* Rainmeter_Initialize();
|
#endif
|
||||||
EXPORT_PLUGIN void Rainmeter_Finalize(void* ptr);
|
|
||||||
|
EXPORT_PLUGIN int RainmeterMain(LPWSTR cmdLine);
|
||||||
#endif
|
|
||||||
|
#endif
|
||||||
|
@ -1,87 +1,87 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2013 spx
|
Copyright (C) 2013 spx
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Section.h"
|
#include "Section.h"
|
||||||
#include "ConfigParser.h"
|
#include "ConfigParser.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The constructor
|
** The constructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
Section::Section(MeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name),
|
Section::Section(MeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name),
|
||||||
m_DynamicVariables(false),
|
m_DynamicVariables(false),
|
||||||
m_UpdateDivider(1),
|
m_UpdateDivider(1),
|
||||||
m_UpdateCounter(1)
|
m_UpdateCounter(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The destructor
|
** The destructor
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
Section::~Section()
|
Section::~Section()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Read the common options specified in the ini file. The inherited classes must
|
** Read the common options specified in the ini file. The inherited classes must
|
||||||
** call this base implementation if they overwrite this method.
|
** call this base implementation if they overwrite this method.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
|
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
|
||||||
if (updateDivider != m_UpdateDivider)
|
if (updateDivider != m_UpdateDivider)
|
||||||
{
|
{
|
||||||
m_UpdateCounter = m_UpdateDivider = updateDivider;
|
m_UpdateCounter = m_UpdateDivider = updateDivider;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_DynamicVariables = parser.ReadBool(section, L"DynamicVariables", false);
|
m_DynamicVariables = parser.ReadBool(section, L"DynamicVariables", false);
|
||||||
|
|
||||||
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
|
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
|
||||||
|
|
||||||
const std::wstring& group = parser.ReadString(section, L"Group", L"");
|
const std::wstring& group = parser.ReadString(section, L"Group", L"");
|
||||||
InitializeGroup(group);
|
InitializeGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Updates the counter value
|
** Updates the counter value
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
bool Section::UpdateCounter()
|
bool Section::UpdateCounter()
|
||||||
{
|
{
|
||||||
++m_UpdateCounter;
|
++m_UpdateCounter;
|
||||||
if (m_UpdateCounter < m_UpdateDivider) return false;
|
if (m_UpdateCounter < m_UpdateDivider) return false;
|
||||||
m_UpdateCounter = 0;
|
m_UpdateCounter = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Execute OnUpdateAction if action is set
|
** Execute OnUpdateAction if action is set
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void Section::DoUpdateAction()
|
void Section::DoUpdateAction()
|
||||||
{
|
{
|
||||||
if (!m_OnUpdateAction.empty())
|
if (!m_OnUpdateAction.empty())
|
||||||
{
|
{
|
||||||
Rainmeter::GetInstance().ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2812
Library/System.cpp
2812
Library/System.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,97 +1,97 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2004 Kimmo Pekkola
|
Copyright (C) 2004 Kimmo Pekkola
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Litestep.h"
|
#include "Litestep.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "TrayWindow.h"
|
#include "TrayWindow.h"
|
||||||
#include "../Version.h"
|
#include "../Version.h"
|
||||||
|
|
||||||
void CheckVersion(void* dummy)
|
void CheckVersion(void* dummy)
|
||||||
{
|
{
|
||||||
HINTERNET hRootHandle = InternetOpen(
|
HINTERNET hRootHandle = InternetOpen(
|
||||||
L"Rainmeter",
|
L"Rainmeter",
|
||||||
INTERNET_OPEN_TYPE_PRECONFIG,
|
INTERNET_OPEN_TYPE_PRECONFIG,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (hRootHandle == nullptr)
|
if (hRootHandle == nullptr)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HINTERNET hUrlDump = InternetOpenUrl(
|
HINTERNET hUrlDump = InternetOpenUrl(
|
||||||
hRootHandle, L"http://rainmeter.github.io/rainmeter/release", nullptr, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
|
hRootHandle, L"http://rainmeter.github.io/rainmeter/release", nullptr, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
|
||||||
if (hUrlDump)
|
if (hUrlDump)
|
||||||
{
|
{
|
||||||
DWORD dwSize;
|
DWORD dwSize;
|
||||||
char urlData[16] = {0};
|
char urlData[16] = {0};
|
||||||
if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
|
if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
|
||||||
{
|
{
|
||||||
auto parseVersion = [](const WCHAR* str)->int
|
auto parseVersion = [](const WCHAR* str)->int
|
||||||
{
|
{
|
||||||
int version = _wtoi(str) * 1000000;
|
int version = _wtoi(str) * 1000000;
|
||||||
const WCHAR* pos = wcschr(str, L'.');
|
const WCHAR* pos = wcschr(str, L'.');
|
||||||
if (pos)
|
if (pos)
|
||||||
{
|
{
|
||||||
++pos; // Skip .
|
++pos; // Skip .
|
||||||
version += _wtoi(pos) * 1000;
|
version += _wtoi(pos) * 1000;
|
||||||
|
|
||||||
pos = wcschr(pos, '.');
|
pos = wcschr(pos, '.');
|
||||||
if (pos)
|
if (pos)
|
||||||
{
|
{
|
||||||
++pos; // Skip .
|
++pos; // Skip .
|
||||||
version += _wtoi(pos);
|
version += _wtoi(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::wstring tmpSz = StringUtil::Widen(urlData);
|
std::wstring tmpSz = StringUtil::Widen(urlData);
|
||||||
const WCHAR* version = tmpSz.c_str();
|
const WCHAR* version = tmpSz.c_str();
|
||||||
|
|
||||||
int availableVersion = parseVersion(version);
|
int availableVersion = parseVersion(version);
|
||||||
if (availableVersion > RAINMETER_VERSION ||
|
if (availableVersion > RAINMETER_VERSION ||
|
||||||
(revision_beta && availableVersion == RAINMETER_VERSION))
|
(revision_beta && availableVersion == RAINMETER_VERSION))
|
||||||
{
|
{
|
||||||
Rainmeter::GetInstance().SetNewVersion();
|
GetRainmeter().SetNewVersion();
|
||||||
|
|
||||||
WCHAR buffer[32];
|
WCHAR buffer[32];
|
||||||
const WCHAR* dataFile = Rainmeter::GetInstance().GetDataFile().c_str();
|
const WCHAR* dataFile = GetRainmeter().GetDataFile().c_str();
|
||||||
GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);
|
GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);
|
||||||
|
|
||||||
// Show tray notification only once per new version
|
// Show tray notification only once per new version
|
||||||
int lastVersion = parseVersion(buffer);
|
int lastVersion = parseVersion(buffer);
|
||||||
if (availableVersion > lastVersion)
|
if (availableVersion > lastVersion)
|
||||||
{
|
{
|
||||||
Rainmeter::GetInstance().GetTrayWindow()->ShowUpdateNotification(version);
|
GetRainmeter().GetTrayWindow()->ShowUpdateNotification(version);
|
||||||
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
|
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InternetCloseHandle(hUrlDump);
|
InternetCloseHandle(hUrlDump);
|
||||||
}
|
}
|
||||||
|
|
||||||
InternetCloseHandle(hRootHandle);
|
InternetCloseHandle(hRootHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckUpdate()
|
void CheckUpdate()
|
||||||
{
|
{
|
||||||
_beginthread(CheckVersion, 0, nullptr);
|
_beginthread(CheckVersion, 0, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -1,240 +1,240 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2010 Matt King, Birunthan Mohanathas
|
Copyright (C) 2010 Matt King, Birunthan Mohanathas
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "../LuaManager.h"
|
#include "../LuaManager.h"
|
||||||
#include "../../Rainmeter.h"
|
#include "../../Rainmeter.h"
|
||||||
#include "../../MeterWindow.h"
|
#include "../../MeterWindow.h"
|
||||||
#include "../../MeterString.h"
|
#include "../../MeterString.h"
|
||||||
|
|
||||||
#define DECLARE_SELF(L) \
|
#define DECLARE_SELF(L) \
|
||||||
void* selfData = lua_touserdata(L, 1); \
|
void* selfData = lua_touserdata(L, 1); \
|
||||||
if (!selfData) return 0; \
|
if (!selfData) return 0; \
|
||||||
MeterWindow* self = *(MeterWindow**)selfData;
|
MeterWindow* self = *(MeterWindow**)selfData;
|
||||||
|
|
||||||
static int Bang(lua_State* L)
|
static int Bang(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
ConfigParser& parser = self->GetParser();
|
ConfigParser& parser = self->GetParser();
|
||||||
|
|
||||||
std::wstring bang = LuaManager::ToWide(2);
|
std::wstring bang = LuaManager::ToWide(2);
|
||||||
|
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
if (top == 2) // 1 argument
|
if (top == 2) // 1 argument
|
||||||
{
|
{
|
||||||
parser.ReplaceVariables(bang);
|
parser.ReplaceVariables(bang);
|
||||||
Rainmeter::GetInstance().ExecuteCommand(bang.c_str(), self);
|
GetRainmeter().ExecuteCommand(bang.c_str(), self);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const WCHAR* bangSz = bang.c_str();
|
const WCHAR* bangSz = bang.c_str();
|
||||||
if (*bangSz == L'!')
|
if (*bangSz == L'!')
|
||||||
{
|
{
|
||||||
++bangSz; // Skip "!"
|
++bangSz; // Skip "!"
|
||||||
std::vector<std::wstring> args;
|
std::vector<std::wstring> args;
|
||||||
for (int i = 3; i <= top; ++i)
|
for (int i = 3; i <= top; ++i)
|
||||||
{
|
{
|
||||||
std::wstring tmpSz = LuaManager::ToWide(i);
|
std::wstring tmpSz = LuaManager::ToWide(i);
|
||||||
parser.ReplaceVariables(tmpSz);
|
parser.ReplaceVariables(tmpSz);
|
||||||
args.push_back(tmpSz);
|
args.push_back(tmpSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rainmeter::GetInstance().ExecuteBang(bangSz, args, self);
|
GetRainmeter().ExecuteBang(bangSz, args, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetMeter(lua_State* L)
|
static int GetMeter(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
const std::wstring meterName = LuaManager::ToWide(2);
|
const std::wstring meterName = LuaManager::ToWide(2);
|
||||||
|
|
||||||
Meter* meter = self->GetMeter(meterName);
|
Meter* meter = self->GetMeter(meterName);
|
||||||
if (meter)
|
if (meter)
|
||||||
{
|
{
|
||||||
*(Meter**)lua_newuserdata(L, sizeof(Meter*)) = meter;
|
*(Meter**)lua_newuserdata(L, sizeof(Meter*)) = meter;
|
||||||
lua_getglobal(L, "Meter");
|
lua_getglobal(L, "Meter");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetMeasure(lua_State* L)
|
static int GetMeasure(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
const std::wstring measureName = LuaManager::ToWide(2);
|
const std::wstring measureName = LuaManager::ToWide(2);
|
||||||
|
|
||||||
Measure* measure = self->GetMeasure(measureName);
|
Measure* measure = self->GetMeasure(measureName);
|
||||||
if (measure)
|
if (measure)
|
||||||
{
|
{
|
||||||
*(Measure**)lua_newuserdata(L, sizeof(Measure*)) = measure;
|
*(Measure**)lua_newuserdata(L, sizeof(Measure*)) = measure;
|
||||||
lua_getglobal(L, "Measure");
|
lua_getglobal(L, "Measure");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetVariable(lua_State* L)
|
static int GetVariable(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
|
|
||||||
const std::wstring name = LuaManager::ToWide(2);
|
const std::wstring name = LuaManager::ToWide(2);
|
||||||
const std::wstring* value = self->GetParser().GetVariable(name);
|
const std::wstring* value = self->GetParser().GetVariable(name);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
LuaManager::PushWide(*value);
|
LuaManager::PushWide(*value);
|
||||||
}
|
}
|
||||||
else if (lua_gettop(L) >= 3)
|
else if (lua_gettop(L) >= 3)
|
||||||
{
|
{
|
||||||
lua_pushvalue(L, 3);
|
lua_pushvalue(L, 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ReplaceVariables(lua_State* L)
|
static int ReplaceVariables(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
std::wstring strTmp = LuaManager::ToWide(2);
|
std::wstring strTmp = LuaManager::ToWide(2);
|
||||||
|
|
||||||
self->GetParser().ReplaceVariables(strTmp);
|
self->GetParser().ReplaceVariables(strTmp);
|
||||||
self->GetParser().ReplaceMeasures(strTmp);
|
self->GetParser().ReplaceMeasures(strTmp);
|
||||||
LuaManager::PushWide(strTmp);
|
LuaManager::PushWide(strTmp);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ParseFormula(lua_State* L)
|
static int ParseFormula(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
std::wstring strTmp = LuaManager::ToWide(2);
|
std::wstring strTmp = LuaManager::ToWide(2);
|
||||||
|
|
||||||
double result;
|
double result;
|
||||||
if (!self->GetParser().ParseFormula(strTmp, &result))
|
if (!self->GetParser().ParseFormula(strTmp, &result))
|
||||||
{
|
{
|
||||||
result = lua_tonumber(L, 2);
|
result = lua_tonumber(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushnumber(L, result);
|
lua_pushnumber(L, result);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int MoveWindow(lua_State* L)
|
static int MoveWindow(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
int x = (int)lua_tonumber(L, 2);
|
int x = (int)lua_tonumber(L, 2);
|
||||||
int y = (int)lua_tonumber(L, 3);
|
int y = (int)lua_tonumber(L, 3);
|
||||||
self->MoveWindow(x, y);
|
self->MoveWindow(x, y);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FadeWindow(lua_State* L)
|
static int FadeWindow(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
int from = (int)lua_tonumber(L, 2);
|
int from = (int)lua_tonumber(L, 2);
|
||||||
int to = (int)lua_tonumber(L, 3);
|
int to = (int)lua_tonumber(L, 3);
|
||||||
self->FadeWindow(from, to);
|
self->FadeWindow(from, to);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetW(lua_State* L)
|
static int GetW(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
lua_pushnumber(L, self->GetW());
|
lua_pushnumber(L, self->GetW());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetH(lua_State* L)
|
static int GetH(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
lua_pushnumber(L, self->GetH());
|
lua_pushnumber(L, self->GetH());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetX(lua_State* L)
|
static int GetX(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
lua_pushnumber(L, self->GetX());
|
lua_pushnumber(L, self->GetX());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetY(lua_State* L)
|
static int GetY(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
lua_pushnumber(L, self->GetY());
|
lua_pushnumber(L, self->GetY());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int MakePathAbsolute(lua_State* L)
|
static int MakePathAbsolute(lua_State* L)
|
||||||
{
|
{
|
||||||
DECLARE_SELF(L)
|
DECLARE_SELF(L)
|
||||||
std::wstring path = LuaManager::ToWide(2);
|
std::wstring path = LuaManager::ToWide(2);
|
||||||
self->MakePathAbsolute(path);
|
self->MakePathAbsolute(path);
|
||||||
LuaManager::PushWide(path);
|
LuaManager::PushWide(path);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::RegisterMeterWindow(lua_State* L)
|
void LuaManager::RegisterMeterWindow(lua_State* L)
|
||||||
{
|
{
|
||||||
const luaL_Reg functions[] =
|
const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "Bang", Bang },
|
{ "Bang", Bang },
|
||||||
{ "GetMeter", GetMeter },
|
{ "GetMeter", GetMeter },
|
||||||
{ "GetMeasure", GetMeasure },
|
{ "GetMeasure", GetMeasure },
|
||||||
{ "GetVariable", GetVariable },
|
{ "GetVariable", GetVariable },
|
||||||
{ "ReplaceVariables", ReplaceVariables },
|
{ "ReplaceVariables", ReplaceVariables },
|
||||||
{ "ParseFormula", ParseFormula },
|
{ "ParseFormula", ParseFormula },
|
||||||
{ "MoveWindow", MoveWindow },
|
{ "MoveWindow", MoveWindow },
|
||||||
{ "FadeWindow", FadeWindow },
|
{ "FadeWindow", FadeWindow },
|
||||||
{ "GetW", GetW },
|
{ "GetW", GetW },
|
||||||
{ "GetH", GetH },
|
{ "GetH", GetH },
|
||||||
{ "GetX", GetX },
|
{ "GetX", GetX },
|
||||||
{ "GetY", GetY },
|
{ "GetY", GetY },
|
||||||
{ "MakePathAbsolute", MakePathAbsolute },
|
{ "MakePathAbsolute", MakePathAbsolute },
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
luaL_register(L, "MeterWindow", functions);
|
luaL_register(L, "MeterWindow", functions);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user