Exemple #1
0
HRESULT CXBMC_PC::Create( HINSTANCE hInstance, LPSTR commandLine )
{
  m_hInstance = hInstance;
  HRESULT hr = S_OK;

  CStdStringW strcl(commandLine);
  LPWSTR *szArglist;
  int nArgs;

  szArglist = CommandLineToArgvW(strcl.c_str(), &nArgs);
  if(szArglist != NULL)
  {
    for(int i=0;i<nArgs;i++)
    {
      CStdStringW strArgW(szArglist[i]);
      if(strArgW.Equals(L"-fs"))
        g_advancedSettings.m_startFullScreen = true;
      else if(strArgW.Equals(L"-p") || strArgW.Equals(L"--portable"))
        g_application.EnablePlatformDirectories(false);
      else if(strArgW.Equals(L"-d"))
      {
        if(++i < nArgs)
        {
          int iSleep = _wtoi(szArglist[i]);
          if(iSleep > 0 && iSleep < 360)
            Sleep(iSleep*1000);
          else
            --i;
        }
      }
    }
    LocalFree(szArglist);
  }

  return S_OK;
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT )
{
#ifdef WIN32_MEMORY_LEAK_DETECT
	// Turn on the heap checking
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF       |
					_CRTDBG_DELAY_FREE_MEM_DF	|
                     _CRTDBG_LEAK_CHECK_DF       ) ;
	// Not adding the _CRTDBG_CHECK_ALWAYS_DF flag either - since it makes Boxee run VERY slow.

#endif

#ifdef USE_MINI_DUMPS
  g_MiniDumps.Install();
#endif

  CStdStringW strcl(commandLine);
  if (strcl.Find(L"-usf") >= 0)
  {        
    CUpdateSourceFile UpdateSourceFile;
    bool success = UpdateSourceFile.UpdateProfilesSourceFile();
    
    if(success)
    {
      printf("main - Successfully updated the profiles source files\n");
    }
    else
    {
      printf("main - Failed to update profiles source files\n");
    }

    success = UpdateSourceFile.UpgradeSettings();

    if(success)
    {
      printf("main - Successfully updated GUI Settings\n");
    }
    else
    {
      printf("main - Failed to update GUI Settings\n");
    }
    
    exit(0);
  }

  // Initializes CreateMiniDump to handle exceptions.
  SetUnhandledExceptionFilter( CreateMiniDump );

  // check if Boxee is already running
  bool AlreadyRunning;
  HANDLE hMutexOneInstance = ::CreateMutex( NULL, FALSE,
    _T("BOXEE-4B71588F-DDBB-40da-AD86-3187B70AA5A3"));

  AlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS || 
    ::GetLastError() == ERROR_ACCESS_DENIED);
  // The call fails with ERROR_ACCESS_DENIED if the Mutex was 
  // created in a different users session because of passing
  // NULL for the SECURITY_ATTRIBUTES on Mutex creation);
#ifndef _DEBUG
  if ( AlreadyRunning )
  {
    HWND m_hwnd = FindWindow("Boxee","Boxee");
    if(m_hwnd != NULL)
    {
      // switch to the running instance
      ShowWindow(m_hwnd,SW_RESTORE);
      SetForegroundWindow(m_hwnd);
    }
   
    return 0;
  }
#endif

  if(CWIN32Util::GetDesktopColorDepth() < 32)
  {
    //FIXME: replace it by a SDL window for all ports
    MessageBox(NULL, "Desktop Color Depth isn't 32Bit", "BOXEE: Fatal Error", MB_OK|MB_ICONERROR);
    return 0;
  }

  // parse the command line
  LPWSTR *szArglist;
  int nArgs;

  g_advancedSettings.m_startFullScreen = false;
  szArglist = CommandLineToArgvW(strcl.c_str(), &nArgs);
  if(szArglist != NULL)
  {
    for(int i=0;i<nArgs;i++)
    {
      CStdStringW strArgW(szArglist[i]);
      if(strArgW.Equals(L"-fs"))
        g_advancedSettings.m_startFullScreen = true;
      else if(strArgW.Equals(L"-p") || strArgW.Equals(L"--portable"))
        g_application.EnablePlatformDirectories(false);
      else if(strArgW.Equals(L"-d"))
      {
        if(++i < nArgs)
        {
          int iSleep = _wtoi(szArglist[i]);
          if(iSleep > 0 && iSleep < 360)
            Sleep(iSleep*1000);
          else
            --i;
}
      }
      // this flag indicate boxee was started from the registry on user login
      // We create a delay to make sure initialization succeed.
      else if (strArgW.Equals(L"-startup"))
      {
        Sleep(5000);
    }
    }
    LocalFree(szArglist);
  }

