AddPlaylist.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "main.h"
  2. #include <shlwapi.h>
  3. #include "resource.h"
  4. wchar_t *createPlayListDBFileName(wchar_t *filename) // filename is ignored but used for temp space, make sure it's 1024+256 chars =)
  5. {
  6. wchar_t *filenameptr;
  7. int x = 32;
  8. for (;;)
  9. {
  10. GetTempFileNameW(g_path, L"plf", GetTickCount() + x*5000, filename);
  11. if ( wcslen(filename) > 4)
  12. {
  13. if (g_config->ReadInt(L"playlist_m3u8", 1))
  14. lstrcpyW(filename + wcslen(filename) - 4, L".m3u8");
  15. else
  16. lstrcpyW(filename + wcslen(filename) - 4, L".m3u");
  17. }
  18. HANDLE h = CreateFileW(filename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, 0, 0);
  19. if (h != INVALID_HANDLE_VALUE)
  20. {
  21. filenameptr = filename + wcslen(g_path) + 1;
  22. CloseHandle(h);
  23. break;
  24. }
  25. if (++x > 4096)
  26. {
  27. filenameptr = L"error.m3u";
  28. break;
  29. }
  30. }
  31. return filenameptr;
  32. }
  33. void playlists_AddToCloudPrompt(HWND hwndDlg)
  34. {
  35. if (g_config->ReadInt(L"cloud_always", 0) && !g_config->ReadInt(L"cloud_prompt", 0) && g_config->ReadInt(L"cloud", 1))
  36. {
  37. wchar_t titleStr[64] = {0};
  38. if (MessageBox(hwndDlg, WASABI_API_LNGSTRINGW(IDS_CLOUD_UNCHECKED),
  39. WASABI_API_LNGSTRINGW_BUF(IDS_SENDTO_NEW_CLOUD_PLAYLIST, titleStr, 64),
  40. MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES)
  41. {
  42. g_config->WriteInt(L"cloud", (IsDlgButtonChecked(hwndDlg, IDC_CLOUD) == BST_CHECKED));
  43. }
  44. else
  45. {
  46. CheckDlgButton(hwndDlg, IDC_CLOUD, playlists_CloudAvailable() && g_config->ReadInt(L"cloud", 1));
  47. }
  48. g_config->WriteInt(L"cloud_prompt", 1);
  49. }
  50. else
  51. {
  52. g_config->WriteInt(L"cloud", (IsDlgButtonChecked(hwndDlg, IDC_CLOUD) == BST_CHECKED));
  53. }
  54. }
  55. int AddToCloud()
  56. {
  57. if (playlists_CloudAvailable())
  58. {
  59. if (g_config->ReadInt(L"cloud_always", 1))
  60. {
  61. g_config->WriteInt(L"cloud", 1);
  62. return 1;
  63. }
  64. else
  65. {
  66. g_config->WriteInt(L"cloud", 0);
  67. }
  68. }
  69. return 0;
  70. }
  71. INT_PTR CALLBACK AddPlaylistDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  72. {
  73. switch (uMsg)
  74. {
  75. case WM_INITDIALOG:
  76. {
  77. SetProp(hwndDlg, L"pladdcb", (HANDLE)lParam);
  78. CheckDlgButton(hwndDlg, IDC_CLOUD, AddToCloud());
  79. PostMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_NAME), TRUE);
  80. break;
  81. }
  82. case WM_COMMAND:
  83. switch (LOWORD(wParam))
  84. {
  85. case IDOK:
  86. {
  87. wchar_t name[256] = {0};
  88. GetDlgItemText(hwndDlg, IDC_NAME, name, 255);
  89. if (!name[0])
  90. {
  91. wchar_t titleStr[32] = {0};
  92. MessageBox(hwndDlg, WASABI_API_LNGSTRINGW(IDS_ENTER_A_NAME),
  93. WASABI_API_LNGSTRINGW_BUF(IDS_ERROR, titleStr, 32), MB_OK);
  94. break;
  95. }
  96. wchar_t filename[1024 + 256] = {0};
  97. createPlayListDBFileName(filename);
  98. bool callback = !!GetProp(hwndDlg, L"pladdcb");
  99. AddPlaylist(callback, name, filename, true, (playlists_CloudAvailable() ? g_config->ReadInt(L"cloud", 1) : 0));
  100. if (callback) AGAVE_API_PLAYLISTS->Flush(); // REVIEW: save immediately? or only at the end?
  101. EndDialog(hwndDlg, 1);
  102. }
  103. break;
  104. case IDCANCEL:
  105. EndDialog(hwndDlg, 0);
  106. break;
  107. case IDC_CLOUD:
  108. {
  109. playlists_AddToCloudPrompt(hwndDlg);
  110. }
  111. break;
  112. }
  113. break;
  114. }
  115. return FALSE;
  116. };