FireBirdLib - Topfield TMS PVR TAP Programming Library
LogoManager_LogoCacheRebuild.c
Go to the documentation of this file.
1#include <string.h>
2#include <stdlib.h>
3#include "libFireBird.h"
4#include "FBLib_LogoManager.h"
5
7{
9
10 char ID[4];
11 dword Version;
12 TYPE_File *f, *fLogo;
13 int i, j, k, NrFiles;
14 TYPE_FolderEntry FolderEntry;
15 dword LogoIndex;
16 byte *PixelData, *TempBuffer;
17 dword BufferSize, CompressedSize;
18 TYPE_GrData *grData;
19 int LogosConverted;
20 char LogoPath[FBLIB_DIR_SIZE];
21
23
24 //Step 1: Kill the current cache
27 TAP_Hdd_Delete(LOGOCACHE);
28
29 //Step 2: iterate through all directories and count the number of logos
31 for(i = LGST_3pgstyle; i < LGST_NRITEMS; i++)
32 {
33 for(j = LGAR_43; j < LGAR_NRITEMS; j++)
34 {
35 if(HDD_ChangeDir(LogoManager_GetDirectory(i, j, LogoPath)))
36 {
37 NrFiles = TAP_Hdd_FindFirst(&FolderEntry, "qtl|qsl|ibl");
38 for(k = 0; k < NrFiles; k++)
39 {
40 if(FolderEntry.attr == ATTR_NORMAL)
41 {
42 FixInvalidFileName(FolderEntry.name);
44 }
45 TAP_Hdd_FindNext(&FolderEntry);
46 }
47 }
48 }
49 }
51
52
53 //Step 3: build the basic cache file
54 LogosConverted = 0;
56 LogoManager_LogoData = TAP_MemAlloc(LogoManager_NrLogos * sizeof(tLogoData));
58 {
61 if(!TAP_Hdd_Exist(LOGOCACHE)) TAP_Hdd_Create(LOGOCACHE, ATTR_NORMAL);
62 f = TAP_Hdd_Fopen(LOGOCACHE);
63 if(f)
64 {
65 strcpy(ID, LOGOCACHEID);
66 Version = LOGOCACHEVERSION;
67
68 TAP_Hdd_Fwrite(ID, 4, 1, f);
69 TAP_Hdd_Fwrite(&Version, sizeof(dword), 1, f);
70 TAP_Hdd_Fwrite(&LogoManager_NrLogos, sizeof(dword), 1, f);
71 TAP_Hdd_Fwrite(LogoManager_LogoData, sizeof(tLogoData), LogoManager_NrLogos, f);
72
73 //Step 4: iterate through all directories again, compress the data and save it to the cache
74 LogoIndex = 0;
75 for(i = LGST_3pgstyle; i < LGST_NRITEMS; i++)
76 {
77 for(j = LGAR_43; j < LGAR_NRITEMS; j++)
78 {
79 if(HDD_ChangeDir(LogoManager_GetDirectory(i, j, LogoPath)))
80 {
81 NrFiles = TAP_Hdd_FindFirst(&FolderEntry, "qtl|qsl|ibl");
82 for(k = 0; k < NrFiles; k++)
83 {
84 if(LogoManager_CB) LogoManager_CB(2, LogosConverted * 100 / LogoManager_NrLogos);
85
86 if(FolderEntry.attr == ATTR_NORMAL)
87 {
88 LogoManager_LogoData[LogoIndex].ChannelID = 0;
89 strncpy(LogoManager_LogoData[LogoIndex].LogoName, FolderEntry.name, MAXLOGONAME);
90 LogoManager_LogoData[LogoIndex].LogoName[MAXLOGONAME] = '\0';
91 LogoManager_LogoData[LogoIndex].LogoName[strlen(LogoManager_LogoData[LogoIndex].LogoName) - 4] = '\0';
92 LogoManager_LogoData[LogoIndex].Style = i;
93
94 if(StringEndsWith(FolderEntry.name, ".qtl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_qtl;
95 if(StringEndsWith(FolderEntry.name, ".qsl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_qsl;
96 if(StringEndsWith(FolderEntry.name, ".ibl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_ibl;
97
98 LogoManager_LogoData[LogoIndex].Aspect = j;
99 LogoManager_LogoData[LogoIndex].grData = NULL;
100
101 fLogo = TAP_Hdd_Fopen(FolderEntry.name);
102 if(fLogo)
103 {
104 BufferSize = TAP_Hdd_Flen(fLogo) - 8;
105 PixelData = TAP_MemAlloc(BufferSize + 8);
106 TempBuffer = TAP_MemAlloc(sizeof(TYPE_GrData) + BufferSize);
107 if(PixelData && TempBuffer)
108 {
109 TAP_Hdd_Fread(PixelData, BufferSize + 8, 1, fLogo);
110 CompressedSize = CompressTFD(&PixelData[8], BufferSize, &TempBuffer[sizeof(TYPE_GrData)], 0x0001, 0xffff, NULL);
111 TAP_Put16bit(&TempBuffer[sizeof(TYPE_GrData) + 0x0e], 0xffff);
112
113 grData = (TYPE_GrData*)TempBuffer;
114 grData->version = 1;
115 grData->reserved = 0;
116 grData->dataFormat = OSD_1555;
117 grData->compessMethod = COMPRESS_Tfp;
118 grData->data = NULL;
119 grData->dataSize = BufferSize;
120 grData->width = TAP_Get32bit(&PixelData[0]);
121 grData->height = TAP_Get32bit(&PixelData[4]);
122
123 LogoManager_LogoData[LogoIndex].CachePosition = TAP_Hdd_Ftell(f);
124 LogoManager_LogoData[LogoIndex].grDataSize = sizeof(TYPE_GrData) + CompressedSize;
125 TAP_Hdd_Fwrite(grData, LogoManager_LogoData[LogoIndex].grDataSize, 1, f);
126 LogoIndex++;
127 }
128 if(PixelData) TAP_MemFree(PixelData);
129 if(TempBuffer) TAP_MemFree(TempBuffer);
130 TAP_Hdd_Fclose(fLogo);
131 }
132 else
133 {
135 }
136 LogosConverted++;
137 }
138 TAP_Hdd_FindNext(&FolderEntry);
139 }
140 }
141 }
142 }
143
144 //Step 5: if the LIL exists, read and update the ChannelID of all Logos
145
146 //Step 6: rewrite the cache structure to update all pointers
147 TAP_Hdd_Fseek(f, sizeof(ID) + sizeof(dword) + sizeof(dword), SEEK_SET);
148 TAP_Hdd_Fwrite(LogoManager_LogoData, sizeof(tLogoData), LogoManager_NrLogos, f);
149 TAP_Hdd_Fclose(f);
150 }
151 }
154
155 TRACEEXIT();
156}
dword CompressTFD(byte *pSrc, dword SourceBufferSize, byte *pDest, word TFDType, word SysID, void *pPercentFinishedCallback)
Definition: CompressTFD.c:20
#define MAXLOGONAME
tLogoData * LogoManager_LogoData
void(* LogoManager_CB)(int CallbackType, int Param1)
int LogoManager_NrLogos
dword BufferSize
Definition: INIOpenFile.c:7
bool FixInvalidFileName(char *FileName)
bool HDD_ChangeDir(const char *Dir)
Definition: HDD_ChangeDir.c:5
void LogoManager_LogoCacheRebuild(void)
#define LOGOROOT
Definition: libFireBird.h:2217
#define SEEK_SET
Definition: libFireBird.h:1875
#define LOGOCACHE
Definition: libFireBird.h:2219
bool HDD_TAP_PushDir(void)
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define LOGOCACHEID
Definition: libFireBird.h:2220
#define LOGOCACHEVERSION
Definition: libFireBird.h:2221
char * LogoManager_GetDirectory(tLogoStyle LogoStyle, tLogoAspect LogoAR, char *LogoPath)
#define TRACEENTER()
Definition: libFireBird.h:1243
bool HDD_TAP_PopDir(void)
Definition: HDD_TAP_PopDir.c:3
bool StringEndsWith(const char *text, const char *postfix)
Definition: StringEndsWith.c:4
@ LGAR_NRITEMS
Definition: libFireBird.h:2250
@ LGAR_43
Definition: libFireBird.h:2248
@ LGSZ_ibl
Definition: libFireBird.h:2241
@ LGSZ_qtl
Definition: libFireBird.h:2240
@ LGSZ_qsl
Definition: libFireBird.h:2242
@ LGST_3pgstyle
Definition: libFireBird.h:2226
@ LGST_NRITEMS
Definition: libFireBird.h:2235
ulong64 ChannelID
char LogoName[MAXLOGONAME+1]
tLogoSize Size
tLogoAspect Aspect
dword CachePosition
tLogoStyle Style
TYPE_GrData * grData