204 lines
6.3 KiB
C
204 lines
6.3 KiB
C
#if defined(WIN32)
|
|
#include <direct.h>
|
|
#include <io.h>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#endif /* WIN32 */
|
|
|
|
#define D_FIL_VariableDefine
|
|
|
|
#include "FIL_CPA.h"
|
|
|
|
#include "ErmFil.h"
|
|
|
|
#define D_FIL_StructureDefine
|
|
|
|
#include "FIL_GF.h"
|
|
#include "FIL_Pub.h"
|
|
#include "FIL_Priv.h"
|
|
|
|
#include "MMG.h"
|
|
/**************************************************************************/
|
|
void FIL_fn_vFirstInit(void)
|
|
{
|
|
Erm_M_InitErrMsg(FIL);
|
|
g_stInternalGeneral.ucDisplayInformation = C_ucErmOpenInfoWindow;
|
|
}
|
|
/**************************************************************************/
|
|
void FIL_fn_vDisplayInformationError(unsigned char bValue)
|
|
{
|
|
if (bValue)
|
|
g_stInternalGeneral.ucDisplayInformation = C_ucErmOpenInfoWindow;
|
|
else
|
|
g_stInternalGeneral.ucDisplayInformation = C_ucErmNoOpenInfoWindow;
|
|
}
|
|
/**************************************************************************/
|
|
unsigned char FIL_fn_bDestroyFileOrDirectory(char *_szFileName)
|
|
{
|
|
return(FIL_fn_bDestroyRecurseDirectory(_szFileName));
|
|
}
|
|
/**************************************************************************/
|
|
FIL_tdxHandleToFileNameList FIL_fn_hSearchFile(char *_szFileName,unsigned long ulAttrib)
|
|
{
|
|
FIL_tdxHandleToFileNameList hFileNameList = NULL;
|
|
MMG_fn_vAddMemoryInfo (MMG_C_lTypeFile , MMG_C_lSubTypeMiscellaneousFile , NULL);
|
|
hFileNameList = (FIL_tdxHandleToFileNameList)TMP_M_p_Malloc(sizeof(struct FIL_tdstFileNameList_));
|
|
LST2_M_DynamicInitAnchor(&hFileNameList->hFileNameListAnchor);
|
|
|
|
FIL_fn_vSearchInFile(hFileNameList,_szFileName,ulAttrib);
|
|
|
|
return(hFileNameList);
|
|
}
|
|
/**************************************************************************/
|
|
FIL_tdxHandleToFileNameList FIL_fn_hSearchRecurseFile(char *_szFileName,unsigned long ulAttrib)
|
|
{
|
|
FIL_tdxHandleToFileNameList hFileNameList = NULL;
|
|
MMG_fn_vAddMemoryInfo (MMG_C_lTypeFile , MMG_C_lSubTypeMiscellaneousFile , NULL);
|
|
hFileNameList = (FIL_tdxHandleToFileNameList)TMP_M_p_Malloc(sizeof(struct FIL_tdstFileNameList_));
|
|
LST2_M_DynamicInitAnchor(&hFileNameList->hFileNameListAnchor);
|
|
|
|
FIL_fn_vSearchRecurseInFile(hFileNameList,"",_szFileName,ulAttrib);
|
|
|
|
return(hFileNameList);
|
|
}
|
|
/**************************************************************************/
|
|
void FIL_fn_vContinueSearchRecurseFile(char *_szFileName,unsigned long ulAttrib,FIL_tdxHandleToFileNameList hFileNameList)
|
|
{
|
|
FIL_fn_vSearchRecurseInFile(hFileNameList,"",_szFileName,ulAttrib);
|
|
}
|
|
/**************************************************************************/
|
|
void FIL_fn_vDestroySearchedFile(FIL_tdxHandleToFileNameList _hFileNameList)
|
|
{
|
|
unsigned long i;
|
|
FIL_tdxHandleToFileNameListElement hFileNameListElement,hNextFileNameListElement;
|
|
|
|
LST2_M_DynamicForEachMovingElementOf(&_hFileNameList->hFileNameListAnchor,hFileNameListElement,hNextFileNameListElement,i)
|
|
{
|
|
FIL_fn_vDestroyOnElementInFileNameList(hFileNameListElement);
|
|
}
|
|
TMP_M_Free(_hFileNameList);
|
|
}
|
|
/**************************************************************************/
|
|
void FIL_fn_vDestroyOnElementInFileNameList(FIL_tdxHandleToFileNameListElement hFileNameListElement)
|
|
{
|
|
LST2_M_DynamicIsolate(hFileNameListElement);
|
|
|
|
TMP_M_Free(hFileNameListElement->szFileName);
|
|
TMP_M_Free(hFileNameListElement);
|
|
}
|
|
/**************************************************************************/
|
|
unsigned char FIL_fn_bIsFileExist(char *_szFileName)
|
|
{
|
|
unsigned char bReturn = FALSE;
|
|
FILE *p_stFile;
|
|
|
|
p_stFile = fopen(_szFileName,"rb");
|
|
if (p_stFile!=NULL)
|
|
{
|
|
fclose(p_stFile);
|
|
bReturn = TRUE;
|
|
}
|
|
return(bReturn);
|
|
}
|
|
/**************************************************************************/
|
|
unsigned char FIL_fn_bIsValidPath(char *_szFileName)
|
|
{
|
|
struct _stat stFileInfo;
|
|
|
|
return (unsigned char)(!_stat(_szFileName,&stFileInfo));
|
|
}
|
|
/**************************************************************************/
|
|
unsigned char FIL_fn_bValidatePath(char *_p_szStartPath, char *_p_szFileName)
|
|
{
|
|
char a_szCurrentDir[_MAX_PATH];
|
|
char a_szCompleteFileName[_MAX_PATH];
|
|
char *p_szCompleteFileName, *p_szTemp;
|
|
char cMemo1, cMemo2;
|
|
unsigned char bReturn = TRUE;
|
|
|
|
/* Unix style convert */
|
|
while(strchr(_p_szStartPath, '/'))
|
|
*strchr(_p_szStartPath,'/') = '\\';
|
|
while(strchr(_p_szFileName,'/'))
|
|
*strchr(_p_szFileName,'/') = '\\';
|
|
|
|
/* Compute complete name */
|
|
if(_p_szStartPath[strlen(_p_szStartPath) - 1] == '\\'||_p_szStartPath[0]==0)
|
|
sprintf(a_szCompleteFileName, "%s%s", _p_szStartPath, _p_szFileName);
|
|
else
|
|
sprintf(a_szCompleteFileName, "%s\\%s", _p_szStartPath, _p_szFileName);
|
|
|
|
p_szCompleteFileName = strrchr(a_szCompleteFileName,'\\');
|
|
*p_szCompleteFileName = 0;
|
|
/* test if the directory already exist */
|
|
if (_access(a_szCompleteFileName,0x00)==-1)
|
|
{
|
|
*p_szCompleteFileName = '\\';
|
|
p_szCompleteFileName = a_szCompleteFileName;
|
|
|
|
/* Get current directory to restore it at the end of the analyse */
|
|
getcwd(a_szCurrentDir, _MAX_PATH);
|
|
|
|
/* Is it an absolute path ? */
|
|
if(p_szCompleteFileName[0] && p_szCompleteFileName[1] == ':')
|
|
{
|
|
cMemo1 = p_szCompleteFileName[2];
|
|
p_szCompleteFileName[2] = '\\';
|
|
cMemo2 = p_szCompleteFileName[3];
|
|
p_szCompleteFileName[3] = '\0';
|
|
|
|
if(chdir(p_szCompleteFileName) == -1)
|
|
{
|
|
bReturn = FALSE;
|
|
}
|
|
p_szCompleteFileName[2] = cMemo1;
|
|
p_szCompleteFileName[3] = cMemo2;
|
|
}
|
|
|
|
/* Get and create directories */
|
|
while(bReturn&&(p_szTemp = strchr(p_szCompleteFileName,'\\')) != NULL)
|
|
{
|
|
*p_szTemp = '\0';
|
|
if(*p_szCompleteFileName != '\0')
|
|
{
|
|
if(chdir(p_szCompleteFileName) == -1)
|
|
{
|
|
mkdir(p_szCompleteFileName);
|
|
if(chdir(p_szCompleteFileName) == -1)
|
|
{
|
|
bReturn = FALSE;
|
|
}
|
|
}
|
|
p_szCompleteFileName += strlen(p_szCompleteFileName) + 1;
|
|
*p_szTemp = '\\';
|
|
}
|
|
else
|
|
chdir("\\");
|
|
}
|
|
if(chdir(a_szCurrentDir) == -1)
|
|
{
|
|
bReturn = FALSE;
|
|
}
|
|
}
|
|
return(bReturn);
|
|
}
|
|
/**************************************************************************/
|
|
unsigned long FIL_fn_ulGetNumberOfFiles(FIL_tdxHandleToFileNameList hHandleToFileNameList)
|
|
{
|
|
return(LST2_M_DynamicGetNumberOfElements(&hHandleToFileNameList->hFileNameListAnchor));
|
|
}
|
|
/**************************************************************************/
|
|
unsigned long FIL_fn_ulGetFileSize(char *_szFileName)
|
|
{
|
|
unsigned long ulReturn = 0;
|
|
int fh;
|
|
|
|
if( (fh = open(_szFileName, _O_BINARY|_O_RDONLY,_S_IREAD)) != -1 )
|
|
{
|
|
ulReturn = filelength(fh);
|
|
close(fh);
|
|
}
|
|
return(ulReturn);
|
|
}
|
|
/**************************************************************************/
|