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
*
* 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
* by the Free Software Foundation.
*
* 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.
*
* Please read README.txt in the same directory as this source file for
* further license information.
*/
*(C) 2006 Roku LLC
*
* 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
* by the Free Software Foundation.
*
* 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.
*
* Please read README.txt in the same directory as this source file for
* further license information.
*/
#include "stdafx.h"
#include "AdvancedPage.h"
@ -21,156 +21,138 @@
LRESULT CAdvancedPage::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CWaitCursor wait;
CWaitCursor wait;
IniFile ini(GetApplication()->GetConfigPath());
m_server_port = ini.GetInteger(_T("general"), _T("port"), 9999);
IniFile ini(GetApplication()->GetConfigPath());
m_server_port = ini.GetInteger(_T("general"), _T("port"), 9999);
DoDataExchange(false);
m_port_spin.SetRange32(1, 65535);
DoDataExchange(false);
m_port_spin.SetRange32(1, 65535);
switch (GetApplication()->IsAutoStartEnabled())
{
case 0:
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();
if(GetApplication()->IsServiceAutoStartEnabled())
m_autostart_check.SetCheck(BST_CHECKED);
else
m_autostart_check.SetCheck(BST_UNCHECKED);
GetDlgItem(IDC_STARTSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
GetDlgItem(IDC_STOPSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
if(GetApplication()->IsAppletAutoStartEnabled())
m_autostart_icon_check.SetCheck(BST_CHECKED);
else
m_autostart_icon_check.SetCheck(BST_UNCHECKED);
GetApplication()->ServiceStatusSubscribe(this);
return 0;
UpdateControls();
GetDlgItem(IDC_STARTSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
GetDlgItem(IDC_STOPSERVICE).SendMessage(BCM_SETSHIELD,0,TRUE);
GetApplication()->ServiceStatusSubscribe(this);
return 0;
}
void CAdvancedPage::OnDestroy()
{
GetApplication()->ServiceStatusUnsubscribe(this);
void CAdvancedPage::OnDestroy() {
GetApplication()->ServiceStatusUnsubscribe(this);
}
void CAdvancedPage::UpdateControls()
{
Service::Status status = GetApplication()->GetServiceStatus();
UpdateControls(status);
void CAdvancedPage::UpdateControls() {
Service::Status status = GetApplication()->GetServiceStatus();
UpdateControls(status);
}
void CAdvancedPage::UpdateControls(Service::Status status)
{
UINT state_id;
if (status.IsPending())
{
state_id = IDS_SERVER_PENDING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
}
else if (status.IsRunning())
{
state_id = IDS_SERVER_RUNNING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_SHOW);
}
else
{
state_id = IDS_SERVER_STOPPED;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_SHOW);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
}
UINT state_id;
if (status.IsPending())
{
state_id = IDS_SERVER_PENDING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
}
else if (status.IsRunning())
{
state_id = IDS_SERVER_RUNNING;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_HIDE);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_SHOW);
}
else
{
state_id = IDS_SERVER_STOPPED;
GetDlgItem(IDC_STARTSERVICE).ShowWindow(SW_SHOW);
GetDlgItem(IDC_STOPSERVICE).ShowWindow(SW_HIDE);
}
const bool can_configure = GetApplication()->CanConfigure();
GetDlgItem(IDC_SERVERPORT).EnableWindow(can_configure);
GetDlgItem(IDC_PORTSPIN).EnableWindow(can_configure);
const bool can_configure = GetApplication()->CanConfigure();
GetDlgItem(IDC_SERVERPORT).EnableWindow(can_configure);
GetDlgItem(IDC_PORTSPIN).EnableWindow(can_configure);
// If we can't control the service then don't give the user
// the impression that we can.
const bool can_control = GetApplication()->CanControlService();
GetDlgItem(IDC_STARTSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_STOPSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_AUTOSTART).EnableWindow(can_control);
// If we can't control the service then don't give the user
// the impression that we can.
const bool can_control = GetApplication()->CanControlService();
GetDlgItem(IDC_STARTSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_STOPSERVICE).EnableWindow(can_control);
GetDlgItem(IDC_AUTOSTART).EnableWindow(can_control);
CString state;
state.LoadString(state_id);
if (!can_control)
{
CString s;
s.LoadString(IDS_NOT_ADMIN);
state += " ";
state += s;
}
CString state;
state.LoadString(state_id);
if (!can_control)
{
CString s;
s.LoadString(IDS_NOT_ADMIN);
state += " ";
state += s;
}
GetDlgItem(IDC_SERVERSTATE).SetWindowText(state);
GetDlgItem(IDC_SERVERSTATE).SetWindowText(state);
}
int CAdvancedPage::OnApply()
{
CWaitCursor wait;
CWaitCursor wait;
ATLTRACE("CAdvancedPage::OnApply\n");
ATLTRACE("CAdvancedPage::OnApply\n");
if (!DoDataExchange(true))
return false;
if (!DoDataExchange(true))
return false;
IniFile ini(GetApplication()->GetConfigPath());
ini.SetInteger(_T("general"), _T("port"), m_server_port);
IniFile ini(GetApplication()->GetConfigPath());
ini.SetInteger(_T("general"), _T("port"), m_server_port);
switch (m_autostart_check.GetCheck())
{
case BST_CHECKED:
GetApplication()->EnableAutoStart(m_hWnd, true);
break;
case BST_UNCHECKED:
GetApplication()->EnableAutoStart(m_hWnd, false);
break;
case BST_INDETERMINATE:
// Ignore
break;
}
GetApplication()->EnableServiceAutoStart(m_hWnd,m_autostart_check.GetCheck() == BST_CHECKED);
GetApplication()->EnableAppletAutoStart(m_hWnd,m_autostart_icon_check.GetCheck() == BST_CHECKED);
// Incorrectly documented in WTL
return true;
// Incorrectly documented in WTL
return true;
}
LRESULT CAdvancedPage::OnStartService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
GetApplication()->StartService(m_hWnd);
UpdateControls();
return 0;
GetApplication()->StartService(m_hWnd);
UpdateControls();
return 0;
}
LRESULT CAdvancedPage::OnStopService(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
GetApplication()->StopService(m_hWnd);
UpdateControls();
return 0;
GetApplication()->StopService(m_hWnd);
UpdateControls();
return 0;
}
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.
IniFile ini(GetApplication()->GetConfigPath());
unsigned int port = ini.GetInteger(_T("general"), _T("port"), 9999);
// Go to the config file because we might not have committed a change yet.
IniFile ini(GetApplication()->GetConfigPath());
unsigned int port = ini.GetInteger(_T("general"), _T("port"), 9999);
CString url;
url.Format(_T("http://localhost:%u/"), port);
CString url;
url.Format(_T("http://localhost:%u/"), port);
::ShellExecute(m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWNORMAL);
return 0;
::ShellExecute(m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWNORMAL);
return 0;
}
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
*
* 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
* by the Free Software Foundation.
*
* 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.
*
* Please read README.txt in the same directory as this source file for
* further license information.
*/
*(C) 2006 Roku LLC
*
* 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
* by the Free Software Foundation.
*
* 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.
*
* Please read README.txt in the same directory as this source file for
* further license information.
*/
#ifndef ADVANCEDPAGE_H
#define ADVANCEDPAGE_H 1
@ -23,76 +23,65 @@
/// @todo Users shouldn't be able to paste non-numbers into the port number.
class CAdvancedPage :
public CPropertyPageImpl<CAdvancedPage>,
public CWinDataExchange<CAdvancedPage>,
public ServiceStatusObserver
public CPropertyPageImpl<CAdvancedPage>,
public CWinDataExchange<CAdvancedPage>,
public ServiceStatusObserver
{
public:
enum { IDD = IDD_PAGE_ADVANCED };
enum { IDD = IDD_PAGE_ADVANCED };
private:
typedef CPropertyPageImpl<CAdvancedPage> base;
typedef CPropertyPageImpl<CAdvancedPage> base;
enum ServiceState
{
Pending = 0,
Running = 1,
Stopped = 2
};
enum ServiceState
{
Pending = 0,
Running = 1,
Stopped = 2
};
enum { TIMER_ID = 42 };
enum { TIMER_ID = 42 };
unsigned int m_server_port;
CUpDownCtrl m_port_spin;
CButton m_autostart_check;
unsigned int m_server_port;
CUpDownCtrl m_port_spin;
CButton m_autostart_check;
CButton m_autostart_icon_check;
void UpdateControls(Service::Status status);
void UpdateControls();
void UpdateControls(Service::Status status);
void UpdateControls();
// ServiceStatusObserver
void OnServiceStatus(Service::Status old_status, Service::Status new_status);
// ServiceStatusObserver
void OnServiceStatus(Service::Status old_status, Service::Status new_status);
BEGIN_MSG_MAP(CAdvancedPage)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
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_STOPSERVICE, OnStopService)
COMMAND_ID_HANDLER(IDC_WEBADMIN, OnWebAdmin)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(base)
END_MSG_MAP()
BEGIN_MSG_MAP(CAdvancedPage)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER_EX(IDC_SERVERPORT, EN_CHANGE, OnChange)
COMMAND_ID_HANDLER(IDC_STARTSERVICE, OnStartService)
COMMAND_ID_HANDLER(IDC_STOPSERVICE, OnStopService)
COMMAND_ID_HANDLER(IDC_WEBADMIN, OnWebAdmin)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(base)
END_MSG_MAP()
BEGIN_DDX_MAP(CAdvancedPage)
DDX_UINT(IDC_SERVERPORT, m_server_port);
DDX_CONTROL_HANDLE(IDC_PORTSPIN, m_port_spin);
DDX_CONTROL_HANDLE(IDC_AUTOSTART, m_autostart_check);
END_DDX_MAP()
BEGIN_DDX_MAP(CAdvancedPage)
DDX_UINT(IDC_SERVERPORT, m_server_port);
DDX_CONTROL_HANDLE(IDC_PORTSPIN, m_port_spin);
DDX_CONTROL_HANDLE(IDC_AUTOSTART, m_autostart_check);
DDX_CONTROL_HANDLE(IDC_AUTOSTART_ICON, m_autostart_icon_check);
END_DDX_MAP()
// MessageHandlers;
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnStartService(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*/);
void OnDestroy();
void OnTimer(UINT id, TIMERPROC proc);
int OnApply();
void OnChange(UINT uCode, int nCtrlID, HWND hwndCtrl)
{
// Lots of things could have changed.
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);
}
// MessageHandlers;
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnStartService(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*/);
void OnDestroy();
void OnTimer(UINT id, TIMERPROC proc);
int OnApply();
void OnChange(UINT uCode, int nCtrlID, HWND hwndCtrl) {
// Lots of things could have changed.
SetModified();
}
};
#endif // ADVANCEDPAGE_H

