- 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:
Birunthan Mohanathas 2012-02-14 17:58:03 +00:00
parent 2c6ed8ed69
commit ac840c1599
7 changed files with 79 additions and 117 deletions

View File

@ -40,5 +40,8 @@
*/ */
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) 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); return RainmeterMain(hInstance, lpCmdLine);
} }

View File

@ -27,13 +27,6 @@ extern CRainmeter* Rainmeter;
static CRITICAL_SECTION g_CsLog = {0}; static CRITICAL_SECTION g_CsLog = {0};
static CRITICAL_SECTION g_CsLogDelay = {0}; static CRITICAL_SECTION g_CsLogDelay = {0};
static int logFound = 0;
void ResetLoggingFlag()
{
logFound = 0;
}
void InitalizeLitestep() void InitalizeLitestep()
{ {
InitializeCriticalSection(&g_CsLog); InitializeCriticalSection(&g_CsLog);
@ -302,7 +295,7 @@ std::wstring ConvertUTF8ToWide(LPCSTR str)
return szWide; return szWide;
} }
BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage) void LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
{ {
// Add timestamp // Add timestamp
WCHAR buffer[128]; WCHAR buffer[128];
@ -310,80 +303,54 @@ BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
Rainmeter->AddAboutLogInfo(nLevel, buffer, 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.append(buffer, len);
message += L") "; message += L") ";
message += pszMessage; message += pszMessage;
message += L'\n';
#ifdef _DEBUG
_RPT0(_CRT_WARN, ConvertToAscii(message.c_str()).c_str()); _RPT0(_CRT_WARN, ConvertToAscii(message.c_str()).c_str());
_RPT0(_CRT_WARN, "\n");
#endif
// The stub implementation const WCHAR* logFile = Rainmeter->GetLogFile().c_str();
if (Rainmeter->GetLogging()) if (_waccess(logFile, 0) == -1)
{
const std::wstring& logfile = Rainmeter->GetLogFile();
if (logFound == 0)
{
// 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 // Disable logging if the file was deleted manually
Rainmeter->StopLogging(); Rainmeter->StopLogging();
} }
else else
{ {
FILE* logFile = _wfopen(logfile.c_str(), L"a+, ccs=UTF-8"); FILE* file = _wfopen(logFile, L"a+, ccs=UTF-8");
if (logFile) if (file)
{ {
message.insert(0, L": "); fputws(message.c_str(), file);
fclose(file);
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);
} }
} }
} }
}
return TRUE;
}
BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage) BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
{ {

View File

@ -35,8 +35,6 @@ enum LOGLEVEL
void InitalizeLitestep(); void InitalizeLitestep();
void FinalizeLitestep(); void FinalizeLitestep();
void ResetLoggingFlag();
HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance); HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance);
std::string ConvertToAscii(LPCTSTR str); std::string ConvertToAscii(LPCTSTR str);

View File

@ -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_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()); m_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, m_IniFile.c_str());
if (m_Logging)
{
StartLogging();
}
// Determine the language resource to load // Determine the language resource to load
std::wstring resource = m_Path + L"Languages\\"; std::wstring resource = m_Path + L"Languages\\";
if (GetPrivateProfileString(L"Rainmeter", L"Language", L"", tmpSzPath, MAX_LINE_LENGTH, m_IniFile.c_str()) == 0) 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"; resource += L".dll";
m_ResourceInstance = LoadLibraryEx(resource.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); 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) 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 = m_AddonPath = m_SkinPath = m_Path;
m_PluginPath += L"Plugins\\"; m_PluginPath += L"Plugins\\";
m_AddonPath += L"Addons\\"; m_AddonPath += L"Addons\\";
@ -1077,6 +1075,20 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
} }
break; 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: default:
return DefWindowProc(hWnd, uMsg, wParam, lParam); 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) else if (_wcsicmp(bang, L"RefreshApp") == 0)
{ {
// Refresh needs to be delayed since it crashes if done during Update() // 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) 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) void CRainmeter::DelayedExecuteCommand(const WCHAR* command)
{ {
WCHAR* bang = _wcsdup(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) if (file != INVALID_HANDLE_VALUE)
{ {
CloseHandle(file); CloseHandle(file);
ResetLoggingFlag(); // Re-enable logging
SetLogging(true); SetLogging(true);
std::wstring text = GetFormattedString(ID_STR_LOGFILECREATED, m_LogFile.c_str()); // std::wstring text = GetFormattedString(ID_STR_LOGFILECREATED, m_LogFile.c_str());
MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONINFORMATION); // MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
} }
else else
{ {
// Disable logging // Disable logging
SetLogging(false); SetLogging(false);
ResetLoggingFlag();
std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, m_LogFile.c_str()); std::wstring text = GetFormattedString(ID_STR_LOGFILECREATEFAIL, m_LogFile.c_str());
MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONERROR); MessageBox(NULL, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONERROR);
@ -3038,8 +3048,6 @@ void CRainmeter::DeleteLogFile()
{ {
// Disable logging // Disable logging
SetLogging(false); SetLogging(false);
ResetLoggingFlag();
CSystem::RemoveFile(m_LogFile); CSystem::RemoveFile(m_LogFile);
} }
} }

View File

@ -42,6 +42,9 @@
#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_EXECUTE WM_APP + 1
struct GlobalConfig struct GlobalConfig
{ {
double netInSpeed; double netInSpeed;

View File

@ -434,7 +434,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
else if (wParam == ID_CONTEXT_REFRESH) 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) else if (wParam == ID_CONTEXT_SHOWLOGFILE)
{ {
@ -692,20 +692,6 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
break; 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: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
break; break;

View File

@ -25,9 +25,6 @@
typedef HRESULT (WINAPI * FPLOADICONMETRIC)(HINSTANCE hinst, PCWSTR pszName, int lims, HICON* phico); 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 WM_TRAY_NOTIFYICON WM_USER + 101
#define TRAYICON_SIZE 16 #define TRAYICON_SIZE 16