Split startup options for service and applet. Toggle service state between "manual" and "auto" rather than "disabled" and "auto".

This commit is contained in:
Ron Pedde 2007-03-15 12:30:12 +00:00
parent aa2a9c2c43
commit cf8b867165
7 changed files with 224 additions and 288 deletions

View File

@ -1,18 +1,18 @@
/* /*
*(C) 2006 Roku LLC *(C) 2006 Roku LLC
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License Version 2 as published * under the terms of the GNU General Public License Version 2 as published
* by the Free Software Foundation. * by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* without any warranty; without even the implied warranty of * without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. See the GNU General * merchantability or fitness for a particular purpose. See the GNU General
* Public License for more details. * Public License for more details.
* *
* Please read README.txt in the same directory as this source file for * Please read README.txt in the same directory as this source file for
* further license information. * further license information.
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "AdvancedPage.h" #include "AdvancedPage.h"
@ -21,156 +21,138 @@
LRESULT CAdvancedPage::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CAdvancedPage::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{ {
CWaitCursor wait; CWaitCursor wait;
IniFile ini(GetApplication()->GetConfigPath()); IniFile ini(GetApplication()->GetConfigPath());
m_server_port = ini.GetInteger(_T("general"), _T("port"), 9999); m_server_port = ini.GetInteger(_T("general"), _T("port"), 9999);
DoDataExchange(false); DoDataExchange(false);
m_port_spin.SetRange32(1, 65535); m_port_spin.SetRange32(1, 65535);
switch (GetApplication()->IsAutoStartEnabled()) if(GetApplication()->IsServiceAutoStartEnabled())
{ m_autostart_check.SetCheck(BST_CHECKED);
case 0: else
m_autostart_check.SetCheck(BST_UNCHECKED); m_autostart_check.SetCheck(BST_UNCHECKED);
break;
case 1:
m_autostart_check.SetCheck(BST_CHECKED);
break;
case 2:
// Be sneaky here. Make it capable of showing indeterminate but
// don't make it automatically change on click. We'll revert
// to a normal checkbox when the click happens.
m_autostart_check.SetButtonStyle(BS_3STATE);
m_autostart_check.SetCheck(BST_INDETERMINATE);
break;
}
UpdateControls();
GetDlgItem(IDC_STARTSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE); if(GetApplication()->IsAppletAutoStartEnabled())
GetDlgItem(IDC_STOPSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE); m_autostart_icon_check.SetCheck(BST_CHECKED);
else
m_autostart_icon_check.SetCheck(BST_UNCHECKED);
GetApplication()->ServiceStatusSubscribe(this); UpdateControls();
return 0;
GetDlgItem(IDC_STARTSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
GetDlgItem(IDC_STOPSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
GetApplication()->ServiceStatusSubscribe(this);
return 0;
} }
void CAdvancedPage::OnDestroy() void CAdvancedPage::OnDestroy() {
{ GetApplication()->ServiceStatusUnsubscribe(this);
GetApplication()->ServiceStatusUnsubscribe(this);
} }
void CAdvancedPage::UpdateControls() void CAdvancedPage::UpdateControls() {
{ Service::Status status = GetApplication()->GetServiceStatus();
Service::Status status = GetApplication()->GetServiceStatus(); UpdateControls(status);
UpdateControls(status);
} }
void CAdvancedPage::UpdateControls(Service::Status status) void CAdvancedPage::UpdateControls(Service::Status status)
{ {
UINT state_id; UINT state_id;
if (status.IsPending()) if (status.IsPending())
{ {
state_id = IDS_SERVER_PENDING; state_id = IDS_SERVER_PENDING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE); GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE); GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
} }
else if (status.IsRunning()) else if (status.IsRunning())
{ {
state_id = IDS_SERVER_RUNNING; state_id = IDS_SERVER_RUNNING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE); GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_SHOW); GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_SHOW);
} }
else else
{ {
state_id = IDS_SERVER_STOPPED; state_id = IDS_SERVER_STOPPED;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_SHOW); GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_SHOW);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE); GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
} }
const bool can_configure = GetApplication()->CanConfigure(); const bool can_configure = GetApplication()->CanConfigure();
GetDlgItem(IDC_SERVERPORT).EnableWindow(can_configure); GetDlgItem(IDC_SERVERPORT).EnableWindow(can_configure);
GetDlgItem(IDC_PORTSPIN).EnableWindow(can_configure); GetDlgItem(IDC_PORTSPIN).EnableWindow(can_configure);
// If we can't control the service then don't give the user // If we can't control the service then don't give the user
// the impression that we can. // the impression that we can.
const bool can_control = GetApplication()->CanControlService(); const bool can_control = GetApplication()->CanControlService();
GetDlgItem(IDC_STARTSERVICE).EnableWindow(can_control); GetDlgItem(IDC_STARTSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_STOPSERVICE).EnableWindow(can_control); GetDlgItem(IDC_STOPSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_AUTOSTART).EnableWindow(can_control); GetDlgItem(IDC_AUTOSTART).EnableWindow(can_control);
CString state; CString state;
state.LoadString(state_id); state.LoadString(state_id);
if (!can_control) if (!can_control)
{ {
CString s; CString s;
s.LoadString(IDS_NOT_ADMIN); s.LoadString(IDS_NOT_ADMIN);
state += " "; state += " ";
state += s; state += s;
} }
GetDlgItem(IDC_SERVERSTATE).SetWindowText(state); GetDlgItem(IDC_SERVERSTATE).SetWindowText(state);
} }
int CAdvancedPage::OnApply() int CAdvancedPage::OnApply()
{ {
CWaitCursor wait; CWaitCursor wait;
ATLTRACE("CAdvancedPage::OnApply\n"); ATLTRACE("CAdvancedPage::OnApply\n");
if (!DoDataExchange(true)) if (!DoDataExchange(true))
return false; return false;
IniFile ini(GetApplication()->GetConfigPath()); IniFile ini(GetApplication()->GetConfigPath());
ini.SetInteger(_T("general"), _T("port"), m_server_port); ini.SetInteger(_T("general"), _T("port"), m_server_port);
switch (m_autostart_check.GetCheck()) GetApplication()->EnableServiceAutoStart(m_hWnd,m_autostart_check.GetCheck() == BST_CHECKED);
{ GetApplication()->EnableAppletAutoStart(m_hWnd,m_autostart_icon_check.GetCheck() == BST_CHECKED);
case BST_CHECKED:
GetApplication()->EnableAutoStart(m_hWnd, true);
break;
case BST_UNCHECKED:
GetApplication()->EnableAutoStart(m_hWnd, false);
break;
case BST_INDETERMINATE:
// Ignore
break;
}
// Incorrectly documented in WTL // Incorrectly documented in WTL
return true; return true;
} }
LRESULT CAdvancedPage::OnStartService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CAdvancedPage::OnStartService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{ {
GetApplication()->StartService(m_hWnd); GetApplication()->StartService(m_hWnd);
UpdateControls(); UpdateControls();
return 0; return 0;
} }
LRESULT CAdvancedPage::OnStopService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CAdvancedPage::OnStopService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{ {
GetApplication()->StopService(m_hWnd); GetApplication()->StopService(m_hWnd);
UpdateControls(); UpdateControls();
return 0; return 0;
} }
LRESULT CAdvancedPage::OnWebAdmin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CAdvancedPage::OnWebAdmin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{ {
CWaitCursor wait; CWaitCursor wait;
// Go to the config file because we might not have committed a change yet. // Go to the config file because we might not have committed a change yet.
IniFile ini(GetApplication()->GetConfigPath()); IniFile ini(GetApplication()->GetConfigPath());
unsigned int port = ini.GetInteger(_T("general"), _T("port"), 9999); unsigned int port = ini.GetInteger(_T("general"), _T("port"), 9999);
CString url; CString url;
url.Format(_T("http://localhost:%u/"), port); url.Format(_T("http://localhost:%u/"), port);
::ShellExecute(m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWNORMAL); ::ShellExecute(m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWNORMAL);
return 0; return 0;
} }
void CAdvancedPage::OnServiceStatus(Service::Status old_status, Service::Status new_status) void CAdvancedPage::OnServiceStatus(Service::Status old_status, Service::Status new_status)
{ {
UpdateControls(new_status); UpdateControls(new_status);
} }

View File

@ -1,18 +1,18 @@
/* /*
*(C) 2006 Roku LLC *(C) 2006 Roku LLC
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License Version 2 as published * under the terms of the GNU General Public License Version 2 as published
* by the Free Software Foundation. * by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* without any warranty; without even the implied warranty of * without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. See the GNU General * merchantability or fitness for a particular purpose. See the GNU General
* Public License for more details. * Public License for more details.
* *
* Please read README.txt in the same directory as this source file for * Please read README.txt in the same directory as this source file for
* further license information. * further license information.
*/ */
#ifndef ADVANCEDPAGE_H #ifndef ADVANCEDPAGE_H
#define ADVANCEDPAGE_H 1 #define ADVANCEDPAGE_H 1
@ -23,76 +23,65 @@
/// @todo Users shouldn't be able to paste non-numbers into the port number. /// @todo Users shouldn't be able to paste non-numbers into the port number.
class CAdvancedPage : class CAdvancedPage :
public CPropertyPageImpl<CAdvancedPage>, public CPropertyPageImpl<CAdvancedPage>,
public CWinDataExchange<CAdvancedPage>, public CWinDataExchange<CAdvancedPage>,
public ServiceStatusObserver public ServiceStatusObserver
{ {
public: public:
enum { IDD = IDD_PAGE_ADVANCED }; enum { IDD = IDD_PAGE_ADVANCED };
private: private:
typedef CPropertyPageImpl<CAdvancedPage> base; typedef CPropertyPageImpl<CAdvancedPage> base;
enum ServiceState enum ServiceState
{ {
Pending = 0, Pending = 0,
Running = 1, Running = 1,
Stopped = 2 Stopped = 2
}; };
enum { TIMER_ID = 42 }; enum { TIMER_ID = 42 };
unsigned int m_server_port; unsigned int m_server_port;
CUpDownCtrl m_port_spin; CUpDownCtrl m_port_spin;
CButton m_autostart_check; CButton m_autostart_check;
CButton m_autostart_icon_check;
void UpdateControls(Service::Status status); void UpdateControls(Service::Status status);
void UpdateControls(); void UpdateControls();
// ServiceStatusObserver // ServiceStatusObserver
void OnServiceStatus(Service::Status old_status, Service::Status new_status); void OnServiceStatus(Service::Status old_status, Service::Status new_status);
BEGIN_MSG_MAP(CAdvancedPage) BEGIN_MSG_MAP(CAdvancedPage)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER_EX(IDC_SERVERPORT, EN_CHANGE, OnChange) COMMAND_HANDLER_EX(IDC_SERVERPORT, EN_CHANGE, OnChange)
COMMAND_HANDLER_EX(IDC_AUTOSTART, BN_CLICKED, OnClickAutostart) COMMAND_ID_HANDLER(IDC_STARTSERVICE, OnStartService)
COMMAND_ID_HANDLER(IDC_STARTSERVICE, OnStartService) COMMAND_ID_HANDLER(IDC_STOPSERVICE, OnStopService)
COMMAND_ID_HANDLER(IDC_STOPSERVICE, OnStopService) COMMAND_ID_HANDLER(IDC_WEBADMIN, OnWebAdmin)
COMMAND_ID_HANDLER(IDC_WEBADMIN, OnWebAdmin) MSG_WM_DESTROY(OnDestroy)
MSG_WM_DESTROY(OnDestroy) CHAIN_MSG_MAP(base)
CHAIN_MSG_MAP(base) END_MSG_MAP()
END_MSG_MAP()
BEGIN_DDX_MAP(CAdvancedPage) BEGIN_DDX_MAP(CAdvancedPage)
DDX_UINT(IDC_SERVERPORT, m_server_port); DDX_UINT(IDC_SERVERPORT, m_server_port);
DDX_CONTROL_HANDLE(IDC_PORTSPIN, m_port_spin); DDX_CONTROL_HANDLE(IDC_PORTSPIN, m_port_spin);
DDX_CONTROL_HANDLE(IDC_AUTOSTART, m_autostart_check); DDX_CONTROL_HANDLE(IDC_AUTOSTART, m_autostart_check);
END_DDX_MAP() DDX_CONTROL_HANDLE(IDC_AUTOSTART_ICON, m_autostart_icon_check);
END_DDX_MAP()
// MessageHandlers; // MessageHandlers;
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnStartService(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnStartService(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnStopService(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnStopService(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnWebAdmin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnWebAdmin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
void OnDestroy(); void OnDestroy();
void OnTimer(UINT id, TIMERPROC proc); void OnTimer(UINT id, TIMERPROC proc);
int OnApply(); int OnApply();
void OnChange(UINT uCode, int nCtrlID, HWND hwndCtrl) void OnChange(UINT uCode, int nCtrlID, HWND hwndCtrl) {
{ // Lots of things could have changed.
// Lots of things could have changed. SetModified();
SetModified(); }
}
void OnClickAutostart(UINT uCode, int nCtrlID, HWND hwndCtrl)
{
// When clicked revert to being a normal checkbox in case
// we were intermediate.
if (m_autostart_check.GetButtonStyle() != BS_AUTOCHECKBOX)
{
m_autostart_check.SetButtonStyle(BS_AUTOCHECKBOX);
m_autostart_check.SetCheck(TRUE);
}
OnChange(uCode, nCtrlID, hwndCtrl);
}
}; };
#endif // ADVANCEDPAGE_H #endif // ADVANCEDPAGE_H

View File

@ -299,63 +299,45 @@ CString Application::MakeRunKeyValue()
return required_path; return required_path;
} }
void Application::EnableAutoStart(HWND hwnd, bool enable) void Application::EnableServiceAutoStart(HWND hwnd, bool enable) {
{ int required_startup = enable ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
// First let's control the service.
int required_startup = enable ? SERVICE_AUTO_START : SERVICE_DISABLED;
if (m_service.GetStartup() != required_startup) if (m_service.GetStartup() != required_startup) {
{ if (!m_service.ConfigureStartup(required_startup)) {
if (!m_service.ConfigureStartup(required_startup))
{
MessageBox(hwnd, IDS_FAILED_CONFIGURE_SERVICE, MB_OK); MessageBox(hwnd, IDS_FAILED_CONFIGURE_SERVICE, MB_OK);
} }
} }
}
// Now let's set up the Run key. void Application::EnableAppletAutoStart(HWND hwnd, bool enable) {
HKEY hkey; HKEY hkey;
LONG result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, RUN_KEY, 0, KEY_SET_VALUE | STANDARD_RIGHTS_WRITE, &hkey); LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_SET_VALUE | STANDARD_RIGHTS_WRITE, &hkey);
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS) {
{ if (enable) {
if (enable)
{
// We need to quote it because the path may contain spaces. // We need to quote it because the path may contain spaces.
CString str = MakeRunKeyValue(); CString str = MakeRunKeyValue();
result = RegSetValueEx(hkey, RUN_VALUE, 0UL, REG_SZ, reinterpret_cast<LPCBYTE>(static_cast<LPCTSTR>(str)), (str.GetLength() + 1) * sizeof(TCHAR)); result = RegSetValueEx(hkey, RUN_VALUE, 0UL, REG_SZ, reinterpret_cast<LPCBYTE>(static_cast<LPCTSTR>(str)), (str.GetLength() + 1) * sizeof(TCHAR));
} } else {
else
{
result = RegDeleteValue(hkey, RUN_VALUE); result = RegDeleteValue(hkey, RUN_VALUE);
if (result == ERROR_FILE_NOT_FOUND) if (result == ERROR_FILE_NOT_FOUND)
result = 0; result = 0;
} }
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS) {
{
ATLTRACE("Error:%u\n", result); ATLTRACE("Error:%u\n", result);
MessageBox(hwnd, IDS_FAILED_CONFIGURE_STARTUP, MB_OK); MessageBox(hwnd, IDS_FAILED_CONFIGURE_STARTUP, MB_OK);
} }
} }
} }
int Application::IsAutoStartEnabled() const bool Application::IsServiceAutoStartEnabled() const {
{ return (m_service.GetStartup() == SERVICE_AUTO_START);
// Look at the service }
int service_result = 2;
switch (m_service.GetStartup())
{
case SERVICE_AUTO_START:
service_result = true;
break;
case SERVICE_DISABLED:
service_result = false;
break;
}
// Look at the Run key bool Application::IsAppletAutoStartEnabled() const {
int run_result = 2; bool run_result = false;
HKEY hkey; HKEY hkey;
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, RUN_KEY, 0, KEY_QUERY_VALUE | STANDARD_RIGHTS_READ, &hkey) == ERROR_SUCCESS) if (::RegOpenKeyEx(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_QUERY_VALUE | STANDARD_RIGHTS_READ, &hkey) == ERROR_SUCCESS)
{ {
DWORD dwType, cbData; DWORD dwType, cbData;
TCHAR buffer[_MAX_PATH + 1]; TCHAR buffer[_MAX_PATH + 1];
@ -370,7 +352,12 @@ int Application::IsAutoStartEnabled() const
else else
{ {
// It's there - but it isn't us that it will start. // It's there - but it isn't us that it will start.
run_result = 2;
// But from the user's perspective, it *is* us, so to make the perception
// match the setting, we'll make this true, rather than some indeterminate
// thing which nobody understands. -- Ron
run_result = true;
} }
} }
else else
@ -380,15 +367,9 @@ int Application::IsAutoStartEnabled() const
} }
} }
else else
{
run_result = false; run_result = false;
}
// If the answers agree then return them. Otherwise we're indeterminate. return run_result;
if (run_result == service_result)
return run_result;
else
return 2;
} }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)

