Menu

[r192]: / trunk / src / CommitMonitor.cpp  Maximize  Restore  History

Download this file

167 lines (138 with data), 4.6 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
// CommitMonitor - simple checker for new commits in svn repositories
// Copyright (C) 2007 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// CommitMonitor.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "CommitMonitor.h"
#include "HiddenWindow.h"
#include "MainDlg.h"
#include "CmdLineParser.h"
#include "DiffViewer.h"
#include "apr_general.h"
// Global Variables:
HINSTANCE hInst; // current instance
HANDLE g_mutex = 0;
#define APPNAME_MUTEX _T("CommitMonitor_{3802F59C-BEBD-49b9-A345-F99CBA2FBD0D}")
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
//CUrlInfos urlinfos;
//urlinfos.Load();
//urlinfos.Save();
//return 0;
::OleInitialize(NULL);
// we need some of the common controls
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LINK_CLASS|ICC_LISTVIEW_CLASSES|ICC_PAGESCROLLER_CLASS
|ICC_PROGRESS_CLASS|ICC_STANDARD_CLASSES|ICC_TAB_CLASSES|ICC_TREEVIEW_CLASSES
|ICC_UPDOWN_CLASS|ICC_USEREX_CLASSES|ICC_WIN95_CLASSES;
InitCommonControlsEx(&icex);
int argc = 0;
const char* const * argv = NULL;
apr_app_initialize(&argc, &argv, NULL);
setlocale(LC_ALL, "");
// first create a hidden window which serves as our main window for receiving
// the window messages, starts the monitoring thread and handles the icon
// in the tray area.
MSG msg;
msg.wParam = FALSE;
HACCEL hAccelTable;
hInst = hInstance;
INITCOMMONCONTROLSEX used = {
sizeof(INITCOMMONCONTROLSEX),
ICC_STANDARD_CLASSES | ICC_BAR_CLASSES
};
InitCommonControlsEx(&used);
CCmdLineParser parser(lpCmdLine);
if (parser.HasKey(_T("patchfile")))
{
hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_CMVIEWER));
// in this case, we start another part of our application, not
// the monitoring part.
CDiffViewer viewer(hInst);
if (parser.HasVal(_T("title")))
viewer.SetTitle(parser.GetVal(_T("title")));
if (viewer.RegisterAndCreateWindow())
{
if (viewer.LoadFile(parser.GetVal(_T("patchfile"))))
{
::ShowWindow(viewer.GetHWNDEdit(), SW_SHOW);
::SetFocus(viewer.GetHWNDEdit());
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(viewer, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
}
}
else
{
//only one instance of this application part allowed
g_mutex = ::CreateMutex(NULL, FALSE, APPNAME_MUTEX);
if (g_mutex != NULL)
{
if ((::GetLastError()==ERROR_ALREADY_EXISTS)&&(!parser.HasKey(_T("task"))))
{
//an instance of this app is already running
HWND hWnd = FindWindow(ResString(hInst, IDS_APP_TITLE), NULL); //try finding the running instance of this app
if (hWnd)
{
UINT COMMITMONITOR_SHOWDLGMSG = RegisterWindowMessage(_T("CommitMonitor_ShowDlgMsg"));
PostMessage(hWnd, COMMITMONITOR_SHOWDLGMSG ,0 ,0); //open the window of the already running app
SetForegroundWindow(hWnd); //set the window to front
}
apr_terminate();
return FALSE;
}
}
CHiddenWindow hiddenWindow(hInst);
hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_COMMITMONITOR));
if (hiddenWindow.RegisterAndCreateWindow())
{
if (parser.HasKey(_T("task")))
{
hiddenWindow.SetTask(true);
}
else if (!parser.HasKey(_T("hidden")))
{
hiddenWindow.ShowDialog();
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(hiddenWindow, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
hiddenWindow.StopThread();
}
::OleUninitialize();
apr_terminate();
return (int) msg.wParam;
}
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.