Пример #1
0
void plAnimComponentProc::EnableGlobal(HWND hWnd, bool enable)
{
    ComboBox_Enable(GetDlgItem(hWnd, IDC_ANIM_GLOBAL_LIST), enable);
    ComboBox_Enable(GetDlgItem(hWnd, IDC_ANIM_NAMES), !enable);
    ComboBox_Enable(GetDlgItem(hWnd, IDC_LOOP_NAMES), !enable);
    Button_Enable(GetDlgItem(hWnd, IDC_COMP_ANIM_AUTOSTART_CKBX), !enable);
    Button_Enable(GetDlgItem(hWnd, IDC_COMP_ANIM_LOOP_CKBX), !enable);
}   
Пример #2
0
// This has to get called after any change to audio driver/in dev/out dev
void PopulateDriverSpecificControls(HWND hwndDlg)
{
#ifdef OS_WIN
  int dt = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
  if(dt)   //ASIO
  {
    ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), FALSE);
    Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), TRUE);
  }
  else
  {
    ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), TRUE);
    Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), FALSE);
  }
#endif

  int indevidx = 0;
  int outdevidx = 0;

  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_RESETCONTENT,0,0);
  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_RESETCONTENT,0,0);

  for (int i = 0; i<gAudioInputDevs.size(); i++)
  {
    SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioInputDevs[i]).c_str());

    if(!strcmp(GetAudioDeviceName(gAudioInputDevs[i]).c_str(), gState->mAudioInDev))
      indevidx = i;
  }

  for (int i = 0; i<gAudioOutputDevs.size(); i++)
  {
    SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioOutputDevs[i]).c_str());

    if(!strcmp(GetAudioDeviceName(gAudioOutputDevs[i]).c_str(), gState->mAudioOutDev))
      outdevidx = i;
  }

  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_SETCURSEL, indevidx, 0);
  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_SETCURSEL, outdevidx, 0);

  RtAudio::DeviceInfo inputDevInfo = gDAC->getDeviceInfo(gAudioInputDevs[indevidx]);
  RtAudio::DeviceInfo outputDevInfo = gDAC->getDeviceInfo(gAudioOutputDevs[outdevidx]);

  PopulateAudioInputList(hwndDlg, &inputDevInfo);
  PopulateAudioOutputList(hwndDlg, &outputDevInfo);
  PopulateSampleRateList(hwndDlg, &inputDevInfo, &outputDevInfo);
}
Пример #3
0
// Initialize Filters section
void SppTabFltr::InitFilterDisplay(HWND hDlg)
{
	// Get handles to the controls
	HWND hFilterFile	= GetDlgItem(hDlg,  IDC_EDIT_FILTERFILE);
	HWND hFilterCB		= GetDlgItem(hDlg,  IDC_CH_FILTER);
	HWND hFilters		= GetDlgItem(hDlg,  IDC_COMBO_FILTERS);
	HWND hInputCh		= GetDlgItem(hDlg,  IDC_RAW_CHANNELS);
	HWND hOutputCh		= GetDlgItem(hDlg,  IDC_OUT_CHANNELS);

	// Clear Filter File, Unselect checkbox and gray-out Selected Filters
	Edit_SetText(hFilterFile, TEXT("Select Filter File"));
	Button_SetCheck(hFilterCB, BST_UNCHECKED);
	ComboBox_Enable(hFilters, FALSE);

	// Just remove everything
	ShowWindow(hFilterCB, SW_HIDE);
	ShowWindow(hFilters, SW_HIDE);
	ShowChannelArea( hDlg, false);

	// Initialize status
	m_FilterActive = false;
	m_FilterFileName[0] = NULL;
	m_FilterName[0] = NULL;

}
Пример #4
0
void SppTabFltr::InitFilter(int nFilters, LPTSTR FilterName)
{

	// Clear Filter display
	HWND hCombo = GetDlgItem(m_hDlg,  IDC_COMBO_FILTERS);
	SendMessage(hCombo,(UINT) CB_RESETCONTENT ,(WPARAM) 0,(LPARAM)0); 

	HWND hFilterCB		= GetDlgItem(m_hDlg,  IDC_CH_FILTER);
	// If there are filters then prepare data for selection
	if (nFilters)
	{
		// Bring "-- Select Filter --" to top
		ComboBox_SetText(hCombo, TEXT("-- Select Filter --"));

		// Display File name
		HWND hFilterFile	= GetDlgItem(m_hDlg,  IDC_EDIT_FILTERFILE);
		_tcscpy_s(&(m_FilterFileName[0]), sizeof(m_FilterFileName)/sizeof(TCHAR),FilterName);
		Edit_SetText(hFilterFile, FilterName);
		UpdateWindow(hFilterFile);
	}
	else
	{
		ComboBox_Enable(hCombo, FALSE);		
		Button_SetCheck(hFilterCB, BST_UNCHECKED);
		ShowChannelArea( m_hDlg, false);
		m_FilterActive = false;
		SentFilterInfo2Parent();
	};

	EnableWindow(hFilterCB, false);
}
Пример #5
0
void SppTabFltr::AddLine2FilterListW(int FilterID, LPCWSTR FilterName)
{
	HWND hFilterList = GetDlgItem(m_hDlg,  IDC_COMBO_FILTERS);
	ShowWindow(hFilterList, SW_SHOW);
	ShowWindow(GetDlgItem(m_hDlg,  IDC_CH_FILTER), SW_SHOW);

	ComboBox_Enable(hFilterList, TRUE);

	int index = (int)SendMessage(hFilterList,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM)FilterName ); 
	SendMessage(hFilterList,(UINT) CB_SETITEMDATA ,(WPARAM) index,(LPARAM)FilterID ); 
}
Пример #6
0
void SppTabFltr::AddLine2FilterListA(int FilterID, const char * FilterName)
{
	HWND hFilterList = GetDlgItem(m_hDlg,  IDC_COMBO_FILTERS);

	ShowWindow(hFilterList, SW_SHOW);
	ShowWindow(GetDlgItem(m_hDlg,  IDC_CH_FILTER), SW_SHOW);

	ComboBox_Enable(hFilterList, TRUE);
	// Convert to a wchar_t*
	size_t origsize = strlen(FilterName) + 1;
	const size_t newsize = 100;
	size_t convertedChars = 0;
	wchar_t FilterNameW[newsize];
	mbstowcs_s(&convertedChars, FilterNameW, origsize, FilterName, _TRUNCATE); // Filter names are converted from ASCII to UNICODE

	int index = (int)SendMessage(hFilterList,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM)FilterNameW ); 
	SendMessage(hFilterList,(UINT) CB_SETITEMDATA ,(WPARAM) index,(LPARAM)FilterID ); 
}
Пример #7
0
INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  int updatestrings = 0;
  if (msg == WM_INITDIALOG) {
    wchar_t txt[20];
    GetPrivateProfileString(L"General", L"AutoFocus", L"0", txt, ARRAY_SIZE(txt), inipath);
    Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOFOCUS), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED);

    GetPrivateProfileString(L"General", L"Aero", L"2", txt, ARRAY_SIZE(txt), inipath);
    Button_SetCheck(GetDlgItem(hwnd,IDC_AERO), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED);

    GetPrivateProfileString(L"General", L"InactiveScroll", L"1", txt, ARRAY_SIZE(txt), inipath);
    Button_SetCheck(GetDlgItem(hwnd,IDC_INACTIVESCROLL), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED);

    GetPrivateProfileString(L"General", L"MDI", L"0", txt, ARRAY_SIZE(txt), inipath);
    Button_SetCheck(GetDlgItem(hwnd,IDC_MDI), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED);

    HWND control = GetDlgItem(hwnd, IDC_LANGUAGE);
    ComboBox_ResetContent(control);
    if (l10n == &l10n_ini) {
      ComboBox_AddString(control, l10n->lang);
      ComboBox_SetCurSel(control, 0);
      ComboBox_Enable(control, FALSE);
    }
    else {
      ComboBox_Enable(control, TRUE);
      int i;
      for (i=0; i < ARRAY_SIZE(languages); i++) {
        ComboBox_AddString(control, languages[i]->lang);
        if (l10n == languages[i]) {
          ComboBox_SetCurSel(control, i);
        }
      }
    }

    Button_Enable(GetDlgItem(hwnd,IDC_ELEVATE), vista && !elevated);
  }
  else if (msg == WM_COMMAND) {
    int id = LOWORD(wParam);
    int event = HIWORD(wParam);
    HWND control = GetDlgItem(hwnd, id);
    int val = Button_GetCheck(control);
    wchar_t txt[10];

    if (id == IDC_AUTOFOCUS) {
      WritePrivateProfileString(L"General", L"AutoFocus", _itow(val,txt,10), inipath);
    }
    else if (id == IDC_AUTOSNAP && event == CBN_SELCHANGE) {
      val = ComboBox_GetCurSel(control);
      WritePrivateProfileString(L"General", L"AutoSnap", _itow(val,txt,10), inipath);
    }
    else if (id == IDC_AERO) {
      WritePrivateProfileString(L"General", L"Aero", _itow(val,txt,10), inipath);
    }
    else if (id == IDC_INACTIVESCROLL) {
      WritePrivateProfileString(L"General", L"InactiveScroll", _itow(val,txt,10), inipath);
    }
    else if (id == IDC_MDI) {
      WritePrivateProfileString(L"General", L"MDI", _itow(val,txt,10), inipath);
    }
    else if (id == IDC_LANGUAGE && event == CBN_SELCHANGE) {
      int i = ComboBox_GetCurSel(control);
      if (i == ARRAY_SIZE(languages)) {
        OpenUrl(L"https://stefansundin.github.io/altdrag/doc/translate.html");
        for (i=0; l10n != languages[i]; i++) {}
        ComboBox_SetCurSel(control, i);
      }
      else {
        l10n = languages[i];
        WritePrivateProfileString(L"General", L"Language", l10n->code, inipath);
        updatestrings = 1;
        UpdateStrings();
      }
    }
    else if (id == IDC_AUTOSTART) {
      SetAutostart(val, 0, 0);
      Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), val);
      Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), val && vista);
      if (!val) {
        Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), BST_UNCHECKED);
        Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), BST_UNCHECKED);
      }
    }
    else if (id == IDC_AUTOSTART_HIDE) {
      int elevate = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE));
      SetAutostart(1, val, elevate);
    }
    else if (id == IDC_AUTOSTART_ELEVATE) {
      int hide = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE));
      SetAutostart(1, hide, val);
      if (val) {
        // Don't nag if UAC is disabled, only check if elevated
        DWORD uac_enabled = 1;
        if (elevated) {
          DWORD len = sizeof(uac_enabled);
          HKEY key;
          RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_QUERY_VALUE, &key);
          RegQueryValueEx(key, L"EnableLUA", NULL, NULL, (LPBYTE)&uac_enabled, &len);
          RegCloseKey(key);
        }
        if (uac_enabled) {
          MessageBox(NULL, l10n->general_autostart_elevate_tip, APP_NAME, MB_ICONINFORMATION|MB_OK);
        }
      }
    }
    else if (id == IDC_ELEVATE && MessageBox(NULL,l10n->general_elevate_tip,APP_NAME,MB_ICONINFORMATION|MB_OK)) {
      wchar_t path[MAX_PATH];
      GetModuleFileName(NULL, path, ARRAY_SIZE(path));
      if ((INT_PTR)ShellExecute(NULL,L"runas",path,L"-config -multi",NULL,SW_SHOWNORMAL) > 32) {
        PostMessage(g_hwnd, WM_CLOSE, 0, 0);
      }
      else {
        MessageBox(NULL, l10n->general_elevation_aborted, APP_NAME, MB_ICONINFORMATION|MB_OK);
      }
      return;
    }
    UpdateSettings();
  }
  else if (msg == WM_NOTIFY) {
    LPNMHDR pnmh = (LPNMHDR) lParam;
    if (pnmh->code == PSN_SETACTIVE) {
      updatestrings = 1;

      // Autostart
      int autostart=0, hidden=0, elevated=0;
      CheckAutostart(&autostart, &hidden, &elevated);
      Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART), autostart?BST_CHECKED:BST_UNCHECKED);
      Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), hidden?BST_CHECKED:BST_UNCHECKED);
      Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), elevated?BST_CHECKED:BST_UNCHECKED);
      Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), autostart);
      Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), autostart && vista);
    }
  }
  if (updatestrings) {
    // Update text
    SetDlgItemText(hwnd, IDC_GENERAL_BOX,        l10n->general_box);
    SetDlgItemText(hwnd, IDC_AUTOFOCUS,          l10n->general_autofocus);
    SetDlgItemText(hwnd, IDC_AERO,               l10n->general_aero);
    SetDlgItemText(hwnd, IDC_INACTIVESCROLL,     l10n->general_inactivescroll);
    SetDlgItemText(hwnd, IDC_MDI,                l10n->general_mdi);
    SetDlgItemText(hwnd, IDC_AUTOSNAP_HEADER,    l10n->general_autosnap);
    SetDlgItemText(hwnd, IDC_LANGUAGE_HEADER,    l10n->general_language);
    SetDlgItemText(hwnd, IDC_AUTOSTART_BOX,      l10n->general_autostart_box);
    SetDlgItemText(hwnd, IDC_AUTOSTART,          l10n->general_autostart);
    SetDlgItemText(hwnd, IDC_AUTOSTART_HIDE,     l10n->general_autostart_hide);
    SetDlgItemText(hwnd, IDC_AUTOSTART_ELEVATE,  l10n->general_autostart_elevate);
    SetDlgItemText(hwnd, IDC_ELEVATE,            (elevated?l10n->general_elevated:l10n->general_elevate));
    SetDlgItemText(hwnd, IDC_AUTOSAVE,           l10n->general_autosave);

    // AutoSnap
    HWND control = GetDlgItem(hwnd, IDC_AUTOSNAP);
    ComboBox_ResetContent(control);
    ComboBox_AddString(control, l10n->general_autosnap0);
    ComboBox_AddString(control, l10n->general_autosnap1);
    ComboBox_AddString(control, l10n->general_autosnap2);
    ComboBox_AddString(control, l10n->general_autosnap3);
    wchar_t txt[10];
    GetPrivateProfileString(L"General", L"AutoSnap", L"0", txt, ARRAY_SIZE(txt), inipath);
    ComboBox_SetCurSel(control, _wtoi(txt));

    // Language
    control = GetDlgItem(hwnd, IDC_LANGUAGE);
    ComboBox_DeleteString(control, ARRAY_SIZE(languages));
    if (l10n == &en_US) {
      ComboBox_AddString(control, L"How can I help translate?");
    }
  }
  return FALSE;
}
Пример #8
0
LRESULT CALLBACK Candify::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	Candify *pApp;

	pApp = (Candify*)GetWindowLong(hWnd, GWL_USERDATA);

	switch (message) {
	case WM_INITDIALOG: 
		{
			HWND hUsernameEdit, hPasswordEdit, hConnectButton, hExitButton;
			HWND hPlaylistCombo, hPlayButton;
			
			hUsernameEdit = GetDlgItem(hWnd, IDC_USERNAMEEDIT);
			hPasswordEdit = GetDlgItem(hWnd, IDC_PASSWORDEDIT);
			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
			hExitButton = GetDlgItem(hWnd, IDC_EXITBUTTON);
			hPlaylistCombo = GetDlgItem(hWnd, IDC_PLAYLISTCOMBO);
			hPlayButton = GetDlgItem(hWnd, IDC_PLAYBUTTON);

			pApp->SubclassControl(hUsernameEdit);
			pApp->SubclassControl(hPasswordEdit);
			pApp->SubclassControl(hConnectButton);
			pApp->SubclassControl(hExitButton);
			pApp->SubclassControl(hPlaylistCombo);
			pApp->SubclassControl(hPlayButton);

			ComboBox_SetMinVisible(hPlaylistCombo, 5);

			SetFocus(hUsernameEdit);
		}
		break;
	case WM_DLGLOGGEDIN:
		{
			HWND hUsernameEdit, hPasswordEdit, hConnectButton;
			hUsernameEdit = GetDlgItem(hWnd, IDC_USERNAMEEDIT);
			hPasswordEdit = GetDlgItem(hWnd, IDC_PASSWORDEDIT);
			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);

			Edit_Enable(hUsernameEdit, FALSE);
			Edit_Enable(hPasswordEdit, FALSE);
			Button_Enable(hConnectButton, FALSE);
		}
		break;
	case WM_DLGUPDATEPLAYLISTS:
		{
			HWND hPlaylistCombo, hPlayButton;
			LPCSTR *playlists;
			int nPlaylists;

			hPlaylistCombo = GetDlgItem(hWnd, IDC_PLAYLISTCOMBO);
			hPlayButton = GetDlgItem(hWnd, IDC_PLAYBUTTON);

			ComboBox_Enable(hPlaylistCombo, TRUE);
			Button_Enable(hPlayButton, TRUE);

			ComboBox_ResetContent(hPlaylistCombo);

			nPlaylists = pApp->m_lpSpotify->getPlaylists(&playlists);
			for (int i = 0; i < nPlaylists; i++) {
				ComboBox_AddString(hPlaylistCombo, playlists[i]);
				free((LPVOID)playlists[i]);
			}
			delete[] playlists;
		}
		break;
	case WM_DLGLOGINFAILED:
		{
			HWND hConnectButton;

			MessageBox(hWnd, "Login failed!", "Candify", MB_ICONINFORMATION);

			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
			Button_Enable(hConnectButton, true);
		}
		break;
	case WM_COMMAND:
		{
			switch (LOWORD(wParam)) {
			case IDC_EXITBUTTON:
				{
					PostQuitMessage(0);
				}
				break;
			case IDC_CONNECTBUTTON:
				{
					HWND hConnectButton;
					CHAR szUsername[100], szPassword[100];

					hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
					Button_Enable(hConnectButton, false);

					GetDlgItemText(hWnd, IDC_USERNAMEEDIT, szUsername, 
						sizeof(szUsername)/sizeof(*szUsername));
					GetDlgItemText(hWnd, IDC_PASSWORDEDIT, szPassword, 
						sizeof(szPassword)/sizeof(*szPassword));
					pApp->Connect(szUsername, szPassword);
				}
				break;
			case IDC_PLAYBUTTON:
				{
					CHAR szPlaylist[100];
					GetDlgItemText(hWnd, IDC_PLAYLISTCOMBO, 
						szPlaylist, sizeof(szPlaylist)/sizeof(*szPlaylist));
					pApp->m_lpSpotify->setPlaylist(szPlaylist);
					ShowWindow(pApp->m_hWnd, SW_SHOW);
					EndDialog(hWnd, 0);
				}
				break;
			}
		}
		break;
	}

	return FALSE;
}
Пример #9
0
        bool downloadUpdates( const char* downloadWebsite, const std::list<EvidyonUpdateFile>& filesAndSizes )
        {
            // Hide the combo box, show the progress bar
            ComboBox_Enable( getDisplayModeCombo(), FALSE );
            ShowWindow( getProgressBar(), SW_SHOWDEFAULT );

            std::vector<std::pair<std::string,std::string>> tempFilesToLocalFiles;

            // Initialize the progress bar.  All files are scaled to 65535 since the 32-bit range
            // doesn't seem to be working correctly.
            Progress_SetRange( getProgressBar(), 0, 65535 );

            // Repeat for each of the files
            for (std::list<EvidyonUpdateFile>::const_iterator p = filesAndSizes.begin(); p != filesAndSizes.end(); ++p)
            {
                // Update the display window
                {
                    // Get the number of bytes
                    char bytes[16];
                    if( p->file_size > 1000 )
                    {
                        sprintf_s( bytes, "%lu KB", p->file_size / 1000 );
                    } else if( p->file_size > 1000000 )
                    {
                        sprintf_s( bytes, "%lu MB", p->file_size / 1000000 );

                    } else
                    {
                        sprintf_s( bytes, "%lu bytes", p->file_size );
                    }

                    std::string text = "Downloading ";
                    text.append( p->file_name );
                    text.append( " - " );
                    text.append( bytes );
                    appendStatusLine( text.c_str() );
                }

                // Get the file's name on the website
                std::string fileUrl = downloadWebsite;
                fileUrl.append( p->file_name );

                // Get the file's local name
                std::string fileLocalName = "~";
                fileLocalName.append( p->file_name );

                // Open the local file
                HANDLE hDestination;
                hDestination = CreateFile( fileLocalName.c_str(),
                                           GENERIC_WRITE,
                                           FILE_SHARE_READ,
                                           NULL,
                                           CREATE_ALWAYS,
                                           FILE_FLAG_WRITE_THROUGH | 
                                           FILE_FLAG_SEQUENTIAL_SCAN,
                                           NULL );
                CONFIRM( hDestination ) else return false;

                // Add to the list of local files
                tempFilesToLocalFiles.push_back( std::pair<std::string,std::string>( fileLocalName, p->file_name ) );

                // Download this file
                dcx::dcxWin32InternetStream reader;
                if( !reader.open( "EvidyonClient", fileUrl.c_str() ) )
                {
                    CloseHandle( hDestination );
                    return false;
                }

                // Reset the progress bar
                Progress_SetPos( getProgressBar(), 0 );

                char buffer[512];
                size_t bytesRead = 0;
                size_t bytes;
                while( reader.scan( buffer, sizeof(buffer), &bytes ) && !reader.end() )
                {
                    // Write this data into the output file
                    DWORD bytesWritten;
                    BOOL success = WriteFile( hDestination,
                                              buffer,
                                              bytes,
                                             &bytesWritten,
                                              NULL );

                    // Exit if the data couldn't be written or the user exited the launcher
                    if( !dcx::dcxWin32StdMessagePump( myMainWindow ) ||
                        APP_WARNING( !success || !bytesWritten )( "Couldn't write data to temporary file" ) )
                        break;

                    // Add to the number of bytes that were read
                    bytesRead += bytes;

                    // Update the progress bar
                    Progress_SetPos( getProgressBar(), (WORD)(((double)bytesRead / (double)p->file_size) * 65535) );
                }

                bool completed = reader.end();

                // Get rid of the output file and internet connection
                reader.close();
                CloseHandle( hDestination );

                // If we didn't finish the download, fail
                if( APP_ERROR( !completed )( "Didn't complete download of %s", fileUrl.c_str() ) )
                    return false;
            }

            // Delete original files and copy files over
            for( std::vector<std::pair<std::string,std::string>>::iterator i  = tempFilesToLocalFiles.begin();
                                                                           i != tempFilesToLocalFiles.end(); ++i )
            {
                // Copy over the existing file
                if (CopyFile( i->first.c_str(), i->second.c_str(), FALSE )) {
                  // Erase the temporary file
                  DeleteFile( i->first.c_str() );
                }
            }

            // Max out the bar
            Progress_SetPos( getProgressBar(), 65535 );

            // Success
            return true;
        }
