FireBirdLib - Topfield TMS PVR TAP Programming Library
FixInvalidFileName.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <string.h>
3#include "libFireBird.h"
4
5bool FixInvalidFileName(char *FileName)
6{
8
9 char NewRecName[MAX_FILE_NAME_SIZE + 1];
10 char *Slash, Path[FBLIB_DIR_SIZE];
11 bool ret;
12
13 ret = FALSE;
14 if(FileName && *FileName && HDD_Exist(FileName))
15 {
16 memset(NewRecName, 0, sizeof(NewRecName));
17
18 //Check if the file is busy
19 if(HDD_isFileInUse(FileName) != FIU_No)
20 {
21 TRACEEXIT();
22 return FALSE;
23 }
24
25 Slash = strrchr(FileName, '/');
26 if(Slash)
27 {
28 dword i;
29
30 i = (dword)Slash - (dword)FileName + 1;
31 strncpy(Path, FileName, i);
32 Path[i] = '\0';
33 strcpy(NewRecName, Slash + 1);
34 }
35 else
36 {
37 Path[0] = '\0';
38 strcpy(NewRecName, FileName);
39 }
40
41 //If necessary, convert to UTF8
42 if(isUTFToppy())
43 {
44 //Use ISO 8859-9 as the default encoding table
45 StrMkUTF8(NewRecName, sizeof(NewRecName), 9);
46 }
47 else
48 {
50 }
51 if(*Path) InsertAt(NewRecName, 0, Path);
52
53 if(!strcmp(FileName, NewRecName))
54 {
55 //No need to rename
56 TRACEEXIT();
57 return TRUE;
58 }
59
60 MakeUniqueFileName(NewRecName);
61 ret = HDD_Rename(FileName, NewRecName);
62 strcpy(FileName, NewRecName);
63 }
64
65 TRACEEXIT();
66 return ret;
67}
bool FixInvalidFileName(char *FileName)
bool HDD_Exist(const char *FileName)
Definition: HDD_Exist.c:4
bool HDD_Rename(const char *FileName, const char *NewFileName)
Definition: HDD_Rename.c:5
tFileInUse HDD_isFileInUse(const char *FileName)
void MakeUniqueFileName(char *FileName)
bool isUTFToppy(void)
Definition: isUTFToppy.c:3
@ ControlChars
Definition: libFireBird.h:2504
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
bool StrMkUTF8(byte *SourceString, size_t SourceSize, byte DefaultISO8859CharSet)
Definition: StrMkUTF8.c:5
void MakeValidFileName(char *strName, eRemoveChars ControlCharacters)
#define TRACEENTER()
Definition: libFireBird.h:1243
void InsertAt(const char *SourceString, int Pos, char *NewString)
Definition: InsertAt.c:4
@ FIU_No
Definition: libFireBird.h:1902