Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1273 lines
26 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. database.c
  5. Abstract:
  6. This module implements the database routines for the CD Audio app.
  7. The information is stored in the ini file "cdaudio.ini" which should
  8. be located in the nt\windows directory.
  9. Author:
  10. Rick Turner (ricktu) 31-Jan-1992
  11. Revision History:
  12. 04-Aug-1992 (ricktu) Incorperated routines from old cdaudio.c,
  13. and made work w/new child window framework.
  14. --*/
  15. #include <windows.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "cdplayer.h"
  20. #include "cdwindef.h"
  21. #include "toolbar.h"
  22. #include "control.h"
  23. #include "trkinfo.h"
  24. #include "status.h"
  25. //#include "ruler.h"
  26. #include "discinfo.h"
  27. #define INI_FILE_NAME "cdplayer.ini"
  28. //
  29. // Private entrypoints
  30. //
  31. BOOL
  32. AddThisEntry(
  33. IN INT cdrom
  34. );
  35. BOOL
  36. AddThisDisc(
  37. IN INT cdrom
  38. );
  39. DWORD
  40. ComputeOldDiscId(
  41. IN INT cdrom
  42. )
  43. /*++
  44. Routine Description:
  45. This routine computes a unique ID based on the information
  46. in the table of contexts a given disc.
  47. Arguments:
  48. cdrom - supplies an index into the gDevices structure, used to
  49. specify which disc to compute an ID for.
  50. Return Value:
  51. A DWORD unique ID.
  52. --*/
  53. {
  54. INT NumTracks,i;
  55. DWORD DiscId = 0;
  56. NumTracks = gDevices[ cdrom ]->toc.LastTrack -
  57. gDevices[ cdrom ]->toc.FirstTrack;
  58. for (i=0; i<NumTracks; i++)
  59. DiscId += ( (TRACK_M(cdrom,i) << 16) +
  60. (TRACK_S(cdrom,i) << 8) +
  61. TRACK_F(cdrom,i) );
  62. return( DiscId );
  63. }
  64. DWORD
  65. ComputeNewDiscId(
  66. IN INT cdrom
  67. )
  68. /*++
  69. Routine Description:
  70. This routine computes a unique ID based on the information
  71. in the table of contexts a given disc. This is done by taking
  72. the TMSF value for each track and XOR'ing it with the previous
  73. quantity shifted left one bit.
  74. Arguments:
  75. cdrom - supplies an index into the gDevices structure, used to
  76. specify which disc to compute an ID for.
  77. Return Value:
  78. A DWORD unique ID.
  79. --*/
  80. {
  81. INT NumTracks,i;
  82. DWORD DiscId = 0;
  83. NumTracks = gDevices[ cdrom ]->toc.LastTrack -
  84. gDevices[ cdrom ]->toc.FirstTrack + 1;
  85. for (i=0; i<NumTracks; i++)
  86. DiscId = (DiscId << 1) ^
  87. ((i<<24) +
  88. (TRACK_M(cdrom,i) << 16) +
  89. (TRACK_S(cdrom,i) << 8) +
  90. TRACK_F(cdrom,i) );
  91. return( DiscId );
  92. }
  93. VOID
  94. ErasePlayList(
  95. IN INT cdrom
  96. )
  97. /*++
  98. Routine Description:
  99. Erases the current play list. This includes freeing the memory
  100. for the nodes in the play list, and resetting the current track
  101. pointer to NULL.
  102. Arguments:
  103. cdrom - supplies an index into the global structure gDevices
  104. Return Value:
  105. none
  106. --*/
  107. {
  108. PTRACK_PLAY temp, temp1;
  109. //
  110. // Free memory for each track in play list
  111. //
  112. DBGPRINT(( 1, "ErasePlayList: PLAYLIST( cdrom ) is 0x%lx\n", PLAYLIST( cdrom ) ));
  113. temp = PLAYLIST( cdrom );
  114. while (temp!=NULL) {
  115. DBGPRINT(( 1, " erasing: (0x%08lx) TocIndex = %d, PP(0x%08lx) NP(0x%08lx)\n",
  116. temp, temp->TocIndex, temp->prevplay, temp->nextplay ));
  117. temp1 = temp->nextplay;
  118. LocalFree( (HLOCAL)temp );
  119. temp = temp1;
  120. }
  121. //
  122. // Reset pointers
  123. //
  124. PLAYLIST( cdrom ) = NULL;
  125. CURRTRACK( cdrom ) = NULL;
  126. }
  127. VOID
  128. EraseSaveList(
  129. IN INT cdrom
  130. )
  131. /*++
  132. Routine Description:
  133. Erases the current save list. This includes freeing the memory
  134. for the nodes in the save list.
  135. Arguments:
  136. cdrom - supplies an index into the global structure gDevices
  137. Return Value:
  138. none
  139. --*/
  140. {
  141. PTRACK_PLAY temp, temp1;
  142. //
  143. // Free memory for each track in play list
  144. //
  145. DBGPRINT(( 1, "EraseSaveList: PLAYLIST( cdrom ) is 0x%lx\n", SAVELIST( cdrom ) ));
  146. temp = SAVELIST( cdrom );
  147. while (temp!=NULL) {
  148. DBGPRINT(( 1, " erasing: (0x%08lx) TocIndex = %d, PP(0x%08lx) NP(0x%08lx)\n",
  149. temp, temp->TocIndex, temp->prevplay, temp->nextplay ));
  150. temp1 = temp->nextplay;
  151. LocalFree( (HLOCAL)temp );
  152. temp = temp1;
  153. }
  154. //
  155. // Reset pointers
  156. //
  157. SAVELIST( cdrom ) = NULL;
  158. }
  159. VOID
  160. EraseTrackList(
  161. IN INT cdrom
  162. )
  163. /*++
  164. Routine Description:
  165. Erases the current track list. This includes freeing the memory
  166. for the nodes in the track list, and resetting the track list
  167. pointer to NULL.
  168. Arguments:
  169. cdrom - supplies an index into the global structure gDevices
  170. Return Value:
  171. none
  172. --*/
  173. {
  174. PTRACK_INF temp, temp1;
  175. //
  176. // Free memory for each track in track list
  177. //
  178. DBGPRINT(( 1, "EraseTrackList: ALLTRACKS( cdrom ) is 0x%lx\n", ALLTRACKS( cdrom ) ));
  179. temp = ALLTRACKS( cdrom );
  180. while (temp!=NULL) {
  181. DBGPRINT(( 1, " erasing: (0x%08lx) TocIndex = %d, next(0x%08lx)\n",
  182. temp, temp->TocIndex, temp->next ));
  183. temp1 = temp->next;
  184. LocalFree( (HLOCAL)temp );
  185. temp = temp1;
  186. }
  187. //
  188. // Reset pointers
  189. //
  190. ALLTRACKS( cdrom ) = NULL;
  191. }
  192. VOID
  193. ResetPlayList(
  194. IN INT cdrom
  195. )
  196. /*++
  197. Routine Description:
  198. Resets play order for the disc. Used to initialize/reset
  199. the play list. This is done by reseting the doubly-linked list
  200. of tracks in the gDevices[...]->CdInfo.PlayList.[prevplay,nextplay]
  201. pointers. All the tracks on the CD are stored in a singly linked list
  202. pointed to by gDevices[...]->CdInfo.AllTracks pointer.
  203. Arguments:
  204. cdrom - supplies an index into the global structure gDevices
  205. Return Value:
  206. none
  207. --*/
  208. {
  209. PTRACK_INF t;
  210. PTRACK_PLAY temp, prev;
  211. DBGPRINT(( 1, "ResetPlayList: Killing old play list...\n" ));
  212. //
  213. // Kill old play list
  214. //
  215. ErasePlayList( cdrom );
  216. EraseSaveList( cdrom );
  217. //
  218. // Duplicate each node in AllTracks and insert in-oder
  219. // in SaveList list. The SaveList is the master which is
  220. // used for the playlist.
  221. //
  222. DBGPRINT(( 1, "ResetPlayList: Create default play list...\n" ));
  223. t = ALLTRACKS( cdrom );
  224. prev = NULL;
  225. while (t!=NULL) {
  226. temp = (PTRACK_PLAY) LocalAlloc( LPTR, sizeof( TRACK_PLAY ) );
  227. //
  228. // BUGBUG -- need to check for NULL return
  229. //
  230. temp->TocIndex = t->TocIndex;
  231. temp->min = 0;
  232. temp->sec = 0;
  233. temp->prevplay = prev;
  234. temp->nextplay = NULL;
  235. if (prev!=NULL) {
  236. prev->nextplay = temp;
  237. } else {
  238. SAVELIST( cdrom ) = temp;
  239. }
  240. prev = temp;
  241. t=t->next;
  242. }
  243. PLAYLIST( cdrom ) = CopyPlayList( SAVELIST( cdrom) );
  244. DUMPPLAYLIST(( PLAYLIST(cdrom) ));
  245. }
  246. BOOL
  247. DeleteEntry(
  248. IN DWORD Id
  249. )
  250. /*++
  251. Routine Description:
  252. The ID format has changed to make the id's for the different CD's
  253. more unique. This routine will completely delete the old key value
  254. from the ini file. We remove it by writing a NULL entry.
  255. Arguments:
  256. Id - Id of the key to delete from the INI file
  257. Return Value:
  258. TRUE if successful, FALSE if not
  259. --*/
  260. {
  261. TCHAR Section[80], Buffer[2]="";
  262. sprintf( Section, "%lX", Id );
  263. return( WritePrivateProfileSection( Section, Buffer, INI_FILE_NAME ) );
  264. }
  265. BOOL
  266. WriteEntry(
  267. IN INT cdrom
  268. )
  269. /*++
  270. Routine Description:
  271. Write current disc information into database ini file.
  272. The section for the current disc (section name is a hex
  273. value of the disc id) is completely rewritten.
  274. Arguments:
  275. cdrom - supplies an index into the global array gDevices
  276. Return Value:
  277. TRUE if successful, FALSE if not
  278. --*/
  279. {
  280. TCHAR Buffer[ 64000 ];
  281. LPTSTR s;
  282. INT i;
  283. TCHAR Section[ 10 ];
  284. PTRACK_INF temp;
  285. PTRACK_PLAY temp1;
  286. //
  287. // Construct ini file buffer, form of:
  288. //
  289. // artist = artist name
  290. // title = Title of disc
  291. // numtracks = n
  292. // 0 = Title of track 1
  293. // 1 = Title of track 2
  294. // n-1 = Title of track n
  295. // order = 0 4 3 2 6 7 8 ... (n-1)
  296. // numplay = # of entries in order list
  297. //
  298. //
  299. // Is it legal to save this information?
  300. //
  301. if (!gDevices[ cdrom ]->CdInfo.save)
  302. return( TRUE );
  303. gDevices[ cdrom ]->CdInfo.IsVirginCd = FALSE;
  304. sprintf( Section, "%lX", gDevices[ cdrom ]->CdInfo.Id );
  305. s = Buffer;
  306. sprintf( s, "EntryType=%d", 1 );
  307. s += (strlen(s) + sizeof(TCHAR));
  308. sprintf( s, "artist=%s", gDevices[ cdrom ]->CdInfo.Artist );
  309. s += (strlen(s) + sizeof(TCHAR));
  310. sprintf( s, "title=%s", gDevices[ cdrom ]->CdInfo.Title );
  311. s += (strlen(s) + sizeof(TCHAR));
  312. sprintf( s, "numtracks=%d", gDevices[ cdrom ]->CdInfo.NumTracks );
  313. s += (strlen(s) + sizeof(TCHAR));
  314. for ( temp = gDevices[ cdrom ]->CdInfo.AllTracks;
  315. temp!=NULL;
  316. temp = temp->next
  317. ) {
  318. sprintf( s, "%d=%s", temp->TocIndex, temp->name );
  319. s += (strlen(s) + sizeof(TCHAR));
  320. }
  321. sprintf( s, "order=" );
  322. s += strlen(s);
  323. i = 0;
  324. for ( temp1 = gDevices[ cdrom ]->CdInfo.SaveList;
  325. temp1!=NULL;
  326. temp1 = temp1->nextplay
  327. ) {
  328. sprintf( s, "%d ", temp1->TocIndex );
  329. s += strlen(s);
  330. i++;
  331. }
  332. s+=sizeof(TCHAR);
  333. sprintf( s, "numplay=%d", i );
  334. s += strlen(s);
  335. //
  336. // Just make sure there are NULLs at end of buffer
  337. //
  338. sprintf( s, "\0\0\0" );
  339. sprintf( Section, "%lX", gDevices[ cdrom ]->CdInfo.Id );
  340. //
  341. // Try writing buffer into ini file
  342. //
  343. return( WritePrivateProfileSection( Section, Buffer, INI_FILE_NAME ) );
  344. }
  345. BOOL
  346. ReadEntry(
  347. IN INT cdrom,
  348. IN DWORD dwId
  349. )
  350. /*++
  351. Routine Description:
  352. Try to read entry for new disc from database ini file.
  353. The section name we are trying to read is a hex
  354. value of the disc id. If the sections is found,
  355. fill in the data for the disc in the cdrom drive.
  356. Arguments:
  357. cdrom - supplies an index into the global array gDevices
  358. dwId - supplies id of disc in cdrom drive
  359. Return Value:
  360. TRUE if successful, FALSE if not
  361. --*/
  362. {
  363. DWORD rc;
  364. TCHAR Section[10];
  365. TCHAR s[100],s1[100];
  366. TCHAR order[ 8192 ];
  367. TCHAR torder[ 8192 ];
  368. INT i;
  369. LPSTR porder;
  370. DWORD numtracks, numplay;
  371. PTRACK_INF temp, curr;
  372. PTRACK_PLAY temp1, prev;
  373. BOOL OldEntry;
  374. gDevices[ cdrom ]->CdInfo.iFrameOffset = NEW_FRAMEOFFSET;
  375. //
  376. // Try to read in section from ini file
  377. //
  378. sprintf( Section, "%lX", dwId );
  379. rc = GetPrivateProfileString( Section,
  380. "title",
  381. "~~^^",
  382. (LPSTR)gDevices[ cdrom ]->CdInfo.Title,
  383. TITLE_LENGTH,
  384. INI_FILE_NAME
  385. );
  386. //
  387. // Was the section found?
  388. //
  389. if ((gDevices[ cdrom ]->CdInfo.Title[0]=='~') &&
  390. (gDevices[ cdrom ]->CdInfo.Title[1]=='~') &&
  391. (gDevices[ cdrom ]->CdInfo.Title[2]=='^') &&
  392. (gDevices[ cdrom ]->CdInfo.Title[3]=='^') &&
  393. (gDevices[ cdrom ]->CdInfo.Title[4]=='\0')
  394. )
  395. //
  396. // Nope, notify caller
  397. //
  398. return( FALSE );
  399. //
  400. // We found an entry for this disc, so copy all the information
  401. // from the ini file entry
  402. //
  403. gDevices[ cdrom ]->CdInfo.Id = dwId;
  404. gDevices[ cdrom ]->CdInfo.save = TRUE;
  405. //
  406. // Is this an old entry?
  407. //
  408. i = GetPrivateProfileInt( Section,
  409. "EntryType",
  410. 0,
  411. INI_FILE_NAME
  412. );
  413. OldEntry = (i==0);
  414. numtracks = GetPrivateProfileInt( Section,
  415. "numtracks",
  416. 0,
  417. INI_FILE_NAME
  418. );
  419. gDevices[ cdrom ]->CdInfo.NumTracks = numtracks;
  420. rc = GetPrivateProfileString( Section,
  421. "artist",
  422. gszUnknownTxt,
  423. (LPSTR)ARTIST(cdrom),
  424. ARTIST_LENGTH,
  425. INI_FILE_NAME
  426. );
  427. //
  428. // Read the track list information
  429. //
  430. DBGPRINT(( 1, "ReadEntry: creating track list from entry...\n" ));
  431. for (i=0, curr = NULL; i<(INT)numtracks; i++) {
  432. temp = (PTRACK_INF) LocalAlloc( LPTR, sizeof( TRACK_INF ) );
  433. temp->TocIndex = i;
  434. temp->next = NULL;
  435. sprintf( s1, IdStr(STR_INIT_TRACK), i+1 );
  436. sprintf( s, "%d", i );
  437. rc = GetPrivateProfileString( Section,
  438. s,
  439. s1,
  440. (LPSTR)temp->name,
  441. TRACK_TITLE_LENGTH,
  442. INI_FILE_NAME
  443. );
  444. if (curr==NULL) {
  445. ALLTRACKS( cdrom ) = curr = temp;
  446. } else {
  447. curr->next = temp;
  448. curr = temp;
  449. }
  450. }
  451. DUMPTRACKLIST(( ALLTRACKS(cdrom) ));
  452. if (OldEntry) {
  453. //
  454. // Generate generic play list (all tracks in order)
  455. //
  456. DBGPRINT(( 1, "ReadEntry: Generating default play list (old entry)\n" ));
  457. ResetPlayList( cdrom );
  458. //
  459. // Need to rewrite this entry in new format
  460. //
  461. WriteEntry( cdrom );
  462. } else {
  463. //
  464. // Read play list (order) information and construct play list doubly
  465. // linked list
  466. //
  467. DBGPRINT(( 1, "ReadEntry: Generating PlayList based on entry.\n" ));
  468. numplay = GetPrivateProfileInt( Section,
  469. "numplay",
  470. 0,
  471. INI_FILE_NAME
  472. );
  473. porder = torder;
  474. memset( porder, '\0', 8192 );
  475. for (i=0; i<(INT)numtracks; i++) {
  476. sprintf( porder, "%d ", i );
  477. porder += (strlen( porder ) * sizeof( TCHAR ));
  478. }
  479. rc = GetPrivateProfileString( Section,
  480. "order",
  481. torder,
  482. (LPTSTR)order,
  483. 8192,
  484. INI_FILE_NAME
  485. );
  486. //
  487. // Ensure a trailing space
  488. //
  489. strcat( order, " " );
  490. porder = order;
  491. prev = NULL;
  492. while ( sscanf( porder, "%d", &i )!=EOF ) {
  493. temp1 = (PTRACK_PLAY) LocalAlloc( LPTR, sizeof( TRACK_PLAY ) );
  494. temp1->TocIndex = i;
  495. temp1->min = 0;
  496. temp1->sec = 0;
  497. temp1->prevplay = prev;
  498. temp1->nextplay = NULL;
  499. if (prev==NULL) {
  500. SAVELIST( cdrom ) = temp1;
  501. } else {
  502. prev->nextplay = temp1;
  503. }
  504. prev = temp1;
  505. porder = (LPSTR)(((DWORD)strchr( porder, ' ' )) + sizeof(TCHAR));
  506. }
  507. PLAYLIST( cdrom ) = CopyPlayList( SAVELIST( cdrom ) );
  508. DUMPPLAYLIST(( PLAYLIST(cdrom) ));
  509. }
  510. return( TRUE );
  511. }
  512. BOOL
  513. WriteSettings(
  514. VOID
  515. )
  516. /*++
  517. Routine Description:
  518. Read app settings from ini file.
  519. Arguments:
  520. none.
  521. Return Value:
  522. TRUE if successful, FALSE if not
  523. --*/
  524. {
  525. TCHAR Buffer[ 1024 ];
  526. LPTSTR s;
  527. WINDOWPLACEMENT wndpl;
  528. s = Buffer;
  529. if (!gSaveSettings) {
  530. WritePrivateProfileString("Settings","SaveSettingsOnExit","0",INI_FILE_NAME);
  531. return(TRUE);
  532. }
  533. sprintf( s, "SaveSettingsOnExit=%lu", (DWORD)gSaveSettings );
  534. s += (strlen(s) + sizeof(TCHAR));
  535. //
  536. // Save disc play settings
  537. //
  538. sprintf( s, "DisplayT=%lu",(DWORD)gDisplayT );
  539. s += (strlen(s) + sizeof(TCHAR));
  540. sprintf( s, "DisplayTr=%lu",(DWORD)gDisplayTr );
  541. s += (strlen(s) + sizeof(TCHAR));
  542. sprintf( s, "DisplayDr=%lu",(DWORD)gDisplayDr );
  543. s += (strlen(s) + sizeof(TCHAR));
  544. sprintf( s, "InOrderPlay=%lu",(DWORD)gOrder );
  545. s += (strlen(s) + sizeof(TCHAR));
  546. sprintf( s, "RandomPlay=%lu", (DWORD)gRandom );
  547. s += (strlen(s) + sizeof(TCHAR));
  548. sprintf( s, "MultiDiscPlay=%lu", (DWORD)gMulti );
  549. s += (strlen(s) + sizeof(TCHAR));
  550. sprintf( s, "IntroPlay=%lu", (DWORD)gIntro );
  551. s += (strlen(s) + sizeof(TCHAR));
  552. sprintf( s, "ContinuousPlay=%lu", (DWORD)gContinuous );
  553. s += (strlen(s) + sizeof(TCHAR));
  554. sprintf( s, "ToolBar=%lu", (DWORD)(gToolBarWnd!=NULL) );
  555. s += (strlen(s) + sizeof(TCHAR));
  556. sprintf( s, "DiscAndTrackDisplay=%lu", (DWORD)(gTrackInfoWnd!=NULL) );
  557. s += (strlen(s) + sizeof(TCHAR));
  558. // sprintf( s, "Ruler=%lu", (DWORD)(gRulerWnd!=NULL) );
  559. // s += (strlen(s) + sizeof(TCHAR));
  560. sprintf( s, "StatusBar=%lu", (DWORD)(gStatusWnd!=NULL) );
  561. s += (strlen(s) + sizeof(TCHAR));
  562. GetWindowPlacement(gMainWnd,&wndpl);
  563. sprintf( s, "WindowOrigin=%d %d",wndpl.rcNormalPosition.left,
  564. wndpl.rcNormalPosition.top);
  565. s += (strlen(s) + sizeof(TCHAR));
  566. sprintf( s, "\0\0\0" );
  567. return( WritePrivateProfileSection( "Settings",
  568. Buffer,
  569. INI_FILE_NAME
  570. )
  571. );
  572. }
  573. BOOL
  574. ReadSettings(
  575. VOID
  576. )
  577. /*++
  578. Routine Description:
  579. Read app settings from ini file.
  580. Arguments:
  581. none.
  582. Return Value:
  583. TRUE if successful, FALSE if not
  584. --*/
  585. {
  586. INT y;
  587. RECT r;
  588. CHAR s[80],t[80];
  589. //
  590. // Get disc play settings
  591. //
  592. gOrder = (BOOL)GetPrivateProfileInt( "Settings",
  593. "InOrderPlay",
  594. (DWORD)FALSE,
  595. INI_FILE_NAME
  596. );
  597. gRandom = (BOOL)GetPrivateProfileInt( "Settings",
  598. "RandomPlay",
  599. (DWORD)FALSE,
  600. INI_FILE_NAME
  601. );
  602. gMulti = (BOOL)GetPrivateProfileInt( "Settings",
  603. "MultiDiscPlay",
  604. (DWORD)FALSE,
  605. INI_FILE_NAME
  606. );
  607. if (gNumCdDevices<=1) {
  608. gMulti = FALSE;
  609. }
  610. if (gOrder && gRandom) {
  611. gRandom = FALSE;
  612. }
  613. gIntro = (BOOL)GetPrivateProfileInt( "Settings",
  614. "IntroPlay",
  615. (DWORD)FALSE,
  616. INI_FILE_NAME
  617. );
  618. gContinuous = (BOOL)GetPrivateProfileInt( "Settings",
  619. "ContinuousPlay",
  620. (DWORD)TRUE,
  621. INI_FILE_NAME
  622. );
  623. gSaveSettings = (BOOL)GetPrivateProfileInt( "Settings",
  624. "SaveSettingsOnExit",
  625. (DWORD)TRUE,
  626. INI_FILE_NAME
  627. );
  628. gDisplayT = (BOOL)GetPrivateProfileInt( "Settings",
  629. "DisplayT",
  630. (DWORD)TRUE,
  631. INI_FILE_NAME
  632. );
  633. gDisplayTr = (BOOL)GetPrivateProfileInt( "Settings",
  634. "DisplayTr",
  635. (DWORD)FALSE,
  636. INI_FILE_NAME
  637. );
  638. gDisplayDr = (BOOL)GetPrivateProfileInt( "Settings",
  639. "DisplayDr",
  640. (DWORD)FALSE,
  641. INI_FILE_NAME
  642. );
  643. if ((BOOL)GetPrivateProfileInt( "Settings",
  644. "ToolBar",
  645. (DWORD)FALSE,
  646. INI_FILE_NAME )) {
  647. ToolBarCreate( 0, 0, TOOLBAR_WIN_W, TOOLBAR_WIN_H );
  648. }
  649. if (gToolBarWnd)
  650. y = TOOLBAR_WIN_H;
  651. else
  652. y = 0;
  653. ControlCreate( 0, y, CONTROL_WIN_W, CONTROL_WIN_H );
  654. if ((BOOL)GetPrivateProfileInt( "Settings",
  655. "DiscAndTrackDisplay",
  656. (DWORD)TRUE,
  657. INI_FILE_NAME )) {
  658. y = CONTROL_WIN_H;
  659. if (gToolBarWnd)
  660. y += TOOLBAR_WIN_H;
  661. TrackInfoCreate( 0, y, TRACKINFO_WIN_W, TRACKINFO_WIN_H );
  662. }
  663. if ((BOOL)GetPrivateProfileInt( "Settings",
  664. "Ruler",
  665. (DWORD)FALSE,
  666. INI_FILE_NAME )) {
  667. y = CONTROL_WIN_H;
  668. if (gToolBarWnd) y+=TOOLBAR_WIN_H;
  669. if (gTrackInfoWnd) y+=TRACKINFO_WIN_H;
  670. //RulerCreate( 0, y, RULER_WIN_W, RULER_WIN_H );
  671. }
  672. if ((BOOL)GetPrivateProfileInt( "Settings",
  673. "StatusBar",
  674. (DWORD)TRUE,
  675. INI_FILE_NAME )) {
  676. y = CONTROL_WIN_H;
  677. if (gToolBarWnd) y+=TOOLBAR_WIN_H;
  678. if (gTrackInfoWnd) y+=TRACKINFO_WIN_H;
  679. // if (gRulerWnd) y+=RULER_WIN_H;
  680. StatusCreate( 0, y, STATUS_WIN_W, STATUS_WIN_H );
  681. }
  682. GetWindowRect( gMainWnd, &r );
  683. sprintf(t,"%d %d",r.left, r.top);
  684. GetPrivateProfileString( "Settings",
  685. "WindowOrigin",
  686. (LPSTR) t,
  687. (LPSTR) s,
  688. 80,
  689. INI_FILE_NAME
  690. );
  691. sscanf(s,"%d %d", &r.left, &r.top);
  692. y = CONTROL_WIN_H;
  693. if (gToolBarWnd) y+=TOOLBAR_WIN_H;
  694. if (gTrackInfoWnd) y+=TRACKINFO_WIN_H;
  695. // if (gRulerWnd) y+=RULER_WIN_H;
  696. if (gStatusWnd) y+=STATUS_WIN_H;
  697. MoveWindow( gMainWnd,
  698. r.left,
  699. r.top,
  700. MAIN_WIN_W,
  701. y+
  702. GetSystemMetrics( SM_CYCAPTION ) +
  703. GetSystemMetrics( SM_CYMENU ) + 2,
  704. FALSE
  705. );
  706. return( TRUE );
  707. }
  708. VOID
  709. AddFindEntry(
  710. IN INT cdrom,
  711. IN DWORD key,
  712. IN PCDROM_TOC lpTOC
  713. )
  714. /*++
  715. Routine Description:
  716. Search the database file for the current disc,
  717. if found, read the information, otherwise, ask
  718. user if they want to add this disc to the database.
  719. Arguments:
  720. cdrom - supplies an index into the global array gDevices
  721. key - disc id of current disc
  722. lpTOC - supplies pointer to table of contents read from
  723. this disc
  724. Return Value:
  725. none
  726. --*/
  727. {
  728. INT i,num;
  729. PTRACK_INF temp, temp1;
  730. //
  731. // Kill off old PlayList, Save lists if they exists.
  732. //
  733. ErasePlayList( cdrom );
  734. EraseSaveList( cdrom );
  735. EraseTrackList( cdrom );
  736. //
  737. // Check ini file for an existing entry
  738. //
  739. //
  740. // Note that we've been passed the new ID, and some old ones
  741. // may be out there. Use short circuit to determine whether
  742. // it's possibly the old ID as well.
  743. //
  744. if (ReadEntry( cdrom, key )) {
  745. gDevices[ cdrom ]->CdInfo.IsVirginCd = FALSE;
  746. } else {
  747. if (ReadEntry(cdrom,ComputeOldDiscId(cdrom))) {
  748. //
  749. // If the disc was under an OLD id, we need to delete the
  750. // old one, convert it to the new format, and save it under
  751. // its new key.
  752. //
  753. DeleteEntry( ComputeOldDiscId(cdrom) );
  754. gDevices[ cdrom ]->CdInfo.IsVirginCd = FALSE;
  755. gDevices[ cdrom ]->CdInfo.Id = key;
  756. gDevices[ cdrom ]->CdInfo.save = TRUE;
  757. WriteEntry( cdrom );
  758. } else {
  759. //
  760. // This is a new entry, fill it in and store it in the database.
  761. //
  762. gDevices[ cdrom ]->CdInfo.IsVirginCd = TRUE;
  763. gDevices[ cdrom ]->CdInfo.Id = key;
  764. sprintf( (LPSTR)ARTIST( cdrom ), IdStr( STR_NEW_ARTIST ) );
  765. sprintf( (LPSTR)TITLE( cdrom ), IdStr( STR_NEW_TITLE ) );
  766. num = lpTOC->LastTrack - lpTOC->FirstTrack + 1;
  767. NUMTRACKS( cdrom ) = num;
  768. //
  769. // Create generic playlist, which is all audio tracks
  770. // played in the order they are on the CD. First, create
  771. // a singly linked list that contains all the tracks.
  772. // Then, create a double linked list, using the nodes of
  773. // from the single linked list for the play list.
  774. //
  775. DBGPRINT(( 1, "AddFindEntry: Creating default track list...\n" ));
  776. for( i=0; i<num; i++ ) {
  777. //
  778. // Create storage for track
  779. //
  780. temp = (PTRACK_INF)LocalAlloc( LPTR, sizeof( TRACK_INF ) );
  781. //
  782. // Initialize information (storage already ZERO initialized)
  783. //
  784. sprintf( (LPSTR)temp->name, IdStr( STR_INIT_TRACK ), i+1 );
  785. temp->TocIndex = i;
  786. temp->next = NULL;
  787. //
  788. // Add node to singly linked list of all tracks
  789. //
  790. if (i==0) {
  791. temp1 = ALLTRACKS( cdrom ) = temp;
  792. } else {
  793. temp1->next = temp;
  794. temp1 = temp;
  795. }
  796. }
  797. DUMPTRACKLIST(( ALLTRACKS(cdrom) ));
  798. //
  799. // Generate generic play list (all tracks in order)
  800. //
  801. ResetPlayList( cdrom );
  802. //
  803. // Save this disc in the .ini file
  804. //
  805. gDevices[ cdrom ]->CdInfo.save = TRUE;
  806. WriteEntry( cdrom );
  807. }
  808. }
  809. }