1
0

settings.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. #include "main.h"
  2. #include "./settings.h"
  3. #include "./resource.h"
  4. #include <shlwapi.h>
  5. #include <strsafe.h>
  6. #define SECTION_DEFAULT TEXT("gen_ml_config")
  7. #define SECTION_DATAVIEW TEXT("data_view")
  8. // Keys
  9. #define KEY_EF_PATH TEXT("extractpath")
  10. #define KEY_EF_TITLEFMT TEXT("extractfmt2")
  11. #define KEY_EF_PLAYLISTFMT TEXT("extractplfmt2")
  12. #define KEY_EF_COMMENTTEXT TEXT("tagcomment")
  13. #define KEY_EF_UPPEREXTENSION TEXT("extractucext")
  14. #define KEY_EF_ADDMETADATA TEXT("extracttag")
  15. #define KEY_EF_CALCULATERG TEXT("auto_rg")
  16. #define KEY_EF_USETOTALTRACKS TEXT("total_tracks")
  17. #define KEY_EF_ADDTOMLDB TEXT("extractaddml")
  18. #define KEY_EF_TRACKOFFSET TEXT("trackoffs")
  19. #define KEY_EF_CREATEM3U TEXT("extractm3u")
  20. #define KEY_EF_CREATEPLS TEXT("extractpls")
  21. #define KEY_EF_CREATEMLPL TEXT("extractplml")
  22. #define KEY_EF_USEM3UEXT TEXT("extractm3uext")
  23. #define KEY_EF_FOURCC TEXT("extract4cc")
  24. // Defeault values
  25. #define DEF_EF_PATH GetDefaultExtractPath()
  26. #define DEF_EF_TITLEFMT TEXT("<Artist> - <Album>\\## - <Trackartist> - <Title>")
  27. #define DEF_EF_PLAYLISTFMT TEXT("<Artist> - <Album>\\<Artist> - <Album>")
  28. #define DEF_EF_COMMENTTEXT TEXT("Ripped by Winamp")
  29. #define DEF_EF_UPPEREXTENSION FALSE
  30. #define DEF_EF_ADDMETADATA TRUE
  31. #define DEF_EF_CALCULATERG FALSE
  32. #define DEF_EF_USETOTALTRACKS FALSE
  33. #define DEF_EF_ADDTOMLDB TRUE
  34. #define DEF_EF_TRACKOFFSET 1
  35. #define DEF_EF_CREATEM3U TRUE
  36. #define DEF_EF_CREATEPLS FALSE
  37. #define DEF_EF_CREATEMLPL TRUE
  38. #define DEF_EF_USEM3UEXT TRUE
  39. #define DEF_EF_FOURCC mmioFOURCC('A','A','C','f')
  40. #define KEY_CF_PATH KEY_EF_PATH
  41. #define KEY_CF_USETITLEFMT TEXT("copy_use_title_fmt")
  42. #define KEY_CF_TITLEFMT TEXT("copy_title_fmt")
  43. #define KEY_CF_ADDTOMLDB TEXT("copy_add_to_mldb")
  44. #define KEY_CF_CALCULATERG TEXT("copy_calc_gain")
  45. #define KEY_CF_GAINMODE TEXT("copy_gain_mode")
  46. #define DEF_CF_PATH DEF_EF_PATH
  47. #define DEF_CF_USETITLEFMT TRUE
  48. #define DEF_CF_TITLEFMT TEXT("<Artist>\\<Album>\\<Filename><extension>")
  49. #define DEF_CF_ADDTOMLDB DEF_EF_ADDTOMLDB
  50. #define DEF_CF_CALCULATERG DEF_EF_CALCULATERG
  51. #define DEF_CF_GAINMODE 0
  52. #define KEY_GF_SHOWINFO TEXT("showinfo")
  53. #define KEY_GF_SHOWPARENT TEXT("showparent")
  54. #define KEY_GF_ENQUEUEBYDEFAULT TEXT("enqueuedef")
  55. #define DEF_GF_SHOWINFO FALSE
  56. #define DEF_GF_SHOWPARENT FALSE
  57. #define DEF_GF_ENQUEUEBYDEFAULT FALSE
  58. #define KEY_DVF_COLUMNLIST TEXT("column_list")
  59. #define KEY_DVF_LASTFOLDER TEXT("last_folder")
  60. #define KEY_DVF_ORDERBY TEXT("column_order_by")
  61. #define KEY_DVF_ORDERASC TEXT("column_order_asc")
  62. #define KEY_DVF_VIEWMODE TEXT("view_mode")
  63. #define KEY_DVF_SHOWAUDIO TEXT("show_audio")
  64. #define KEY_DVF_SHOWVIDEO TEXT("show_video")
  65. #define KEY_DVF_SHOWPLAYLIST TEXT("show_playlist")
  66. #define KEY_DVF_SHOWUNKNOWN TEXT("show_unknown")
  67. #define KEY_DVF_HIDEEXTENSION TEXT("hide_extension")
  68. #define KEY_DVF_IGNOREHIDDEN TEXT("ignore_hidden")
  69. #define KEY_DVF_DIVIDERPOS TEXT("horz_divider_pos")
  70. #define DEF_DVF_COLUMNLIST NULL
  71. #define DEF_DVF_LASTFOLDER NULL
  72. #define DEF_DVF_ORDERBY 0
  73. #define DEF_DVF_ORDERASC TRUE
  74. #define DEF_DVF_VIEWMODE -1
  75. #define DEF_DVF_SHOWAUDIO TRUE
  76. #define DEF_DVF_SHOWVIDEO TRUE
  77. #define DEF_DVF_SHOWPLAYLIST TRUE
  78. #define DEF_DVF_SHOWUNKNOWN FALSE
  79. #define DEF_DVF_HIDEEXTENSION TRUE
  80. #define DEF_DVF_IGNOREHIDDEN TRUE
  81. #define DEF_DVF_DIVIDERPOS 240
  82. // configs
  83. #define GLOBAL g_config
  84. #define VIEW g_view_metaconf
  85. // readers
  86. #define READ_LPTSTR(config) (config)->ReadCbStringEx
  87. #define READ_QUOTED_LPTSTR(config) (config)->ReadCbQuotedString
  88. #define GET_INT(config) (config)->ReadIntEx
  89. #define GET_BOOL(config) (config)->ReadBoolEx
  90. // writers
  91. #define WRITE_LPCTSTR(config) (config)->WriteStringEx
  92. #define WRITE_QUOTED_LPCTSTR(config) (config)->WriteQuotedString
  93. #define WRITE_INT(config) (config)->WriteIntEx
  94. #define WRITE_BOOL(config) (config)->WriteBoolEx
  95. #define CHECK_EXREAD(type, config, section, field, buffer, cb) case field##: READ_##type##(config)(((##type##)buffer), cb, section, KEY_##field, DEF_##field); return S_OK;
  96. #define CHECK_EXREAD_QUOTED(type, config, section, field, buffer, cb) case field##: READ_QUOTED_##type##(config)(((##type##)buffer), cb, section, KEY_##field, DEF_##field); return S_OK;
  97. #define CHECK_EXGET(type, config, section, field, result) case field##: *((##type##*)result) = GET_##type##(config)(section, KEY_##field, DEF_##field); return S_OK;
  98. #define CHECK_EXWRITE(type, config, section, field, value) case field##: WRITE_##type##(config)(section, KEY_##field, value); return S_OK;
  99. #define CHECK_EXWRITE_QUOTED(type, config, section, field, value) case field##: WRITE_QUOTED_##type##(config)(section, KEY_##field, value); return S_OK;
  100. #define CHECK_DEFAULT(type, field, result) case field##: *((##type##*)result) = DEF_##field; return S_OK;
  101. #define CHECK_READ(type, config, field, buffer, cb) CHECK_EXREAD(type, config, SECTION_DEFAULT, field, buffer, cb)
  102. #define CHECK_READ_QUOTED(type, config, field, buffer, cb) CHECK_EXREAD_QUOTED(type, config, SECTION_DEFAULT, field, buffer, cb)
  103. #define CHECK_GET(type, config, field, result) CHECK_EXGET(type, config, SECTION_DEFAULT, field, result)
  104. #define CHECK_WRITE(type, config, field, value) CHECK_EXWRITE(type, config, SECTION_DEFAULT, field, value)
  105. #define CHECK_WRITE_QUOTED(type, config, field, value) CHECK_EXWRITE_QUOTED(type, config, SECTION_DEFAULT, field, value)
  106. #define CHECK_EXREAD_VIEW(type, section, field, buffer, cb) CHECK_EXREAD(type, VIEW, section, field, buffer, cb)
  107. #define CHECK_EXGET_VIEW(type, section, field, result) CHECK_EXGET(type, VIEW, section, field, result)
  108. #define CHECK_EXWRITE_VIEW(type, section, field, value) CHECK_EXWRITE(type, VIEW, section, field, value)
  109. #define CHECK_READ_GLOBAL(type, field, buffer, cb) CHECK_READ(type, GLOBAL, field, buffer, cb)
  110. #define CHECK_READ_QUOTED_GLOBAL(type, field, buffer, cb) CHECK_READ_QUOTED(type, GLOBAL, field, buffer, cb)
  111. #define CHECK_GET_GLOBAL(type, field, result) CHECK_GET(type, GLOBAL, field, result)
  112. #define CHECK_READ_VIEW(type, field, buffer, cb) CHECK_READ(type, VIEW, field, buffer, cb)
  113. #define CHECK_GET_VIEW(type, field, result) CHECK_GET(type, VIEW, field, result)
  114. #define CHECK_WRITE_GLOBAL(type, field, value) CHECK_WRITE(type, GLOBAL, field, value)
  115. #define CHECK_WRITE_QUOTED_GLOBAL(type, field, value) CHECK_WRITE_QUOTED(type, GLOBAL, field, value)
  116. #define CHECK_WRITE_VIEW(type, field, value) CHECK_WRITE(type, VIEW, field, value)
  117. #define STR_CHECK_DEFAULT(field, result) CHECK_DEFAULT(LPCTSTR, field, result)
  118. #define INT_CHECK_DEFAULT(field, result) CHECK_DEFAULT(INT, field, result)
  119. #define BOOL_CHECK_DEFAULT(field, result) CHECK_DEFAULT(BOOL, field, result)
  120. #define STR_CHECK_READ_GLOBAL(field, buffer, cb) CHECK_READ_GLOBAL(LPTSTR, field, buffer, cb)
  121. #define STR_CHECK_READ_QUOTED_GLOBAL(field, buffer, cb) CHECK_READ_QUOTED_GLOBAL(LPTSTR, field, buffer, cb)
  122. #define INT_CHECK_GET_GLOBAL(field, result) CHECK_GET_GLOBAL(INT, field, result)
  123. #define BOOL_CHECK_GET_GLOBAL(field, result) CHECK_GET_GLOBAL(BOOL, field, result)
  124. #define STR_CHECK_WRITE_GLOBAL(field, value) CHECK_WRITE_GLOBAL(LPCTSTR, field, value)
  125. #define STR_CHECK_WRITE_QUOTED_GLOBAL(field, value) CHECK_WRITE_QUOTED_GLOBAL(LPCTSTR, field, value)
  126. #define INT_CHECK_WRITE_GLOBAL(field, value) CHECK_WRITE_GLOBAL(INT, field, value)
  127. #define BOOL_CHECK_WRITE_GLOBAL(field, value) CHECK_WRITE_GLOBAL(BOOL, field, value)
  128. #define STR_CHECK_EXREAD_VIEW(section, field, buffer, cb) CHECK_EXREAD_VIEW(LPTSTR, section, field, buffer, cb)
  129. #define INT_CHECK_EXGET_VIEW(section, field, result) CHECK_EXGET_VIEW(INT, section, field, result)
  130. #define BOOL_CHECK_EXGET_VIEW(section, field, result) CHECK_EXGET_VIEW(BOOL, section, field, result)
  131. #define STR_CHECK_EXWRITE_VIEW(section, field, value) CHECK_EXWRITE_VIEW(LPCTSTR, section, field, value)
  132. #define INT_CHECK_EXWRITE_VIEW(section, field, value) CHECK_EXWRITE_VIEW(INT, section, field, value)
  133. #define BOOL_CHECK_EXWRITE_VIEW(section, field, value) CHECK_EXWRITE_VIEW(BOOL, section, field, value)
  134. #define STR_CHECK_READ_VIEW(field, buffer, cb) CHECK_READ_VIEW(LPTSTR, field, buffer, cb)
  135. #define INT_CHECK_GET_VIEW(field, result) CHECK_GET_VIEW(INT, field, result)
  136. #define BOOL_CHECK_GET_VIEW(field, result) CHECK_GET_VIEW(BOOL, field, result)
  137. #define STR_CHECK_WRITE_VIEW(field, value) CHECK_WRITE_VIEW(LPCTSTR, field, value)
  138. #define INT_CHECK_WRITE_VIEW(field, value) CHECK_WRITE_VIEW(INT, field, value)
  139. #define BOOL_CHECK_WRITE_VIEW(field, value) CHECK_WRITE_VIEW(BOOL, field, value)
  140. static LPCWSTR GetDefaultExtractPath()
  141. {
  142. static TCHAR m_def_extract_path[MAX_PATH] = { TEXT('\0'), };
  143. if (L'\0' == m_def_extract_path[0])
  144. {
  145. if(FAILED(SHGetFolderPath(NULL, CSIDL_MYMUSIC, NULL, SHGFP_TYPE_CURRENT, m_def_extract_path)))
  146. {
  147. if(FAILED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, m_def_extract_path)))
  148. {
  149. // and if that all fails then do a reasonable default
  150. StringCchCopyW(m_def_extract_path, ARRAYSIZE(m_def_extract_path), L"C:\\My Music");
  151. }
  152. // if there's no valid My Music folder (typically win2k) then default to %my_documents%\my music
  153. else PathCombineW(m_def_extract_path, m_def_extract_path, L"My Music");
  154. }
  155. }
  156. return m_def_extract_path;
  157. }
  158. HRESULT Settings_GetDefault(INT categoryId, INT fieldId, VOID *pValue)
  159. {
  160. switch(categoryId)
  161. {
  162. case C_EXTRACT:
  163. switch(fieldId)
  164. {
  165. STR_CHECK_DEFAULT(EF_PATH, pValue);
  166. STR_CHECK_DEFAULT(EF_TITLEFMT, pValue);
  167. STR_CHECK_DEFAULT(EF_PLAYLISTFMT, pValue);
  168. STR_CHECK_DEFAULT(EF_COMMENTTEXT, pValue);
  169. BOOL_CHECK_DEFAULT(EF_UPPEREXTENSION, pValue);
  170. BOOL_CHECK_DEFAULT(EF_ADDMETADATA, pValue);
  171. BOOL_CHECK_DEFAULT(EF_CALCULATERG, pValue);
  172. BOOL_CHECK_DEFAULT(EF_USETOTALTRACKS, pValue);
  173. BOOL_CHECK_DEFAULT(EF_ADDTOMLDB, pValue);
  174. INT_CHECK_DEFAULT(EF_TRACKOFFSET, pValue);
  175. BOOL_CHECK_DEFAULT(EF_CREATEM3U, pValue);
  176. BOOL_CHECK_DEFAULT(EF_CREATEPLS, pValue);
  177. BOOL_CHECK_DEFAULT(EF_CREATEMLPL, pValue);
  178. BOOL_CHECK_DEFAULT(EF_USEM3UEXT, pValue);
  179. INT_CHECK_DEFAULT(EF_FOURCC, pValue);
  180. }
  181. break;
  182. case C_COPY:
  183. switch(fieldId)
  184. {
  185. STR_CHECK_DEFAULT(CF_PATH, pValue);
  186. STR_CHECK_DEFAULT(CF_TITLEFMT, pValue);
  187. BOOL_CHECK_DEFAULT(CF_USETITLEFMT, pValue);
  188. BOOL_CHECK_DEFAULT(CF_ADDTOMLDB, pValue);
  189. BOOL_CHECK_DEFAULT(CF_CALCULATERG, pValue);
  190. INT_CHECK_DEFAULT(CF_GAINMODE, pValue);
  191. }
  192. break;
  193. case C_GLOBAL:
  194. switch(fieldId)
  195. {
  196. BOOL_CHECK_DEFAULT(GF_SHOWINFO, pValue);
  197. BOOL_CHECK_DEFAULT(GF_SHOWPARENT, pValue);
  198. BOOL_CHECK_DEFAULT(GF_ENQUEUEBYDEFAULT, pValue);
  199. }
  200. break;
  201. case C_DATAVIEW:
  202. switch(fieldId)
  203. {
  204. STR_CHECK_DEFAULT(DVF_COLUMNLIST, pValue);
  205. STR_CHECK_DEFAULT(DVF_LASTFOLDER, pValue);
  206. INT_CHECK_DEFAULT(DVF_ORDERBY, pValue);
  207. BOOL_CHECK_DEFAULT(DVF_ORDERASC, pValue);
  208. INT_CHECK_DEFAULT(DVF_VIEWMODE, pValue);
  209. BOOL_CHECK_DEFAULT(DVF_SHOWAUDIO, pValue);
  210. BOOL_CHECK_DEFAULT(DVF_SHOWVIDEO, pValue);
  211. BOOL_CHECK_DEFAULT(DVF_SHOWPLAYLIST, pValue);
  212. BOOL_CHECK_DEFAULT(DVF_SHOWUNKNOWN, pValue);
  213. BOOL_CHECK_DEFAULT(DVF_HIDEEXTENSION, pValue);
  214. BOOL_CHECK_DEFAULT(DVF_IGNOREHIDDEN, pValue);
  215. INT_CHECK_DEFAULT(DVF_DIVIDERPOS, pValue);
  216. }
  217. break;
  218. }
  219. return E_INVALIDARG;
  220. }
  221. HRESULT Settings_ReadValue(INT categoryId, INT fieldId, VOID *pValue, INT cbSize)
  222. {
  223. LPCTSTR pszSection;
  224. switch(categoryId)
  225. {
  226. case C_EXTRACT:
  227. switch(fieldId)
  228. {
  229. STR_CHECK_READ_GLOBAL(EF_PATH, pValue, cbSize);
  230. STR_CHECK_READ_QUOTED_GLOBAL(EF_TITLEFMT, pValue, cbSize);
  231. STR_CHECK_READ_QUOTED_GLOBAL(EF_PLAYLISTFMT, pValue, cbSize);
  232. STR_CHECK_READ_QUOTED_GLOBAL(EF_COMMENTTEXT, pValue, cbSize);
  233. BOOL_CHECK_GET_GLOBAL(EF_UPPEREXTENSION, pValue);
  234. BOOL_CHECK_GET_GLOBAL(EF_ADDMETADATA, pValue);
  235. BOOL_CHECK_GET_GLOBAL(EF_CALCULATERG, pValue);
  236. BOOL_CHECK_GET_GLOBAL(EF_USETOTALTRACKS, pValue);
  237. BOOL_CHECK_GET_GLOBAL(EF_ADDTOMLDB, pValue);
  238. INT_CHECK_GET_GLOBAL(EF_TRACKOFFSET, pValue);
  239. BOOL_CHECK_GET_GLOBAL(EF_CREATEM3U, pValue);
  240. BOOL_CHECK_GET_GLOBAL(EF_CREATEPLS, pValue);
  241. BOOL_CHECK_GET_GLOBAL(EF_CREATEMLPL, pValue);
  242. BOOL_CHECK_GET_GLOBAL(EF_USEM3UEXT, pValue);
  243. INT_CHECK_GET_GLOBAL(EF_FOURCC, pValue);
  244. }
  245. break;
  246. case C_COPY:
  247. switch(fieldId)
  248. {
  249. STR_CHECK_READ_GLOBAL(CF_PATH, pValue, cbSize);
  250. STR_CHECK_READ_QUOTED_GLOBAL(CF_TITLEFMT, pValue, cbSize);
  251. BOOL_CHECK_GET_GLOBAL(CF_USETITLEFMT, pValue);
  252. BOOL_CHECK_GET_GLOBAL(CF_ADDTOMLDB, pValue);
  253. BOOL_CHECK_GET_GLOBAL(CF_CALCULATERG, pValue);
  254. INT_CHECK_GET_GLOBAL(CF_GAINMODE, pValue);
  255. }
  256. break;
  257. case C_GLOBAL:
  258. switch(fieldId)
  259. {
  260. BOOL_CHECK_GET_VIEW(GF_SHOWINFO, pValue);
  261. BOOL_CHECK_GET_VIEW(GF_SHOWPARENT, pValue);
  262. BOOL_CHECK_GET_GLOBAL(GF_ENQUEUEBYDEFAULT, pValue);
  263. }
  264. break;
  265. case C_DATAVIEW:
  266. pszSection = SECTION_DATAVIEW;
  267. switch(fieldId)
  268. {
  269. STR_CHECK_EXREAD_VIEW(pszSection, DVF_COLUMNLIST, pValue, cbSize);
  270. STR_CHECK_EXREAD_VIEW(pszSection, DVF_LASTFOLDER, pValue, cbSize);
  271. INT_CHECK_EXGET_VIEW(pszSection, DVF_ORDERBY, pValue);
  272. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_ORDERASC, pValue);
  273. INT_CHECK_EXGET_VIEW(pszSection, DVF_VIEWMODE, pValue);
  274. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_SHOWAUDIO, pValue);
  275. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_SHOWVIDEO, pValue);
  276. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_SHOWPLAYLIST, pValue);
  277. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_SHOWUNKNOWN, pValue);
  278. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_HIDEEXTENSION, pValue);
  279. BOOL_CHECK_EXGET_VIEW(pszSection, DVF_IGNOREHIDDEN, pValue);
  280. INT_CHECK_EXGET_VIEW(pszSection, DVF_DIVIDERPOS, pValue);
  281. }
  282. break;
  283. }
  284. return E_INVALIDARG;
  285. }
  286. HRESULT Settings_SetString(INT categoryId, INT fieldId, LPCWSTR pszBuffer)
  287. {
  288. LPCTSTR pszSection;
  289. switch(categoryId)
  290. {
  291. case C_EXTRACT:
  292. switch(fieldId)
  293. {
  294. STR_CHECK_WRITE_QUOTED_GLOBAL(EF_PATH, pszBuffer);
  295. STR_CHECK_WRITE_QUOTED_GLOBAL(EF_TITLEFMT, pszBuffer);
  296. STR_CHECK_WRITE_QUOTED_GLOBAL(EF_PLAYLISTFMT, pszBuffer);
  297. STR_CHECK_WRITE_QUOTED_GLOBAL(EF_COMMENTTEXT, pszBuffer);
  298. STR_CHECK_WRITE_GLOBAL(EF_UPPEREXTENSION, pszBuffer);
  299. STR_CHECK_WRITE_GLOBAL(EF_ADDMETADATA, pszBuffer);
  300. STR_CHECK_WRITE_GLOBAL(EF_CALCULATERG, pszBuffer);
  301. STR_CHECK_WRITE_GLOBAL(EF_USETOTALTRACKS, pszBuffer);
  302. STR_CHECK_WRITE_GLOBAL(EF_ADDTOMLDB, pszBuffer);
  303. STR_CHECK_WRITE_GLOBAL(EF_TRACKOFFSET, pszBuffer);
  304. STR_CHECK_WRITE_GLOBAL(EF_CREATEM3U, pszBuffer);
  305. STR_CHECK_WRITE_GLOBAL(EF_CREATEPLS, pszBuffer);
  306. STR_CHECK_WRITE_GLOBAL(EF_CREATEMLPL, pszBuffer);
  307. STR_CHECK_WRITE_GLOBAL(EF_USEM3UEXT, pszBuffer);
  308. STR_CHECK_WRITE_GLOBAL(EF_FOURCC, pszBuffer);
  309. }
  310. break;
  311. case C_COPY:
  312. switch(fieldId)
  313. {
  314. STR_CHECK_WRITE_QUOTED_GLOBAL(CF_PATH, pszBuffer);
  315. STR_CHECK_WRITE_QUOTED_GLOBAL(CF_TITLEFMT, pszBuffer);
  316. STR_CHECK_WRITE_GLOBAL(CF_USETITLEFMT, pszBuffer);
  317. STR_CHECK_WRITE_GLOBAL(CF_ADDTOMLDB, pszBuffer);
  318. STR_CHECK_WRITE_GLOBAL(CF_CALCULATERG, pszBuffer);
  319. STR_CHECK_WRITE_GLOBAL(CF_GAINMODE, pszBuffer);
  320. }
  321. break;
  322. case C_GLOBAL:
  323. switch(fieldId)
  324. {
  325. STR_CHECK_WRITE_VIEW(GF_SHOWINFO, pszBuffer);
  326. STR_CHECK_WRITE_VIEW(GF_SHOWPARENT, pszBuffer);
  327. STR_CHECK_WRITE_VIEW(GF_ENQUEUEBYDEFAULT, pszBuffer);
  328. }
  329. break;
  330. case C_DATAVIEW:
  331. pszSection = SECTION_DATAVIEW;
  332. switch(fieldId)
  333. {
  334. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_COLUMNLIST, pszBuffer);
  335. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_LASTFOLDER, pszBuffer);
  336. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_ORDERBY, pszBuffer);
  337. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_ORDERASC, pszBuffer);
  338. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_VIEWMODE, pszBuffer);
  339. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_SHOWAUDIO, pszBuffer);
  340. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_SHOWVIDEO, pszBuffer);
  341. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_SHOWPLAYLIST, pszBuffer);
  342. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_SHOWUNKNOWN, pszBuffer);
  343. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_HIDEEXTENSION, pszBuffer);
  344. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_IGNOREHIDDEN, pszBuffer);
  345. STR_CHECK_EXWRITE_VIEW(pszSection, DVF_DIVIDERPOS, pszBuffer);
  346. }
  347. break;
  348. }
  349. return E_INVALIDARG;
  350. }
  351. HRESULT Settings_GetInt(INT categoryId, INT fieldId, INT *pnVal)
  352. {
  353. return Settings_ReadValue(categoryId, fieldId, pnVal, sizeof(INT));
  354. }
  355. HRESULT Settings_GetBool(INT categoryId, INT fieldId, BOOL *pbVal)
  356. {
  357. return Settings_ReadValue(categoryId, fieldId, pbVal, sizeof(BOOL));
  358. }
  359. HRESULT Settings_ReadString(INT categoryId, INT fieldId, LPTSTR pszBuffer, INT cchBufferMax)
  360. {
  361. return Settings_ReadValue(categoryId, fieldId, pszBuffer, cchBufferMax * sizeof(TCHAR));
  362. }
  363. HRESULT Settings_SetWindowText(INT categoryId, INT fieldId, HWND hwnd)
  364. {
  365. TCHAR szBuffer[8192] = {0};
  366. HRESULT hr = Settings_ReadValue(categoryId, fieldId, szBuffer, sizeof(szBuffer));
  367. if (S_OK == hr) SetWindowText(hwnd, szBuffer);
  368. return hr;
  369. }
  370. HRESULT Settings_SetWindowInt(INT categoryId, INT fieldId, HWND hwnd)
  371. {
  372. INT nVal;
  373. HRESULT hr = Settings_ReadValue(categoryId, fieldId, &nVal, sizeof(nVal));
  374. if (S_OK == hr)
  375. {
  376. TCHAR szBuffer[256] = {0};
  377. hr = StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), TEXT("%d"), nVal);
  378. if (S_OK == hr) SetWindowText(hwnd, szBuffer);
  379. }
  380. return hr;
  381. }
  382. HRESULT Settings_SetDlgItemText(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  383. {
  384. HWND hctrl = GetDlgItem(hdlg, nItemId);
  385. return (hctrl) ? Settings_SetWindowText(categoryId, fieldId, hctrl) : E_HANDLE;
  386. }
  387. HRESULT Settings_SetDlgItemInt(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  388. {
  389. HWND hctrl = GetDlgItem(hdlg, nItemId);
  390. return (hctrl) ? Settings_SetWindowInt(categoryId, fieldId, hctrl) : E_HANDLE;
  391. }
  392. HRESULT Settings_SetCheckBox(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  393. {
  394. INT nVal;
  395. HRESULT hr = Settings_GetInt(categoryId, fieldId, &nVal);
  396. if (S_OK == hr) hr = (CheckDlgButton(hdlg, nItemId, (0 != nVal) ? BST_CHECKED : BST_UNCHECKED)) ? S_OK : E_HANDLE;
  397. return hr;
  398. }
  399. HRESULT Settings_SetInt(INT categoryId, INT fieldId, INT nValue)
  400. {
  401. TCHAR szBuffer[64] = {0};
  402. HRESULT hr = StringCchPrintfW(szBuffer, ARRAYSIZE(szBuffer), TEXT("%d"), nValue);
  403. if (S_OK == hr) hr = Settings_SetString(categoryId, fieldId, szBuffer);
  404. return hr;
  405. }
  406. HRESULT Settings_SetBool(INT categoryId, INT fieldId, BOOL bValue)
  407. {
  408. return Settings_SetInt(categoryId, fieldId, (0 != bValue));
  409. }
  410. HRESULT Settings_FromWindowText(INT categoryId, INT fieldId, HWND hwnd)
  411. {
  412. if (!hwnd) return E_HANDLE;
  413. INT l = GetWindowTextLength(hwnd);
  414. if (l < 1024)
  415. {
  416. TCHAR szBuffer[1024] = {0};
  417. GetWindowText(hwnd, szBuffer, ARRAYSIZE(szBuffer));
  418. return Settings_SetString(categoryId, fieldId, szBuffer);
  419. }
  420. else
  421. {
  422. LPTSTR pszBuffer = (LPTSTR)calloc((l + 1), sizeof(TCHAR));
  423. if (!pszBuffer) return E_OUTOFMEMORY;
  424. GetWindowText(hwnd, pszBuffer, sizeof(TCHAR)*(l + 1));
  425. HRESULT hr = Settings_SetString(categoryId, fieldId, pszBuffer);
  426. free(pszBuffer);
  427. return hr;
  428. }
  429. }
  430. HRESULT Settings_FromDlgItemText(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  431. {
  432. HWND hctrl = GetDlgItem(hdlg, nItemId);
  433. return (hctrl) ? Settings_FromWindowText(categoryId, fieldId, hctrl) : E_HANDLE;
  434. }
  435. HRESULT Settings_FromCheckBox(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  436. {
  437. UINT v = IsDlgButtonChecked(hdlg, nItemId);
  438. return Settings_SetInt(categoryId, fieldId, v);
  439. }
  440. typedef struct _FBROWSER
  441. {
  442. LPCWSTR pszSelection;
  443. } FBROWSER;
  444. BOOL CALLBACK browseEnumProc(HWND hwnd, LPARAM lParam)
  445. {
  446. wchar_t cl[32] = {0};
  447. GetClassNameW(hwnd, cl, ARRAYSIZE(cl));
  448. if (!lstrcmpiW(cl, WC_TREEVIEW))
  449. {
  450. PostMessage(hwnd, TVM_ENSUREVISIBLE, 0, (LPARAM)TreeView_GetSelection(hwnd));
  451. return FALSE;
  452. }
  453. return TRUE;
  454. }
  455. int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM pData)
  456. {
  457. FBROWSER *pfb = (FBROWSER*)pData;
  458. switch(uMsg)
  459. {
  460. case BFFM_INITIALIZED:
  461. if (pfb && pfb->pszSelection) SendMessageW(hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM)pfb->pszSelection);
  462. // this is not nice but it fixes the selection not working correctly on all OSes
  463. EnumChildWindows(hwnd, browseEnumProc, 0);
  464. break;
  465. }
  466. return 0;
  467. }
  468. HRESULT Settings_BrowseForFolder(INT categoryId, INT fieldId, HWND hDlg, INT nEditId)
  469. {
  470. BROWSEINFO bi = {0};
  471. FBROWSER fb;
  472. wchar_t szPath[MAX_PATH] = {0};
  473. HRESULT hr = Settings_ReadString(categoryId,fieldId, szPath, ARRAYSIZE(szPath));
  474. if (S_OK != hr) return hr;
  475. fb.pszSelection = szPath;
  476. bi.hwndOwner = hDlg;
  477. bi.pidlRoot = NULL;
  478. bi.pszDisplayName = szPath;
  479. bi.lpszTitle = WASABI_API_LNGSTRINGW(IDS_CHOOSE_A_FOLDER);
  480. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS | BIF_NEWDIALOGSTYLE;
  481. bi.lpfn = BrowseCallbackProc;
  482. bi.lParam = (LPARAM)&fb;
  483. HRESULT hrCom = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  484. if (SUCCEEDED(hrCom))
  485. {
  486. ITEMIDLIST *idlist = SHBrowseForFolder(&bi);
  487. if (idlist)
  488. {
  489. if (SHGetPathFromIDList(idlist, szPath))
  490. {
  491. hr = Settings_SetString(categoryId,fieldId, szPath);
  492. if (S_OK == hr) SetDlgItemText(hDlg, nEditId, szPath);
  493. }
  494. else hr = S_FALSE;
  495. CoTaskMemFree(idlist);
  496. }
  497. }
  498. else hr = hrCom;
  499. if (S_OK == hrCom) CoUninitialize();
  500. return hr;
  501. }
  502. HRESULT Settings_SetDirectoryCtrl(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  503. {
  504. TCHAR szBuffer[MAX_PATH] = {0};
  505. HRESULT hr;
  506. hr = Settings_ReadString(categoryId, fieldId, szBuffer, ARRAYSIZE(szBuffer));
  507. if (S_OK != hr) *szBuffer = TEXT('\0');
  508. else CleanupDirectoryString(szBuffer);
  509. SetDlgItemText(hdlg, nItemId, szBuffer);
  510. return hr;
  511. }
  512. HRESULT Settings_FromDirectoryCtrl(INT categoryId, INT fieldId, HWND hdlg, INT nItemId)
  513. {
  514. TCHAR szBuffer[MAX_PATH] = {0};
  515. GetDlgItemText(hdlg, nItemId, szBuffer, ARRAYSIZE(szBuffer));
  516. CleanupDirectoryString(szBuffer);
  517. return Settings_SetString(categoryId, fieldId, szBuffer);
  518. }