📄 vfile.c
字号:
if ( io_path( path ) && !stricmp(io_path( path ),fileroot) && ( attrib & FA_DIREC ) ) {
l_text file = drv->GetFile ( drv,path );
done = findfirst( _strdup( file ) , &ffblk->info, ffblk->ff_attrib);
ffblk->fst = ffblk->nxt = NULL;
ffblk->drv = drv;
while ( !done && ( !io_testlinks(ffblk) || !IAMOK(ffblk->info.ff_name) ) )
done = findnext(&ffblk->info);
return done;
} else {
l_text file = drv->GetFile ( drv,path );
done = findfirst( _strdup( file ) , &ffblk->info, attrib);
ffblk->ff_attrib = attrib;
ffblk->fst = ffblk->nxt = NULL;
ffblk->drv = drv;
while ( !done && !io_testlinks(ffblk) )
done = findnext(&ffblk->info);
return done;
};
};
////////////////////////////////////////////////////////////////////////////////
// Default driver FindNext
int RealFindNext(struct t_ffblk *ffblk)
{
l_int done = findnext(&ffblk->info);
while ( !done && !io_testlinks(ffblk) )
done = findnext(&ffblk->info);
return done;
};
////////////////////////////////////////////////////////////////////////////////
// Default driver FileOpen
FILE* RealFileOpen ( p_vfile o, l_text SealFile, l_text mode ) {
if ( o && SealFile && mode ) {
l_text file = o->GetFile(o,SealFile);
FILE *f = NULL;
if ( file ) {
f = _fopen(file,mode);
_free(file);
};
return f;
};
return NULL;
};
////////////////////////////////////////////////////////////////////////////////
// Default driver FileClose
void RealFileClose ( p_vfile o, l_text path, FILE *f )
{
_fclose(f);
};
////////////////////////////////////////////////////////////////////////////////
//
l_int RealFileDelete ( p_vfile o, l_text path ) {
if ( !o || !path ) return 0;
if ( remove(o->GetFile(o,path)) )
return !rmdir(o->GetFile(o,path));
return true;
};
////////////////////////////////////////////////////////////////////////////////
//
l_int RealDirMake ( p_vfile o, l_text path ) {
if ( !o || !path ) return 0;
return (!mkdir(o->GetFile(o,path), S_IWUSR));
};
////////////////////////////////////////////////////////////////////////////////
//
l_int RealFileRename ( p_vfile o, l_text src, l_text dst ) {
if ( o && src && dst )
if ( stricmp(src, dst) ) {
l_int t = rename(o->GetFile(o,src), o->GetFile(o,dst));
return abs(t);
} else return -1;
return -2;
};
////////////////////////////////////////////////////////////////////////////////
// Substitue a drive /xxxx/ to a dos path (x:\xxxx\xxx)
void Subst ( l_text drive, l_text path ) {
if ( drive && path )
AddVDrive( drive, path, FatVFile_list );
};
////////////////////////////////////////////////////////////////////////////////
// Open a file (SealFile) in the submitted mode
FILE* SealFileOpen ( l_text SealFile, l_text mode ) {
if ( SealFile ) {
l_text pth = NULL;
p_vfile o = GetVFile(SealFile,&pth);
if ( o ) {
FILE *f = o->FileOpen(o,pth,mode);
if ( pth ) _free(pth);
return f;
};
};
return NULL;
};
////////////////////////////////////////////////////////////////////////////////
// Close a file
void SealFileClose ( FILE *f ) {
return _fclose ( f );
};
////////////////////////////////////////////////////////////////////////////////
// Internal function of io_removefile
l_int _io_removefile ( l_text file ) {
if ( file ) {
l_text pth = NULL;
p_vfile o = GetVFile(file,&pth);
if ( pth && o ) return o->FileDelete(o,pth);
};
return 0;
};
////////////////////////////////////////////////////////////////////////////////
//
l_bool io_mkdir ( l_text dir )
{
if ( dir ) {
l_text pth = NULL;
p_vfile o = GetVFile(dir,&pth);
if ( o && pth ) return o->DirMake(o,pth);
};
return 0;
};
////////////////////////////////////////////////////////////////////////////////
//
l_int io_rename ( l_text nameold, l_text namenew ) {
if ( nameold && namenew ) {
l_text pth1;
l_text pth2;
p_vfile o1 = GetVFile(nameold,&pth1);
p_vfile o2 = GetVFile(namenew,&pth2);
if ( o1 != o2 ) return -2; // (will copy and delete in the futur ...)
return o1->FileRename(o1,pth1,pth2);
};
return -2;
};
// Seal 1.xx Functions Support /////////////////////////////////////////////////
// Return true if file is a directory, return false if it's a file or not-exists
l_bool io_isdir ( l_text file ) {
return ( GetFileAttr(file) == ATTR_DIRECTORY);
};
////////////////////////////////////////////////////////////////////////////////
// Return true if file is a file, return false if it's a directory or not-exists
l_bool io_isfile ( l_text file ) {
return ( GetFileAttr(file) == ATTR_FILE);
};
////////////////////////////////////////////////////////////////////////////////
// Retun true if file exists, return true if not-exists
l_bool io_exist ( l_text file ) {
return ( GetFileAttr(file) != ATTR_NOT_EXISTS);
};
////////////////////////////////////////////////////////////////////////////////
// Return the text contain by the file filename, return NULL if file not-exists
// or can't be read
l_text file_gettext ( l_text filename ) {
FILE *f = SealFileOpen(filename, "rt");
if ( f ) {
l_long size = filelength(fileno(f));
l_text text = _malloc(size+1);
if ( text ) {
clear_type(text, size+1);
fread(text, size, 1, f);
};
fclose(f);
return text;
};
return NULL;
};
////////////////////////////////////////////////////////////////////////////////
// Write the text in the file filename, return true if written else return false
l_bool file_puttext ( l_text filename, l_text text ) {
FILE *f = SealFileOpen(filename, "wt");
if ( f ) {
if ( text ) {
fwrite(text, strlen(text), 1, f);
};
fclose(f);
return true;
};
return false;
};
////////////////////////////////////////////////////////////////////////////////
l_text io_realpath ( l_text path, l_text file )
{
if ( path ) {
l_int s = strlen(path);
if ( s && *(path+s-1) == '/' || *(path+s-1) == '\\' ) {
if ( file ) return set_format_text(NULL, "%s%s", path, file);
else return _strdup(path);
} else if ( s )
if ( file ) return set_format_text(NULL, "%s/%s", path, file);
else return _strdup(path);
} else {
if ( file ) return _strdup(file);
};
return NULL;
};
////////////////////////////////////////////////////////////////////////////////
int io_findfirst(const char *pathname, struct t_ffblk *ffblk, int attrib)
{
if ( !strcmp(io_path( (l_text) pathname ),"/") && ( attrib & FA_DIREC ) ) {
ffblk->fst = VirtualDrives->first(VirtualDrives);
ffblk->nxt = ffblk->fst;
ffblk->pathname = _strdup(pathname);
ffblk->ff_attrib = attrib;
ffblk->info.ff_attrib = (FA_DIREC|FA_SYSTEM);
strcpy(ffblk->info.ff_name,VDRIVE( ffblk->nxt->rec )->drive);
io_testlinks(ffblk);
return 0;
} else {
l_text pth;
p_vfile o = GetVFile((l_text)pathname,&pth);
ffblk->fst = ffblk->nxt = NULL;
ffblk->drv = o;
return o->FindFirst(o,pth,ffblk,attrib);
};
};
////////////////////////////////////////////////////////////////////////////////
int io_findnext(struct t_ffblk *ffblk) {
if ( !ffblk->fst ) {
return ffblk->drv->FindNext(ffblk);
} else {
ffblk->nxt = ffblk->nxt->next;
if ( ffblk->fst == ffblk->nxt ) {
l_text pth;
p_vfile o = GetVFile(ffblk->pathname,&pth);
ffblk->fst = ffblk->nxt = NULL;
ffblk->drv = o;
return o->FindFirst(o,pth,ffblk,ffblk->ff_attrib);
} else {
ffblk->info.ff_attrib = (FA_DIREC|FA_SYSTEM);
strcpy(ffblk->info.ff_name,VDRIVE( ffblk->nxt->rec )->drive);
io_testlinks(ffblk);
return 0;
};
};
};
////////////////////////////////////////////////////////////////////////////////
// Initianlise Virtual File System
void ini_vfile ( void ) {
int a = 0;
DEBUG_printf("\n - Start Virtual File System 1.00 ...\n - Prepare Default V Drive\n");
FatVFile = malloc(sizeof(t_vfile)); // Alloc memory
clear_type(FatVFile,sizeof(t_vfile)); // Clear memory alloced
FatVFile->data = "";
FatVFile->GetFile = &RealGetFile;
FatVFile->GetFileAttr = &RealGetFileAttr;
FatVFile->FindFirst = &RealFindFirst;
FatVFile->FindNext = &RealFindNext;
FatVFile->FileOpen = &RealFileOpen;
FatVFile->FileClose = &RealFileClose;
FatVFile->FileDelete = &RealFileDelete;
FatVFile->DirMake = &RealDirMake;
FatVFile->FileRename = &RealFileRename;
DEBUG_printf(" - Create Dos drives ...\n");
while ( a < 27) { // loop to test all dos drives
if ( _is_remote_drive(a) != -1 ) { // If dos drive exists
if ( a != 1 ) {
DEBUG_printf(" - Drive %c:\\ installed as /%c/ \n",'a'+a,'a'+a);
Subst(set_format_text(NULL,"%c",'a'+a),set_format_text(NULL,"%c:/",'a'+a)); // Add the dos drive in seal drives
};
};
a++;
};
Subst("documents","./docs/"); // Load default drives
Subst("system","./"); //
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -