| 1 | /* BoCA - BonkEnc Component Architecture |
| 2 | * Copyright (C) 2007-2020 Robert Kausch <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation, either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 12 | |
| 13 | #include "cdplayerini.h" |
| 14 | #include "../dllinterface.h" |
| 15 | |
| 16 | using namespace smooth::IO; |
| 17 | |
| 18 | BoCA::CDPlayerIni::CDPlayerIni() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | BoCA::CDPlayerIni::~CDPlayerIni() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | Int BoCA::CDPlayerIni::ReadCDInfo(Int drive) |
| 27 | { |
| 28 | CDROMDRIVE *cd = ex_CR_OpenCDROM(drive); |
| 29 | |
| 30 | if (cd == NIL) return Error(); |
| 31 | |
| 32 | cdInfo.Clear(); |
| 33 | |
| 34 | Int numTocEntries = ex_CR_GetNumTocEntries(cd); |
| 35 | UnsignedInt32 discID = 0; |
| 36 | |
| 37 | for (Int i = 0; i < numTocEntries; i++) |
| 38 | { |
| 39 | Int startSector = ex_CR_GetTocEntry(cd, i).dwStartSector + 150; |
| 40 | |
| 41 | Int minutes = startSector / 75 / 60; |
| 42 | Int seconds = startSector / 75 % 60; |
| 43 | Int frames = startSector % 75; |
| 44 | |
| 45 | discID += minutes * 0x10000 + seconds * 0x100 + frames; |
| 46 | } |
| 47 | |
| 48 | if (numTocEntries < 3) |
| 49 | { |
| 50 | discID += ex_CR_GetTocEntry(cd, 0).dwStartSector; |
| 51 | discID += ex_CR_GetTocEntry(cd, numTocEntries).dwStartSector; |
| 52 | } |
| 53 | |
| 54 | String discIDString = DiscIDToString(discID); |
| 55 | |
| 56 | /* Strip leading zeroes. |
| 57 | */ |
| 58 | while (discIDString.StartsWith("0")) discIDString = discIDString.Tail(discIDString.Length() - 1); |
| 59 | |
| 60 | /* Open cdplayer.ini |
| 61 | */ |
| 62 | InStream *in = new InStream(STREAM_FILE, S::System::System::GetWindowsRootDirectory().Append("cdplayer.ini"), IS_READ); |
| 63 | String idString = String("[").Append(discIDString).Append("]"); |
| 64 | String result; |
| 65 | |
| 66 | while (in->GetPos() < in->Size()) |
| 67 | { |
| 68 | if (in->InputLine().ToLower() == idString) |
| 69 | { |
| 70 | while (in->GetPos() < in->Size()) |
| 71 | { |
| 72 | String line = in->InputLine(); |
| 73 | |
| 74 | if (line.ToLower().StartsWith("artist=")) |
| 75 | { |
| 76 | String artist; |
| 77 | |
| 78 | for (Int i = 7; i < line.Length(); i++) artist[i - 7] = line[i]; |
| 79 | |
| 80 | cdInfo.SetArtist(artist); |
| 81 | } |
| 82 | else if (line.ToLower().StartsWith("title=")) |
| 83 | { |
| 84 | String title; |
| 85 | |
| 86 | for (Int i = 6; i < line.Length(); i++) title[i - 6] = line[i]; |
| 87 | |
| 88 | cdInfo.SetTitle(title); |
| 89 | } |
| 90 | else if (line.StartsWith("0=") || line.ToInt() > 0) |
| 91 | { |
| 92 | String title; |
| 93 | Int length = 2 + (line.ToInt() >= 10 ? 1 : 0); |
| 94 | |
| 95 | for (Int i = length; i < line.Length(); i++) title[i - length] = line[i]; |
| 96 | |
| 97 | cdInfo.SetTrackTitle(line.ToInt() + 1, title); |
| 98 | } |
| 99 | else if (line.StartsWith("[")) |
| 100 | { |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | delete in; |
| 110 | |
| 111 | ex_CR_CloseCDROM(cd); |
| 112 | |
| 113 | return Success(); |
| 114 | } |
| 115 | |
| 116 | const BoCA::CDInfo &BoCA::CDPlayerIni::GetCDInfo() const |
| 117 | { |
| 118 | return cdInfo; |
| 119 | } |
| 120 | |
| 121 | String BoCA::CDPlayerIni::DiscIDToString(UnsignedInt32 discID) |
| 122 | { |
| 123 | String result; |
| 124 | |
| 125 | for (Int i = 28; i >= 0; i -= 4) |
| 126 | { |
| 127 | if (((discID >> i) & 15) <= 9) result[(28 - i) / 4] = '0' + ((discID >> i) & 15); |
| 128 | else result[(28 - i) / 4] = 'a' + ((discID >> i) & 15) - 10; |
| 129 | } |
| 130 | |
| 131 | return result; |
| 132 | } |