Пример #10
0
        void execute( HINSTANCE hInstance, dcx::dcxCPUFeatures* cpuFeatures ) {
            myMainWindow = createMainDialog( hInstance );

            dcx::dcxIniFileWriter ini_file_writer;
            DisplayModeList display_mode_list;
            {
              dcx::dcxIniFileReader ini_file_reader;
              ini_file_reader.read("config.ini");
              ini_file_writer.scan(&ini_file_reader);
              DWORD current_display_mode_index = 
                EnumDisplayModes(ini_file_reader.getSetting("Graphics", "ResolutionX", 0),
                                 ini_file_reader.getSetting("Graphics", "ResolutionY", 0),
                                 ini_file_reader.getSetting("Graphics", "ColorDepth", 0),
                                 ini_file_reader.getSetting("Graphics", "Fullscreen", 0) == 0, display_mode_list);

              { // re-sort
                DisplayMode current;
                if (current_display_mode_index < display_mode_list.size()) current = display_mode_list.at(current_display_mode_index);
                qsort(&display_mode_list.at(0), display_mode_list.size(), sizeof(DisplayModeList::value_type), CompareDisplayMode);
                DWORD index = 0;
                for (DisplayModeList::iterator i = display_mode_list.begin(); i != display_mode_list.end(); ++i, ++index) {
                  DisplayMode& dm = *i;
                  if (dm.width == current.width &&
                      dm.height == current.height &&
                      dm.windowed == current.windowed &&
                      (current.windowed == true || dm.bpp == current.bpp)) {
                    current_display_mode_index = index; break;
                  }
                }
              }


              HWND hDisplayModeCombo = getDisplayModeCombo();
              DWORD index = 0;
              for (DisplayModeList::iterator i = display_mode_list.begin(); i != display_mode_list.end(); ++i, ++index) {
                int k = ComboBox_AddString(hDisplayModeCombo, i->text.c_str());
                ComboBox_SetItemData(hDisplayModeCombo, k, index);
              }
              ComboBox_SetCurSel(hDisplayModeCombo, current_display_mode_index);
            }

            Evidyon::UpdateFile update_file;
            std::list<EvidyonUpdateFile> files_to_update;
            if (!Evidyon::DownloadUpdateFile(Evidyon::ONLINE_CLIENT_UPDATE_FILE, &update_file)) {
                errorMessageBox( "Couldn't contact the update server; please try again later" );
                goto EXIT;
            }

            if (update_file.major != MAJOR_VERSION) {
              // download the full installer
              MessageBox(myMainWindow, "The game has been significantly updated and you\n"
                                       "should re-download from www.unseenstudios.com", "Major Update!", MB_OK);
              goto EXIT;
            } else {
              ShowWindow( getEditboxStatus(), SW_SHOW);
              for (std::map<std::string, Evidyon::UpdateFileData>::const_iterator i = update_file.files.begin();
                   i != update_file.files.end(); ++i) {
                const std::string& filename = i->first;
                md5wrapper wrappy;
                std::string local_md5 = wrappy.getHashFromFile(filename);
                if (local_md5.compare(i->second.md5) != 0) {  // this file needs to be updated
                  EvidyonUpdateFile file;
                  file.file_name = filename;
                  file.file_size = i->second.file_bytes;
                  files_to_update.push_back(file);
                }
              }
            }
            // Update the client
            bool allowGameStart = false;
            if (files_to_update.size() > 0) {
              if (downloadUpdates(Evidyon::ONLINE_CLIENT_UPDATE_FOLDER, files_to_update)) {
                allowGameStart = true;
              } else {
                appendStatusLine( "ERROR!  Unable to download updates at this time.  If you are running Vista, this could "\
                                  "be due to the permissions for the directory in which Evidyon is installed being set to read-only." );
              }
            }
            else
                allowGameStart = true;

            // Add the update text to the output
            {
              //dc::dcFileStream fs;
              //if (fs.open("notes.txt", STREAM_TEXT)) {
              //  std::string notes;
              //  size_t len = fs.size();
              //  char text = new char[len+1];
              //  fs.read(text, len);
              //  text[len] = '\0';
              //  fs.close();
              //  appendStatusLine(text);
              //  delete[] text;
              //}
            }


            if (allowGameStart) {
                // Re-enable the "launch" button
                Button_Enable( getStartgameButton(), TRUE );
            }

            ShowWindow(getStartgameButton(), SW_SHOW);
            ShowWindow(getProgressBar(), SW_HIDE);

            // Wait for the user to do something
            myLaunchGameFlag = false;
            ComboBox_Enable(getDisplayModeCombo(), TRUE);
            while( dcx::dcxWin32StdMessagePump( myMainWindow ) && !myLaunchGameFlag );

            // Get the display mode selection
            int current_sel = ComboBox_GetCurSel(getDisplayModeCombo());
            current_sel = min(current_sel, display_mode_list.size() - 1);
            current_sel = max(current_sel, 0);
            DisplayMode& dm = display_mode_list.at(current_sel);
            ini_file_writer.setSetting("Graphics", "ResolutionX", dm.width),
            ini_file_writer.setSetting("Graphics", "ResolutionY", dm.height),
            ini_file_writer.setSetting("Graphics", "ColorDepth", dm.bpp),
            ini_file_writer.setSetting("Graphics", "Fullscreen", dm.windowed ? 0 : 1);
            {
              dc::dcFileStream ini_fs;
              ini_fs.open("config.ini", STREAM_OVERWRITE|STREAM_TEXT);
              ini_file_writer.write(&ini_fs);
              ini_fs.close();
            }

            // Close the window
            if( IsWindow( myMainWindow ) )
            {
                EndDialog( myMainWindow, 0 );
                DestroyWindow( myMainWindow );
                dcx::dcxWin32StdMessagePump( 0 );

                // Launch the client
                std::string exeFile = "evidyon";

                STARTUPINFO startupInfo;
                ZeroMemory( &startupInfo, sizeof(startupInfo) );

                PROCESS_INFORMATION processInfo;
                /*
                // Build the version to run based on the computer's capabilities
                if( cpuFeatures->sse2 ) {
                    exeFile.append( "_sse2" );
                }
                else if( cpuFeatures->sse ) {
                    exeFile.append( "_sse" );
                }*/

                exeFile.append( ".exe" );
                
                // Start the server
                if( !CreateProcessA( exeFile.c_str(), NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE|ABOVE_NORMAL_PRIORITY_CLASS,
                                     NULL, NULL, &startupInfo, &processInfo ) )
                {
                    DWORD error = GetLastError();
                    MessageBox( NULL, "Failed to launch Evidyon", "Error", MB_OK );
                    goto EXIT;
                }

                // Run the client
                WaitForSingleObject( processInfo.hProcess, INFINITE );

                // Free the process and exit
                CloseHandle( processInfo.hProcess );
                CloseHandle( processInfo.hThread );
            }

EXIT:
            DestroyWindow( myMainWindow );
        }