// we don't want to see the "no disc in drive" windows message box
  SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);

  // Create and run the app
  if (!SUCCEEDED(g_application.Create(NULL)))
  {
    return 1;
  }  

  g_application.Run();

  char *a = new char[50];
  return 0;
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT )
{
  //this can't be set from CAdvancedSettings::Initialize() because it will overwrite
  //the loglevel set with the --debug flag
#ifdef _DEBUG
  g_advancedSettings.m_logLevel     = LOG_LEVEL_DEBUG;
  g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
#else
  g_advancedSettings.m_logLevel     = LOG_LEVEL_NORMAL;
  g_advancedSettings.m_logLevelHint = LOG_LEVEL_NORMAL;
#endif

  // Initializes CreateMiniDump to handle exceptions.
  SetUnhandledExceptionFilter( CreateMiniDump );

  // check if XBMC is already running
  CreateMutex(NULL, FALSE, "XBMC Media Center");
  if(GetLastError() == ERROR_ALREADY_EXISTS)
  {
    HWND m_hwnd = FindWindow("XBMC","XBMC");
    if(m_hwnd != NULL)
    {
      // switch to the running instance
      ShowWindow(m_hwnd,SW_RESTORE);
      SetForegroundWindow(m_hwnd);
    }
    return 0;
  }

#ifndef HAS_DX
  if(CWIN32Util::GetDesktopColorDepth() < 32)
  {
    //FIXME: replace it by a SDL window for all ports
    MessageBox(NULL, "Desktop Color Depth isn't 32Bit", "XBMC: Fatal Error", MB_OK|MB_ICONERROR);
    return 0;
  }
#endif

  //Initialize COM
  CoInitializeEx(NULL, COINIT_MULTITHREADED);

  // parse the command line
  CStdStringW strcl(commandLine);
  LPWSTR *szArglist;
  int nArgs;

  setlocale(LC_NUMERIC, "C");
  g_advancedSettings.Initialize();
  szArglist = CommandLineToArgvW(strcl.c_str(), &nArgs);
  if(szArglist != NULL)
  {
    for(int i=0;i<nArgs;i++)
    {
      CStdStringW strArgW(szArglist[i]);
      if(strArgW.Equals(L"-fs"))
        g_advancedSettings.m_startFullScreen = true;
      else if(strArgW.Equals(L"-p") || strArgW.Equals(L"--portable"))
        g_application.EnablePlatformDirectories(false);
      else if(strArgW.Equals(L"-d"))
      {
        if(++i < nArgs)
        {
          int iSleep = _wtoi(szArglist[i]);
          if(iSleep > 0 && iSleep < 360)
            Sleep(iSleep*1000);
          else
            --i;
        }
      }
      else if(strArgW.Equals(L"--debug"))
      {
        g_advancedSettings.m_logLevel     = LOG_LEVEL_DEBUG;
        g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
      }
    }
    LocalFree(szArglist);
  }

  WSADATA wd;
  WSAStartup(MAKEWORD(2,2), &wd);

  // Create and run the app
  if(!g_application.Create())
  {
    CStdString errorMsg;
    errorMsg.Format("CApplication::Create() failed - check log file and that it is writable");
    MessageBox(NULL, errorMsg.c_str(), "XBMC: Error", MB_OK|MB_ICONERROR);
    return 0;
  }

#ifndef _DEBUG
  // we don't want to see the "no disc in drive" windows message box
  SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
#endif

  g_application.Run();
  
  // put everything in CApplication::Cleanup() since this point is never reached

  return 0;
}