Process Hacker
main.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Plugins -
3  * Update Checker Plugin
4  *
5  * Copyright (C) 2011-2015 dmex
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "updater.h"
24 
30 
31 static VOID NTAPI MainWindowShowingCallback(
32  _In_opt_ PVOID Parameter,
33  _In_opt_ PVOID Context
34  )
35 {
36  // Check if the user want's us to auto-check for updates.
38  {
39  // All good, queue up our update check.
41  }
42 }
43 
45  _In_opt_ PVOID Parameter,
46  _In_opt_ PVOID Context
47  )
48 {
49  PPH_PLUGIN_MENU_INFORMATION menuInfo = Parameter;
50 
51  // Check this menu is the Help menu
52  if (menuInfo->u.MainMenu.SubMenuIndex != 4)
53  return;
54 
55  PhInsertEMenuItem(menuInfo->Menu, PhPluginCreateEMenuItem(PluginInstance, 0, UPDATE_MENUITEM, L"Check for Updates", NULL), 0);
56 }
57 
58 static VOID NTAPI MenuItemCallback(
59  _In_opt_ PVOID Parameter,
60  _In_opt_ PVOID Context
61  )
62 {
63  PPH_PLUGIN_MENU_ITEM menuItem = Parameter;
64 
65  if (menuItem->Id == UPDATE_MENUITEM)
66  {
67  ShowUpdateDialog(NULL);
68  }
69 }
70 
71 static VOID NTAPI ShowOptionsCallback(
72  _In_opt_ PVOID Parameter,
73  _In_opt_ PVOID Context
74  )
75 {
76  DialogBox(
77  PluginInstance->DllBase,
78  MAKEINTRESOURCE(IDD_OPTIONS),
79  (HWND)Parameter,
81  );
82 }
83 
85  _In_ mxml_node_t *xmlNode
86  )
87 {
88  if (xmlNode && xmlNode->child && xmlNode->child->type == MXML_OPAQUE && xmlNode->child->value.opaque)
89  {
90  return PhConvertUtf8ToUtf16(xmlNode->child->value.opaque);
91  }
92 
93  return PhReferenceEmptyString();
94 }
95 
97  VOID
98  )
99 {
100  static PH_STRINGREF keyName = PH_STRINGREF_INIT(L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Process_Hacker2_is1");
101 
102  HANDLE keyHandle = NULL;
103 
104  // Check uninstall entries for the 'Process_Hacker2_is1' registry key.
105  if (NT_SUCCESS(PhOpenKey(
106  &keyHandle,
107  KEY_READ,
109  &keyName,
110  0
111  )))
112  {
113  NtClose(keyHandle);
114  return TRUE;
115  }
116 
117  return FALSE;
118 }
119 
121  _In_ HINSTANCE Instance,
122  _In_ ULONG Reason,
123  _Reserved_ PVOID Reserved
124  )
125 {
126  switch (Reason)
127  {
128  case DLL_PROCESS_ATTACH:
129  {
131  PH_SETTING_CREATE settings[] =
132  {
134  };
135 
136  PluginInstance = PhRegisterPlugin(PLUGIN_NAME, Instance, &info);
137 
138  if (!PluginInstance)
139  return FALSE;
140 
141  info->DisplayName = L"Update Checker";
142  info->Author = L"dmex";
143  info->Description = L"Plugin for checking new Process Hacker releases via the Help menu.";
144  info->Url = L"http://processhacker.sf.net/forums/viewtopic.php?t=1121";
145  info->HasOptions = TRUE;
146 
150  NULL,
151  &MainWindowShowingCallbackRegistration
152  );
156  NULL,
157  &MainMenuInitializingCallbackRegistration
158  );
162  NULL,
163  &PluginMenuItemCallbackRegistration
164  );
168  NULL,
169  &PluginShowOptionsCallbackRegistration
170  );
171 
172  PhAddSettings(settings, _countof(settings));
173  }
174  break;
175  }
176 
177  return TRUE;
178 }