infodlg.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. #include <windows.h>
  2. #include "api.h"
  3. #include "resource.h"
  4. #include "../Winamp/in2.h"
  5. extern In_Module mod; // the output module (filled in near the bottom of this file)
  6. extern "C" { extern wchar_t lastextfn[1024]; };
  7. #define MAX_EDITABLE_METASTRING 8192
  8. #include "../nsv/nsvlib.h"
  9. static int isplaying;
  10. static int timems;
  11. extern char lastfn[1024];
  12. extern int g_play_needseek;
  13. static void restartPlayback()
  14. {
  15. if (isplaying)
  16. {
  17. SendMessage(mod.hMainWindow,WM_USER,0,3007); // disable stats updating
  18. SendMessage(mod.hMainWindow,WM_COMMAND,40045,0);
  19. if (timems)
  20. {
  21. g_play_needseek=timems;
  22. // SendMessage(mod.hMainWindow,WM_USER,timems,106);
  23. }
  24. if (isplaying & 2)
  25. {
  26. SendMessage(mod.hMainWindow,WM_COMMAND,40046,0);
  27. }
  28. SendMessage(mod.hMainWindow,WM_USER,1,3007); // enable stats updating
  29. }
  30. }
  31. static void stopPlayback(const char *fn)
  32. {
  33. isplaying=0;
  34. timems=0;
  35. if (!_stricmp(lastfn,fn))
  36. {
  37. isplaying= (int)SendMessage(mod.hMainWindow,WM_USER,0,104);
  38. if (isplaying)
  39. {
  40. timems= (int)SendMessage(mod.hMainWindow,WM_USER,0,105);
  41. SendMessage(mod.hMainWindow,WM_COMMAND,40047,0);
  42. }
  43. }
  44. }
  45. extern int config_padtag;
  46. int fillBs(HANDLE hFile, nsv_InBS &bs, int lenbytes);
  47. static nsv_fileHeader m_set_lhdr;
  48. static char m_set_lfile[1024];
  49. static void closeset()
  50. {
  51. free(m_set_lhdr.toc);
  52. free(m_set_lhdr.metadata);
  53. memset(&m_set_lhdr,0,sizeof(m_set_lhdr));
  54. m_set_lfile[0]=0;
  55. }
  56. extern int config_bufms, config_prebufms, config_underunbuf;
  57. extern "C"
  58. {
  59. __declspec( dllexport ) int winampSetExtendedFileInfo(const char *fn, const char *data, char *val)
  60. {
  61. if(!fn || !fn[0]) return 0;
  62. //muahaha, <3 hacks
  63. if(!_stricmp(data,"setHttpConfigValues"))
  64. {
  65. config_bufms=atoi(val);
  66. char *p=strstr(val,",");
  67. if(!p) return 0;
  68. config_prebufms=atoi(p+1);
  69. p=strstr(p+1,",");
  70. if(!p) return 0;
  71. config_underunbuf=atoi(p+1);
  72. return 1;
  73. }
  74. if(strcmpi(fn,m_set_lfile))
  75. {
  76. closeset();
  77. lstrcpynA(m_set_lfile,fn,sizeof(m_set_lfile));
  78. HANDLE hFile = CreateFileA(fn,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  79. if (hFile != INVALID_HANDLE_VALUE)
  80. {
  81. nsv_InBS bs;
  82. for (;;)
  83. {
  84. int ret=nsv_readheader(bs,&m_set_lhdr);
  85. if (ret <= 0 || fillBs(hFile,bs,ret)) break;
  86. }
  87. CloseHandle(hFile);
  88. }
  89. }
  90. char *p=(char*)m_set_lhdr.metadata;
  91. unsigned int pos=0;
  92. int omdl=m_set_lhdr.metadata_len;
  93. if (p) while (pos < m_set_lhdr.metadata_len)
  94. {
  95. // scan for =
  96. while (pos < m_set_lhdr.metadata_len && (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) { pos++; p++; }
  97. if (pos >= m_set_lhdr.metadata_len) break;
  98. char *lp=p;
  99. while (pos < m_set_lhdr.metadata_len && *p != '=') { pos++; p++; }
  100. if (pos >= m_set_lhdr.metadata_len) break;
  101. // skip =
  102. p++; if (++pos >= m_set_lhdr.metadata_len) break;
  103. // get delim char
  104. char divc=*p++; if (++pos >= m_set_lhdr.metadata_len) break;
  105. // scan for new delim char
  106. while (pos < m_set_lhdr.metadata_len && *p != divc) { pos++; p++; }
  107. p++; // advance over our delim char
  108. if (++pos > m_set_lhdr.metadata_len) break;
  109. if (!strncmp(lp,data,strlen(data)) && lp[strlen(data)]=='=')
  110. {
  111. if (pos >= m_set_lhdr.metadata_len)
  112. {
  113. m_set_lhdr.metadata_len = (unsigned int)(lp - (char*)m_set_lhdr.metadata);
  114. }
  115. else
  116. {
  117. memcpy(lp,p,m_set_lhdr.metadata_len - (p-(char*)m_set_lhdr.metadata));
  118. m_set_lhdr.metadata_len -= (unsigned int)(p-lp);
  119. }
  120. break;
  121. }
  122. }
  123. if (val && *val)
  124. {
  125. unsigned char divc; //fucko
  126. int x;
  127. for (x = 1; x < 256 && strchr(val,x); x ++);
  128. if (x == 256) return 1;
  129. divc=(unsigned char)x;
  130. int nmdl= (int)(m_set_lhdr.metadata_len + 5 + strlen(data) + strlen(val));
  131. if (!m_set_lhdr.metadata || omdl<nmdl)
  132. m_set_lhdr.metadata=realloc(m_set_lhdr.metadata,nmdl);
  133. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len,data,strlen(data));
  134. m_set_lhdr.metadata_len+= (int)strlen(data);
  135. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len,"=",1);
  136. m_set_lhdr.metadata_len++;
  137. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len,&divc,1);
  138. m_set_lhdr.metadata_len++;
  139. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len,val,strlen(val));
  140. m_set_lhdr.metadata_len+= (int)strlen(val);
  141. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len,&divc,1);
  142. m_set_lhdr.metadata_len++;
  143. memcpy((char*)m_set_lhdr.metadata + m_set_lhdr.metadata_len," ",1); //space to be ghey
  144. m_set_lhdr.metadata_len++;
  145. }
  146. return 1;
  147. }
  148. __declspec( dllexport ) int winampWriteExtendedFileInfo()
  149. {
  150. lastextfn[0]=0; // flush cache
  151. if (m_set_lfile[0])
  152. {
  153. HANDLE hFile = CreateFileA(m_set_lfile,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  154. if (hFile == INVALID_HANDLE_VALUE)
  155. {
  156. // MessageBox(mod.hMainWindow,"Error opening NSV file for update","NSV Tag Error",MB_OK);
  157. return 0;
  158. }
  159. nsv_OutBS bs;
  160. int osize=m_set_lhdr.header_size;
  161. nsv_writeheader(bs,&m_set_lhdr,osize);
  162. int hdrlen;
  163. char *hdr=(char*)bs.get(&hdrlen);
  164. if (hdr && hdrlen == (int)osize) // fast update of header
  165. {
  166. DWORD dw = 0;
  167. SetFilePointer(hFile,0,NULL,SEEK_SET);
  168. WriteFile(hFile,hdr,hdrlen,&dw,NULL);
  169. CloseHandle(hFile);
  170. }
  171. else
  172. {
  173. if (hdr && config_padtag>0) // enlarge header by config_padtag bytes =)
  174. {
  175. bs.clear();
  176. nsv_writeheader(bs,&m_set_lhdr,config_padtag+m_set_lhdr.header_size);
  177. hdr=(char*)bs.get(&hdrlen); // update
  178. }
  179. char tmpfn[1024+8];
  180. char tmpfn2[1024+8];
  181. wsprintfA(tmpfn,"%s.new",m_set_lfile);
  182. wsprintfA(tmpfn2,"%s.old",m_set_lfile);
  183. HANDLE hTempFile=CreateFileA(tmpfn,GENERIC_READ|GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
  184. if (hTempFile == INVALID_HANDLE_VALUE)
  185. {
  186. // MessageBox(mod.hMainWindow,"Can't create tempfile - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  187. CloseHandle(hFile);
  188. return 0;
  189. }
  190. SetFilePointer(hFile,osize,NULL,SEEK_SET);
  191. if (hdrlen)
  192. {
  193. DWORD dw = 0;
  194. if (!WriteFile(hTempFile,hdr,hdrlen,&dw,NULL) || (int)dw != hdrlen)
  195. {
  196. CloseHandle(hTempFile);
  197. CloseHandle(hFile);
  198. DeleteFileA(tmpfn);
  199. // MessageBox(mod.hMainWindow,"Error copying source - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  200. return 0;
  201. }
  202. }
  203. for (;;)
  204. {
  205. char buf[8192] = {0};
  206. DWORD dw = 0;
  207. BOOL r1=ReadFile(hFile,buf,sizeof(buf),&dw,NULL);
  208. if (r1 && !dw) break;
  209. DWORD dwout = 0;
  210. if (!r1 || !WriteFile(hTempFile,buf,dw,&dwout,NULL) || dwout < dw)
  211. {
  212. CloseHandle(hTempFile);
  213. DeleteFileA(tmpfn);
  214. // MessageBox(mod.hMainWindow,"Error copying source - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  215. return 0;
  216. }
  217. }
  218. if (GetFileSize(hFile,NULL)-osize != GetFileSize(hTempFile,NULL)-hdrlen)
  219. {
  220. CloseHandle(hTempFile);
  221. CloseHandle(hFile);
  222. DeleteFileA(tmpfn);
  223. // MessageBox(mod.hMainWindow,"Error size mismatch - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  224. return 0;
  225. }
  226. CloseHandle(hFile);
  227. CloseHandle(hTempFile);
  228. stopPlayback(m_set_lfile);
  229. if (!MoveFileA(m_set_lfile,tmpfn2))
  230. {
  231. DeleteFileA(tmpfn);
  232. restartPlayback();
  233. // MessageBox(mod.hMainWindow,"Error renaming source - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  234. return 0;
  235. }
  236. if (!MoveFileA(tmpfn,m_set_lfile))
  237. {
  238. MoveFileA(tmpfn2,m_set_lfile);
  239. DeleteFileA(tmpfn);
  240. restartPlayback();
  241. // MessageBox(mod.hMainWindow,"Error renaming new file - can't update tag!","NSV Tag Editor Error",MB_ICONSTOP|MB_OK);
  242. return 0;
  243. }
  244. DeleteFileA(tmpfn2);
  245. restartPlayback();
  246. }
  247. }
  248. closeset();
  249. lastextfn[0]=0;
  250. return 1;
  251. }
  252. }
  253. const char *g_lastfile;
  254. HANDLE g_hFile=INVALID_HANDLE_VALUE;
  255. nsv_fileHeader g_filehdr={0,~0,~0,};
  256. unsigned int g_oldtag_size;
  257. unsigned int *g_toc_save, *g_toc_save_ex, g_toc_savesize;
  258. void enableControls(HWND hwndDlg, int en)
  259. {
  260. EnableWindow(GetDlgItem(hwndDlg,IDC_SETTOCSIZE),en);
  261. EnableWindow(GetDlgItem(hwndDlg,IDC_TOC),en);
  262. EnableWindow(GetDlgItem(hwndDlg,IDC_ANALYZE),en);
  263. EnableWindow(GetDlgItem(hwndDlg,IDOK),en);
  264. EnableWindow(GetDlgItem(hwndDlg,IDC_REMTAG),en);
  265. EnableWindow(GetDlgItem(hwndDlg,IDC_ADD),en);
  266. EnableWindow(GetDlgItem(hwndDlg,IDC_REM),en);
  267. EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT),en);
  268. EnableWindow(GetDlgItem(hwndDlg,IDC_FASTUPD),en);
  269. }
  270. void closeNsv(HWND hwndDlg)
  271. {
  272. if (g_hFile != INVALID_HANDLE_VALUE)
  273. {
  274. CloseHandle(g_hFile);
  275. g_hFile=INVALID_HANDLE_VALUE;
  276. }
  277. free(g_filehdr.metadata);
  278. g_filehdr.metadata=0;
  279. g_filehdr.metadata_len=0;
  280. free(g_filehdr.toc);
  281. g_filehdr.toc=0;
  282. g_filehdr.toc_ex=0;
  283. free(g_toc_save);
  284. g_toc_save=0;
  285. g_toc_save_ex=0;
  286. g_toc_savesize=0;
  287. g_filehdr.toc_size=0;
  288. g_filehdr.toc_alloc=0;
  289. g_filehdr.file_lenbytes=~0;
  290. g_filehdr.file_lenms=~0;
  291. g_filehdr.header_size=0;
  292. SetDlgItemTextA(hwndDlg,IDC_LENBYTES,"");
  293. SetDlgItemTextA(hwndDlg,IDC_LENMS,"");
  294. SetDlgItemTextA(hwndDlg,IDC_AVGBITRATE,"");
  295. CheckDlgButton(hwndDlg,IDC_TOC,0);
  296. SetDlgItemTextA(hwndDlg,IDC_TOCSIZE,"");
  297. SetDlgItemTextA(hwndDlg,IDC_SETTOCSIZE,"");
  298. SetDlgItemTextA(hwndDlg,IDC_FN,"");
  299. int x;
  300. int cnt= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETCOUNT,0,0);
  301. for ( x= 0; x < cnt; x ++)
  302. {
  303. void *v=(void *)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,x,0);
  304. if (v) free(v);
  305. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_SETITEMDATA,x,0);
  306. }
  307. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_RESETCONTENT,0,0);
  308. SetDlgItemTextA(hwndDlg,IDC_TAG_LEN,WASABI_API_LNGSTRING(IDS_TOTAL_TAG_SIZE));
  309. SetDlgItemTextA(hwndDlg,IDC_METADATA_LEN,WASABI_API_LNGSTRING(IDS_NO_METADATA));
  310. enableControls(hwndDlg,0);
  311. }
  312. int fillBs(HANDLE hFile, nsv_InBS &bs, int lenbytes)
  313. {
  314. while (lenbytes > 0)
  315. {
  316. DWORD r=0;
  317. char buf[8192] = {0};
  318. BOOL ret=ReadFile(hFile,buf,sizeof(buf),&r,NULL);
  319. lenbytes-=r;
  320. bs.add(buf,r);
  321. if (!ret || !r) return 1;
  322. }
  323. return lenbytes > 0;
  324. }
  325. void makeNewHeaderInfo(HWND hwndDlg)
  326. {
  327. nsv_OutBS bs;
  328. g_filehdr.toc_alloc=0;
  329. nsv_writeheader(bs,&g_filehdr,0);
  330. EnableWindow(GetDlgItem(hwndDlg,IDC_FASTUPD),g_filehdr.header_size <= g_oldtag_size);
  331. char buf[128] = {0};
  332. if (g_filehdr.header_size) wsprintfA(buf,WASABI_API_LNGSTRING(IDS_TOTAL_TAG_SIZE_X_BYTES),g_filehdr.header_size);
  333. else WASABI_API_LNGSTRING_BUF(IDS_NO_TAG,buf,128);
  334. SetDlgItemTextA(hwndDlg,IDC_TAG_LEN,buf);
  335. }
  336. void populateInfo(HWND hwndDlg)
  337. {
  338. if (g_filehdr.file_lenbytes != ~0)
  339. {
  340. wchar_t buf[128] = {0};
  341. unsigned int low=g_filehdr.file_lenbytes;
  342. SetDlgItemTextW(hwndDlg,IDC_LENBYTES,WASABI_API_LNG->FormattedSizeString(buf, 128, low));
  343. }
  344. else SetDlgItemTextA(hwndDlg,IDC_LENBYTES,"?");
  345. if (g_filehdr.file_lenms != ~0)
  346. {
  347. char buf[128] = {0};
  348. unsigned int timems=g_filehdr.file_lenms;
  349. if (timems < 1000) wsprintfA(buf,"%ums",timems);
  350. else if (timems < 1000*60) wsprintfA(buf,"%02u.%03us",timems/1000,timems%1000);
  351. else if (timems < 1000*60*60) wsprintfA(buf,"%02u:%02u.%03us",timems/60000,(timems/1000)%60,timems%1000);
  352. else wsprintfA(buf,"%u:%02u:%02u.%03us",timems/3600000,(timems/60000)%60,(timems/1000)%60,timems%1000);
  353. SetDlgItemTextA(hwndDlg,IDC_LENMS,buf);
  354. }
  355. else SetDlgItemTextA(hwndDlg,IDC_LENMS,"?");
  356. CheckDlgButton(hwndDlg,IDC_TOC,g_filehdr.toc_size?BST_CHECKED:BST_UNCHECKED);
  357. if (g_filehdr.toc_size)
  358. {
  359. char buf[128] = {0};
  360. wsprintfA(buf,"%d%s",g_filehdr.toc_size,g_filehdr.toc_ex ? " (TOC 2.0)":"");
  361. SetDlgItemTextA(hwndDlg,IDC_TOCSIZE,buf);
  362. SetDlgItemInt(hwndDlg,IDC_SETTOCSIZE,g_filehdr.toc_size,FALSE);
  363. }
  364. else
  365. {
  366. SetDlgItemTextA(hwndDlg,IDC_TOCSIZE,"");
  367. SetDlgItemTextA(hwndDlg,IDC_SETTOCSIZE,"4096");
  368. }
  369. if (g_filehdr.file_lenms != ~0 && g_filehdr.file_lenbytes != ~0)
  370. {
  371. unsigned int bitrate = g_filehdr.file_lenms ? MulDiv(g_filehdr.file_lenbytes,8000,g_filehdr.file_lenms) : 0;
  372. char buf[1024] = {0};
  373. wsprintfA(buf,"%u %s",bitrate/1000,WASABI_API_LNGSTRING(IDS_KBPS));
  374. SetDlgItemTextA(hwndDlg,IDC_AVGBITRATE,buf);
  375. }
  376. else SetDlgItemTextA(hwndDlg,IDC_AVGBITRATE,"?");
  377. char buf[128] = {0};
  378. if (g_filehdr.header_size) wsprintfA(buf,WASABI_API_LNGSTRING(IDS_TOTAL_TAG_SIZE_X_BYTES),g_filehdr.header_size);
  379. else WASABI_API_LNGSTRING_BUF(IDS_NO_TAG,buf,128);
  380. SetDlgItemTextA(hwndDlg,IDC_TAG_LEN,buf);
  381. }
  382. void updateMetaData(HWND hwndDlg)
  383. {
  384. free(g_filehdr.metadata);
  385. g_filehdr.metadata=0;
  386. g_filehdr.metadata_len=0;
  387. int n= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETCOUNT,0,0);
  388. int x;
  389. int total_size=0;
  390. for (x = 0; x < n; x ++)
  391. {
  392. int l;
  393. char *bigstr = (char *)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,x,0);
  394. if (bigstr) l = (int)strlen((char *)bigstr)+2;
  395. else l= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETTEXTLEN,x,0);
  396. total_size+=l+2; // text+ two chars
  397. if (x) total_size++; // space
  398. }
  399. g_filehdr.metadata=malloc(total_size+1);
  400. char *metaout=(char*)g_filehdr.metadata;
  401. for (x = 0; x < n; x ++)
  402. {
  403. if (x) *metaout++=' ';
  404. const char *bigstr = (const char *)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,x,0);
  405. char *this_text;
  406. if (bigstr) this_text=_strdup((const char *)bigstr);
  407. else
  408. {
  409. int l= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETTEXTLEN,x,0);
  410. this_text=(char*)malloc(l+1);
  411. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETTEXT,x,(LPARAM)this_text);
  412. }
  413. char *p=this_text;
  414. while (p && *p != '=' && *p) *metaout++=*p++;
  415. if (p && *p)
  416. {
  417. *metaout++=*p++;
  418. int x;
  419. for (x = 1; x < 256 && strchr(p,x); x ++);
  420. if (x == 256)
  421. {
  422. char title[64] = {0};
  423. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_WRITING_STRING_TO_TAG),
  424. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  425. MB_OK|MB_ICONSTOP);
  426. x=1;
  427. }
  428. *metaout++=x;
  429. while (p && *p)
  430. {
  431. int a=*p++;
  432. if (a == x) a = '!';
  433. *metaout++=a;
  434. }
  435. *metaout++=x;
  436. }
  437. free(this_text);
  438. }
  439. g_filehdr.metadata_len= unsigned int(metaout - (char*)g_filehdr.metadata);
  440. *metaout=0;
  441. }
  442. void populateMetaData(HWND hwndDlg)
  443. {
  444. wchar_t buf[128] = {0};
  445. if (g_filehdr.metadata_len) WASABI_API_LNG->FormattedSizeString(buf,128,g_filehdr.metadata_len);
  446. else WASABI_API_LNGSTRINGW_BUF(IDS_NO_METADATA, buf, 128);
  447. SetDlgItemTextW(hwndDlg,IDC_METADATA_LEN,buf);
  448. int x;
  449. int cnt= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETCOUNT,0,0);
  450. for ( x= 0; x < cnt; x ++)
  451. {
  452. void *v=(void *)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,x,0);
  453. if (v) free(v);
  454. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_SETITEMDATA,x,0);
  455. }
  456. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_RESETCONTENT,0,0);
  457. if (g_filehdr.metadata)
  458. {
  459. char *p=(char*)g_filehdr.metadata;
  460. for (;;)
  461. {
  462. while (p && (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) p++;
  463. if (!p || !*p) break;
  464. char *this_name=p;
  465. // advance to next item
  466. while (p && *p && *p != '=') p++;
  467. char *end_name=p;
  468. if (!*p++) break;
  469. if (!*p) break;
  470. char c=*p++;
  471. char *begin_value=p;
  472. while (p && *p && *p != c) p++;
  473. char *end_value=p;
  474. if (*p) p++;
  475. char *name=(char *)malloc(end_name-this_name + 1 + end_value-begin_value + 1);
  476. char *tmp=name;
  477. memcpy(tmp,this_name,end_name-this_name); tmp+=end_name-this_name;
  478. *tmp++='=';
  479. memcpy(tmp,begin_value,end_value-begin_value); tmp+=end_value-begin_value;
  480. *tmp=0;
  481. if (strlen(name) < MAX_EDITABLE_METASTRING)
  482. {
  483. LRESULT a=SendDlgItemMessageA(hwndDlg,IDC_METADATA,LB_ADDSTRING,0,(LPARAM)name);
  484. SendDlgItemMessageA(hwndDlg,IDC_METADATA,LB_SETITEMDATA,(WPARAM)a,(LPARAM)0);
  485. free(name);
  486. }
  487. else
  488. {
  489. char buf[512] = {0};
  490. WASABI_API_LNGSTRING_BUF(IDS_LARGE_DATA,buf,512);
  491. lstrcpynA(buf+strlen(buf),name,128);
  492. strcpy(buf+strlen(buf),"...");
  493. LRESULT a=SendDlgItemMessageA(hwndDlg,IDC_METADATA,LB_ADDSTRING,0,(LPARAM)buf);
  494. SendDlgItemMessageA(hwndDlg,IDC_METADATA,LB_SETITEMDATA,(WPARAM)a,(LPARAM)name);
  495. }
  496. }
  497. }
  498. }
  499. void openNsv(HWND hwndDlg)
  500. {
  501. closeNsv(hwndDlg);
  502. g_hFile = CreateFileA(g_lastfile,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  503. SetDlgItemTextA(hwndDlg,IDC_FN,g_lastfile);
  504. if (g_hFile == INVALID_HANDLE_VALUE) return;
  505. enableControls(hwndDlg,1);
  506. CheckDlgButton(hwndDlg,IDC_FASTUPD,BST_CHECKED);
  507. // try to read existing tag.
  508. nsv_InBS bs;
  509. for (;;)
  510. {
  511. int ret=nsv_readheader(bs,&g_filehdr);
  512. if (ret <= 0 || fillBs(g_hFile,bs,ret)) break;
  513. }
  514. nsv_Unpacketer unpacket;
  515. char infobuf[256] = {0};
  516. WASABI_API_LNGSTRING_BUF(IDS_NO_VALID_NSV_BITSTREAM_FOUND,infobuf,256);
  517. for (;;)
  518. {
  519. int ret=unpacket.unpacket(bs);
  520. if (ret < 0) break;
  521. if (ret > 0 && fillBs(g_hFile,bs,ret)) break;
  522. if (!ret)
  523. {
  524. char vfmt[32] = {0};
  525. char afmt[5] = {0};
  526. int fr=(int)(unpacket.getFrameRate()*100.0);
  527. if (unpacket.getVidFmt()!=NSV_MAKETYPE('V','L','B',' ')) nsv_type_to_string(unpacket.getVidFmt(),vfmt);
  528. else strcpy(vfmt,"Dolby AAC");
  529. nsv_type_to_string(unpacket.getAudFmt(),afmt);
  530. wsprintfA(infobuf,WASABI_API_LNGSTRING(IDS_VIDEO_X_AUDIO_X),
  531. vfmt,unpacket.getWidth(),
  532. unpacket.getHeight(),
  533. fr/100,fr%100,afmt);
  534. break;
  535. }
  536. }
  537. SetDlgItemTextA(hwndDlg,IDC_BSINFO,infobuf);
  538. g_oldtag_size=g_filehdr.header_size;
  539. populateInfo(hwndDlg);
  540. populateMetaData(hwndDlg);
  541. }
  542. static int g_metaitem_edit;
  543. INT_PTR CALLBACK EditProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  544. {
  545. if (uMsg == WM_INITDIALOG)
  546. {
  547. if (g_metaitem_edit>=0)
  548. {
  549. HWND ctl=GetDlgItem(GetParent(hwndDlg),IDC_METADATA);
  550. int x= (int)SendMessage(ctl,LB_GETTEXTLEN,g_metaitem_edit,0);
  551. if (x != LB_ERR)
  552. {
  553. char *t=(char*)malloc(x+1);
  554. if (SendMessage(ctl,LB_GETTEXT,g_metaitem_edit,(LPARAM)t) != LB_ERR)
  555. {
  556. SetDlgItemTextA(hwndDlg,IDC_EDIT1,t);
  557. }
  558. free(t);
  559. }
  560. }
  561. }
  562. if (uMsg == WM_CLOSE) EndDialog(hwndDlg,0);
  563. if (uMsg == WM_COMMAND)
  564. {
  565. if (LOWORD(wParam) == IDCANCEL) EndDialog(hwndDlg,0);
  566. if (LOWORD(wParam) == IDOK)
  567. {
  568. int x= (int)SendDlgItemMessage(hwndDlg,IDC_EDIT1,WM_GETTEXTLENGTH,0,0);
  569. char *t=(char*)malloc(x+3);
  570. GetDlgItemTextA(hwndDlg,IDC_EDIT1,t,x+2);
  571. if (!strstr(t,"="))
  572. {
  573. char title[32] = {0};
  574. free(t);
  575. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_METADATA_STRING_MUST_CONTAIN_ONE_EQUAL_SIGN),
  576. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR,title,32),MB_OK|MB_ICONINFORMATION);
  577. }
  578. else
  579. {
  580. HWND ctl=GetDlgItem(GetParent(hwndDlg),IDC_METADATA);
  581. LRESULT added;
  582. if (g_metaitem_edit>=0)
  583. {
  584. SendMessage(ctl,LB_DELETESTRING,g_metaitem_edit,0);
  585. added=SendMessage(ctl,LB_INSERTSTRING,g_metaitem_edit,(LPARAM)t);
  586. }
  587. else added=SendMessage(ctl,LB_ADDSTRING,0,(LPARAM)t);
  588. SendMessage(ctl,LB_SETITEMDATA,(WPARAM)added,0);
  589. free(t);
  590. EndDialog(hwndDlg,1);
  591. }
  592. }
  593. }
  594. return 0;
  595. }
  596. int doTagWrite(HWND hwndDlg, int writeheader)
  597. {
  598. nsv_OutBS bs;
  599. if (writeheader)
  600. {
  601. g_filehdr.toc_alloc=0;
  602. nsv_writeheader(bs,&g_filehdr,IsDlgButtonChecked(hwndDlg,IDC_FASTUPD)?g_oldtag_size:0);
  603. }
  604. int hdrlen;
  605. char *hdr=(char*)bs.get(&hdrlen);
  606. if (hdr && writeheader && hdrlen == (int)g_oldtag_size) // fast update of header
  607. {
  608. DWORD dw = 0;
  609. SetFilePointer(g_hFile,0,NULL,SEEK_SET);
  610. WriteFile(g_hFile,hdr,hdrlen,&dw,NULL);
  611. }
  612. else if (writeheader || g_oldtag_size)
  613. {
  614. if (hdr && writeheader && config_padtag>0) // enlarge header by config_padtag bytes =)
  615. {
  616. bs.clear();
  617. g_filehdr.toc_alloc=0;
  618. nsv_writeheader(bs,&g_filehdr,config_padtag+g_filehdr.header_size);
  619. hdr=(char*)bs.get(&hdrlen); // update
  620. }
  621. char tmpfn[1024+8] = {0};
  622. char tmpfn2[1024+8] = {0};
  623. wsprintfA(tmpfn,"%s.new",g_lastfile);
  624. wsprintfA(tmpfn2,"%s.old",g_lastfile);
  625. HANDLE hTempFile=CreateFileA(tmpfn,GENERIC_READ|GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
  626. if (hTempFile == INVALID_HANDLE_VALUE)
  627. {
  628. char title[64] = {0};
  629. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_CANNOT_CREATE_TEMPFILE_CANNOT_UPDATE_TAG),
  630. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  631. MB_ICONSTOP|MB_OK);
  632. return 1;
  633. }
  634. SetFilePointer(g_hFile,g_oldtag_size,NULL,SEEK_SET);
  635. if (hdrlen)
  636. {
  637. DWORD dw = 0;
  638. if (!WriteFile(hTempFile,hdr,hdrlen,&dw,NULL) || (int)dw != hdrlen)
  639. {
  640. char title[64] = {0};
  641. CloseHandle(hTempFile);
  642. DeleteFileA(tmpfn);
  643. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_COPYING_SOURCE),
  644. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  645. MB_ICONSTOP|MB_OK);
  646. return 1;
  647. }
  648. }
  649. unsigned int bytes=0;
  650. for (;;)
  651. {
  652. DWORD dw = 0;
  653. char buf[8192] = {0};
  654. BOOL r1=ReadFile(g_hFile,buf,sizeof(buf),&dw,NULL);
  655. if (r1 && !dw) break;
  656. DWORD dwout = 0;
  657. if (!r1 || !WriteFile(hTempFile,buf,dw,&dwout,NULL) || dwout < dw)
  658. {
  659. char title[64] = {0};
  660. CloseHandle(hTempFile);
  661. DeleteFileA(tmpfn);
  662. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_COPYING_SOURCE),
  663. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  664. MB_ICONSTOP|MB_OK);
  665. return 1;
  666. }
  667. bytes+=dwout;
  668. wsprintfA(buf,WASABI_API_LNGSTRING(IDS_COPYING_X_BYTES),bytes);
  669. SetDlgItemTextA(hwndDlg,IDC_TAG_LEN,buf);
  670. }
  671. if (GetFileSize(g_hFile,NULL)-g_oldtag_size != GetFileSize(hTempFile,NULL)-hdrlen)
  672. {
  673. char title[64] = {0};
  674. CloseHandle(hTempFile);
  675. DeleteFileA(tmpfn);
  676. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_SIZE_MISMATCH),
  677. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  678. MB_ICONSTOP|MB_OK);
  679. return 1;
  680. }
  681. CloseHandle(g_hFile);
  682. CloseHandle(hTempFile);
  683. stopPlayback(g_lastfile);
  684. if (!MoveFileA(g_lastfile,tmpfn2))
  685. {
  686. char title[64] = {0};
  687. DeleteFileA(tmpfn);
  688. restartPlayback();
  689. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_RENAMING_SOURCE),
  690. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  691. MB_ICONSTOP|MB_OK);
  692. return 1;
  693. }
  694. if (!MoveFileA(tmpfn,g_lastfile))
  695. {
  696. char title[64] = {0};
  697. MoveFileA(tmpfn2,g_lastfile);
  698. DeleteFileA(tmpfn);
  699. restartPlayback();
  700. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_ERROR_RENAMING_NEW_FILE),
  701. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64),
  702. MB_ICONSTOP|MB_OK);
  703. return 1;
  704. }
  705. g_hFile = CreateFileA(g_lastfile,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  706. DeleteFileA(tmpfn2);
  707. restartPlayback();
  708. }
  709. return 0;
  710. }
  711. void analyzeFile(HWND hwndDlg)
  712. {
  713. unsigned int nframes=0;
  714. nsv_Unpacketer unpack;
  715. nsv_InBS bs;
  716. GrowBuf framePos;
  717. unsigned int lastPos=0;
  718. SetFilePointer(g_hFile,g_oldtag_size,NULL,SEEK_SET);
  719. for (;;)
  720. {
  721. int ret=unpack.unpacket(bs);
  722. if (ret)
  723. {
  724. if (ret<0) break;
  725. if (fillBs(g_hFile,bs,ret>0?ret:8)) unpack.setEof();
  726. }
  727. else
  728. {
  729. if (unpack.isSynchFrame())
  730. {
  731. framePos.add(&lastPos,4);
  732. framePos.add(&nframes,4);
  733. }
  734. lastPos=SetFilePointer(g_hFile,0,NULL,SEEK_CUR) - (unsigned int)(bs.avail()+7)/8 - g_oldtag_size;
  735. bs.compact();
  736. nframes++;
  737. char buf[128] = {0};
  738. wsprintfA(buf,WASABI_API_LNGSTRING(IDS_READING_X_FRAMES),nframes);
  739. SetDlgItemTextA(hwndDlg,IDC_TAG_LEN,buf);
  740. }
  741. }
  742. if (unpack.isValid() && nframes)
  743. {
  744. g_filehdr.file_lenbytes=lastPos;
  745. g_filehdr.file_lenms = (int) (nframes * 1000.0 / unpack.getFrameRate());
  746. if (IsDlgButtonChecked(hwndDlg,IDC_TOC))
  747. {
  748. BOOL t;
  749. DWORD d=GetDlgItemInt(hwndDlg,IDC_SETTOCSIZE,&t,FALSE);
  750. if (d && t)
  751. {
  752. g_filehdr.toc_size=d;
  753. g_filehdr.toc_alloc=0;
  754. free(g_filehdr.toc);
  755. unsigned int x;
  756. unsigned int *in=(unsigned int *)framePos.get();
  757. unsigned int tf=(unsigned int)framePos.getlen()/8;
  758. g_filehdr.toc=(unsigned int *)malloc(g_filehdr.toc_size * sizeof(unsigned int) * 2);
  759. g_filehdr.toc_ex=g_filehdr.toc + g_filehdr.toc_size;
  760. if (tf < g_filehdr.toc_size) // we can store all keyframes without dropping any
  761. {
  762. g_filehdr.toc_size=tf;
  763. for (x = 0; x < tf; x ++)
  764. {
  765. g_filehdr.toc[x]=in[x*2];
  766. g_filehdr.toc_ex[x]=in[x*2+1];
  767. }
  768. }
  769. else // drop keyframes to fit
  770. {
  771. double pos=0.0;
  772. double dpos = (double) tf / (double) g_filehdr.toc_size;
  773. for (x = 0; x < g_filehdr.toc_size; x ++)
  774. {
  775. unsigned int ipos=(unsigned int)pos;
  776. if (ipos >= tf)
  777. {
  778. g_filehdr.toc_size=x;
  779. break;
  780. }
  781. g_filehdr.toc[x]=in[ipos*2];
  782. g_filehdr.toc_ex[x]=in[ipos*2+1];
  783. pos+=dpos;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. else
  790. {
  791. char title[64] = {0};
  792. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_NSV_ANALYSIS_FAILED),
  793. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR_ERROR,title,64), MB_OK);
  794. }
  795. }
  796. INT_PTR CALLBACK StreamProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  797. {
  798. extern int g_streaminfobuf_used;
  799. switch (uMsg)
  800. {
  801. case WM_INITDIALOG:
  802. SetDlgItemTextA(hwndDlg,IDC_FN,g_lastfile);
  803. g_streaminfobuf_used=1;
  804. SetTimer(hwndDlg,1,1000,NULL);
  805. SendMessage(hwndDlg,WM_TIMER,1,0);
  806. return TRUE;
  807. case WM_CLOSE:
  808. g_streaminfobuf_used=0;
  809. KillTimer(hwndDlg,1);
  810. EndDialog(hwndDlg,1);
  811. return 0;
  812. case WM_TIMER:
  813. if (wParam == 1)
  814. {
  815. extern char lastfn[];
  816. extern char g_streaminfobuf[];
  817. extern CRITICAL_SECTION g_decoder_cs;
  818. if (!lstrcmpiA(g_lastfile,lastfn) && g_streaminfobuf[0])
  819. {
  820. int start = -1, end = 0;
  821. EnterCriticalSection(&g_decoder_cs);
  822. SendDlgItemMessage(hwndDlg, IDC_INFO, EM_GETSEL, (WPARAM)&start, (LPARAM)&end);
  823. SetDlgItemTextA(hwndDlg,IDC_INFO,g_streaminfobuf);
  824. SendDlgItemMessage(hwndDlg, IDC_INFO, EM_SETSEL, start, end);
  825. LeaveCriticalSection(&g_decoder_cs);
  826. EnableWindow(GetDlgItem(hwndDlg,IDC_INFO),1);
  827. EnableWindow(GetDlgItem(hwndDlg,IDC_INFOBORDER),1);
  828. }
  829. else
  830. {
  831. SetDlgItemTextA(hwndDlg,IDC_INFO,"");
  832. EnableWindow(GetDlgItem(hwndDlg,IDC_INFO),0);
  833. EnableWindow(GetDlgItem(hwndDlg,IDC_INFOBORDER),0);
  834. }
  835. }
  836. break;
  837. case WM_COMMAND:
  838. switch (LOWORD(wParam))
  839. {
  840. case IDOK:
  841. case IDCANCEL:
  842. g_streaminfobuf_used=0;
  843. KillTimer(hwndDlg,1);
  844. EndDialog(hwndDlg,1);
  845. return 0;
  846. }
  847. return 0;
  848. }
  849. return 0;
  850. }
  851. INT_PTR CALLBACK MainProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  852. {
  853. switch (uMsg)
  854. {
  855. case WM_INITDIALOG:
  856. openNsv(hwndDlg);
  857. return TRUE;
  858. case WM_COMMAND:
  859. switch (LOWORD(wParam))
  860. {
  861. case IDCANCEL:
  862. closeNsv(hwndDlg);
  863. EndDialog(hwndDlg,1);
  864. return 0;
  865. case IDOK:
  866. case IDC_REMTAG:
  867. if (!doTagWrite(hwndDlg,LOWORD(wParam) == IDOK))
  868. {
  869. closeNsv(hwndDlg);
  870. lastextfn[0]=0;
  871. EndDialog(hwndDlg,0);
  872. }
  873. else lastextfn[0]=0;
  874. return 0;
  875. case IDC_ANALYZE:
  876. analyzeFile(hwndDlg);
  877. populateInfo(hwndDlg);
  878. makeNewHeaderInfo(hwndDlg);
  879. return 0;
  880. case IDC_ADD:
  881. g_metaitem_edit=-1;
  882. if (WASABI_API_DIALOGBOXW(IDD_DIALOG2,hwndDlg,EditProc))
  883. {
  884. updateMetaData(hwndDlg);
  885. populateMetaData(hwndDlg);
  886. makeNewHeaderInfo(hwndDlg);
  887. }
  888. return 0;
  889. case IDC_METADATA:
  890. if (HIWORD(wParam) != LBN_DBLCLK) return 0;
  891. case IDC_EDIT:
  892. {
  893. DWORD res=(DWORD)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETCURSEL,0,0);
  894. if (res != LB_ERR)
  895. {
  896. int ptr= (int)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,res,0);
  897. if (ptr)
  898. {
  899. char title[32] = {0};
  900. MessageBoxA(hwndDlg,WASABI_API_LNGSTRING(IDS_METADATA_ITEM_CONTAINS_LARGE_AMOUNT_DATA),
  901. WASABI_API_LNGSTRING_BUF(IDS_NSV_TAG_EDITOR,title,32), MB_OK);
  902. }
  903. else
  904. {
  905. g_metaitem_edit=res;
  906. if (WASABI_API_DIALOGBOXW(IDD_DIALOG2,hwndDlg,EditProc))
  907. {
  908. updateMetaData(hwndDlg);
  909. populateMetaData(hwndDlg);
  910. makeNewHeaderInfo(hwndDlg);
  911. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_SETCURSEL,(WPARAM)res,0);
  912. }
  913. }
  914. }
  915. }
  916. return 0;
  917. case IDC_REM:
  918. {
  919. DWORD res=(DWORD)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETCURSEL,0,0);
  920. if (res != LB_ERR)
  921. {
  922. void *ptr=(void *)SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_GETITEMDATA,res,0);
  923. if (ptr) free(ptr);
  924. SendDlgItemMessage(hwndDlg,IDC_METADATA,LB_DELETESTRING,res,0);
  925. updateMetaData(hwndDlg);
  926. populateMetaData(hwndDlg);
  927. makeNewHeaderInfo(hwndDlg);
  928. }
  929. }
  930. return 0;
  931. case IDC_TOC:
  932. if (HIWORD(wParam) == BN_CLICKED)
  933. {
  934. int ch=!!IsDlgButtonChecked(hwndDlg,IDC_TOC);
  935. if (ch)
  936. {
  937. if (g_toc_save)
  938. {
  939. g_filehdr.toc=g_toc_save;
  940. g_filehdr.toc_ex=g_toc_save_ex;
  941. g_filehdr.toc_size=g_toc_savesize;
  942. g_toc_save=0;
  943. g_toc_save_ex=0;
  944. g_toc_savesize=0;
  945. makeNewHeaderInfo(hwndDlg);
  946. }
  947. }
  948. else
  949. {
  950. if (!g_toc_save)
  951. {
  952. g_toc_save=g_filehdr.toc;
  953. g_toc_save_ex=g_filehdr.toc_ex;
  954. g_toc_savesize=g_filehdr.toc_size;
  955. g_filehdr.toc=0;
  956. g_filehdr.toc_size=0;
  957. g_filehdr.toc_ex=0;
  958. makeNewHeaderInfo(hwndDlg);
  959. }
  960. }
  961. }
  962. return 0;
  963. }
  964. return 0;
  965. case WM_CLOSE:
  966. closeNsv(hwndDlg);
  967. EndDialog(hwndDlg,1);
  968. return 0;
  969. }
  970. return 0;
  971. }
  972. int infoDlg(const char *fn, HWND hwnd)
  973. {
  974. g_lastfile=fn;
  975. if (strstr(fn,"://")) return (int)WASABI_API_DIALOGBOXW(IDD_DIALOG4,hwnd,StreamProc);
  976. else return (int)WASABI_API_DIALOGBOXW(IDD_DIALOG3,hwnd,MainProc);
  977. }