mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Modified the behavior when the log file was deleted manually.
This commit is contained in:
parent
05c14bfa26
commit
d07e8665b0
@ -538,50 +538,55 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
|
|||||||
// The stub implementation
|
// The stub implementation
|
||||||
if (Rainmeter && Rainmeter->GetLogging())
|
if (Rainmeter && Rainmeter->GetLogging())
|
||||||
{
|
{
|
||||||
FILE* logFile;
|
|
||||||
std::wstring logfile = Rainmeter->GetLogFile();
|
std::wstring logfile = Rainmeter->GetLogFile();
|
||||||
if (logFound == 0)
|
if (logFound == 0)
|
||||||
{
|
{
|
||||||
// Check if the file exists
|
// Check if the file exists
|
||||||
logFile = _wfopen(logfile.c_str(), L"r");
|
if (_waccess(logfile.c_str(), 0) != -1)
|
||||||
if (logFile)
|
|
||||||
{
|
{
|
||||||
logFound = 1;
|
logFound = 1;
|
||||||
fclose(logFile);
|
|
||||||
|
|
||||||
// Clear the file
|
// Clear the file
|
||||||
logFile = _wfopen(logfile.c_str(), L"w");
|
FILE* logFile = _wfopen(logfile.c_str(), L"w");
|
||||||
fclose(logFile);
|
fclose(logFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logFound = 2;
|
logFound = 2; // not found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logFound == 1)
|
if (logFound == 1)
|
||||||
{
|
{
|
||||||
logFile = _wfopen(logfile.c_str(), L"a+, ccs=UTF-8");
|
if (_waccess(logfile.c_str(), 0) == -1)
|
||||||
if (logFile)
|
|
||||||
{
|
{
|
||||||
switch(nLevel)
|
// Disable logging if the file was deleted manually
|
||||||
|
Rainmeter->StopLogging();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FILE* logFile = _wfopen(logfile.c_str(), L"a+, ccs=UTF-8");
|
||||||
|
if (logFile)
|
||||||
{
|
{
|
||||||
case 1:
|
switch(nLevel)
|
||||||
fputws(L"ERROR: ", logFile);
|
{
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
fputws(L"ERROR: ", logFile);
|
||||||
fputws(L"WARNING: ", logFile);
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 3:
|
fputws(L"WARNING: ", logFile);
|
||||||
fputws(L"NOTICE: ", logFile);
|
break;
|
||||||
break;
|
case 3:
|
||||||
case 4:
|
fputws(L"NOTICE: ", logFile);
|
||||||
fputws(L"DEBUG: ", logFile);
|
break;
|
||||||
break;
|
case 4:
|
||||||
|
fputws(L"DEBUG: ", logFile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fputws(message.c_str(), logFile);
|
||||||
|
fputws(L"\n", logFile);
|
||||||
|
fclose(logFile);
|
||||||
}
|
}
|
||||||
fputws(message.c_str(), logFile);
|
|
||||||
fputws(L"\n", logFile);
|
|
||||||
fclose(logFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -913,6 +913,11 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR 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());
|
||||||
c_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, m_IniFile.c_str());
|
c_Debug = 0!=GetPrivateProfileInt(L"Rainmeter", L"Debug", 0, m_IniFile.c_str());
|
||||||
|
|
||||||
|
if (m_Logging)
|
||||||
|
{
|
||||||
|
StartLogging();
|
||||||
|
}
|
||||||
|
|
||||||
m_PluginPath = tmpName;
|
m_PluginPath = tmpName;
|
||||||
m_PluginPath += L"Plugins\\";
|
m_PluginPath += L"Plugins\\";
|
||||||
m_SkinPath = m_Path + L"Skins\\";
|
m_SkinPath = m_Path + L"Skins\\";
|
||||||
@ -2086,6 +2091,11 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
|
|||||||
m_Logging = 0!=parser.ReadInt(L"Rainmeter", L"Logging", 0);
|
m_Logging = 0!=parser.ReadInt(L"Rainmeter", L"Logging", 0);
|
||||||
c_Debug = 0!=parser.ReadInt(L"Rainmeter", L"Debug", 0);
|
c_Debug = 0!=parser.ReadInt(L"Rainmeter", L"Debug", 0);
|
||||||
|
|
||||||
|
if (m_Logging)
|
||||||
|
{
|
||||||
|
StartLogging();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_TrayWindow)
|
if (m_TrayWindow)
|
||||||
{
|
{
|
||||||
m_TrayWindow->ReadConfig(parser);
|
m_TrayWindow->ReadConfig(parser);
|
||||||
@ -2404,15 +2414,18 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
|
|||||||
{
|
{
|
||||||
EnableMenuItem(subMenu, ID_CONTEXT_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED);
|
EnableMenuItem(subMenu, ID_CONTEXT_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED);
|
||||||
EnableMenuItem(subMenu, ID_CONTEXT_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED);
|
EnableMenuItem(subMenu, ID_CONTEXT_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED);
|
||||||
}
|
EnableMenuItem(subMenu, ID_CONTEXT_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
|
||||||
|
|
||||||
if (m_Logging)
|
|
||||||
{
|
|
||||||
EnableMenuItem(subMenu, ID_CONTEXT_STARTLOG, MF_BYCOMMAND | MF_GRAYED);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnableMenuItem(subMenu, ID_CONTEXT_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
|
if (m_Logging)
|
||||||
|
{
|
||||||
|
EnableMenuItem(subMenu, ID_CONTEXT_STARTLOG, MF_BYCOMMAND | MF_GRAYED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EnableMenuItem(subMenu, ID_CONTEXT_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c_Debug)
|
if (c_Debug)
|
||||||
@ -2788,6 +2801,64 @@ void CRainmeter::ChangeSkinIndex(HMENU menu, int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRainmeter::StartLogging()
|
||||||
|
{
|
||||||
|
// Check if the file exists
|
||||||
|
if (_waccess(m_LogFile.c_str(), 0) == -1)
|
||||||
|
{
|
||||||
|
// Create log file
|
||||||
|
HANDLE file = CreateFile(m_LogFile.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (file != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(file);
|
||||||
|
ResetLoggingFlag(); // Re-enable logging
|
||||||
|
SetLogging(true);
|
||||||
|
|
||||||
|
std::wstring message = L"Log file created at: ";
|
||||||
|
message += m_LogFile;
|
||||||
|
MessageBox(NULL, message.c_str(), L"Rainmeter", MB_OK | MB_ICONINFORMATION);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Disable logging
|
||||||
|
SetLogging(false);
|
||||||
|
ResetLoggingFlag();
|
||||||
|
|
||||||
|
std::wstring message = L"Unable to create log file: ";
|
||||||
|
message += m_LogFile;
|
||||||
|
MessageBox(NULL, message.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetLogging(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRainmeter::StopLogging()
|
||||||
|
{
|
||||||
|
SetLogging(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRainmeter::DeleteLogFile()
|
||||||
|
{
|
||||||
|
// Check if the file exists
|
||||||
|
if (_waccess(m_LogFile.c_str(), 0) != -1)
|
||||||
|
{
|
||||||
|
std::wstring message = L"Do you want to delete the following log file?\n";
|
||||||
|
message += m_LogFile;
|
||||||
|
int res = MessageBox(NULL, message.c_str(), L"Rainmeter", MB_YESNO | MB_ICONQUESTION);
|
||||||
|
if (res == IDYES)
|
||||||
|
{
|
||||||
|
// Disable logging
|
||||||
|
SetLogging(false);
|
||||||
|
ResetLoggingFlag();
|
||||||
|
|
||||||
|
DeleteFile(m_LogFile.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CRainmeter::SetLogging(bool logging)
|
void CRainmeter::SetLogging(bool logging)
|
||||||
{
|
{
|
||||||
m_Logging = logging;
|
m_Logging = logging;
|
||||||
|
@ -163,8 +163,11 @@ public:
|
|||||||
void SetDisableVersionCheck(BOOL check) { m_DisableVersionCheck = check; };
|
void SetDisableVersionCheck(BOOL check) { m_DisableVersionCheck = check; };
|
||||||
void SetNewVersion(BOOL NewVer) { m_NewVersion = NewVer; };
|
void SetNewVersion(BOOL NewVer) { m_NewVersion = NewVer; };
|
||||||
|
|
||||||
void SetLogging(bool logging);
|
|
||||||
bool GetLogging() { return m_Logging; }
|
bool GetLogging() { return m_Logging; }
|
||||||
|
void StartLogging();
|
||||||
|
void StopLogging();
|
||||||
|
void DeleteLogFile();
|
||||||
|
|
||||||
void SetDebug(bool debug);
|
void SetDebug(bool debug);
|
||||||
|
|
||||||
void ShowContextMenu(POINT pos, CMeterWindow* meterWindow);
|
void ShowContextMenu(POINT pos, CMeterWindow* meterWindow);
|
||||||
@ -205,6 +208,7 @@ private:
|
|||||||
HMENU CreateThemeMenu();
|
HMENU CreateThemeMenu();
|
||||||
void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow);
|
void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow);
|
||||||
void CreateDefaultConfigFile(std::wstring strFile);
|
void CreateDefaultConfigFile(std::wstring strFile);
|
||||||
|
void SetLogging(bool logging);
|
||||||
void TestSettingsFile(bool bDefaultIniLocation);
|
void TestSettingsFile(bool bDefaultIniLocation);
|
||||||
void CheckSkinVersions();
|
void CheckSkinVersions();
|
||||||
int CompareVersions(std::wstring strA, std::wstring strB);
|
int CompareVersions(std::wstring strA, std::wstring strB);
|
||||||
|
@ -430,54 +430,15 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
|
|||||||
}
|
}
|
||||||
else if(wParam == ID_CONTEXT_STARTLOG)
|
else if(wParam == ID_CONTEXT_STARTLOG)
|
||||||
{
|
{
|
||||||
// Check if the file exists
|
Rainmeter->StartLogging();
|
||||||
std::wstring log = Rainmeter->GetLogFile();
|
|
||||||
if (_waccess(log.c_str(), 0) == -1)
|
|
||||||
{
|
|
||||||
// Create log file
|
|
||||||
HANDLE file = CreateFile(log.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (file != INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
CloseHandle(file);
|
|
||||||
ResetLoggingFlag(); // Re-enable logging
|
|
||||||
Rainmeter->SetLogging(true);
|
|
||||||
|
|
||||||
std::wstring message;
|
|
||||||
message = L"Log file created at: ";
|
|
||||||
message += log;
|
|
||||||
MessageBox(tray->GetWindow(), message.c_str(), L"Rainmeter", MB_OK | MB_ICONINFORMATION);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::wstring message;
|
|
||||||
message = L"Unable to create log file: ";
|
|
||||||
message += log;
|
|
||||||
MessageBox(tray->GetWindow(), message.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Rainmeter->SetLogging(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(wParam == ID_CONTEXT_STOPLOG)
|
else if(wParam == ID_CONTEXT_STOPLOG)
|
||||||
{
|
{
|
||||||
Rainmeter->SetLogging(false);
|
Rainmeter->StopLogging();
|
||||||
}
|
}
|
||||||
else if(wParam == ID_CONTEXT_DELETELOGFILE)
|
else if(wParam == ID_CONTEXT_DELETELOGFILE)
|
||||||
{
|
{
|
||||||
// Check if the file exists
|
Rainmeter->DeleteLogFile();
|
||||||
std::wstring log = Rainmeter->GetLogFile();
|
|
||||||
if (_waccess(log.c_str(), 0) != -1)
|
|
||||||
{
|
|
||||||
int res = MessageBox(tray->GetWindow(), L"Do you want to delete log file?", L"Rainmeter", MB_YESNO | MB_ICONQUESTION);
|
|
||||||
if (res == IDYES)
|
|
||||||
{
|
|
||||||
Rainmeter->SetLogging(false);
|
|
||||||
ResetLoggingFlag();
|
|
||||||
DeleteFile(log.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(wParam == ID_CONTEXT_DEBUGLOG)
|
else if(wParam == ID_CONTEXT_DEBUGLOG)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user