Menu

[r30]: / trunk / src / HiddenWindow.cpp  Maximize  Restore  History

Download this file

200 lines (182 with data), 4.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "StdAfx.h"
#include "HiddenWindow.h"
#include "resource.h"
#include "MainDlg.h"
#include "SVN.h"
#include "AppUtils.h"
extern HINSTANCE hInst;
DWORD WINAPI MonitorThread(LPVOID lpParam);
CHiddenWindow::~CHiddenWindow(void)
{
}
bool CHiddenWindow::RegisterAndCreateWindow()
{
WNDCLASSEX wcx;
// Fill in the window class structure with default parameters
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = CWindow::stWinMsgHandler;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hResource;
wcx.hCursor = LoadCursor(NULL, IDC_SIZEWE);
wcx.lpszClassName = ResString(hResource, IDS_APP_TITLE);
wcx.hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_COMMITMONITOR));
wcx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wcx.lpszMenuName = MAKEINTRESOURCE(IDC_COMMITMONITOR);
wcx.hIconSm = LoadIcon(wcx.hInstance, MAKEINTRESOURCE(IDI_COMMITMONITOR));
if (RegisterWindow(&wcx))
{
if (Create(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, NULL))
{
COMMITMONITOR_SHOWDLGMSG = RegisterWindowMessage(_T("CommitMonitor_ShowDlgMsg"));
COMMITMONITOR_CHANGEDINFO = RegisterWindowMessage(_T("CommitMonitor_ChangedInfo"));
ShowWindow(m_hwnd, SW_HIDE);
return true;
}
}
return false;
}
INT_PTR CHiddenWindow::ShowDialog()
{
return ::SendMessage(*this, COMMITMONITOR_SHOWDLGMSG, 0, 0);
}
LRESULT CALLBACK CHiddenWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// the custom messages are not constant, therefore we can't handle them in the
// switch-case below
if (uMsg == COMMITMONITOR_SHOWDLGMSG)
{
CMainDlg dlg;
dlg.DoModal(hInst, IDD_MAINDLG, NULL);
wstring urlfile = CAppUtils::GetAppDataDir() + _T("\\urls");
if (PathFileExists(urlfile.c_str()))
m_UrlInfos.Load(urlfile.c_str());
}
else if (uMsg == COMMITMONITOR_CHANGEDINFO)
{
wstring urlfile = CAppUtils::GetAppDataDir() + _T("\\urls");
if (PathFileExists(urlfile.c_str()))
m_UrlInfos.Save(urlfile.c_str());
}
switch (uMsg)
{
case WM_CREATE:
{
m_hwnd = hwnd;
// set the timers we use to start the monitoring threads
::SetTimer(*this, IDT_MONITOR, 10, NULL);
}
break;
case WM_TIMER:
{
if (wParam == IDT_MONITOR)
{
DoTimer();
}
}
break;
case WM_COMMAND:
{
return DoCommand(LOWORD(wParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
::DestroyWindow(m_hwnd);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
};
LRESULT CHiddenWindow::DoCommand(int id)
{
switch (id)
{
default:
break;
};
return 1;
}
void CHiddenWindow::DoTimer()
{
// go through all url infos and check if
// we need to refresh them
if (m_UrlInfos.infos.empty())
return;
bool bStartThread = false;
__time64_t currenttime = NULL;
_time64(&currenttime);
for (map<wstring,CUrlInfo>::const_iterator it = m_UrlInfos.infos.begin(); it != m_UrlInfos.infos.end(); ++it)
{
if ((it->second.lastchecked + (it->second.minutesinterval*60000)) < currenttime)
{
bStartThread = true;
break;
}
}
if ((bStartThread)&&(m_ThreadRunning == 0))
{
::SetTimer(*this, IDT_MONITOR, TIMER_ELAPSE, NULL);
// start the monitoring thread to update the infos
DWORD dwThreadId = 0;
HANDLE hMonitorThread = CreateThread(
NULL, // no security attribute
0, // default stack size
MonitorThread,
(LPVOID)this, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
if (hMonitorThread == NULL)
return;
else
CloseHandle(hMonitorThread);
}
}
DWORD CHiddenWindow::RunThread()
{
m_ThreadRunning = TRUE;
__time64_t currenttime = NULL;
_time64(&currenttime);
bool bNewEntries = false;
for (map<wstring,CUrlInfo>::iterator it = m_UrlInfos.infos.begin(); it != m_UrlInfos.infos.end(); ++it)
{
if ((it->second.lastchecked + (it->second.minutesinterval*60000)) < currenttime)
{
// get the highest revision of the repository
SVN svn;
svn.SetAuthInfo(it->second.username, it->second.password);
svn_revnum_t headrev = svn.GetHEADRevision(it->first);
if (headrev > it->second.lastcheckedrev)
{
if (svn.GetLog(it->first, headrev, it->second.lastcheckedrev))
{
it->second.lastcheckedrev = headrev;
it->second.lastchecked = currenttime;
bNewEntries = true;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator logit = svn.m_logs.begin(); logit != svn.m_logs.end(); ++logit)
{
it->second.logentries[logit->first] = logit->second;
}
}
}
}
}
if (bNewEntries)
{
// save the changed entries
::PostMessage(*this, COMMITMONITOR_CHANGEDINFO, 0, 0);
}
m_ThreadRunning = FALSE;
return 0L;
}
DWORD WINAPI MonitorThread(LPVOID lpParam)
{
CHiddenWindow * pThis = (CHiddenWindow*)lpParam;
if (pThis)
return pThis->RunThread();
return 0L;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.