View File

@ -137,10 +137,12 @@ public:
void EnableServerEvents(bool); void EnableServerEvents(bool);
/// Enable/disable automatic startup of service and FireflyShell. /// Enable/disable automatic startup of service and FireflyShell.
void EnableAutoStart(HWND, bool); void EnableAppletAutoStart(HWND, bool);
void EnableServiceAutoStart(HWND, bool);
/// Reports 0 for disabled, 1 for enabled, 2 for indeterminate /// Reports 0 for disabled, 1 for enabled
int IsAutoStartEnabled() const; bool IsAppletAutoStartEnabled() const;
bool IsServiceAutoStartEnabled() const;
int MessageBox(HWND hwnd, UINT id, UINT flags) int MessageBox(HWND hwnd, UINT id, UINT flags)
{ {

View File

@ -68,21 +68,16 @@ STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About" CAPTION "About"
FONT 8, "MS Sans Serif", 0, 0, 0x0 FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN BEGIN
CTEXT "For help, tips and troubleshooting advice...", CTEXT "For help, tips and troubleshooting advice...",IDC_FIREFLYLINK,12,92,276,9,NOT WS_GROUP
IDC_FIREFLYLINK,12,92,276,9,NOT WS_GROUP
GROUPBOX "Version information",IDC_STATIC,6,121,288,100 GROUPBOX "Version information",IDC_STATIC,6,121,288,100
CONTROL "",IDC_VERSIONLIST,"SysListView32",LVS_REPORT | CONTROL "",IDC_VERSIONLIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,12,132,276,68
LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,12,132,276,68
PUSHBUTTON "&Copy to Clipboard",IDC_COPY,192,203,96,14 PUSHBUTTON "&Copy to Clipboard",IDC_COPY,192,203,96,14
CONTROL 208,IDC_LOGO,"Static",SS_BITMAP | SS_CENTERIMAGE | CONTROL 208,IDC_LOGO,"Static",SS_BITMAP | SS_CENTERIMAGE | SS_SUNKEN | WS_BORDER,6,7,288,73
SS_SUNKEN | WS_BORDER,6,7,288,73 CTEXT "For information on Firefly compatible music players...",IDC_ROKULINK,12,106,276,9,NOT WS_GROUP
CTEXT "For information on Firefly compatible music players...",
IDC_ROKULINK,12,106,276,9,NOT WS_GROUP
END END
IDD_PAGE_BASIC DIALOGEX 0, 0, 300, 230 IDD_PAGE_BASIC DIALOGEX 0, 0, 300, 230
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
WS_SYSMENU
CAPTION "Library" CAPTION "Library"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
@ -92,51 +87,43 @@ BEGIN
EDITTEXT IDC_PATH,86,57,202,14,ES_AUTOHSCROLL EDITTEXT IDC_PATH,86,57,202,14,ES_AUTOHSCROLL
PUSHBUTTON "&Browse...",IDC_BROWSE,228,76,60,14 PUSHBUTTON "&Browse...",IDC_BROWSE,228,76,60,14
GROUPBOX "Security",IDC_STATIC,7,113,287,103 GROUPBOX "Security",IDC_STATIC,7,113,287,103
CONTROL "&Protect Firefly media library with a password", CONTROL "&Protect Firefly media library with a password",IDC_PROTECT,
IDC_PROTECT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135,276,10
276,10
LTEXT "Pass&word",IDC_STATIC,12,156,74,8 LTEXT "Pass&word",IDC_STATIC,12,156,74,8
EDITTEXT IDC_PASSWORD,86,154,114,14,ES_PASSWORD | ES_AUTOHSCROLL EDITTEXT IDC_PASSWORD,86,154,114,14,ES_PASSWORD | ES_AUTOHSCROLL
LTEXT "You can limit access to your music library by assigning a password. If a password is assigned, only clients that provide the correct password will be able to play music from your library.", LTEXT "You can limit access to your music library by assigning a password. If a password is assigned, only clients that provide the correct password will be able to play music from your library.",IDC_STATIC,12,180,276,26,SS_NOPREFIX
IDC_STATIC,12,180,276,26,SS_NOPREFIX
END END
IDD_PAGE_LOG DIALOGEX 0, 0, 300, 220 IDD_PAGE_LOG DIALOGEX 0, 0, 300, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
WS_SYSMENU
CAPTION "Log" CAPTION "Log"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
EDITTEXT IDC_LOG,6,6,288,189,ES_MULTILINE | ES_AUTOHSCROLL | EDITTEXT IDC_LOG,6,6,288,189,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
ES_READONLY | WS_VSCROLL | WS_HSCROLL
PUSHBUTTON "&Refresh",IDC_REFRESH,244,200,50,14 PUSHBUTTON "&Refresh",IDC_REFRESH,244,200,50,14
END END
IDD_PAGE_ADVANCED DIALOGEX 0, 0, 300, 220 IDD_PAGE_ADVANCED DIALOGEX 0, 0, 300, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
WS_SYSMENU
CAPTION "Server" CAPTION "Server"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
GROUPBOX "Server Status",IDC_STATIC,6,7,288,82 GROUPBOX "Server Status",IDC_STATIC,6,7,288,82
LTEXT "Current state of the server goes here",IDC_SERVERSTATE, LTEXT "Current state of the server goes here",IDC_SERVERSTATE,12,28,199,25
12,28,199,25
PUSHBUTTON "&Stop Server",IDC_STOPSERVICE,218,28,70,14 PUSHBUTTON "&Stop Server",IDC_STOPSERVICE,218,28,70,14
PUSHBUTTON "&Start Server",IDC_STARTSERVICE,218,28,70,14
CONTROL "&Start Firefly when Windows starts",IDC_AUTOSTART, CONTROL "&Start Firefly when Windows starts",IDC_AUTOSTART,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,63,276,10 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,55,276,10
CONTROL "&Enable Firefly icon in system tray",IDC_AUTOSTART_ICON,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,68,276,10
GROUPBOX "Advanced",IDC_STATIC,6,93,288,61 GROUPBOX "Advanced",IDC_STATIC,6,93,288,61
LTEXT "Server port number",IDC_STATIC,12,108,99,11 LTEXT "Server port number",IDC_STATIC,12,108,99,11
EDITTEXT IDC_SERVERPORT,105,105,42,14,ES_AUTOHSCROLL | ES_NUMBER EDITTEXT IDC_SERVERPORT,105,105,42,14,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_PORTSPIN,"msctls_updown32",UDS_SETBUDDYINT | CONTROL "",IDC_PORTSPIN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_HOTTRACK,146,105,11,14
UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | LTEXT "You may need to change this if another program is already using this port.",IDC_STATIC,12,129,276,23
UDS_NOTHOUSANDS | UDS_HOTTRACK,146,105,11,14
LTEXT "You may need to change this if another program is already using this port.",
IDC_STATIC,12,129,276,23
GROUPBOX "Web administration",IDC_STATIC,6,159,288,54 GROUPBOX "Web administration",IDC_STATIC,6,159,288,54
LTEXT "Firefly Media Server also provides a web administration interface.", LTEXT "Firefly Media Server also provides a web administration interface.",IDC_STATIC,12,177,198,20
IDC_STATIC,12,177,198,20
PUSHBUTTON "&Open",IDC_WEBADMIN,218,177,70,14 PUSHBUTTON "&Open",IDC_WEBADMIN,218,177,70,14
PUSHBUTTON "&Start Server",IDC_STARTSERVICE,218,28,70,14
END END

View File

@ -65,17 +65,13 @@ bool Service::Open(const TCHAR *name)
DWORD dwDesiredAccess = USER_ACCESS; DWORD dwDesiredAccess = USER_ACCESS;
m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess); m_sc_manager = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, dwDesiredAccess);
if (!m_sc_manager)
{
m_can_control = false;
}
else
{
m_can_control = true;
}
if (m_sc_manager) if (!m_sc_manager)
{ m_can_control = false;
else
m_can_control = true;
if (m_sc_manager) {
m_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess); m_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess);
if (m_sc_service) { if (m_sc_service) {
m_name = name; m_name = name;
@ -87,15 +83,12 @@ bool Service::Open(const TCHAR *name)
return false; return false;
} }
void Service::Close() void Service::Close() {
{ if (m_sc_service) {
if (m_sc_service)
{
::CloseServiceHandle(m_sc_service); ::CloseServiceHandle(m_sc_service);
m_sc_service = NULL; m_sc_service = NULL;
} }
if (m_sc_manager) if (m_sc_manager) {
{
::CloseServiceHandle(m_sc_manager); ::CloseServiceHandle(m_sc_manager);
m_sc_manager = NULL; m_sc_manager = NULL;
} }
@ -231,12 +224,12 @@ DWORD Service::GetStartup() const
return result; return result;
} }
bool Service::ConfigureStartup(DWORD startup) bool Service::ConfigureStartup(DWORD startup) {
{ if(startup != GetStartup()) { // don't boost privs if we don't need to
if (::ChangeServiceConfig(m_sc_service, SERVICE_NO_CHANGE, startup, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) if (!::ChangeServiceConfig(m_sc_service, SERVICE_NO_CHANGE, startup, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
return true; return false;
else }
return false; return true;
} }
void ServiceStatusMonitor::Poll(Service *service) void ServiceStatusMonitor::Poll(Service *service)

View File

@ -46,6 +46,8 @@
#define IDC_AUTOSTART 1012 #define IDC_AUTOSTART 1012
#define IDC_WEBADMIN 1013 #define IDC_WEBADMIN 1013
#define IDC_WEBSITE 1014 #define IDC_WEBSITE 1014
#define IDC_AUTOSTART2 1014
#define IDC_AUTOSTART_ICON 1014
#define IDC_VERSIONLIST 1015 #define IDC_VERSIONLIST 1015
#define IDC_COPY 1016 #define IDC_COPY 1016
#define IDC_REFRESH 1018 #define IDC_REFRESH 1018