1
0

config.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "main.h"
  2. #include "config.h"
  3. #include "resource.h"
  4. char config_extensions[1024] = {0};
  5. bool config_upsample8bit=false;
  6. static int ExtensionInList(HWND hwndDlg, int id, const char *string)
  7. {
  8. return (int)SendMessageA(GetDlgItem(hwndDlg, id), LB_FINDSTRINGEXACT, 0, (LPARAM)string);
  9. }
  10. void FillExtensionList( HWND hwndDlg )
  11. {
  12. int numTypes;
  13. sf_command( 0, SFC_GET_FORMAT_MAJOR_COUNT, &numTypes, sizeof( numTypes ) );
  14. SF_FORMAT_INFO info;
  15. for ( int i = 0; i < numTypes; i++ )
  16. {
  17. info.format = i;
  18. sf_command( 0, SFC_GET_FORMAT_MAJOR, &info, sizeof( info ) );
  19. if ( !_strcmpi( info.extension, "mpc" ) )
  20. continue;
  21. if ( ExtensionInList( hwndDlg, IDC_EXTENSION_LIST, info.extension ) == LB_ERR )
  22. {
  23. LRESULT index = SendMessageA( GetDlgItem( hwndDlg, IDC_EXTENSION_LIST ), LB_ADDSTRING, 0, (LPARAM)info.extension );
  24. if ( ExtensionExists( info.extension, config_extensions ) )
  25. SendMessage( GetDlgItem( hwndDlg, IDC_EXTENSION_LIST ), LB_SETSEL, TRUE, index );
  26. }
  27. }
  28. }
  29. void FillExtensionsEditControl( HWND hwndDlg )
  30. {
  31. char extensions[ 256 ] = "";
  32. char temp[ 20 ] = { 0 };
  33. char *s = config_extensions;
  34. while ( s && *s )
  35. {
  36. lstrcpynA( temp, s, 20 );
  37. char *scan = temp;
  38. while ( scan && *scan && *scan != ';' )
  39. scan = CharNextA( scan );
  40. *scan = 0;
  41. if ( ExtensionInList( hwndDlg, IDC_EXTENSION_LIST, temp ) == LB_ERR )
  42. {
  43. if ( *extensions )
  44. lstrcatA( extensions, ";" );
  45. lstrcatA( extensions, temp );
  46. }
  47. s += lstrlenA( temp );
  48. if ( *s == ';' )
  49. s = CharNextA( s );
  50. }
  51. SetDlgItemTextA( hwndDlg, IDC_ADDITIONAL_EXTENSIONS, extensions );
  52. }
  53. void Preferences_Init( HWND hwndDlg )
  54. {
  55. SendMessageA( GetDlgItem( hwndDlg, IDC_OUTPUTBITS ), CB_ADDSTRING, 0, (LPARAM)"16 bit" ); // TODO: string table
  56. SendMessageA( GetDlgItem( hwndDlg, IDC_OUTPUTBITS ), CB_ADDSTRING, 0, (LPARAM)"32 bit" ); // TODO: string table
  57. FillExtensionList( hwndDlg );
  58. FillExtensionsEditControl( hwndDlg );
  59. }
  60. void Preferences_OnOK( HWND hwndDlg )
  61. {
  62. config_extensions[ 0 ] = 0;
  63. LRESULT num = SendMessage( GetDlgItem( hwndDlg, IDC_EXTENSION_LIST ), LB_GETCOUNT, 0, 0 );
  64. for ( int i = 0; i < num; i++ )
  65. {
  66. if ( SendMessage( GetDlgItem( hwndDlg, IDC_EXTENSION_LIST ), LB_GETSEL, i, 0 ) > 0 )
  67. {
  68. char thisExtension[ 256 ] = { 0 };
  69. if ( config_extensions[ 0 ] )
  70. lstrcatA( config_extensions, ";" );
  71. SendMessageA( GetDlgItem( hwndDlg, IDC_EXTENSION_LIST ), LB_GETTEXT, i, (LPARAM)thisExtension );
  72. lstrcatA( config_extensions, thisExtension );
  73. }
  74. }
  75. char additional[ 1024 ] = { 0 };
  76. GetDlgItemTextA( hwndDlg, IDC_ADDITIONAL_EXTENSIONS, additional, 1024 );
  77. if ( additional[ 0 ] )
  78. {
  79. if ( config_extensions[ 0 ] )
  80. lstrcatA( config_extensions, ";" );
  81. lstrcatA( config_extensions, additional );
  82. }
  83. SetFileExtensions( config_extensions );
  84. }
  85. BOOL CALLBACK PreferencesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  86. {
  87. switch ( uMsg )
  88. {
  89. case WM_INITDIALOG:
  90. Preferences_Init( hwndDlg );
  91. break;
  92. case WM_COMMAND:
  93. switch ( LOWORD( wParam ) )
  94. {
  95. case IDOK:
  96. Preferences_OnOK( hwndDlg );
  97. EndDialog( hwndDlg, 0 );
  98. break;
  99. case IDCANCEL:
  100. EndDialog( hwndDlg, 0 );
  101. break;
  102. }
  103. }
  104. return 0;
  105. }