WelcomeDialog.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * WelcomeDialog.cpp
  3. * -----------------
  4. * Purpose: "First run" OpenMPT welcome dialog
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "WelcomeDialog.h"
  11. #include "resource.h"
  12. #include "Mainfrm.h"
  13. #include "../common/mptStringBuffer.h"
  14. #include "InputHandler.h"
  15. #include "CommandSet.h"
  16. #include "SelectPluginDialog.h"
  17. #include "UpdateCheck.h"
  18. OPENMPT_NAMESPACE_BEGIN
  19. BEGIN_MESSAGE_MAP(WelcomeDlg, CDialog)
  20. ON_COMMAND(IDC_BUTTON1, &WelcomeDlg::OnOptions)
  21. ON_COMMAND(IDC_BUTTON2, &WelcomeDlg::OnScanPlugins)
  22. END_MESSAGE_MAP()
  23. WelcomeDlg::WelcomeDlg(CWnd *parent)
  24. {
  25. Create(IDD_WECLOME, parent);
  26. CenterWindow(parent);
  27. }
  28. static mpt::PathString GetFullKeyPath(const char *keyFile)
  29. {
  30. return theApp.GetInstallPkgPath() + P_("extraKeymaps\\") + mpt::PathString::FromUTF8(keyFile) + P_(".mkb");
  31. }
  32. BOOL WelcomeDlg::OnInitDialog()
  33. {
  34. CDialog::OnInitDialog();
  35. #ifdef MPT_WITH_VST
  36. HKEY hkEnum = NULL;
  37. TCHAR str[MAX_PATH];
  38. DWORD datasize = sizeof(str);
  39. DWORD datatype = REG_SZ;
  40. if(RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\VST"), &hkEnum) == ERROR_SUCCESS
  41. && RegQueryValueEx(hkEnum, _T("VSTPluginsPath"), 0, &datatype, (LPBYTE)str, &datasize) == ERROR_SUCCESS)
  42. {
  43. m_vstPath = mpt::PathString::FromNative(ParseMaybeNullTerminatedStringFromBufferWithSizeInBytes<mpt::winstring>(str, datasize));
  44. } else if(SHGetSpecialFolderPath(0, str, CSIDL_PROGRAM_FILES, FALSE))
  45. {
  46. m_vstPath = mpt::PathString::FromNative(ParseMaybeNullTerminatedStringFromBufferWithSizeInBytes<mpt::winstring>(str, datasize)) + P_("\\Steinberg\\VstPlugins\\");
  47. if(!m_vstPath.IsDirectory())
  48. {
  49. m_vstPath = mpt::PathString();
  50. }
  51. }
  52. SetDlgItemText(IDC_EDIT2, mpt::ToCString(TrackerSettings::Instance().defaultArtist));
  53. if(!m_vstPath.empty())
  54. {
  55. SetDlgItemText(IDC_EDIT1, m_vstPath.AsNative().c_str());
  56. if(TrackerSettings::Instance().PathPlugins.GetDefaultDir().empty())
  57. {
  58. TrackerSettings::Instance().PathPlugins.SetDefaultDir(m_vstPath);
  59. }
  60. } else
  61. #endif // MPT_WITH_VST
  62. {
  63. SetDlgItemText(IDC_EDIT1, _T("No plugin path found!"));
  64. GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
  65. }
  66. const char *keyFile = nullptr;
  67. const TCHAR *keyFileName = nullptr;
  68. const uint16 language = LOWORD(GetKeyboardLayout(0)), primaryLang = language & 0x3FF;
  69. CComboBox *combo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  70. combo->AddString(_T("OpenMPT / Chromatic (Default)"));
  71. combo->SetCurSel(0);
  72. switch(primaryLang)
  73. {
  74. case LANG_GERMAN:
  75. keyFile = "DE_jojo";
  76. keyFileName = _T("German");
  77. break;
  78. case LANG_SPANISH:
  79. // Spanish latin-american keymap, so we ignore Spain.
  80. if(language != SUBLANG_SPANISH_MODERN && language != SUBLANG_SPANISH)
  81. {
  82. keyFile = "es-LA_mpt_(jmkz)";
  83. keyFileName = _T("Spanish");
  84. }
  85. break;
  86. case LANG_FRENCH:
  87. keyFile = "FR_mpt_(legovitch)";
  88. keyFileName = _T("French");
  89. break;
  90. case LANG_NORWEGIAN:
  91. keyFile = "NO_mpt_classic_(rakib)";
  92. keyFileName = _T("Norwegian");
  93. break;
  94. }
  95. if(keyFile != nullptr)
  96. {
  97. if(GetFullKeyPath(keyFile).IsFile())
  98. {
  99. int i = combo->AddString(_T("OpenMPT / Chromatic (") + CString(keyFileName) + _T(")"));
  100. combo->SetItemDataPtr(i, (void *)keyFile);
  101. combo->SetCurSel(i);
  102. // As this is presented as the default, load it right now, even if the user closes the dialog through the close button
  103. auto cmdSet = std::make_unique<CCommandSet>();
  104. cmdSet->LoadFile(GetFullKeyPath(keyFile));
  105. CMainFrame::GetInputHandler()->SetNewCommandSet(cmdSet.get());
  106. }
  107. }
  108. combo->SetItemDataPtr(combo->AddString(_T("Impulse Tracker")), (void*)("US_mpt-it2_classic"));
  109. combo->SetItemDataPtr(combo->AddString(_T("FastTracker 2")), (void*)("US_mpt-ft2_classic"));
  110. CheckDlgButton(IDC_CHECK1, BST_CHECKED);
  111. CheckDlgButton(IDC_CHECK3, BST_CHECKED);
  112. #if defined(MPT_ENABLE_UPDATE)
  113. GetDlgItem(IDC_STATIC_WELCOME_STATISTICS)->SetWindowText(mpt::ToCString(mpt::String::Replace(CUpdateCheck::GetStatisticsUserInformation(false), U_("\n"), U_(" "))));
  114. #endif // MPT_ENABLE_UPDATE
  115. CheckDlgButton(IDC_CHECK2, (TrackerSettings::Instance().patternFont.Get().name == PATTERNFONT_LARGE) ? BST_CHECKED : BST_UNCHECKED);
  116. ShowWindow(SW_SHOW);
  117. return TRUE;
  118. }
  119. void WelcomeDlg::OnOptions()
  120. {
  121. OnOK();
  122. CMainFrame::GetMainFrame()->PostMessage(WM_COMMAND, ID_VIEW_OPTIONS);
  123. }
  124. void WelcomeDlg::OnScanPlugins()
  125. {
  126. #ifdef MPT_WITH_VST
  127. CSelectPluginDlg::ScanPlugins(m_vstPath, this);
  128. #endif // MPT_WITH_VST
  129. }
  130. void WelcomeDlg::OnOK()
  131. {
  132. CDialog::OnOK();
  133. #if defined(MPT_ENABLE_UPDATE)
  134. bool runUpdates = IsDlgButtonChecked(IDC_CHECK1) != BST_UNCHECKED;
  135. TrackerSettings::Instance().UpdateIntervalDays = (runUpdates ? 7 : -1);
  136. TrackerSettings::Instance().UpdateStatistics = (IsDlgButtonChecked(IDC_CHECK3) != BST_UNCHECKED);
  137. TrackerSettings::Instance().UpdateShowUpdateHint = false;
  138. TrackerSettings::Instance().UpdateStatisticsConsentAsked = true;
  139. CString artistName;
  140. GetDlgItemText(IDC_EDIT2, artistName);
  141. TrackerSettings::Instance().defaultArtist = mpt::ToUnicode(artistName);
  142. #endif // MPT_ENABLE_UPDATE
  143. if(IsDlgButtonChecked(IDC_CHECK2) != BST_UNCHECKED)
  144. {
  145. FontSetting font = TrackerSettings::Instance().patternFont;
  146. font.name = PATTERNFONT_LARGE;
  147. TrackerSettings::Instance().patternFont = font;
  148. }
  149. CComboBox *combo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  150. const char *keyFile = static_cast<char *>(combo->GetItemDataPtr(combo->GetCurSel()));
  151. auto cmdSet = std::make_unique<CCommandSet>();
  152. if(keyFile != nullptr)
  153. cmdSet->LoadFile(GetFullKeyPath(keyFile));
  154. else
  155. cmdSet->LoadDefaultKeymap();
  156. CMainFrame::GetInputHandler()->SetNewCommandSet(cmdSet.get());
  157. #if defined(MPT_ENABLE_UPDATE)
  158. if(runUpdates)
  159. {
  160. CUpdateCheck::DoAutoUpdateCheck();
  161. }
  162. #endif // MPT_ENABLE_UPDATE
  163. CMainFrame::GetMainFrame()->PostMessage(WM_MOD_INVALIDATEPATTERNS, HINT_MPTOPTIONS);
  164. DestroyWindow();
  165. }
  166. void WelcomeDlg::OnCancel()
  167. {
  168. CDialog::OnCancel();
  169. DestroyWindow();
  170. }
  171. OPENMPT_NAMESPACE_END