View File

@ -299,63 +299,45 @@ CString Application::MakeRunKeyValue()
return required_path;
}
void Application::EnableAutoStart(HWND hwnd, bool enable)
{
// First let's control the service.
int required_startup = enable ? SERVICE_AUTO_START : SERVICE_DISABLED;
void Application::EnableServiceAutoStart(HWND hwnd, bool enable) {
int required_startup = enable ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
if (m_service.GetStartup() != required_startup)
{
if (!m_service.ConfigureStartup(required_startup))
{
if (m_service.GetStartup() != required_startup) {
if (!m_service.ConfigureStartup(required_startup)) {
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;
LONG result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, RUN_KEY, 0, KEY_SET_VALUE | STANDARD_RIGHTS_WRITE, &hkey);
if (result == ERROR_SUCCESS)
{
if (enable)
{
LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_SET_VALUE | STANDARD_RIGHTS_WRITE, &hkey);
if (result == ERROR_SUCCESS) {
if (enable) {
// We need to quote it because the path may contain spaces.
CString str = MakeRunKeyValue();
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);
if (result == ERROR_FILE_NOT_FOUND)
result = 0;
}
if (result != ERROR_SUCCESS)
{
if (result != ERROR_SUCCESS) {
ATLTRACE("Error:%u\n", result);
MessageBox(hwnd, IDS_FAILED_CONFIGURE_STARTUP, MB_OK);
}
}
}
int Application::IsAutoStartEnabled() const
{
// 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;
}
bool Application::IsServiceAutoStartEnabled() const {
return (m_service.GetStartup() == SERVICE_AUTO_START);
}
// Look at the Run key
int run_result = 2;
bool Application::IsAppletAutoStartEnabled() const {
bool run_result = false;
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;
TCHAR buffer[_MAX_PATH + 1];
@ -370,7 +352,12 @@ int Application::IsAutoStartEnabled() const
else
{
// 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
@ -380,15 +367,9 @@ int Application::IsAutoStartEnabled() const
}
}
else
{
run_result = false;
}
// If the answers agree then return them. Otherwise we're indeterminate.
if (run_result == service_result)
return run_result;
else
return 2;
return run_result;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)

View File

@ -137,10 +137,12 @@ public:
void EnableServerEvents(bool);
/// 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
int IsAutoStartEnabled() const;
/// Reports 0 for disabled, 1 for enabled
bool IsAppletAutoStartEnabled() const;
bool IsServiceAutoStartEnabled() const;
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"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CTEXT "For help, tips and troubleshooting advice...",
IDC_FIREFLYLINK,12,92,276,9,NOT WS_GROUP
CTEXT "For help, tips and troubleshooting advice...",IDC_FIREFLYLINK,12,92,276,9,NOT WS_GROUP
GROUPBOX "Version information",IDC_STATIC,6,121,288,100
CONTROL "",IDC_VERSIONLIST,"SysListView32",LVS_REPORT |
LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,12,132,276,68
CONTROL "",IDC_VERSIONLIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,12,132,276,68
PUSHBUTTON "&Copy to Clipboard",IDC_COPY,192,203,96,14
CONTROL 208,IDC_LOGO,"Static",SS_BITMAP | SS_CENTERIMAGE |
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
CONTROL 208,IDC_LOGO,"Static",SS_BITMAP | SS_CENTERIMAGE | 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
END
IDD_PAGE_BASIC DIALOGEX 0, 0, 300, 230
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Library"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
@ -92,51 +87,43 @@ BEGIN
EDITTEXT IDC_PATH,86,57,202,14,ES_AUTOHSCROLL
PUSHBUTTON "&Browse...",IDC_BROWSE,228,76,60,14
GROUPBOX "Security",IDC_STATIC,7,113,287,103
CONTROL "&Protect Firefly media library with a password",
IDC_PROTECT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135,
276,10
CONTROL "&Protect Firefly media library with a password",IDC_PROTECT,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135,276,10
LTEXT "Pass&word",IDC_STATIC,12,156,74,8
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.",
IDC_STATIC,12,180,276,26,SS_NOPREFIX
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
END
IDD_PAGE_LOG DIALOGEX 0, 0, 300, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Log"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_LOG,6,6,288,189,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY | WS_VSCROLL | WS_HSCROLL
EDITTEXT IDC_LOG,6,6,288,189,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
PUSHBUTTON "&Refresh",IDC_REFRESH,244,200,50,14
END
IDD_PAGE_ADVANCED DIALOGEX 0, 0, 300, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Server"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
GROUPBOX "Server Status",IDC_STATIC,6,7,288,82
LTEXT "Current state of the server goes here",IDC_SERVERSTATE,
12,28,199,25
LTEXT "Current state of the server goes here",IDC_SERVERSTATE,12,28,199,25
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,
"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
LTEXT "Server port number",IDC_STATIC,12,108,99,11
EDITTEXT IDC_SERVERPORT,105,105,42,14,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_PORTSPIN,"msctls_updown32",UDS_SETBUDDYINT |
UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS |
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
CONTROL "",IDC_PORTSPIN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | 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
LTEXT "Firefly Media Server also provides a web administration interface.",
IDC_STATIC,12,177,198,20
LTEXT "Firefly Media Server also provides a web administration interface.",IDC_STATIC,12,177,198,20
PUSHBUTTON "&Open",IDC_WEBADMIN,218,177,70,14
PUSHBUTTON "&Start Server",IDC_STARTSERVICE,218,28,70,14
END

View File

@ -65,17 +65,13 @@ bool Service::Open(const TCHAR *name)
DWORD dwDesiredAccess = USER_ACCESS;
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_sc_service = ::OpenService(m_sc_manager, name, dwDesiredAccess);
if (m_sc_service) {
m_name = name;
@ -87,15 +83,12 @@ bool Service::Open(const TCHAR *name)
return false;
}
void Service::Close()
{
if (m_sc_service)
{
void Service::Close() {
if (m_sc_service) {
::CloseServiceHandle(m_sc_service);
m_sc_service = NULL;
}
if (m_sc_manager)
{
if (m_sc_manager) {
::CloseServiceHandle(m_sc_manager);
m_sc_manager = NULL;
}
@ -231,12 +224,12 @@ DWORD Service::GetStartup() const
return result;
}
bool Service::ConfigureStartup(DWORD startup)
{
if (::ChangeServiceConfig(m_sc_service, SERVICE_NO_CHANGE, startup, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
return true;
else
return false;
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))
return false;
}
return true;
}
void ServiceStatusMonitor::Poll(Service *service)

View File

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