1
0

Preferences.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. ** Copyright (C) 2007-2011 Nullsoft, Inc.
  3. **
  4. ** This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
  5. ** liable for any damages arising from the use of this software.
  6. **
  7. ** Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
  8. ** alter it and redistribute it freely, subject to the following restrictions:
  9. **
  10. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  11. ** If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. **
  13. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  14. **
  15. ** 3. This notice may not be removed or altered from any source distribution.
  16. **
  17. ** Author: Ben Allison [email protected]
  18. ** Created: March 1, 2007
  19. **
  20. */
  21. #include "main.h"
  22. #include <FLAC/all.h>
  23. #include "resource.h"
  24. #include "../Agave/Language/api_language.h"
  25. #include "../nu/AutoChar.h"
  26. #include <assert.h>
  27. #include <strsafe.h>
  28. bool fixBitrate=false;
  29. bool config_average_bitrate=true;
  30. // the return pointer has been malloc'd. Use free() when you are done.
  31. char *BuildExtensions(const char *extensions)
  32. {
  33. char name[64] = {0};
  34. WASABI_API_LNGSTRING_BUF(IDS_FLAC_FILES,name,64);
  35. size_t length = strlen(extensions) + 1 + strlen(name) + 2;
  36. char *newExt = (char *)malloc(length);
  37. char *ret = newExt; // save because we modify newExt
  38. // copy extensions
  39. StringCchCopyExA(newExt, length, extensions, &newExt, &length, 0);
  40. newExt++;
  41. length--;
  42. // copy description
  43. StringCchCopyExA(newExt, length, name, &newExt, &length, 0);
  44. newExt++;
  45. length--;
  46. // double null terminate
  47. assert(length == 1);
  48. *newExt = 0;
  49. return ret;
  50. }
  51. static INT_PTR CALLBACK PreferencesProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  52. {
  53. switch(msg)
  54. {
  55. case WM_INITDIALOG:
  56. {
  57. wchar_t config_extensions[128] = {0};
  58. GetPrivateProfileStringW(L"in_flac", L"extensions", DEFAULT_EXTENSIONSW, config_extensions, 128, winampINI);
  59. SetDlgItemTextW(hwndDlg, IDC_EXTENSIONS, config_extensions);
  60. CheckDlgButton(hwndDlg, IDC_AVERAGE_BITRATE, config_average_bitrate?BST_CHECKED:BST_UNCHECKED);
  61. }
  62. return TRUE;
  63. case WM_DESTROY:
  64. break;
  65. case WM_COMMAND:
  66. switch(LOWORD(wParam))
  67. {
  68. case IDOK:
  69. {
  70. wchar_t config_extensions[128] = {0};
  71. GetDlgItemTextW(hwndDlg, IDC_EXTENSIONS, config_extensions, 128);
  72. if (!lstrcmpiW(config_extensions, DEFAULT_EXTENSIONSW))
  73. WritePrivateProfileStringW(L"in_flac", L"extensions", 0, winampINI);
  74. else
  75. WritePrivateProfileStringW(L"in_flac", L"extensions", config_extensions, winampINI);
  76. plugin.FileExtensions = BuildExtensions(AutoChar(config_extensions));
  77. config_average_bitrate = !!IsDlgButtonChecked(hwndDlg, IDC_AVERAGE_BITRATE);
  78. if (config_average_bitrate)
  79. WritePrivateProfileStringW(L"in_flac", L"average_bitrate", L"1", winampINI);
  80. else
  81. WritePrivateProfileStringW(L"in_flac", L"average_bitrate", L"0", winampINI);
  82. fixBitrate=true;
  83. EndDialog(hwndDlg, 0);
  84. }
  85. break;
  86. case IDCANCEL:
  87. EndDialog(hwndDlg, 0);
  88. break;
  89. }
  90. break;
  91. }
  92. return 0;
  93. }
  94. void Config(HWND hwndParent)
  95. {
  96. WASABI_API_DIALOGBOXW(IDD_PREFERENCES, hwndParent, PreferencesProc);
  97. }