123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /////////////////////////////////////////////////////////////////////////////
- // AllSrvUI.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "AllSrvUI.h"
- #include "AllSrvUISheet.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CAllSrvUIApp object
- CAllSrvUIApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CAllSrvUIApp
- /////////////////////////////////////////////////////////////////////////////
- // Message Map
- BEGIN_MESSAGE_MAP(CAllSrvUIApp, CWinApp)
- //{{AFX_MSG_MAP(CAllSrvUIApp)
- //}}AFX_MSG
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // Construction
- CAllSrvUIApp::CAllSrvUIApp() :
- m_hrCoInit(E_FAIL)
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // Attributes
- void CAllSrvUIApp::GetArtPath(char * szArtPath)
- {
- strcpy(szArtPath, ".\\Artwork\\");
- CRegKey key;
- if (ERROR_SUCCESS == key.Open(HKEY_LOCAL_MACHINE, HKLM_FedSrv, KEY_READ))
- {
- ZString strArtPath;
- if (SUCCEEDED(LoadRegString(key, "Artpath", strArtPath)))
- {
- // if reg value exists copy over default
- strncpy(szArtPath, PCC(strArtPath), MAX_PATH);
- }
- // ensure last character is a backslash
- int nLast = max(0, strlen(szArtPath)-1);
- if (szArtPath[nLast] != '\\' || szArtPath[nLast] != '/')
- szArtPath[nLast+1] = '\\';
- szArtPath[nLast+2] = 0;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // Overrides
- BOOL CAllSrvUIApp::InitInstance()
- {
- // Determine if another instance is already running
- HANDLE hEvent = GetAllSrvUIEvent();
- if (hEvent)
- {
- // Signal the other instance to activate itself
- ::SetEvent(hEvent);
- // Close the event handle and exit
- ::CloseHandle(hEvent);
- return false;
- }
- // Ensure that the EULA has been agreed to
- HRESULT hr = FirstRunEula();
- if (E_FAIL == hr)
- {
- ::MessageBox(0, "Error while loading loading ebueula.dll", "Allegiance Server", 0);
- return false;
- }
- else if (S_FALSE == hr)
- {
- ::MessageBox(0, "You must accept the End User License Agreement before running the Allegiance Server", "Allegiance Server", 0);
- return false;
- }
- else
- {
- assert(S_OK == hr);
- }
- // Create the instance event
- CreateAllSrvUIEvent();
- // Initialize COM
- // m_hrCoInit = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- m_hrCoInit = CoInitialize(NULL);
- // Create the property sheet window
- CAllSrvUISheet* pps = new CAllSrvUISheet;
- // Create the property sheet as a modeless dialog box
- if (pps->Create())
- m_pMainWnd = pps;
- // Continue processing the application
- return true;
- }
- int CAllSrvUIApp::ExitInstance()
- {
- // Uninitialize COM
- if (SUCCEEDED(m_hrCoInit))
- CoUninitialize();
- // Perform default processing
- return CWinApp::ExitInstance();
- }
- BOOL CAllSrvUIApp::OnIdle(LONG lCount)
- {
- HANDLE hEvents[] = {m_shEventSync};
- DWORD dwWait = ::MsgWaitForMultipleObjects(sizeofArray(hEvents), hEvents,
- false, INFINITE, QS_ALLINPUT);
- if (WAIT_OBJECT_0 == dwWait)
- {
- ::ResetEvent(m_shEventSync);
- m_pMainWnd->SetForegroundWindow();
- m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
- }
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Implementation
- HANDLE CAllSrvUIApp::GetAllSrvUIEvent()
- {
- // Open the mutex using the global name first
- DWORD dwAccess = EVENT_MODIFY_STATE | SYNCHRONIZE;
- HANDLE hEvent = ::OpenEvent(dwAccess, false, szAllSrvUIRunningGlobal);
- if (!hEvent)
- hEvent = ::OpenEvent(dwAccess, false, szAllSrvUIRunning);
- return hEvent;
- }
- void CAllSrvUIApp::CreateAllSrvUIEvent()
- {
- // Create a NULL dacl to give "everyone" access
- SECURITY_ATTRIBUTES* psa = NULL;
- SECURITY_DESCRIPTOR sd;
- SECURITY_ATTRIBUTES sa = {sizeof(sa), &sd, false};
- if (IsWinNT())
- {
- InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(&sd, true, NULL, FALSE);
- psa = &sa;
- }
- // Create the event using the global name first
- HANDLE hEvent = ::CreateEvent(psa, true, false, szAllSrvUIRunningGlobal);
- if (!hEvent)
- hEvent = ::CreateEvent(psa, true, false, szAllSrvUIRunning);
- m_shEventSync = hEvent;
- }
- //
- // EULA related files should be in the artwork folder so that they may be autoupdated
- //
- HRESULT CAllSrvUIApp::FirstRunEula()
- {
- TCHAR szArtpath[MAX_PATH];
- GetArtPath(szArtpath);
- PathString strArtPath = szArtpath;
- PathString strEulaRTF = strArtPath + "eula.rtf";
- {
- ZFile file(strEulaRTF);
- int n = file.GetLength(); // -1 means error
- if (n == -1)
- return E_FAIL;
- }
- // don't use += operator cause it's buggy with PathString
- strArtPath = strArtPath + "EBUEula.dll";
- HINSTANCE hMod = LoadLibrary(PCC(strArtPath));
- if (NULL == hMod) // can't attach to DLL
- {
- // this time, search path
- hMod = LoadLibrary("EBUEula.dll");
- if (NULL == hMod) // can't attach to DLL
- return E_FAIL;
- }
- EBUPROC pfnEBUEula = (EBUPROC) GetProcAddress(hMod, "EBUEula");
- if (NULL == pfnEBUEula) // can't find entry point
- {
- FreeLibrary(hMod);
- return E_FAIL;
- }
- /*
- TCHAR szWarranty[MAX_PATH];
- LoadString(GetModuleHandle(), STR_EULAFILENAME, szEULA, sizeof(szEULA));
- LoadString(GetModuleHandle(), STR_WARRANTYNAME, szWarranty, sizeof(szWarranty));
- //
- //This call enables both EULA and warranty accepting/viewing/printing. If your
- //game doesn't ship with a WARRANTY file, specifiy NULL instead of szWarranty…
- //The code below, for instance, works with both OEM and retail builds…
- //
- TCHAR *pszWarrantyParam = 0xFFFFFFFF != GetFileAttributes(szWarranty) ? szWarranty : NULL;
- */
- bool bAllowGameToRun = pfnEBUEula(HKLM_AllSrvUI, PCC(strEulaRTF), NULL, TRUE) != 0;
- FreeLibrary(hMod);
- return (bAllowGameToRun ? S_OK : S_FALSE);
- }
|