mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Disabled "Log file created" messagebox
- Fixed empty messagebox when Rainmeter is launched with Logging=1 and no existing log file - Minor changes to log output
This commit is contained in:
parent
2c6ed8ed69
commit
ac840c1599
@ -40,5 +40,8 @@
|
||||
*/
|
||||
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
||||
//_CrtSetBreakAlloc(000);
|
||||
|
||||
return RainmeterMain(hInstance, lpCmdLine);
|
||||
}
|
||||
|
@ -27,13 +27,6 @@ extern CRainmeter* Rainmeter;
|
||||
static CRITICAL_SECTION g_CsLog = {0};
|
||||
static CRITICAL_SECTION g_CsLogDelay = {0};
|
||||
|
||||
static int logFound = 0;
|
||||
|
||||
void ResetLoggingFlag()
|
||||
{
|
||||
logFound = 0;
|
||||
}
|
||||
|
||||
void InitalizeLitestep()
|
||||
{
|
||||
InitializeCriticalSection(&g_CsLog);
|
||||
@ -302,7 +295,7 @@ std::wstring ConvertUTF8ToWide(LPCSTR str)
|
||||
return szWide;
|
||||
}
|
||||
|
||||
BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
|
||||
void LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
|
||||
{
|
||||
// Add timestamp
|
||||
WCHAR buffer[128];
|
||||
@ -310,79 +303,53 @@ BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
|
||||
|
||||
Rainmeter->AddAboutLogInfo(nLevel, buffer, pszMessage);
|
||||
|
||||
std::wstring message(1, L'(');
|
||||
#ifndef _DEBUG
|
||||
if (!Rainmeter->GetLogging()) return;
|
||||
#endif
|
||||
|
||||
std::wstring message;
|
||||
switch (nLevel)
|
||||
{
|
||||
case LOG_ERROR:
|
||||
message = L"ERRO";
|
||||
break;
|
||||
|
||||
case LOG_WARNING:
|
||||
message = L"WARN";
|
||||
break;
|
||||
|
||||
case LOG_NOTICE:
|
||||
message = L"NOTE";
|
||||
break;
|
||||
|
||||
case LOG_DEBUG:
|
||||
message = L"DBUG";
|
||||
break;
|
||||
}
|
||||
|
||||
message += L" (";
|
||||
message.append(buffer, len);
|
||||
message += L") ";
|
||||
message += pszMessage;
|
||||
message += L'\n';
|
||||
|
||||
#ifdef _DEBUG
|
||||
_RPT0(_CRT_WARN, ConvertToAscii(message.c_str()).c_str());
|
||||
_RPT0(_CRT_WARN, "\n");
|
||||
#endif
|
||||
|
||||
// The stub implementation
|
||||
if (Rainmeter->GetLogging())
|
||||
const WCHAR* logFile = Rainmeter->GetLogFile().c_str();
|
||||
if (_waccess(logFile, 0) == -1)
|
||||
{
|
||||
const std::wstring& logfile = Rainmeter->GetLogFile();
|
||||
if (logFound == 0)
|
||||
// Disable logging if the file was deleted manually
|
||||
Rainmeter->StopLogging();
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE* file = _wfopen(logFile, L"a+, ccs=UTF-8");
|
||||
if (file)
|
||||
{
|
||||
// Check if the file exists
|
||||
if (_waccess(logfile.c_str(), 0) != -1)
|
||||
{
|
||||
logFound = 1;
|
||||
|
||||
// Clear the file
|
||||
FILE* logFile = _wfopen(logfile.c_str(), L"w");
|
||||
fclose(logFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
logFound = 2; // not found
|
||||
}
|
||||
}
|
||||
|
||||
if (logFound == 1)
|
||||
{
|
||||
if (_waccess(logfile.c_str(), 0) == -1)
|
||||
{
|
||||
// Disable logging if the file was deleted manually
|
||||
Rainmeter->StopLogging();
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE* logFile = _wfopen(logfile.c_str(), L"a+, ccs=UTF-8");
|
||||
if (logFile)
|
||||
{
|
||||
message.insert(0, L": ");
|
||||
|
||||
switch (nLevel)
|
||||
{
|
||||
case LOG_ERROR:
|
||||
message.insert(0, L"ERROR");
|
||||
break;
|
||||
|
||||
case LOG_WARNING:
|
||||
message.insert(0, L"WARNING");
|
||||
break;
|
||||
|
||||
case LOG_NOTICE:
|
||||
message.insert(0, L"NOTICE");
|
||||
break;
|
||||
|
||||
case LOG_DEBUG:
|
||||
message.insert(0, L"DEBUG");
|
||||
break;
|
||||
}
|
||||
|
||||
message += L'\n';
|
||||
fputws(message.c_str(), logFile);
|
||||
fclose(logFile);
|
||||
}
|
||||
}
|
||||
fputws(message.c_str(), file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
|
||||
@ -486,12 +453,12 @@ std::wstring GetFormattedString(UINT id, ...)
|
||||
va_start(args, id);
|
||||
|
||||
DWORD len = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
GetString(id),
|
||||
0,
|
||||
0,
|
||||
(LPWSTR)&pBuffer,
|
||||
0,
|
||||
&args);
|
||||
GetString(id),
|
||||
0,
|
||||
0,
|
||||
(LPWSTR)&pBuffer,
|
||||
0,
|
||||
&args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
@ -500,7 +467,7 @@ std::wstring GetFormattedString(UINT id, ...)
|
||||
return tmpSz;
|
||||
}
|
||||
|
||||
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.
|
||||
}
|
||||
|
@ -35,8 +35,6 @@ enum LOGLEVEL
|
||||
void InitalizeLitestep();
|
||||
void FinalizeLitestep();
|
||||
|
||||
void ResetLoggingFlag();
|
||||
|
||||
HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance);
|
||||
|
||||
std::string ConvertToAscii(LPCTSTR str);
|
||||
@ -53,6 +51,6 @@ void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = fals
|
||||
WCHAR* GetString(UINT id);
|
||||
std::wstring GetFormattedString(UINT id, ...);
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
@ -845,11 +845,6 @@ int CRainmeter::Initialize(HINSTANCE hInstance, LPCWSTR szPath)
|
||||
m_Logging = 0!=GetPrivateProfileInt(L"Rainmeter", L"Logging", 0, m_IniFile.c_str());
|
||||
m_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, m_IniFile.c_str());
|
||||
|
||||
if (m_Logging)
|
||||
{
|
||||
StartLogging();
|
||||
}
|
||||
|
||||
// Determine the language resource to load
|
||||
std::wstring resource = m_Path + L"Languages\\";
|
||||
if (GetPrivateProfileString(L"Rainmeter", L"Language", L"", tmpSzPath, MAX_LINE_LENGTH, m_IniFile.c_str()) == 0)
|
||||
@ -876,11 +871,6 @@ int CRainmeter::Initialize(HINSTANCE hInstance, LPCWSTR szPath)
|
||||
resource += L".dll";
|
||||
|
||||
m_ResourceInstance = LoadLibraryEx(resource.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (!m_ResourceInstance)
|
||||
{
|
||||
resource.insert(0, L"Unable to load language: ");
|
||||
Log(LOG_ERROR, resource.c_str());
|
||||
}
|
||||
}
|
||||
if (!m_ResourceInstance)
|
||||
{
|
||||
@ -895,6 +885,14 @@ int CRainmeter::Initialize(HINSTANCE hInstance, LPCWSTR szPath)
|
||||
}
|
||||
}
|
||||
|
||||
// Reset log file
|
||||
CSystem::RemoveFile(m_LogFile);
|
||||
|
||||
if (m_Logging)
|
||||
{
|
||||
StartLogging();
|
||||
}
|
||||
|
||||
m_PluginPath = m_AddonPath = m_SkinPath = m_Path;
|
||||
m_PluginPath += L"Plugins\\";
|
||||
m_AddonPath += L"Addons\\";
|
||||
@ -1077,6 +1075,20 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_RAINMETER_DELAYED_REFRESH_ALL:
|
||||
Rainmeter->RefreshAll();
|
||||
return 0;
|
||||
|
||||
case WM_RAINMETER_DELAYED_EXECUTE:
|
||||
if (lParam)
|
||||
{
|
||||
// Execute bang
|
||||
WCHAR* bang = (WCHAR*)lParam;
|
||||
Rainmeter->ExecuteCommand(bang, NULL);
|
||||
free(bang); // _wcsdup()
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
@ -1603,7 +1615,7 @@ void CRainmeter::ExecuteBang(const std::wstring& name, std::wstring& arg, CMeter
|
||||
else if (_wcsicmp(bang, L"RefreshApp") == 0)
|
||||
{
|
||||
// Refresh needs to be delayed since it crashes if done during Update()
|
||||
PostMessage(GetTrayWindow()->GetWindow(), WM_TRAY_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
|
||||
PostMessage(m_Window, WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
|
||||
}
|
||||
else if (_wcsicmp(bang, L"Redraw") == 0)
|
||||
{
|
||||
@ -2047,7 +2059,7 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
|
||||
void CRainmeter::DelayedExecuteCommand(const WCHAR* command)
|
||||
{
|
||||
WCHAR* bang = _wcsdup(command);
|
||||
PostMessage(m_TrayWindow->GetWindow(), WM_TRAY_DELAYED_EXECUTE, (WPARAM)NULL, (LPARAM)bang);
|
||||
PostMessage(m_Window, WM_RAINMETER_DELAYED_EXECUTE, (WPARAM)NULL, (LPARAM)bang);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3000,17 +3012,15 @@ void CRainmeter::StartLogging()
|
||||
if (file != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(file);
|
||||
ResetLoggingFlag(); // Re-enable logging
|
||||
SetLogging(true);
|
||||
|
||||
std::wstring text = GetFormattedString(ID_STR_LOGFILECREATED, m_LogFile.c_str());
|
||||
MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
|
||||
// std::wstring text = GetFormattedString(ID_STR_LOGFILECREATED, m_LogFile.c_str());
|
||||
// MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable logging
|
||||
SetLogging(false);
|
||||
ResetLoggingFlag();
|
||||
|
||||
std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, m_LogFile.c_str());
|
||||
MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONERROR);
|
||||
@ -3038,8 +3048,6 @@ void CRainmeter::DeleteLogFile()
|
||||
{
|
||||
// Disable logging
|
||||
SetLogging(false);
|
||||
ResetLoggingFlag();
|
||||
|
||||
CSystem::RemoveFile(m_LogFile);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,9 @@
|
||||
#define RAINMETER_CLASS_NAME L"DummyRainWClass"
|
||||
#define RAINMETER_WINDOW_NAME L"Rainmeter control window"
|
||||
|
||||
#define WM_RAINMETER_DELAYED_REFRESH_ALL WM_APP + 0
|
||||
#define WM_RAINMETER_DELAYED_EXECUTE WM_APP + 1
|
||||
|
||||
struct GlobalConfig
|
||||
{
|
||||
double netInSpeed;
|
||||
|
@ -434,7 +434,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
|
||||
}
|
||||
else if (wParam == ID_CONTEXT_REFRESH)
|
||||
{
|
||||
PostMessage(tray->GetWindow(), WM_TRAY_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
|
||||
PostMessage(Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
|
||||
}
|
||||
else if (wParam == ID_CONTEXT_SHOWLOGFILE)
|
||||
{
|
||||
@ -692,20 +692,6 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_TRAY_DELAYED_REFRESH_ALL:
|
||||
Rainmeter->RefreshAll();
|
||||
return 0;
|
||||
|
||||
case WM_TRAY_DELAYED_EXECUTE:
|
||||
if (lParam)
|
||||
{
|
||||
// Execute bang
|
||||
WCHAR* bang = (WCHAR*)lParam;
|
||||
Rainmeter->ExecuteCommand(bang, NULL);
|
||||
free(bang); // _wcsdup()
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
@ -25,9 +25,6 @@
|
||||
|
||||
typedef HRESULT (WINAPI * FPLOADICONMETRIC)(HINSTANCE hinst, PCWSTR pszName, int lims, HICON* phico);
|
||||
|
||||
#define WM_TRAY_DELAYED_REFRESH_ALL WM_APP + 0
|
||||
#define WM_TRAY_DELAYED_EXECUTE WM_APP + 1
|
||||
|
||||
#define WM_TRAY_NOTIFYICON WM_USER + 101
|
||||
#define TRAYICON_SIZE 16
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user