root/lang/c/sonydb/sonydb.h

Revision 1760, 8.8 kB (checked in by mattn, 13 months ago)

lang/c/sonydb,
lang/c/sonydb/sonydb.cpp,
lang/c/sonydb/frontend.cpp,
lang/c/sonydb/sonydb.rc,
lang/c/sonydb/sonydb.h,
lang/c/sonydb/TODO,
lang/c/sonydb/Makefile.w32,
lang/c/sonydb/sonydb.ico,
lang/c/sonydb/Makefile.gcc,
lang/c/sonydb/images.h,
lang/c/sonydb/resource.h,
lang/c/sonydb/README:

added 'sonydb' that is a maintenance application

for sony network players.

Line 
1/*
2** Sonydb.h
3**
4** Made by (julien)
5*/
6
7#ifndef SONYDB_H
8# define SONYDB_H
9
10#ifdef __GNUC__
11#undef _WIN32
12#endif
13
14#ifdef _WIN32
15#include <windows.h>
16#include <direct.h>
17#else
18#ifdef __MINGW32__
19#include <io.h>
20#endif
21#endif
22#include <stdio.h>
23#include <string>
24#include <vector>
25#include <sys/stat.h>
26#include <algorithm>
27
28using namespace std;
29
30#ifndef _ID3LIB_ID3_H_
31typedef short                 int16;
32typedef int                   int32;
33//typedef long long           int64;
34typedef char                  int8;
35typedef unsigned short        uint16;
36typedef unsigned int          uint32;
37//typedef unsigned long long    uint64;
38typedef unsigned char         uint8;
39#endif
40#if !defined(_WIN32) && !defined(__MINGW32__)
41typedef long long __int64;
42#endif
43typedef unsigned short       utf16char;
44
45#define UINT32_SWAP_BE_LE(val) ((uint32) ( \
46(((uint32) (val) & (uint32) 0x000000ffU) << 24) | \
47(((uint32) (val) & (uint32) 0x0000ff00U) <<  8) | \
48(((uint32) (val) & (uint32) 0x00ff0000U) >>  8) | \
49(((uint32) (val) & (uint32) 0xff000000U) >> 24)))
50
51#define UINT16_SWAP_BE_LE(val) ((uint16) ( \
52(((uint16) (val) & (uint16) 0x00ffU) << 8) | \
53(((uint16) (val) & (uint16) 0xff00U) >> 8)))
54
55#define SYNCHSAFE_B1(val) (((uint32) (val) >> 21) & (uint32) 0x000007F)
56#define SYNCHSAFE_B2(val) (((uint32) (val) >> 14) & (uint32) 0x000007F)
57#define SYNCHSAFE_B3(val) (((uint32) (val) >> 7) & (uint32) 0x000007F)
58#define SYNCHSAFE_B4(val) (((uint32) (val) & (uint32) 0x0000007F))
59
60#define NOT_SYNCHSAFE_B1(val) (uint8) (((val) & (uint32) 0xff000000U) >> 24);
61#define NOT_SYNCHSAFE_B2(val) (uint8) (((val) & (uint32) 0x00ff0000U) >> 16);
62#define NOT_SYNCHSAFE_B3(val) (uint8) (((val) & (uint32) 0x0000ff00U) >>  8);
63#define NOT_SYNCHSAFE_B4(val) (uint8) ((val) & (uint32)  0x000000ffU);
64
65utf16char *ansi_to_utf16(const char  *str, long len, bool endian);
66char *utf16_to_ansi(const utf16char *str, long len, bool endian);
67
68#define TAGSIZE 128
69#define OUTPUT_TAGSIZE 128
70
71#define ON_DEVICE             0
72#define ADD_TO_DEVICE         1
73#define REMOVE_FROM_DEVICE    2
74// 3 is reserved for MODIFIED
75#define EMPTYTRACK            4
76
77#define NOT_LOADED            0
78#define LOADED                1
79#define MODIFIED              2
80
81#define ENCODING_USE_NONE             0
82#define ENCODING_USE_TABLE            1
83#define ENCODING_USE_KEY              2
84
85#define DATABASE_HEADER_SIZE 0
86
87
88typedef struct {
89     char *artist;
90     char *title;
91     char *album;
92     char *filename;
93     char *genre;
94     utf16char *wArtist;
95     utf16char *wTitle;
96     utf16char *wAlbum;
97     //utf16char *wFilename;
98     utf16char *wGenre;
99     int songlen; // seconds?
100     int track_nr;
101     int year;
102     
103     int       sonyDbOrder;
104     int       statusOfSong; //0 was present on player, 1 was not present on player needs & to be added, 2 was present & needs to be removed
105     uint8     encoding; // mpeg version(2bits), layer version(2bits), bitrate(4bits)
106} Song;
107
108typedef struct {
109         int  index;
110     char *name;
111     vector<Song*> songs;
112} Playlist;
113
114typedef struct
115{
116  uint8 magic[4];      /* "magic file descriptor" */
117  uint8 cte[4];        /* Constant value */
118  uint8 count;         /* Number of object pointers */
119  uint8 padding[7];    /* padding to 16 bytes */
120} sonyFileHeader;
121
122typedef struct
123{
124  uint8  magic[4];      /* magic (same as object) */
125  uint32 offset;        /* offset of the object (from the beginning)*/
126  uint32 length;        /* size of object in bytes */
127  uint32 padding;       /* padding to 16 bytes */
128} sonyObjectPointer;
129
130typedef struct
131{
132  uint8 magic[4];       /* magic (same as object pointer) */
133  uint16 count;         /* record count */
134  uint16 size;          /* record size */
135  uint32 padding[2];    /* padding to 16 bytes */
136} sonyObject;
137
138typedef struct
139{
140 uint8  fileType[4];
141 uint32 trackEncoding;
142 uint32 trackLength;
143 uint16 nbTagRecords;
144 uint16 sizeTagRecords;
145} sonyTrack;
146
147typedef struct
148{
149     uint8 tagType[4];
150     uint8 tagEncoding[2];
151}sonyTrackTag;
152
153bool sortByIndex(Song *a, Song *b);
154bool sortByTrackNumber(Song *a, Song *b);
155bool sortByAlbumName(Song *a, Song *b);
156bool sortByArtistName(Song *a, Song *b);
157bool sortByTitleName(Song *a, Song *b);
158bool sortByGenreName(Song *a, Song *b);
159bool sortPlaylist(Playlist s, Playlist s2);
160bool sortByPlaylistIndex(Playlist s, Playlist s2);
161
162
163class SonyDb
164{
165  private:
166
167     
168     int  id;
169     int  lastTrackIndex;
170     int  nbTrackToDel;
171     int  nbTrackToAdd;
172     char* driveLetter;   
173     int  trackListLoaded; //0 not loaded, 1 loaded, 2 modified
174     char *deviceName;
175     char *decodeTableFilename;
176     bool useAllTags; //if you want to have "all albums" "all genre" etc...
177
178     /* disk space */
179     __int64 addTrackTotalByte;
180     __int64 delTrackTotalByte;
181     __int64 usedSpaceDisk;
182     __int64 freeSpaceDisk;
183     __int64 neededSpaceValue;
184     __int64 totalDiskSpaceValue;
185     char *totalDiskSpace;
186     char *totalUsedSpaceAfterApply;
187     char *freeDiskSpaceAfterApply;
188     char *addTrackTotalByteString;
189     char *delTrackTotalByteString;
190     char *neededSpace;
191
192     /* estimated time */
193     int bytePerSec; //estimated value will be calculated after first file as been transfered
194     __int64 totalByteLeftToWrite;
195
196     /* encoding decoding*/
197     int  getTrackNumber(char *filename); //read the track number directly from the omg header
198     uint32 DvId;
199     int  codeType; //0 no code, 1 decodeKeys.dat, 2 DvId.dat
200
201     /* copy progress */
202     bool copying; //currently getting or adding Oma files, or rewriting db
203     int  copyIndex; //current file index
204     float copyPercent;// progress of the current file (in percent)
205
206
207     /* device related */
208     void freeAllTracks();
209     void freeAllPlaylist();
210     bool writeDatabase(vector<Song *> songsToSend);
211     char *GetOMAFilename(int id);
212
213
214     /* common header files */
215     bool getHeader(sonyFileHeader *fh, FILE *f);
216     bool getObjectPointer(sonyObjectPointer *op, FILE *f);
217     bool getObject(sonyObject *obj, FILE *f);
218     bool getTrack(FILE *f, Song *output);
219     bool writeHeader(sonyFileHeader *h, FILE *f);
220     bool writeHeader(sonyFileHeader *h, FILE *f, int count);
221     bool writeObjectPointer(sonyObjectPointer *p, FILE *f);
222     bool writeObject(sonyObject *obj, FILE *f);
223     bool writeTrackHeader(sonyTrack *t, FILE *f);
224     bool writeTrackTag(sonyTrackTag *tt, char *input, FILE *f);
225
226     /* file writers */
227     bool write_00GTRLST();
228     bool write_01TREEXX(vector<Song *> songsToSend, vector<Song *> list, int type);
229     bool write_01TREE22();
230     bool write_02TREINF(vector<Song *> songsToSend);
231     bool write_03GINFXX(vector<Song *> songsToSend, int type);
232     bool write_03GINF22();
233     bool write_04CNTINF(vector<Song *> songsToSend);
234     bool write_05CIDLST(vector<Song *> songsToSend);
235     bool write_TrackNumber(vector<Song *> songsToSend);
236
237
238     /* decoder encoder */
239     uint8 codeTable[1024];
240     bool loadCodeTable(int id);
241     bool addOMA(Song *s, int destination);
242     void deleteOMA(char *filename);
243
244     /* directory */
245     void createDir(int highestValue);
246
247     //debug
248     FILE *fp;
249     vector<Song>     songs;
250     vector<Song>     songs_temporary;
251     vector<Playlist> playlist;
252     vector<Playlist> playlist_temporary;
253
254  public:
255
256     SonyDb();
257     ~SonyDb();
258
259     bool writeTracks();
260     int  readAllTracks();
261     int  readAllPlaylist();
262     
263     vector<Song*> getSongs();
264     vector<Song*> getSongsInPlaylist(int source);
265     vector<Playlist*> getPlaylist();
266     bool deletePlaylist(int source, bool removeSongs);
267
268     bool addSong(Song *s); //add to the database
269     int  delSong(Song *s); //del to the database
270         bool updSong(Song *s); //update to the database
271     bool getOMA(Song *s, char *destination);//download oma to mp3
272
273     
274     /*encode decoder*/
275     void setTable(char *decodeTableFileName, int type);
276
277     /* misc */
278     bool isPresent();
279     bool isCopying();
280     int  progressIndex();
281     int  getCopyPercent();
282     bool detectPlayer();
283     bool detectPlayer(char* drive);
284     char* getDriveLetter();
285     int  getNumberOfTracks();
286     char *getDeviceName();
287     int  getId();
288     void setId(int newId);
289     int  getNbTrackToDel();
290     int  getNbTrackToAdd();
291     int  isTrackListLoaded();
292     void setUseAllTags(bool value); //if you want to have "all albums" "all genre" etc...
293     bool getUseAllTags();
294
295     /* disk space*/
296     void updateDiskSpaceInfo();
297     char *getTotalDiskSpace();
298     char *getTotalUsedSpaceAfterApply();
299     char *getFreeDiskSpaceAfterApply();
300     char *getSizeTrackToAdd();
301     char *getSizeTrackToDel();
302     char *getNeededSpace();
303     int  getNeededSpaceValue();
304
305     /* playlist */
306     bool addPlaylist(Playlist *p);
307     int  getNbPlaylist();
308
309
310};
311
312#endif /* !SONYDB_H */
Note: See TracBrowser for help on using the browser.